您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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. }