2020-03-12 16:23:21 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using LeanCloud;
|
|
|
|
|
using LeanCloud.Realtime;
|
|
|
|
|
|
2020-04-26 11:53:54 +08:00
|
|
|
|
using static NUnit.Framework.TestContext;
|
|
|
|
|
|
2020-03-12 16:23:21 +08:00
|
|
|
|
namespace Realtime.Test {
|
|
|
|
|
public class Conversation {
|
2020-04-24 17:42:45 +08:00
|
|
|
|
private LCIMClient c1;
|
|
|
|
|
private LCIMClient c2;
|
2020-04-26 11:53:54 +08:00
|
|
|
|
private LCIMClient lean;
|
2020-04-24 17:42:45 +08:00
|
|
|
|
private LCIMConversation conversation;
|
|
|
|
|
|
2020-03-12 16:23:21 +08:00
|
|
|
|
[SetUp]
|
2020-04-24 17:42:45 +08:00
|
|
|
|
public async Task SetUp() {
|
2020-03-12 16:23:21 +08:00
|
|
|
|
LCLogger.LogDelegate += Utils.Print;
|
|
|
|
|
LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
|
2020-04-24 17:42:45 +08:00
|
|
|
|
c1 = new LCIMClient(Guid.NewGuid().ToString());
|
|
|
|
|
await c1.Open();
|
|
|
|
|
c2 = new LCIMClient(Guid.NewGuid().ToString());
|
|
|
|
|
await c2.Open();
|
2020-04-26 11:53:54 +08:00
|
|
|
|
lean = new LCIMClient("lean");
|
|
|
|
|
await lean.Open();
|
2020-04-24 17:42:45 +08:00
|
|
|
|
conversation = await c1.CreateConversation(new string[] { "lean", "cloud" });
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
2020-04-24 17:42:45 +08:00
|
|
|
|
public async Task TearDown() {
|
|
|
|
|
await c1.Close();
|
|
|
|
|
await c2.Close();
|
2020-04-26 11:53:54 +08:00
|
|
|
|
await lean.Close();
|
2020-03-12 16:23:21 +08:00
|
|
|
|
LCLogger.LogDelegate -= Utils.Print;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-04-24 17:42:45 +08:00
|
|
|
|
[Order(0)]
|
|
|
|
|
public async Task AddMember() {
|
2020-04-26 11:53:54 +08:00
|
|
|
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
|
|
|
|
c2.OnInvited = (conv, initBy) => {
|
|
|
|
|
WriteLine($"{c2.Id} is invited by {initBy}");
|
|
|
|
|
tcs.SetResult(null);
|
|
|
|
|
};
|
2020-04-24 17:42:45 +08:00
|
|
|
|
await conversation.AddMembers(new string[] { c2.Id });
|
|
|
|
|
Assert.AreEqual(conversation.MemberIds.Count, 4);
|
2020-04-26 11:53:54 +08:00
|
|
|
|
await tcs.Task;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-04-24 17:42:45 +08:00
|
|
|
|
[Order(1)]
|
|
|
|
|
public async Task MuteMembers() {
|
2020-04-26 11:53:54 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-04-24 17:42:45 +08:00
|
|
|
|
await conversation.MuteMembers(new string[] { "lean" });
|
|
|
|
|
Assert.True(conversation.MutedMemberIds.Contains("lean"));
|
2020-04-26 11:53:54 +08:00
|
|
|
|
await tcs.Task;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-04-24 17:42:45 +08:00
|
|
|
|
[Order(2)]
|
|
|
|
|
public async Task UnmuteMembers() {
|
2020-04-26 11:53:54 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-04-24 17:42:45 +08:00
|
|
|
|
await conversation.UnmuteMembers(new string[] { "lean" });
|
|
|
|
|
Assert.False(conversation.MutedMemberIds.Contains("lean"));
|
2020-04-26 11:53:54 +08:00
|
|
|
|
await tcs.Task;
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
2020-03-17 11:41:38 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
2020-04-24 17:42:45 +08:00
|
|
|
|
[Order(3)]
|
|
|
|
|
public async Task BlockMembers() {
|
2020-04-26 11:53:54 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-04-24 17:42:45 +08:00
|
|
|
|
await conversation.BlockMembers(new string[] { "lean" });
|
|
|
|
|
LCIMPageResult result = await conversation.QueryBlockedMembers();
|
|
|
|
|
Assert.True(result.Results.Contains("lean"));
|
2020-04-26 11:53:54 +08:00
|
|
|
|
await tcs.Task;
|
2020-03-17 11:41:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
2020-04-24 17:42:45 +08:00
|
|
|
|
[Order(4)]
|
|
|
|
|
public async Task UnblockMembers() {
|
2020-04-26 11:53:54 +08:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
};
|
2020-04-24 17:42:45 +08:00
|
|
|
|
await conversation.UnblockMembers(new string[] { "lean" });
|
|
|
|
|
LCIMPageResult result = await conversation.QueryBlockedMembers();
|
|
|
|
|
Assert.False(result.Results.Contains("lean"));
|
2020-04-26 11:53:54 +08:00
|
|
|
|
await tcs.Task;
|
2020-04-24 17:42:45 +08:00
|
|
|
|
}
|
2020-03-17 11:41:38 +08:00
|
|
|
|
|
2020-04-24 17:42:45 +08:00
|
|
|
|
[Test]
|
|
|
|
|
[Order(5)]
|
|
|
|
|
public async Task UpdateRole() {
|
2020-04-26 11:53:54 +08:00
|
|
|
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
|
|
|
|
c1.OnMemberInfoUpdated = (conv, member, role, initBy) => {
|
|
|
|
|
WriteLine($"{member} is {role} by {initBy}");
|
|
|
|
|
tcs.SetResult(null);
|
|
|
|
|
};
|
2020-04-24 17:42:45 +08:00
|
|
|
|
await conversation.UpdateMemberRole("cloud", LCIMConversationMemberInfo.Manager);
|
|
|
|
|
LCIMConversationMemberInfo memberInfo = await conversation.GetMemberInfo("cloud");
|
|
|
|
|
Assert.True(memberInfo.IsManager);
|
2020-04-26 11:53:54 +08:00
|
|
|
|
await tcs.Task;
|
2020-04-24 17:42:45 +08:00
|
|
|
|
}
|
2020-03-17 11:41:38 +08:00
|
|
|
|
|
2020-04-24 17:42:45 +08:00
|
|
|
|
[Test]
|
|
|
|
|
[Order(6)]
|
|
|
|
|
public async Task RemoveMember() {
|
2020-04-26 11:53:54 +08:00
|
|
|
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
|
|
|
|
c2.OnKicked = (conv, initBy) => {
|
|
|
|
|
WriteLine($"{c2.Id} is kicked by {initBy}");
|
|
|
|
|
tcs.SetResult(null);
|
|
|
|
|
};
|
2020-04-24 17:42:45 +08:00
|
|
|
|
await conversation.RemoveMembers(new string[] { c2.Id });
|
|
|
|
|
Assert.AreEqual(conversation.MemberIds.Count, 3);
|
2020-04-26 11:53:54 +08:00
|
|
|
|
await tcs.Task;
|
2020-04-24 17:42:45 +08:00
|
|
|
|
}
|
2020-03-17 11:41:38 +08:00
|
|
|
|
|
2020-04-24 17:42:45 +08:00
|
|
|
|
[Test]
|
|
|
|
|
[Order(7)]
|
|
|
|
|
public async Task UpdateInfo() {
|
2020-04-26 11:53:54 +08:00
|
|
|
|
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);
|
|
|
|
|
};
|
2020-03-27 17:30:18 +08:00
|
|
|
|
await conversation.UpdateInfo(new Dictionary<string, object> {
|
|
|
|
|
{ "name", "leancloud" },
|
|
|
|
|
{ "k1", "v1" },
|
|
|
|
|
{ "k2", "v2" }
|
|
|
|
|
});
|
2020-03-17 11:41:38 +08:00
|
|
|
|
Assert.AreEqual(conversation.Name, "leancloud");
|
|
|
|
|
Assert.AreEqual(conversation["k1"], "v1");
|
|
|
|
|
Assert.AreEqual(conversation["k2"], "v2");
|
2020-06-23 15:25:30 +08:00
|
|
|
|
// BUG: 已知
|
|
|
|
|
//await tcs.Task;
|
2020-03-17 11:41:38 +08:00
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|