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.Common;
|
|
|
|
|
using LeanCloud.Realtime;
|
|
|
|
|
|
|
|
|
|
namespace Realtime.Test {
|
|
|
|
|
public class Conversation {
|
|
|
|
|
[SetUp]
|
|
|
|
|
public void SetUp() {
|
|
|
|
|
LCLogger.LogDelegate += Utils.Print;
|
|
|
|
|
LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public void TearDown() {
|
|
|
|
|
LCLogger.LogDelegate -= Utils.Print;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task CreateConversation() {
|
|
|
|
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
|
|
|
|
|
|
|
|
|
string clientId = Guid.NewGuid().ToString();
|
|
|
|
|
LCIMClient client = new LCIMClient(clientId);
|
|
|
|
|
|
|
|
|
|
await client.Open();
|
|
|
|
|
|
|
|
|
|
client.OnInvited = (conv, initBy) => {
|
|
|
|
|
TestContext.WriteLine($"on invited: {initBy}");
|
2020-03-13 17:22:46 +08:00
|
|
|
|
TestContext.WriteLine(conv.CreatorId);
|
2020-03-12 16:23:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
client.OnMembersJoined = (conv, memberList, initBy) => {
|
|
|
|
|
TestContext.WriteLine($"on members joined: {initBy}");
|
2020-03-13 17:22:46 +08:00
|
|
|
|
foreach (string memberId in conv.MemberIdList) {
|
|
|
|
|
TestContext.WriteLine(memberId);
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
tcs.SetResult(null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
List<string> memberIdList = new List<string> { "world" };
|
|
|
|
|
string name = Guid.NewGuid().ToString();
|
|
|
|
|
await client.CreateConversation(memberIdList, name: name, unique: false);
|
|
|
|
|
|
|
|
|
|
await tcs.Task;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task CreateChatRoom() {
|
|
|
|
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
|
|
|
|
|
|
|
|
|
string clientId = Guid.NewGuid().ToString();
|
|
|
|
|
LCIMClient client = new LCIMClient(clientId);
|
|
|
|
|
|
|
|
|
|
await client.Open();
|
|
|
|
|
|
|
|
|
|
client.OnInvited = (conv, initBy) => {
|
|
|
|
|
TestContext.WriteLine($"on invited: {initBy}");
|
|
|
|
|
tcs.SetResult(null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string name = Guid.NewGuid().ToString();
|
|
|
|
|
await client.CreateChatRoom(name);
|
|
|
|
|
|
|
|
|
|
await tcs.Task;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task CreateTemporaryConversation() {
|
|
|
|
|
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
|
|
|
|
|
|
|
|
|
|
string clientId = Guid.NewGuid().ToString();
|
|
|
|
|
LCIMClient client = new LCIMClient(clientId);
|
|
|
|
|
|
|
|
|
|
await client.Open();
|
|
|
|
|
|
|
|
|
|
client.OnInvited = (conv, initBy) => {
|
|
|
|
|
TestContext.WriteLine($"on invited: {initBy}");
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
client.OnMembersJoined = (conv, memberList, initBy) => {
|
|
|
|
|
TestContext.WriteLine($"on members joined: {initBy}");
|
|
|
|
|
tcs.SetResult(null);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
List<string> memberIdList = new List<string> { "world" };
|
|
|
|
|
await client.CreateTemporaryConversation(memberIdList);
|
|
|
|
|
|
|
|
|
|
await tcs.Task;
|
|
|
|
|
}
|
2020-03-17 11:41:38 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Query() {
|
|
|
|
|
LCIMClient client = new LCIMClient("hello123");
|
|
|
|
|
await client.Open();
|
|
|
|
|
|
|
|
|
|
LCIMConversationQuery query = new LCIMConversationQuery(client);
|
|
|
|
|
await query.Find();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Save() {
|
|
|
|
|
string clientId = Guid.NewGuid().ToString();
|
|
|
|
|
LCIMClient client = new LCIMClient(clientId);
|
|
|
|
|
|
|
|
|
|
await client.Open();
|
|
|
|
|
|
|
|
|
|
string otherId = Guid.NewGuid().ToString();
|
|
|
|
|
LCIMConversation conversation = await client.CreateConversation(new List<string> { otherId });
|
|
|
|
|
|
|
|
|
|
conversation.Name = "leancloud";
|
|
|
|
|
conversation["k1"] = "v1";
|
|
|
|
|
conversation["k2"] = "v2";
|
2020-03-25 16:42:30 +08:00
|
|
|
|
await conversation.UpdateInfo();
|
2020-03-17 11:41:38 +08:00
|
|
|
|
|
|
|
|
|
Assert.AreEqual(conversation.Name, "leancloud");
|
|
|
|
|
Assert.AreEqual(conversation["k1"], "v1");
|
|
|
|
|
Assert.AreEqual(conversation["k2"], "v2");
|
|
|
|
|
}
|
2020-03-12 16:23:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|