From 328ffc734fe1d6b6fcdd257444682c47c32bd586 Mon Sep 17 00:00:00 2001 From: JanEggers Date: Sat, 28 Dec 2019 15:55:35 +0100 Subject: [PATCH] dont allow publish before the client is started and adjusted testclient accordingly --- .../MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs | 3 +-- Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs index 9bb1e54..d12a6a3 100644 --- a/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs +++ b/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs @@ -49,8 +49,6 @@ namespace MQTTnet.Extensions.ManagedClient if (logger == null) throw new ArgumentNullException(nameof(logger)); _logger = logger.CreateChildLogger(nameof(ManagedMqttClient)); - - Options = new ManagedMqttClientOptions(); } public bool IsConnected => _mqttClient.IsConnected; @@ -150,6 +148,7 @@ namespace MQTTnet.Extensions.ManagedClient ThrowIfDisposed(); if (applicationMessage == null) throw new ArgumentNullException(nameof(applicationMessage)); + if (Options == null) throw new InvalidOperationException("call StartAsync before publishing messages"); MqttTopicValidator.ThrowIfInvalid(applicationMessage.ApplicationMessage.Topic); diff --git a/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs b/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs index dc7d925..c4fd68f 100644 --- a/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs +++ b/Tests/MQTTnet.TestApp.NetCore/ManagedClientTest.cs @@ -40,11 +40,11 @@ namespace MQTTnet.TestApp.NetCore Console.WriteLine(">> RECEIVED: " + e.ApplicationMessage.Topic); }); - await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("1")); - await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("2").WithAtLeastOnceQoS()); - await managedClient.StartAsync(options); + await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("1")); + await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("2").WithAtLeastOnceQoS()); + await managedClient.SubscribeAsync(new TopicFilter { Topic = "xyz", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce }); await managedClient.SubscribeAsync(new TopicFilter { Topic = "abc", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });