test: 重命名自定义类型消息

oneRain 2020-04-28 11:20:51 +08:00
parent 63552e17de
commit 8a036a6354
1 changed files with 11 additions and 11 deletions

View File

@ -10,12 +10,12 @@ using LeanCloud.Realtime;
using static NUnit.Framework.TestContext; using static NUnit.Framework.TestContext;
/// <summary> /// <summary>
/// 自定义消息 /// Emoji 消息
/// </summary> /// </summary>
class CustomMessage : LCIMTypedMessage { class EmojiMessage : LCIMTypedMessage {
public const int CustomMessageType = 1; public const int EmojiMessageType = 1;
public override int MessageType => CustomMessageType; public override int MessageType => EmojiMessageType;
public string Ecode { public string Ecode {
get { get {
@ -215,18 +215,18 @@ namespace Realtime.Test {
public async Task Custom() { public async Task Custom() {
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>(); TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
// 注册自定义类型消息 // 注册自定义类型消息
LCIMTypedMessage.Register(CustomMessage.CustomMessageType, LCIMTypedMessage.Register(EmojiMessage.EmojiMessageType,
() => new CustomMessage()); () => new EmojiMessage());
m2.OnMessage = (conv, msg) => { m2.OnMessage = (conv, msg) => {
Assert.True(msg is CustomMessage); Assert.True(msg is EmojiMessage);
CustomMessage customMsg = msg as CustomMessage; EmojiMessage emojiMsg = msg as EmojiMessage;
Assert.AreEqual(customMsg.Ecode, "#0123"); Assert.AreEqual(emojiMsg.Ecode, "#0123");
tcs.SetResult(null); tcs.SetResult(null);
}; };
CustomMessage customMessage = new CustomMessage { EmojiMessage emojiMessage = new EmojiMessage {
Ecode = "#0123" Ecode = "#0123"
}; };
await conversation.Send(customMessage); await conversation.Send(emojiMessage);
await tcs.Task; await tcs.Task;
} }