diff --git a/Build/MQTTnet.nuspec b/Build/MQTTnet.nuspec
index 9e3a8f5..645ed58 100644
--- a/Build/MQTTnet.nuspec
+++ b/Build/MQTTnet.nuspec
@@ -12,16 +12,7 @@
true
MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker) and supports v3.1.0, v3.1.1 and v5.0.0 of the MQTT protocol.
-* [LowLevelClient] Fixed a null reference exception when connecting to a not existing server (thanks to @SGStino).
-* [RcpClient] Adjusted some namespaces (BREAKING CHANGE!).
-* [AspNetCore] Adjusted some namespaces (BREAKING CHANGE!).
-* [Server] Adjusted some namespaces (BREAKING CHANGE!).
-* [Server] Added state checks (throw if not started etc.) for most server APIs.
-* [Server] Exposed real X509Certificate2 (instead byte array) to TLS options (thanks to @borigas).
-* [Server] Fixed memory leak with TCP sockets (MqttServer is now Disposable!) (BREAKING CHANGE!).
-* [Core] Fixed a null reference exception in the MqttTcpChannel with WriteAsync and ReadAsync.
-* [Core] Added server interceptor for undelivered messages (thanks to @cshark-inator).
-* [nuget] Added support for SourceLink (thanks to @JTOne123).
+* [Client] Fixed wrong value for "ClientWasConnected" in "MqttClientDisconnectedEventArgs" #976 (thanks to @dbeinder).
Copyright Christian Kratky 2016-2020
MQTT Message Queue Telemetry Transport MQTTClient MQTTServer Server MQTTBroker Broker NETStandard IoT InternetOfThings Messaging Hardware Arduino Sensor Actuator M2M ESP Smart Home Cities Automation Xamarin Blazor
diff --git a/Source/MQTTnet/Client/MqttClient.cs b/Source/MQTTnet/Client/MqttClient.cs
index c80dd54..8a045be 100644
--- a/Source/MQTTnet/Client/MqttClient.cs
+++ b/Source/MQTTnet/Client/MqttClient.cs
@@ -254,8 +254,7 @@ namespace MQTTnet.Client
_adapter?.Dispose();
}
-
-
+
protected override void Dispose(bool disposing)
{
if (disposing)
@@ -302,7 +301,7 @@ namespace MQTTnet.Client
async Task DisconnectInternalAsync(Task sender, Exception exception, MqttClientAuthenticateResult authenticateResult)
{
- var clientWasConnected = IsConnected;
+ var clientWasConnected = _isConnected;
var reasonCode = MqttClientDisconnectReason.NormalDisconnection;
TryInitiateDisconnect();
diff --git a/Tests/MQTTnet.Core.Tests/MqttClient_Tests.cs b/Tests/MQTTnet.Core.Tests/MqttClient_Tests.cs
index 87c98c9..16405de 100644
--- a/Tests/MQTTnet.Core.Tests/MqttClient_Tests.cs
+++ b/Tests/MQTTnet.Core.Tests/MqttClient_Tests.cs
@@ -23,6 +23,38 @@ namespace MQTTnet.Tests
{
public TestContext TestContext { get; set; }
+ [TestMethod]
+ public async Task Set_ClientWasConnected_On_ServerDisconnect()
+ {
+ using (var testEnvironment = new TestEnvironment(TestContext))
+ {
+ var server = await testEnvironment.StartServerAsync();
+ var client = await testEnvironment.ConnectClientAsync();
+
+ Assert.IsTrue(client.IsConnected);
+ client.UseDisconnectedHandler(e => Assert.IsTrue(e.ClientWasConnected));
+
+ await server.StopAsync();
+ await Task.Delay(4000);
+ }
+ }
+
+ [TestMethod]
+ public async Task Set_ClientWasConnected_On_ClientDisconnect()
+ {
+ using (var testEnvironment = new TestEnvironment(TestContext))
+ {
+ var server = await testEnvironment.StartServerAsync();
+ var client = await testEnvironment.ConnectClientAsync();
+
+ Assert.IsTrue(client.IsConnected);
+ client.UseDisconnectedHandler(e => Assert.IsTrue(e.ClientWasConnected));
+
+ await client.DisconnectAsync();
+ await Task.Delay(200);
+ }
+ }
+
[TestMethod]
[ExpectedException(typeof(MqttCommunicationTimedOutException))]
public async Task Connect_To_Invalid_Server_Wrong_IP()