浏览代码

Add UnitTests.

release/3.x.x
Christian Kratky 5 年前
父节点
当前提交
f0be3ef0cf
共有 1 个文件被更改,包括 34 次插入0 次删除
  1. +34
    -0
      Tests/MQTTnet.Core.Tests/MqttClient_Tests.cs

+ 34
- 0
Tests/MQTTnet.Core.Tests/MqttClient_Tests.cs 查看文件

@@ -20,6 +20,40 @@ namespace MQTTnet.Tests
[TestClass]
public class Client_Tests
{
[TestMethod]
public async Task Send_Reply_In_Message_Handler_For_Same_Client()
{
using (var testEnvironment = new TestEnvironment())
{
await testEnvironment.StartServerAsync();
var client = await testEnvironment.ConnectClientAsync();
await client.SubscribeAsync("#");
var replyReceived = false;

client.UseApplicationMessageReceivedHandler(c =>
{
if (c.ApplicationMessage.Topic == "request")
{
#pragma warning disable 4014
Task.Run(() => client.PublishAsync("reply", null, MqttQualityOfServiceLevel.AtLeastOnce));
#pragma warning restore 4014
}
else
{
replyReceived = true;
}
});

await client.PublishAsync("request", null, MqttQualityOfServiceLevel.AtLeastOnce);

SpinWait.SpinUntil(() => replyReceived, TimeSpan.FromSeconds(10));

Assert.IsTrue(replyReceived);
}
}

[TestMethod]
public async Task Send_Reply_In_Message_Handler()
{


正在加载...
取消
保存