2020-03-16 11:50:49 +08:00
|
|
|
|
using NUnit.Framework;
|
2020-04-26 16:14:45 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Threading;
|
2020-03-16 11:50:49 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2020-04-26 16:14:45 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-03-16 11:50:49 +08:00
|
|
|
|
using LeanCloud;
|
|
|
|
|
using LeanCloud.Common;
|
2020-04-24 17:42:45 +08:00
|
|
|
|
using LeanCloud.Storage;
|
2020-03-16 11:50:49 +08:00
|
|
|
|
using LeanCloud.Realtime;
|
|
|
|
|
|
2020-04-26 16:14:45 +08:00
|
|
|
|
using static System.Console;
|
2020-04-24 17:42:45 +08:00
|
|
|
|
|
2020-03-16 11:50:49 +08:00
|
|
|
|
namespace Realtime.Test {
|
|
|
|
|
public class Message {
|
2020-04-24 17:42:45 +08:00
|
|
|
|
private LCIMClient m1;
|
|
|
|
|
private LCIMClient m2;
|
|
|
|
|
|
|
|
|
|
private LCIMConversation conversation;
|
|
|
|
|
|
2020-03-16 11:50:49 +08:00
|
|
|
|
[SetUp]
|
2020-04-24 17:42:45 +08:00
|
|
|
|
public async Task SetUp() {
|
2020-03-16 11:50:49 +08:00
|
|
|
|
LCLogger.LogDelegate += Utils.Print;
|
|
|
|
|
LCApplication.Initialize("ikGGdRE2YcVOemAaRbgp1xGJ-gzGzoHsz", "NUKmuRbdAhg1vrb2wexYo1jo", "https://ikggdre2.lc-cn-n1-shared.com");
|
2020-04-24 17:42:45 +08:00
|
|
|
|
m1 = new LCIMClient("m1");
|
|
|
|
|
m2 = new LCIMClient("m2");
|
|
|
|
|
await m1.Open();
|
|
|
|
|
await m2.Open();
|
|
|
|
|
conversation = await m1.CreateConversation(new string[] { "m2" });
|
2020-03-16 11:50:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TearDown]
|
2020-04-24 17:42:45 +08:00
|
|
|
|
public async Task TearDown() {
|
|
|
|
|
await m1.Close();
|
|
|
|
|
await m2.Close();
|
2020-03-16 11:50:49 +08:00
|
|
|
|
LCLogger.LogDelegate -= Utils.Print;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public async Task Send() {
|
2020-04-26 16:14:45 +08:00
|
|
|
|
AutoResetEvent are = new AutoResetEvent(false);
|
2020-04-24 17:42:45 +08:00
|
|
|
|
m2.OnMessage = (conv, msg) => {
|
|
|
|
|
WriteLine(msg.Id);
|
|
|
|
|
if (msg is LCIMImageMessage imageMsg) {
|
|
|
|
|
WriteLine($"-------- url: {imageMsg.Url}");
|
|
|
|
|
} else if (msg is LCIMFileMessage fileMsg) {
|
|
|
|
|
WriteLine($"-------- name: {fileMsg.Format}");
|
|
|
|
|
} else if (msg is LCIMTextMessage textMsg) {
|
|
|
|
|
WriteLine($"-------- text: {textMsg.Text}");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LCIMTextMessage textMessage = new LCIMTextMessage("hello, world");
|
|
|
|
|
await conversation.Send(textMessage);
|
|
|
|
|
Assert.NotNull(textMessage.Id);
|
|
|
|
|
|
|
|
|
|
LCFile image = new LCFile("hello", "../../../../assets/hello.png");
|
|
|
|
|
await image.Save();
|
|
|
|
|
LCIMImageMessage imageMessage = new LCIMImageMessage(image);
|
|
|
|
|
await conversation.Send(imageMessage);
|
|
|
|
|
Assert.NotNull(imageMessage.Id);
|
|
|
|
|
|
|
|
|
|
LCFile file = new LCFile("apk", "../../../../assets/test.apk");
|
|
|
|
|
await file.Save();
|
|
|
|
|
LCIMFileMessage fileMessage = new LCIMFileMessage(file);
|
|
|
|
|
await conversation.Send(fileMessage);
|
|
|
|
|
Assert.NotNull(fileMessage.Id);
|
2020-03-16 11:50:49 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|