fixed disconnect to be triggered just once

This commit is contained in:
JanEggers
2018-07-19 21:13:28 +02:00
parent 0dea9e6a2b
commit e6cfef5295
3 changed files with 30 additions and 13 deletions
+8 -5
View File
@@ -1,4 +1,5 @@
using System.Net.Sockets;
using System;
using System.Net.Sockets;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Client;
@@ -16,10 +17,10 @@ namespace MQTTnet.Core.Tests
var factory = new MqttFactory();
var client = factory.CreateMqttClient();
var exceptionIsCorrect = false;
Exception ex = null;
client.Disconnected += (s, e) =>
{
exceptionIsCorrect = e.Exception is MqttCommunicationException c && c.InnerException is SocketException;
ex = e.Exception;
};
try
@@ -29,8 +30,10 @@ namespace MQTTnet.Core.Tests
catch
{
}
Assert.IsTrue(exceptionIsCorrect);
Assert.IsNotNull(ex);
Assert.IsInstanceOfType(ex, typeof(MqttCommunicationException));
Assert.IsInstanceOfType(ex.InnerException, typeof(SocketException));
}
}
}
+3 -3
View File
@@ -244,12 +244,12 @@ namespace MQTTnet.Core.Tests
.WithTcpServer("localhost")
.Build();
bool disconnectCalled = false;
var disconnectCalled = 0;
await s.StartAsync(new MqttServerOptions());
var c1 = new MqttFactory().CreateMqttClient();
c1.Disconnected += (sender, args) => disconnectCalled = true;
c1.Disconnected += (sender, args) => disconnectCalled++;
await c1.ConnectAsync(clientOptions);
@@ -259,7 +259,7 @@ namespace MQTTnet.Core.Tests
await Task.Delay(100);
Assert.IsTrue(disconnectCalled);
Assert.AreEqual(1, disconnectCalled);
}
[TestMethod]