25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MqttClientTests.cs 952 B

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