* Conversation.cs:
* Utils.cs: test: 完善对话相关测试
parent
fa2b4d9c79
commit
3f8eae6da8
|
@ -6,10 +6,14 @@ using LeanCloud;
|
||||||
using LeanCloud.Common;
|
using LeanCloud.Common;
|
||||||
using LeanCloud.Realtime;
|
using LeanCloud.Realtime;
|
||||||
|
|
||||||
|
using static NUnit.Framework.TestContext;
|
||||||
|
|
||||||
namespace Realtime.Test {
|
namespace Realtime.Test {
|
||||||
public class Conversation {
|
public class Conversation {
|
||||||
private LCIMClient c1;
|
private LCIMClient c1;
|
||||||
private LCIMClient c2;
|
private LCIMClient c2;
|
||||||
|
private LCIMClient lean;
|
||||||
|
private LCIMClient cloud;
|
||||||
private LCIMConversation conversation;
|
private LCIMConversation conversation;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
|
@ -20,6 +24,8 @@ namespace Realtime.Test {
|
||||||
await c1.Open();
|
await c1.Open();
|
||||||
c2 = new LCIMClient(Guid.NewGuid().ToString());
|
c2 = new LCIMClient(Guid.NewGuid().ToString());
|
||||||
await c2.Open();
|
await c2.Open();
|
||||||
|
lean = new LCIMClient("lean");
|
||||||
|
await lean.Open();
|
||||||
conversation = await c1.CreateConversation(new string[] { "lean", "cloud" });
|
conversation = await c1.CreateConversation(new string[] { "lean", "cloud" });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,64 +33,162 @@ namespace Realtime.Test {
|
||||||
public async Task TearDown() {
|
public async Task TearDown() {
|
||||||
await c1.Close();
|
await c1.Close();
|
||||||
await c2.Close();
|
await c2.Close();
|
||||||
|
await lean.Close();
|
||||||
LCLogger.LogDelegate -= Utils.Print;
|
LCLogger.LogDelegate -= Utils.Print;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Order(0)]
|
[Order(0)]
|
||||||
public async Task AddMember() {
|
public async Task AddMember() {
|
||||||
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
||||||
|
c2.OnInvited = (conv, initBy) => {
|
||||||
|
WriteLine($"{c2.Id} is invited by {initBy}");
|
||||||
|
tcs.SetResult(null);
|
||||||
|
};
|
||||||
await conversation.AddMembers(new string[] { c2.Id });
|
await conversation.AddMembers(new string[] { c2.Id });
|
||||||
Assert.AreEqual(conversation.MemberIds.Count, 4);
|
Assert.AreEqual(conversation.MemberIds.Count, 4);
|
||||||
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Order(1)]
|
[Order(1)]
|
||||||
public async Task MuteMembers() {
|
public async Task MuteMembers() {
|
||||||
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
||||||
|
bool f1 = false, f2 = false;
|
||||||
|
c1.OnMembersMuted = (conv, mutedMembers, initBy) => {
|
||||||
|
Assert.True(mutedMembers.Contains(lean.Id));
|
||||||
|
Assert.True(conversation.MutedMemberIds.Contains(lean.Id));
|
||||||
|
f1 = true;
|
||||||
|
if (f1 && f2) {
|
||||||
|
tcs.SetResult(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lean.OnMuted = (conv, initBy) => {
|
||||||
|
WriteLine($"{lean.Id} is muted by {initBy}");
|
||||||
|
f2 = true;
|
||||||
|
if (f1 && f2) {
|
||||||
|
tcs.SetResult(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
await conversation.MuteMembers(new string[] { "lean" });
|
await conversation.MuteMembers(new string[] { "lean" });
|
||||||
Assert.True(conversation.MutedMemberIds.Contains("lean"));
|
Assert.True(conversation.MutedMemberIds.Contains("lean"));
|
||||||
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Order(2)]
|
[Order(2)]
|
||||||
public async Task UnmuteMembers() {
|
public async Task UnmuteMembers() {
|
||||||
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
||||||
|
bool f1 = false, f2 = false;
|
||||||
|
c1.OnMembersUnmuted = (conv, unmutedMembers, initBy) => {
|
||||||
|
Assert.True(unmutedMembers.Contains(lean.Id));
|
||||||
|
Assert.False(conversation.MutedMemberIds.Contains(lean.Id));
|
||||||
|
f1 = true;
|
||||||
|
if (f1 && f2) {
|
||||||
|
tcs.SetResult(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lean.OnUnmuted = (conv, initBy) => {
|
||||||
|
WriteLine($"{lean.Id} is unmuted by {initBy}");
|
||||||
|
f2 = true;
|
||||||
|
if (f1 && f2) {
|
||||||
|
tcs.SetResult(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
await conversation.UnmuteMembers(new string[] { "lean" });
|
await conversation.UnmuteMembers(new string[] { "lean" });
|
||||||
Assert.False(conversation.MutedMemberIds.Contains("lean"));
|
Assert.False(conversation.MutedMemberIds.Contains("lean"));
|
||||||
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Order(3)]
|
[Order(3)]
|
||||||
public async Task BlockMembers() {
|
public async Task BlockMembers() {
|
||||||
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
||||||
|
bool f1 = false, f2 = false;
|
||||||
|
c1.OnMembersBlocked = (conv, blockedMembers, initBy) => {
|
||||||
|
Assert.True(blockedMembers.Contains(lean.Id));
|
||||||
|
f1 = true;
|
||||||
|
if (f1 && f2) {
|
||||||
|
tcs.SetResult(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lean.OnBlocked = (conv, initBy) => {
|
||||||
|
WriteLine($"{lean.Id} is blocked by {initBy}");
|
||||||
|
f2 = true;
|
||||||
|
if (f1 && f2) {
|
||||||
|
tcs.SetResult(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
await conversation.BlockMembers(new string[] { "lean" });
|
await conversation.BlockMembers(new string[] { "lean" });
|
||||||
LCIMPageResult result = await conversation.QueryBlockedMembers();
|
LCIMPageResult result = await conversation.QueryBlockedMembers();
|
||||||
Assert.True(result.Results.Contains("lean"));
|
Assert.True(result.Results.Contains("lean"));
|
||||||
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Order(4)]
|
[Order(4)]
|
||||||
public async Task UnblockMembers() {
|
public async Task UnblockMembers() {
|
||||||
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
||||||
|
bool f1 = false, f2 = false;
|
||||||
|
c1.OnMembersUnblocked = (conv, blockedMembers, initBy) => {
|
||||||
|
Assert.True(blockedMembers.Contains(lean.Id));
|
||||||
|
f1 = true;
|
||||||
|
if (f1 && f2) {
|
||||||
|
tcs.SetResult(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
lean.OnUnblocked = (conv, initBy) => {
|
||||||
|
WriteLine($"{lean.Id} is unblocked by {initBy}");
|
||||||
|
f2 = true;
|
||||||
|
if (f1 && f2) {
|
||||||
|
tcs.SetResult(null);
|
||||||
|
}
|
||||||
|
};
|
||||||
await conversation.UnblockMembers(new string[] { "lean" });
|
await conversation.UnblockMembers(new string[] { "lean" });
|
||||||
LCIMPageResult result = await conversation.QueryBlockedMembers();
|
LCIMPageResult result = await conversation.QueryBlockedMembers();
|
||||||
Assert.False(result.Results.Contains("lean"));
|
Assert.False(result.Results.Contains("lean"));
|
||||||
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Order(5)]
|
[Order(5)]
|
||||||
public async Task UpdateRole() {
|
public async Task UpdateRole() {
|
||||||
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
||||||
|
c1.OnMemberInfoUpdated = (conv, member, role, initBy) => {
|
||||||
|
WriteLine($"{member} is {role} by {initBy}");
|
||||||
|
tcs.SetResult(null);
|
||||||
|
};
|
||||||
await conversation.UpdateMemberRole("cloud", LCIMConversationMemberInfo.Manager);
|
await conversation.UpdateMemberRole("cloud", LCIMConversationMemberInfo.Manager);
|
||||||
LCIMConversationMemberInfo memberInfo = await conversation.GetMemberInfo("cloud");
|
LCIMConversationMemberInfo memberInfo = await conversation.GetMemberInfo("cloud");
|
||||||
Assert.True(memberInfo.IsManager);
|
Assert.True(memberInfo.IsManager);
|
||||||
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Order(6)]
|
[Order(6)]
|
||||||
public async Task RemoveMember() {
|
public async Task RemoveMember() {
|
||||||
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
||||||
|
c2.OnKicked = (conv, initBy) => {
|
||||||
|
WriteLine($"{c2.Id} is kicked by {initBy}");
|
||||||
|
tcs.SetResult(null);
|
||||||
|
};
|
||||||
await conversation.RemoveMembers(new string[] { c2.Id });
|
await conversation.RemoveMembers(new string[] { c2.Id });
|
||||||
Assert.AreEqual(conversation.MemberIds.Count, 3);
|
Assert.AreEqual(conversation.MemberIds.Count, 3);
|
||||||
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Order(7)]
|
[Order(7)]
|
||||||
public async Task UpdateInfo() {
|
public async Task UpdateInfo() {
|
||||||
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
||||||
|
lean.OnConversationInfoUpdated = (conv, attrs, initBy) => {
|
||||||
|
Assert.AreEqual(conv.Name, "leancloud");
|
||||||
|
Assert.AreEqual(conv["k1"], "v1");
|
||||||
|
Assert.AreEqual(conv["k2"], "v2");
|
||||||
|
Assert.AreEqual(attrs["k1"], "v1");
|
||||||
|
Assert.AreEqual(attrs["k2"], "v2");
|
||||||
|
tcs.SetResult(null);
|
||||||
|
};
|
||||||
await conversation.UpdateInfo(new Dictionary<string, object> {
|
await conversation.UpdateInfo(new Dictionary<string, object> {
|
||||||
{ "name", "leancloud" },
|
{ "name", "leancloud" },
|
||||||
{ "k1", "v1" },
|
{ "k1", "v1" },
|
||||||
|
@ -93,6 +197,7 @@ namespace Realtime.Test {
|
||||||
Assert.AreEqual(conversation.Name, "leancloud");
|
Assert.AreEqual(conversation.Name, "leancloud");
|
||||||
Assert.AreEqual(conversation["k1"], "v1");
|
Assert.AreEqual(conversation["k1"], "v1");
|
||||||
Assert.AreEqual(conversation["k2"], "v2");
|
Assert.AreEqual(conversation["k2"], "v2");
|
||||||
|
await tcs.Task;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,13 @@ namespace Realtime.Test {
|
||||||
internal static void Print(LCLogLevel level, string info) {
|
internal static void Print(LCLogLevel level, string info) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case LCLogLevel.Debug:
|
case LCLogLevel.Debug:
|
||||||
TestContext.Out.WriteLine($"[DEBUG] {info}");
|
TestContext.Out.WriteLine($"[DEBUG] {info}\n");
|
||||||
break;
|
break;
|
||||||
case LCLogLevel.Warn:
|
case LCLogLevel.Warn:
|
||||||
TestContext.Out.WriteLine($"[WARNING] {info}");
|
TestContext.Out.WriteLine($"[WARNING] {info}\n");
|
||||||
break;
|
break;
|
||||||
case LCLogLevel.Error:
|
case LCLogLevel.Error:
|
||||||
TestContext.Out.WriteLine($"[ERROR] {info}");
|
TestContext.Out.WriteLine($"[ERROR] {info}\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
TestContext.Out.WriteLine(info);
|
TestContext.Out.WriteLine(info);
|
||||||
|
|
Loading…
Reference in New Issue