25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

MqttClientTests.cs 966 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Net.Sockets;
  3. using System.Threading.Tasks;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5. using MQTTnet.Client;
  6. using MQTTnet.Exceptions;
  7. namespace MQTTnet.Core.Tests
  8. {
  9. [TestClass]
  10. public class MqttClientTests
  11. {
  12. [TestMethod]
  13. public async Task ClientDisconnectException()
  14. {
  15. var factory = new MqttFactory();
  16. var client = factory.CreateMqttClient();
  17. var exceptionIsCorrect = false;
  18. client.Disconnected += (s, e) =>
  19. {
  20. exceptionIsCorrect = e.Exception is MqttCommunicationException c && c.InnerException is SocketException;
  21. };
  22. try
  23. {
  24. await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("wrong-server").Build());
  25. }
  26. catch
  27. {
  28. }
  29. Assert.IsTrue(exceptionIsCorrect);
  30. }
  31. }
  32. }