This repository has been archived by the owner on Feb 8, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from onerain88/unit_test
test: 增加单元测试模块
- Loading branch information
Showing
8 changed files
with
234 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
80
LeanCloud.Realtime/Test/Test.Portable/Test.Portable.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |