From 9ca71dba3975477878129d884c5aeda06ef07297 Mon Sep 17 00:00:00 2001 From: oneRain Date: Mon, 27 Apr 2020 17:44:53 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E8=87=AA=E5=AE=9A=E4=B9=89=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E6=B6=88=E6=81=AF=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Test/Realtime.Test/Message.cs | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Test/Realtime.Test/Message.cs b/Test/Realtime.Test/Message.cs index a496ddf..01083c5 100644 --- a/Test/Realtime.Test/Message.cs +++ b/Test/Realtime.Test/Message.cs @@ -9,6 +9,23 @@ using LeanCloud.Realtime; using static NUnit.Framework.TestContext; +/// +/// 自定义消息 +/// +class CustomMessage : LCIMTypedMessage { + public const int CustomMessageType = 1; + + public override int MessageType => CustomMessageType; + + public string Ecode { + get { + return data["ecode"] as string; + } set { + data["ecode"] = value; + } + } +} + namespace Realtime.Test { public class Message { private LCIMClient m1; @@ -192,5 +209,26 @@ namespace Realtime.Test { await tcs.Task; } + + [Test] + [Order(7)] + public async Task Custom() { + TaskCompletionSource tcs = new TaskCompletionSource(); + // 注册自定义类型消息 + LCIMTypedMessage.Register(CustomMessage.CustomMessageType, + () => new CustomMessage()); + m2.OnMessage = (conv, msg) => { + Assert.True(msg is CustomMessage); + CustomMessage customMsg = msg as CustomMessage; + Assert.AreEqual(customMsg.Ecode, "#0123"); + tcs.SetResult(null); + }; + CustomMessage customMessage = new CustomMessage { + Ecode = "#0123" + }; + await conversation.Send(customMessage); + + await tcs.Task; + } } }