Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Commit

Permalink
Merge pull request #167 from onerain88/unit_test
Browse files Browse the repository at this point in the history
test: 增加单元测试模块
  • Loading branch information
onerain88 committed May 5, 2019
2 parents a8e86c9 + a74c657 commit 2e955ee
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 55 deletions.
60 changes: 14 additions & 46 deletions LeanCloud.Realtime/LeanCloud.Realtime.sln
Expand Up @@ -12,13 +12,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeanCloud.Realtime.Unity.Ne
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{F24A5744-E022-41C8-BE20-312322E30262}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Rx", "Rx", "{4C1E2836-1A6F-45CD-8CE7-8E755B1BC7FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeanCloud.Realtime.Reactive.Portable", "..\Rx\LeanCloud.Realtime.Reactive.Portable.csproj", "{FB411054-8ED5-43D5-9636-AD61E60F451B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeanCloud.Realtime.Reactive.Unity", "..\Rx\LeanCloud.Realtime.Reactive.Unity.csproj", "{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LeanCloud.Realtime.Reactive.Unity.NetFx35", "..\Rx\LeanCloud.Realtime.Reactive.Unity.NetFx35.csproj", "{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test.Portable", "Test\Test.Portable\Test.Portable.csproj", "{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -66,50 +60,24 @@ Global
{4442C93D-060D-4CE9-8062-4DBCB58541B6}.Release|iPhone.Build.0 = Release|Any CPU
{4442C93D-060D-4CE9-8062-4DBCB58541B6}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{4442C93D-060D-4CE9-8062-4DBCB58541B6}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Debug|iPhone.Build.0 = Debug|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Release|Any CPU.Build.0 = Release|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Release|iPhone.ActiveCfg = Release|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Release|iPhone.Build.0 = Release|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{FB411054-8ED5-43D5-9636-AD61E60F451B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Debug|Any CPU.Build.0 = Debug|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Debug|iPhone.Build.0 = Debug|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Release|Any CPU.ActiveCfg = Release|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Release|Any CPU.Build.0 = Release|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Release|iPhone.ActiveCfg = Release|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Release|iPhone.Build.0 = Release|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Debug|iPhone.Build.0 = Debug|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Release|Any CPU.Build.0 = Release|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Release|iPhone.ActiveCfg = Release|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Release|iPhone.Build.0 = Release|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Debug|iPhone.Build.0 = Debug|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Release|Any CPU.Build.0 = Release|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Release|iPhone.ActiveCfg = Release|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Release|iPhone.Build.0 = Release|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{FB411054-8ED5-43D5-9636-AD61E60F451B} = {4C1E2836-1A6F-45CD-8CE7-8E755B1BC7FA}
{93CB874F-5213-4B01-9CF6-C2FB6B1E4D59} = {4C1E2836-1A6F-45CD-8CE7-8E755B1BC7FA}
{5EA551BC-C961-4A32-ABEA-D5E4B36F3E51} = {4C1E2836-1A6F-45CD-8CE7-8E755B1BC7FA}
{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3} = {F24A5744-E022-41C8-BE20-312322E30262}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6ADB001B-71B3-4A4A-B406-90F6A58BEF3E}
Expand Down
17 changes: 8 additions & 9 deletions LeanCloud.Realtime/Public/AVIMClient.cs
Expand Up @@ -398,6 +398,8 @@ internal Task<AVIMConversation> CreateConversationAsync(AVIMConversation convers
bool isSystem = false,
bool isTransient = false,
bool isUnique = true,
bool isTemporary = false,
int ttl = 86400,
IDictionary<string, object> options = null)
{
if (member == null) member = ClientId;
Expand All @@ -406,7 +408,10 @@ internal Task<AVIMConversation> CreateConversationAsync(AVIMConversation convers
name: name,
isUnique: isUnique,
isSystem: isSystem,
isTransient: isTransient, client: this);
isTransient: isTransient,
isTemporary: isTemporary,
ttl: ttl,
client: this);
if (options != null)
{
foreach (var key in options.Keys)
Expand Down Expand Up @@ -447,17 +452,11 @@ public AVIMConversationBuilder GetConversationBuilder()
/// <param name="ttl">过期时间,默认是一天(86400 秒),单位是秒</param>
/// <returns></returns>
public Task<AVIMConversation> CreateTemporaryConversationAsync(string member = null,
IEnumerable<string> members = null, long ttl = 86400)
IEnumerable<string> members = null, int ttl = 86400)
{
if (member == null) member = ClientId;
var membersAsList = Concat<string>(member, members, "创建对话时被操作的 member(s) 不可以为空。");

var conversation = new AVIMTemporaryConversation(ttl)
{
MemberIds = membersAsList
};

return CreateConversationAsync(conversation);
return CreateConversationAsync(member, membersAsList, isTemporary: true, ttl: ttl);
}

/// <summary>
Expand Down
14 changes: 14 additions & 0 deletions LeanCloud.Realtime/Test/Test.Portable/BasicTest.cs
@@ -0,0 +1,14 @@
using NUnit.Framework;
using System.Threading.Tasks;

namespace Test.Portable {
[TestFixture]
public class BasicTest {
[Test]
public async Task CreateClient() {
var realtime = Utils.NewRealtime();
var client = await realtime.CreateClientAsync("leancloud");
Assert.AreEqual(client.ClientId, "leancloud");
}
}
}
65 changes: 65 additions & 0 deletions LeanCloud.Realtime/Test/Test.Portable/ConversationTest.cs
@@ -0,0 +1,65 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using LeanCloud;
using LeanCloud.Realtime;

namespace Test.Portable {
[TestFixture]
public class ConversationTest {
[Test]
public async Task ChatRoom() {
var r = Utils.NewRealtime();
var c = await r.CreateClientAsync("ct0_c0");
var chatroom = await c.CreateChatRoomAsync("ct0_conv0");
Assert.AreEqual(chatroom.Name, "ct0_conv0");
}

[Test]
public async Task Invite() {
var mre = new ManualResetEvent(false);
var r0 = Utils.NewRealtime();
var c0 = await r0.CreateClientAsync("ct1_c0");
var r1 = Utils.NewRealtime();
var c1 = await r1.CreateClientAsync("ct1_c1");

c1.OnInvited += (sender, e) => {
Console.WriteLine($"I am invited by {e.InvitedBy} in {e.ConversationId}");
mre.Set();
};

var conv = await c0.CreateConversationAsync(new List<string> { "xxx" }, "conv");
var invite = c0.InviteAsync(conv, "ct1_c1");
mre.WaitOne();
}

[Test]
public async Task Kick() {
var mre = new ManualResetEvent(false);
var r0 = Utils.NewRealtime();
var c0 = await r0.CreateClientAsync("ct2_c0");
var r1 = Utils.NewRealtime();
var c1 = await r1.CreateClientAsync("ct2_c1");

c1.OnKicked += (sender, e) => {
Console.WriteLine($"I am kicked by {e.KickedBy} in {e.ConversationId}");
mre.Set();
};

var conv = await c0.CreateConversationAsync(new List<string> { "ct2_c1" }, "ct2_conv0");
await c0.KickAsync(conv, "ct2_c1");

mre.WaitOne();
}

[Test]
public async Task TempotaryConversation() {
var r = Utils.NewRealtime();
var c = await r.CreateClientAsync("ct3");
var tempConv = await c.CreateTemporaryConversationAsync(ttl: 100);
Assert.AreEqual(tempConv.ConversationId.StartsWith("_tmp:", StringComparison.Ordinal), true);
}
}
}
27 changes: 27 additions & 0 deletions LeanCloud.Realtime/Test/Test.Portable/MessageTest.cs
@@ -0,0 +1,27 @@
using NUnit.Framework;
using System;
using System.Threading;
using System.Threading.Tasks;
using LeanCloud.Realtime;

namespace Test.Portable {
[TestFixture]
public class MessageTest {
[Test]
public async Task ModifyMessage() {
var mre = new ManualResetEvent(false);
string msgId = null;
var r = Utils.NewRealtime();
var c = await r.CreateClientAsync("mt0_c0");
c.OnMessageUpdated += (sender, e) => {
Assert.AreEqual(msgId, e.Message.Id);
};
var chatroom = await c.CreateConversationAsync("leancloud");
var textMsg = new AVIMTextMessage("hello");
var msg = await chatroom.SendMessageAsync(textMsg);
var newMsg = new AVIMTextMessage("hi");
msg = await chatroom.UpdateAsync(msg, newMsg);
msgId = msg.Id;
}
}
}
80 changes: 80 additions & 0 deletions LeanCloud.Realtime/Test/Test.Portable/Test.Portable.csproj
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\..\packages\NUnit.3.11.0\build\NUnit.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{04B1CD72-3A2B-49F8-BC4D-0026DF5C5DE3}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>Test.Portable</RootNamespace>
<AssemblyName>Test.Portable</AssemblyName>
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="nunit.framework">
<HintPath>..\..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Websockets.Net">
<HintPath>..\..\packages\Websockets.Pcl.1.1.9\lib\net45\Websockets.Net.dll</HintPath>
</Reference>
<Reference Include="WebSockets.PCL">
<HintPath>..\..\packages\Websockets.Pcl.1.1.9\lib\net45\WebSockets.PCL.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Extensions">
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Extensions.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http.Primitives">
<HintPath>..\..\packages\Microsoft.Net.Http.2.2.29\lib\net45\System.Net.Http.Primitives.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Net.Http.WebRequest" />
<Reference Include="PCLStorage.Abstractions">
<HintPath>..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.Abstractions.dll</HintPath>
</Reference>
<Reference Include="PCLStorage">
<HintPath>..\..\packages\PCLStorage.1.0.2\lib\net45\PCLStorage.dll</HintPath>
</Reference>
<Reference Include="AssemblyLister">
<HintPath>..\..\packages\LeanCloud.Storage.2019.4.23.2\lib\net45\AssemblyLister.dll</HintPath>
</Reference>
<Reference Include="LeanCloud.Core">
<HintPath>..\..\packages\LeanCloud.Storage.2019.4.23.2\lib\net45\LeanCloud.Core.dll</HintPath>
</Reference>
<Reference Include="LeanCloud.Storage">
<HintPath>..\..\packages\LeanCloud.Storage.2019.4.23.2\lib\net45\LeanCloud.Storage.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BasicTest.cs" />
<Compile Include="Utils.cs" />
<Compile Include="ConversationTest.cs" />
<Compile Include="MessageTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\LeanCloud.Realtime.Portable.csproj">
<Project>{6F0554F3-8CC8-4A34-BD68-33A555CCA74D}</Project>
<Name>LeanCloud.Realtime.Portable</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\packages\Microsoft.Bcl.Build.1.0.21\build\Microsoft.Bcl.Build.targets')" />
</Project>
16 changes: 16 additions & 0 deletions LeanCloud.Realtime/Test/Test.Portable/Utils.cs
@@ -0,0 +1,16 @@
using System;
using System.Threading.Tasks;
using LeanCloud;
using LeanCloud.Realtime;

namespace Test.Portable {
public static class Utils {
internal static AVRealtime NewRealtime() {
Websockets.Net.WebsocketConnection.Link();
var appId = "Eohx7L4EMfe4xmairXeT7q1w-gzGzoHsz";
var appKey = "GSBSGpYH9FsRdCss8TGQed0F";
AVClient.Initialize(appId, appKey);
return new AVRealtime(appId, appKey);
}
}
}
10 changes: 10 additions & 0 deletions LeanCloud.Realtime/Test/Test.Portable/packages.config
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="LeanCloud.Storage" version="2019.4.23.2" targetFramework="net47" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="net47" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net47" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net47" />
<package id="NUnit" version="3.11.0" targetFramework="net47" />
<package id="PCLStorage" version="1.0.2" targetFramework="net47" />
<package id="Websockets.Pcl" version="1.1.9" targetFramework="net47" developmentDependency="true" />
</packages>

0 comments on commit 2e955ee

Please sign in to comment.