You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

712 lines
26 KiB

  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using MQTTnet.Client;
  3. using MQTTnet.Client.Connecting;
  4. using MQTTnet.Client.Disconnecting;
  5. using MQTTnet.Client.Options;
  6. using MQTTnet.Client.Subscribing;
  7. using MQTTnet.Exceptions;
  8. using MQTTnet.Protocol;
  9. using MQTTnet.Server;
  10. using MQTTnet.Tests.Mockups;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Net.Sockets;
  15. using System.Text;
  16. using System.Threading;
  17. using System.Threading.Tasks;
  18. namespace MQTTnet.Tests
  19. {
  20. [TestClass]
  21. public class Client_Tests
  22. {
  23. public TestContext TestContext { get; set; }
  24. [TestMethod]
  25. [ExpectedException(typeof(MqttCommunicationTimedOutException))]
  26. public async Task Connect_To_Invalid_Server_Wrong_IP()
  27. {
  28. var client = new MqttFactory().CreateMqttClient();
  29. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("1.2.3.4").WithCommunicationTimeout(TimeSpan.FromSeconds(2)).Build());
  30. }
  31. [TestMethod]
  32. [ExpectedException(typeof(MqttCommunicationException))]
  33. public async Task Connect_To_Invalid_Server_Port_Not_Opened()
  34. {
  35. var client = new MqttFactory().CreateMqttClient();
  36. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1", 12345).WithCommunicationTimeout(TimeSpan.FromSeconds(5)).Build());
  37. }
  38. [TestMethod]
  39. [ExpectedException(typeof(MqttCommunicationException))]
  40. public async Task Connect_To_Invalid_Server_Wrong_Protocol()
  41. {
  42. var client = new MqttFactory().CreateMqttClient();
  43. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("http://127.0.0.1", 12345).WithCommunicationTimeout(TimeSpan.FromSeconds(2)).Build());
  44. }
  45. [TestMethod]
  46. public async Task Send_Manual_Ping()
  47. {
  48. using (var testEnvironment = new TestEnvironment(TestContext))
  49. {
  50. await testEnvironment.StartServerAsync();
  51. var client = await testEnvironment.ConnectClientAsync();
  52. await client.PingAsync(CancellationToken.None);
  53. }
  54. }
  55. [TestMethod]
  56. public async Task Send_Reply_In_Message_Handler_For_Same_Client()
  57. {
  58. using (var testEnvironment = new TestEnvironment(TestContext))
  59. {
  60. await testEnvironment.StartServerAsync();
  61. var client = await testEnvironment.ConnectClientAsync();
  62. await client.SubscribeAsync("#");
  63. var replyReceived = false;
  64. client.UseApplicationMessageReceivedHandler(c =>
  65. {
  66. if (c.ApplicationMessage.Topic == "request")
  67. {
  68. #pragma warning disable 4014
  69. Task.Run(() => client.PublishAsync("reply", null, MqttQualityOfServiceLevel.AtLeastOnce));
  70. #pragma warning restore 4014
  71. }
  72. else
  73. {
  74. replyReceived = true;
  75. }
  76. });
  77. await client.PublishAsync("request", null, MqttQualityOfServiceLevel.AtLeastOnce);
  78. SpinWait.SpinUntil(() => replyReceived, TimeSpan.FromSeconds(10));
  79. Assert.IsTrue(replyReceived);
  80. }
  81. }
  82. [TestMethod]
  83. public async Task Send_Reply_In_Message_Handler()
  84. {
  85. using (var testEnvironment = new TestEnvironment(TestContext))
  86. {
  87. await testEnvironment.StartServerAsync();
  88. var client1 = await testEnvironment.ConnectClientAsync();
  89. var client2 = await testEnvironment.ConnectClientAsync();
  90. await client1.SubscribeAsync("#");
  91. await client2.SubscribeAsync("#");
  92. var replyReceived = false;
  93. client1.UseApplicationMessageReceivedHandler(c =>
  94. {
  95. if (c.ApplicationMessage.Topic == "reply")
  96. {
  97. replyReceived = true;
  98. }
  99. });
  100. client2.UseApplicationMessageReceivedHandler(async c =>
  101. {
  102. // Use AtMostOnce here because with QoS 1 or even QoS 2 the process waits for
  103. // the ACK etc. The problem is that the SpinUntil below only waits until the
  104. // flag is set. It does not wait until the client has sent the ACK
  105. await client2.PublishAsync("reply", null, MqttQualityOfServiceLevel.AtMostOnce);
  106. });
  107. await client1.PublishAsync("request", null, MqttQualityOfServiceLevel.AtLeastOnce);
  108. SpinWait.SpinUntil(() => replyReceived, TimeSpan.FromSeconds(10));
  109. Assert.IsTrue(replyReceived);
  110. }
  111. }
  112. [TestMethod]
  113. public async Task Reconnect()
  114. {
  115. using (var testEnvironment = new TestEnvironment(TestContext))
  116. {
  117. var server = await testEnvironment.StartServerAsync();
  118. var client = await testEnvironment.ConnectClientAsync();
  119. await Task.Delay(500);
  120. Assert.IsTrue(client.IsConnected);
  121. await server.StopAsync();
  122. await Task.Delay(500);
  123. Assert.IsFalse(client.IsConnected);
  124. await server.StartAsync(new MqttServerOptionsBuilder().WithDefaultEndpointPort(testEnvironment.ServerPort).Build());
  125. await Task.Delay(500);
  126. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1", testEnvironment.ServerPort).Build());
  127. Assert.IsTrue(client.IsConnected);
  128. }
  129. }
  130. [TestMethod]
  131. public async Task Reconnect_While_Server_Offline()
  132. {
  133. using (var testEnvironment = new TestEnvironment(TestContext))
  134. {
  135. testEnvironment.IgnoreClientLogErrors = true;
  136. var server = await testEnvironment.StartServerAsync();
  137. var client = await testEnvironment.ConnectClientAsync();
  138. await Task.Delay(500);
  139. Assert.IsTrue(client.IsConnected);
  140. await server.StopAsync();
  141. await Task.Delay(500);
  142. Assert.IsFalse(client.IsConnected);
  143. for (var i = 0; i < 5; i++)
  144. {
  145. try
  146. {
  147. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1", testEnvironment.ServerPort).Build());
  148. Assert.Fail("Must fail!");
  149. }
  150. catch
  151. {
  152. }
  153. }
  154. await server.StartAsync(new MqttServerOptionsBuilder().WithDefaultEndpointPort(testEnvironment.ServerPort).Build());
  155. await Task.Delay(500);
  156. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1", testEnvironment.ServerPort).Build());
  157. Assert.IsTrue(client.IsConnected);
  158. }
  159. }
  160. [TestMethod]
  161. public async Task Reconnect_From_Disconnected_Event()
  162. {
  163. using (var testEnvironment = new TestEnvironment(TestContext))
  164. {
  165. testEnvironment.IgnoreClientLogErrors = true;
  166. var client = testEnvironment.CreateClient();
  167. var tries = 0;
  168. var maxTries = 3;
  169. client.UseDisconnectedHandler(async e =>
  170. {
  171. if (tries >= maxTries)
  172. {
  173. return;
  174. }
  175. Interlocked.Increment(ref tries);
  176. await Task.Delay(100);
  177. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1", testEnvironment.ServerPort).Build());
  178. });
  179. try
  180. {
  181. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1", testEnvironment.ServerPort).Build());
  182. Assert.Fail("Must fail!");
  183. }
  184. catch
  185. {
  186. }
  187. SpinWait.SpinUntil(() => tries >= maxTries, 10000);
  188. Assert.AreEqual(maxTries, tries);
  189. }
  190. }
  191. [TestMethod]
  192. public async Task PacketIdentifier_In_Publish_Result()
  193. {
  194. using (var testEnvironment = new TestEnvironment(TestContext))
  195. {
  196. await testEnvironment.StartServerAsync();
  197. var client = await testEnvironment.ConnectClientAsync();
  198. var result = await client.PublishAsync("a", "a", MqttQualityOfServiceLevel.AtMostOnce);
  199. Assert.AreEqual(null, result.PacketIdentifier);
  200. result = await client.PublishAsync("b", "b", MqttQualityOfServiceLevel.AtMostOnce);
  201. Assert.AreEqual(null, result.PacketIdentifier);
  202. result = await client.PublishAsync("a", "a", MqttQualityOfServiceLevel.AtLeastOnce);
  203. Assert.AreEqual((ushort)1, result.PacketIdentifier);
  204. result = await client.PublishAsync("b", "b", MqttQualityOfServiceLevel.AtLeastOnce);
  205. Assert.AreEqual((ushort)2, result.PacketIdentifier);
  206. result = await client.PublishAsync("a", "a", MqttQualityOfServiceLevel.ExactlyOnce);
  207. Assert.AreEqual((ushort)3, result.PacketIdentifier);
  208. result = await client.PublishAsync("b", "b", MqttQualityOfServiceLevel.ExactlyOnce);
  209. Assert.AreEqual((ushort)4, result.PacketIdentifier);
  210. }
  211. }
  212. [TestMethod]
  213. public async Task Invalid_Connect_Throws_Exception()
  214. {
  215. var factory = new MqttFactory();
  216. using (var client = factory.CreateMqttClient())
  217. {
  218. try
  219. {
  220. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("wrong-server").Build());
  221. Assert.Fail("Must fail!");
  222. }
  223. catch (Exception exception)
  224. {
  225. Assert.IsNotNull(exception);
  226. Assert.IsInstanceOfType(exception, typeof(MqttCommunicationException));
  227. Assert.IsInstanceOfType(exception.InnerException, typeof(SocketException));
  228. }
  229. }
  230. }
  231. [TestMethod]
  232. public async Task ConnectTimeout_Throws_Exception()
  233. {
  234. var factory = new MqttFactory();
  235. using (var client = factory.CreateMqttClient())
  236. {
  237. bool disconnectHandlerCalled = false;
  238. try
  239. {
  240. client.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(args =>
  241. {
  242. disconnectHandlerCalled = true;
  243. });
  244. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("1.2.3.4").Build());
  245. Assert.Fail("Must fail!");
  246. }
  247. catch (Exception exception)
  248. {
  249. Assert.IsNotNull(exception);
  250. Assert.IsInstanceOfType(exception, typeof(MqttCommunicationException));
  251. //Assert.IsInstanceOfType(exception.InnerException, typeof(SocketException));
  252. }
  253. await Task.Delay(100); // disconnected handler is called async
  254. Assert.IsTrue(disconnectHandlerCalled);
  255. }
  256. }
  257. [TestMethod]
  258. public async Task Fire_Disconnected_Event_On_Server_Shutdown()
  259. {
  260. using (var testEnvironment = new TestEnvironment(TestContext))
  261. {
  262. var server = await testEnvironment.StartServerAsync();
  263. var client = await testEnvironment.ConnectClientAsync();
  264. var handlerFired = false;
  265. client.UseDisconnectedHandler(e => handlerFired = true);
  266. await server.StopAsync();
  267. await Task.Delay(4000);
  268. Assert.IsTrue(handlerFired);
  269. }
  270. }
  271. [TestMethod]
  272. public async Task Disconnect_Event_Contains_Exception()
  273. {
  274. var factory = new MqttFactory();
  275. using (var client = factory.CreateMqttClient())
  276. {
  277. Exception ex = null;
  278. client.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(e =>
  279. {
  280. ex = e.Exception;
  281. });
  282. try
  283. {
  284. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("wrong-server").Build());
  285. }
  286. catch
  287. {
  288. }
  289. await Task.Delay(500);
  290. Assert.IsNotNull(ex);
  291. Assert.IsInstanceOfType(ex, typeof(MqttCommunicationException));
  292. Assert.IsInstanceOfType(ex.InnerException, typeof(SocketException));
  293. }
  294. }
  295. [TestMethod]
  296. public async Task Preserve_Message_Order()
  297. {
  298. // The messages are sent in reverse or to ensure that the delay in the handler
  299. // needs longer for the first messages and later messages may be processed earlier (if there
  300. // is an issue).
  301. const int MessagesCount = 50;
  302. using (var testEnvironment = new TestEnvironment(TestContext))
  303. {
  304. await testEnvironment.StartServerAsync();
  305. var client1 = await testEnvironment.ConnectClientAsync();
  306. await client1.SubscribeAsync("x");
  307. var receivedValues = new List<int>();
  308. async Task Handler1(MqttApplicationMessageReceivedEventArgs eventArgs)
  309. {
  310. var value = int.Parse(eventArgs.ApplicationMessage.ConvertPayloadToString());
  311. await Task.Delay(value);
  312. lock (receivedValues)
  313. {
  314. receivedValues.Add(value);
  315. }
  316. }
  317. client1.UseApplicationMessageReceivedHandler(Handler1);
  318. var client2 = await testEnvironment.ConnectClientAsync();
  319. for (var i = MessagesCount; i > 0; i--)
  320. {
  321. await client2.PublishAsync("x", i.ToString());
  322. }
  323. await Task.Delay(5000);
  324. for (var i = MessagesCount; i > 0; i--)
  325. {
  326. Assert.AreEqual(i, receivedValues[MessagesCount - i]);
  327. }
  328. }
  329. }
  330. [TestMethod]
  331. public async Task Send_Reply_For_Any_Received_Message()
  332. {
  333. using (var testEnvironment = new TestEnvironment(TestContext))
  334. {
  335. await testEnvironment.StartServerAsync();
  336. var client1 = await testEnvironment.ConnectClientAsync();
  337. await client1.SubscribeAsync("request/+");
  338. async Task Handler1(MqttApplicationMessageReceivedEventArgs eventArgs)
  339. {
  340. await client1.PublishAsync($"reply/{eventArgs.ApplicationMessage.Topic}");
  341. }
  342. client1.UseApplicationMessageReceivedHandler(Handler1);
  343. var client2 = await testEnvironment.ConnectClientAsync();
  344. await client2.SubscribeAsync("reply/#");
  345. var replies = new List<string>();
  346. void Handler2(MqttApplicationMessageReceivedEventArgs eventArgs)
  347. {
  348. lock (replies)
  349. {
  350. replies.Add(eventArgs.ApplicationMessage.Topic);
  351. }
  352. }
  353. client2.UseApplicationMessageReceivedHandler((Action<MqttApplicationMessageReceivedEventArgs>)Handler2);
  354. await Task.Delay(500);
  355. await client2.PublishAsync("request/a");
  356. await client2.PublishAsync("request/b");
  357. await client2.PublishAsync("request/c");
  358. await Task.Delay(500);
  359. Assert.AreEqual("reply/request/a,reply/request/b,reply/request/c", string.Join(",", replies));
  360. }
  361. }
  362. [TestMethod]
  363. public async Task Publish_With_Correct_Retain_Flag()
  364. {
  365. using (var testEnvironment = new TestEnvironment(TestContext))
  366. {
  367. await testEnvironment.StartServerAsync();
  368. var receivedMessages = new List<MqttApplicationMessage>();
  369. var client1 = await testEnvironment.ConnectClientAsync();
  370. client1.UseApplicationMessageReceivedHandler(c =>
  371. {
  372. lock (receivedMessages)
  373. {
  374. receivedMessages.Add(c.ApplicationMessage);
  375. }
  376. });
  377. await client1.SubscribeAsync("a");
  378. var client2 = await testEnvironment.ConnectClientAsync();
  379. var message = new MqttApplicationMessageBuilder().WithTopic("a").WithRetainFlag().Build();
  380. await client2.PublishAsync(message);
  381. await Task.Delay(500);
  382. Assert.AreEqual(1, receivedMessages.Count);
  383. Assert.IsFalse(receivedMessages.First().Retain); // Must be false even if set above!
  384. }
  385. }
  386. [TestMethod]
  387. public async Task Publish_QoS_1_In_ApplicationMessageReceiveHandler()
  388. {
  389. using (var testEnvironment = new TestEnvironment(TestContext))
  390. {
  391. await testEnvironment.StartServerAsync();
  392. const string client1Topic = "client1/topic";
  393. const string client2Topic = "client2/topic";
  394. const string expectedClient2Message = "hello client2";
  395. var client1 = await testEnvironment.ConnectClientAsync();
  396. client1.UseApplicationMessageReceivedHandler(async c =>
  397. {
  398. await client1.PublishAsync(client2Topic, expectedClient2Message, MqttQualityOfServiceLevel.AtLeastOnce);
  399. });
  400. await client1.SubscribeAsync(client1Topic, MqttQualityOfServiceLevel.AtLeastOnce);
  401. var client2 = await testEnvironment.ConnectClientAsync();
  402. var client2TopicResults = new List<string>();
  403. client2.UseApplicationMessageReceivedHandler(c =>
  404. {
  405. client2TopicResults.Add(Encoding.UTF8.GetString(c.ApplicationMessage.Payload));
  406. });
  407. await client2.SubscribeAsync(client2Topic);
  408. var client3 = await testEnvironment.ConnectClientAsync();
  409. var message = new MqttApplicationMessageBuilder().WithTopic(client1Topic).Build();
  410. await client3.PublishAsync(message);
  411. await client3.PublishAsync(message);
  412. await Task.Delay(500);
  413. Assert.AreEqual(2, client2TopicResults.Count);
  414. Assert.AreEqual(expectedClient2Message, client2TopicResults[0]);
  415. Assert.AreEqual(expectedClient2Message, client2TopicResults[1]);
  416. }
  417. }
  418. [TestMethod]
  419. public async Task Subscribe_In_Callback_Events()
  420. {
  421. using (var testEnvironment = new TestEnvironment(TestContext))
  422. {
  423. await testEnvironment.StartServerAsync();
  424. var receivedMessages = new List<MqttApplicationMessage>();
  425. var client = testEnvironment.CreateClient();
  426. client.ConnectedHandler = new MqttClientConnectedHandlerDelegate(async e =>
  427. {
  428. await client.SubscribeAsync("RCU/P1/H0001/R0003");
  429. var msg = new MqttApplicationMessageBuilder()
  430. .WithPayload("DA|18RS00SC00XI0000RV00R100R200R300R400L100L200L300L400Y100Y200AC0102031800BELK0000BM0000|")
  431. .WithTopic("RCU/P1/H0001/R0003");
  432. await client.PublishAsync(msg.Build());
  433. });
  434. client.UseApplicationMessageReceivedHandler(c =>
  435. {
  436. lock (receivedMessages)
  437. {
  438. receivedMessages.Add(c.ApplicationMessage);
  439. }
  440. });
  441. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("localhost", testEnvironment.ServerPort).Build());
  442. await Task.Delay(500);
  443. Assert.AreEqual(1, receivedMessages.Count);
  444. Assert.AreEqual("DA|18RS00SC00XI0000RV00R100R200R300R400L100L200L300L400Y100Y200AC0102031800BELK0000BM0000|", receivedMessages.First().ConvertPayloadToString());
  445. }
  446. }
  447. [TestMethod]
  448. public async Task Message_Send_Retry()
  449. {
  450. using (var testEnvironment = new TestEnvironment(TestContext))
  451. {
  452. testEnvironment.IgnoreClientLogErrors = true;
  453. testEnvironment.IgnoreServerLogErrors = true;
  454. await testEnvironment.StartServerAsync(
  455. new MqttServerOptionsBuilder()
  456. .WithPersistentSessions()
  457. .WithDefaultCommunicationTimeout(TimeSpan.FromMilliseconds(250)));
  458. var client1 = await testEnvironment.ConnectClientAsync(new MqttClientOptionsBuilder().WithCleanSession(false));
  459. await client1.SubscribeAsync("x", MqttQualityOfServiceLevel.AtLeastOnce);
  460. var retries = 0;
  461. async Task Handler1(MqttApplicationMessageReceivedEventArgs eventArgs)
  462. {
  463. retries++;
  464. await Task.Delay(1000);
  465. throw new Exception("Broken!");
  466. }
  467. client1.UseApplicationMessageReceivedHandler(Handler1);
  468. var client2 = await testEnvironment.ConnectClientAsync();
  469. await client2.PublishAsync("x");
  470. await Task.Delay(3000);
  471. // The server should disconnect clients which are not responding.
  472. Assert.IsFalse(client1.IsConnected);
  473. await client1.ReconnectAsync().ConfigureAwait(false);
  474. await Task.Delay(1000);
  475. Assert.AreEqual(2, retries);
  476. }
  477. }
  478. [TestMethod]
  479. public async Task NoConnectedHandler_Connect_DoesNotThrowException()
  480. {
  481. using (var testEnvironment = new TestEnvironment(TestContext))
  482. {
  483. await testEnvironment.StartServerAsync();
  484. var client = await testEnvironment.ConnectClientAsync();
  485. Assert.IsTrue(client.IsConnected);
  486. }
  487. }
  488. [TestMethod]
  489. public async Task NoDisconnectedHandler_Disconnect_DoesNotThrowException()
  490. {
  491. using (var testEnvironment = new TestEnvironment(TestContext))
  492. {
  493. await testEnvironment.StartServerAsync();
  494. var client = await testEnvironment.ConnectClientAsync();
  495. Assert.IsTrue(client.IsConnected);
  496. await client.DisconnectAsync();
  497. Assert.IsFalse(client.IsConnected);
  498. }
  499. }
  500. [TestMethod]
  501. public async Task Frequent_Connects()
  502. {
  503. using (var testEnvironment = new TestEnvironment(TestContext))
  504. {
  505. await testEnvironment.StartServerAsync();
  506. var clients = new List<IMqttClient>();
  507. for (var i = 0; i < 100; i++)
  508. {
  509. clients.Add(await testEnvironment.ConnectClientAsync(new MqttClientOptionsBuilder().WithClientId("a")));
  510. }
  511. await Task.Delay(500);
  512. var clientStatus = await testEnvironment.Server.GetClientStatusAsync();
  513. var sessionStatus = await testEnvironment.Server.GetSessionStatusAsync();
  514. for (var i = 0; i < 98; i++)
  515. {
  516. Assert.IsFalse(clients[i].IsConnected, $"clients[{i}] is not connected");
  517. }
  518. Assert.IsTrue(clients[99].IsConnected);
  519. Assert.AreEqual(1, clientStatus.Count);
  520. Assert.AreEqual(1, sessionStatus.Count);
  521. var receiveClient = clients[99];
  522. object receivedPayload = null;
  523. receiveClient.UseApplicationMessageReceivedHandler(e =>
  524. {
  525. receivedPayload = e.ApplicationMessage.ConvertPayloadToString();
  526. });
  527. await receiveClient.SubscribeAsync("x");
  528. var sendClient = await testEnvironment.ConnectClientAsync();
  529. await sendClient.PublishAsync("x", "1");
  530. await Task.Delay(250);
  531. Assert.AreEqual("1", receivedPayload);
  532. }
  533. }
  534. [TestMethod]
  535. public async Task No_Payload()
  536. {
  537. using (var testEnvironment = new TestEnvironment(TestContext))
  538. {
  539. await testEnvironment.StartServerAsync();
  540. var sender = await testEnvironment.ConnectClientAsync();
  541. var receiver = await testEnvironment.ConnectClientAsync();
  542. var message = new MqttApplicationMessageBuilder()
  543. .WithTopic("A");
  544. await receiver.SubscribeAsync(new MqttClientSubscribeOptions
  545. {
  546. TopicFilters = new List<MqttTopicFilter> { new MqttTopicFilter { Topic = "#" } }
  547. }, CancellationToken.None);
  548. MqttApplicationMessage receivedMessage = null;
  549. receiver.UseApplicationMessageReceivedHandler(e => receivedMessage = e.ApplicationMessage);
  550. await sender.PublishAsync(message.Build(), CancellationToken.None);
  551. await Task.Delay(1000);
  552. Assert.IsNotNull(receivedMessage);
  553. Assert.AreEqual("A", receivedMessage.Topic);
  554. Assert.AreEqual(null, receivedMessage.Payload);
  555. }
  556. }
  557. }
  558. }