2020-04-24 17:42:45 +08:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using LeanCloud.Realtime;
|
|
|
|
|
|
2020-04-23 12:07:30 +08:00
|
|
|
|
namespace Realtime.Test {
|
|
|
|
|
public class ConversationQuery {
|
2020-12-24 10:58:16 +08:00
|
|
|
|
private readonly string clientId = "m1";
|
2020-04-24 17:42:45 +08:00
|
|
|
|
private LCIMClient client;
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
public async Task SetUp() {
|
2020-12-24 10:58:16 +08:00
|
|
|
|
Utils.SetUp();
|
2020-04-24 17:42:45 +08:00
|
|
|
|
client = new LCIMClient(clientId);
|
|
|
|
|
await client.Open();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
|
|
|
|
public async Task TearDown() {
|
|
|
|
|
await client.Close();
|
2020-12-24 10:58:16 +08:00
|
|
|
|
Utils.TearDown();
|
2020-04-24 17:42:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task QueryMyConversation() {
|
|
|
|
|
LCIMConversationQuery query = new LCIMConversationQuery(client);
|
|
|
|
|
ReadOnlyCollection<LCIMConversation> conversations = await query.Find();
|
|
|
|
|
Assert.Greater(conversations.Count, 0);
|
|
|
|
|
foreach (LCIMConversation conversation in conversations) {
|
|
|
|
|
Assert.True(conversation.MemberIds.Contains(clientId));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task QueryMemberConversation() {
|
2020-12-24 10:58:16 +08:00
|
|
|
|
string memberId = "m1";
|
2020-04-24 17:42:45 +08:00
|
|
|
|
LCIMConversationQuery query = new LCIMConversationQuery(client);
|
2020-04-26 16:15:30 +08:00
|
|
|
|
query.WhereEqualTo("m", memberId);
|
2020-04-24 17:42:45 +08:00
|
|
|
|
ReadOnlyCollection<LCIMConversation> conversations = await query.Find();
|
|
|
|
|
Assert.Greater(conversations.Count, 0);
|
|
|
|
|
foreach (LCIMConversation conversation in conversations) {
|
|
|
|
|
Assert.True(conversation.MemberIds.Contains(memberId));
|
|
|
|
|
}
|
2020-04-23 12:07:30 +08:00
|
|
|
|
}
|
2020-12-24 10:58:16 +08:00
|
|
|
|
|
2021-04-07 18:08:17 +08:00
|
|
|
|
//[Test]
|
|
|
|
|
//public async Task QueryCompact() {
|
|
|
|
|
// string memberId = "m1";
|
|
|
|
|
// LCIMConversationQuery query = new LCIMConversationQuery(client)
|
|
|
|
|
// .WhereEqualTo("m", memberId);
|
|
|
|
|
// query.Compact = true;
|
|
|
|
|
// ReadOnlyCollection<LCIMConversation> conversations = await query.Find();
|
|
|
|
|
// foreach (LCIMConversation conversation in conversations) {
|
|
|
|
|
// Assert.True(conversation.MemberIds.Count == 0);
|
|
|
|
|
// await conversation.Fetch();
|
|
|
|
|
// Assert.True(conversation.MemberIds.Count > 0);
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2020-12-24 10:58:16 +08:00
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task QueryWithLastMessage() {
|
|
|
|
|
string memberId = "m1";
|
|
|
|
|
LCIMConversationQuery query = new LCIMConversationQuery(client)
|
|
|
|
|
.WhereEqualTo("m", memberId);
|
|
|
|
|
query.WithLastMessageRefreshed = true;
|
|
|
|
|
ReadOnlyCollection<LCIMConversation> conversations = await query.Find();
|
|
|
|
|
foreach (LCIMConversation conversation in conversations) {
|
|
|
|
|
Assert.True(!string.IsNullOrEmpty(conversation.LastMessage.Id));
|
|
|
|
|
if (conversation.LastMessage is LCIMBinaryMessage binaryMessage) {
|
|
|
|
|
TestContext.WriteLine(System.Text.Encoding.UTF8.GetString(binaryMessage.Data));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-04-23 12:07:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|