csharp-sdk-upm/Realtime/Realtime.Test/ConversationQuery.cs

76 lines
2.9 KiB
C#
Raw Permalink Normal View History

using NUnit.Framework;
using System.Collections.ObjectModel;
using System.Threading.Tasks;
using LeanCloud.Realtime;
namespace Realtime.Test {
public class ConversationQuery {
2020-12-24 10:58:16 +08:00
private readonly string clientId = "m1";
private LCIMClient client;
[SetUp]
public async Task SetUp() {
2020-12-24 10:58:16 +08:00
Utils.SetUp();
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();
}
[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";
LCIMConversationQuery query = new LCIMConversationQuery(client);
2020-04-26 16:15:30 +08:00
query.WhereEqualTo("m", memberId);
ReadOnlyCollection<LCIMConversation> conversations = await query.Find();
Assert.Greater(conversations.Count, 0);
foreach (LCIMConversation conversation in conversations) {
Assert.True(conversation.MemberIds.Contains(memberId));
}
}
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));
}
}
}
}
}