mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 17:23:04 +08:00
40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using System;
|
|
using System.Net.Sockets;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using MQTTnet.Client;
|
|
using MQTTnet.Diagnostics;
|
|
using MQTTnet.Exceptions;
|
|
using MQTTnet.Implementations;
|
|
using MQTTnet.Server;
|
|
|
|
namespace MQTTnet.Core.Tests
|
|
{
|
|
[TestClass]
|
|
public class MqttClientTests
|
|
{
|
|
[TestMethod]
|
|
public async Task ClientDisconnectException()
|
|
{
|
|
var factory = new MqttFactory();
|
|
var client = factory.CreateMqttClient();
|
|
|
|
var exceptionIsCorrect = false;
|
|
client.Disconnected += (s, e) =>
|
|
{
|
|
exceptionIsCorrect = e.Exception is MqttCommunicationException c && c.InnerException is SocketException;
|
|
};
|
|
|
|
try
|
|
{
|
|
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("wrong-server").Build());
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
|
|
Assert.IsTrue(exceptionIsCorrect);
|
|
}
|
|
}
|
|
}
|