From 16cbddb13631e4644d7b7ebcd734f1acf5778ea5 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Wed, 29 May 2024 11:32:48 +0200 Subject: [PATCH] Improved Package Spec & Reduced Warnings (#168) --- Source/HiveMQtt/HiveMQtt.csproj | 16 +++---- .../Operational/QueuedPublishesTest.cs | 3 +- .../HiveMQClient/PublishBuilderTest.cs | 44 ++++++++++--------- .../HiveMQtt.Test/HiveMQClient/PublishTest.cs | 2 +- Tests/HiveMQtt.Test/HiveMQtt.Test.csproj | 2 +- 5 files changed, 33 insertions(+), 34 deletions(-) diff --git a/Source/HiveMQtt/HiveMQtt.csproj b/Source/HiveMQtt/HiveMQtt.csproj index 7e9e30bc..e5f7f8ec 100644 --- a/Source/HiveMQtt/HiveMQtt.csproj +++ b/Source/HiveMQtt/HiveMQtt.csproj @@ -1,23 +1,21 @@ - HiveMQtt - The HiveMQ MQTT Client is a MQTT 5.0 compatible C# library. - - - - net6.0;net7.0;net8.0 + net6.0;net7.0;net8.0; true - + true + + true + snupkg - v HiveMQtt The HiveMQ MQTT Client is a MQTT 5.0 compatible C# library. - MQTT;HIVEMQ;IOT + MQTT;HIVEMQ;IOT;MQTTClient;MQTT5;QoS;MQTTTopics;IndustrialIoT;ConnectedDevices;EdgeComputing;IoTDevices;Queue;Message;EmbeddedSystems;M2M;SensorNetwork + Copyright (c) HiveMQ GmbH diff --git a/Tests/HiveMQtt.Test/HiveMQClient/Operational/QueuedPublishesTest.cs b/Tests/HiveMQtt.Test/HiveMQClient/Operational/QueuedPublishesTest.cs index 9f5000dd..644e181a 100644 --- a/Tests/HiveMQtt.Test/HiveMQClient/Operational/QueuedPublishesTest.cs +++ b/Tests/HiveMQtt.Test/HiveMQClient/Operational/QueuedPublishesTest.cs @@ -10,7 +10,6 @@ public class QueuedPublishesTest [Fact] public async Task Queued_Messages_Chain_Async() { - var batchSize = 1000; var tasks = new[] @@ -78,7 +77,7 @@ private async Task RelayClientAsync() // Republish the Message to the second topic var payload = args.PublishMessage.Payload; var publishResult = await subscribeClient.PublishAsync(secondTopic, payload, QualityOfService.ExactlyOnceDelivery).ConfigureAwait(false); - Assert.NotNull(publishResult.QoS2ReasonCode); + Assert.NotNull(publishResult?.QoS2ReasonCode); // Atomically increment the relayCount Interlocked.Increment(ref relayCount); diff --git a/Tests/HiveMQtt.Test/HiveMQClient/PublishBuilderTest.cs b/Tests/HiveMQtt.Test/HiveMQClient/PublishBuilderTest.cs index e2f344a6..3038f600 100644 --- a/Tests/HiveMQtt.Test/HiveMQClient/PublishBuilderTest.cs +++ b/Tests/HiveMQtt.Test/HiveMQClient/PublishBuilderTest.cs @@ -1,6 +1,5 @@ namespace HiveMQtt.Test.HiveMQClient; -using System.Text; using System.Threading.Tasks; using HiveMQtt.Client; using HiveMQtt.MQTT5.ReasonCodes; @@ -9,6 +8,9 @@ namespace HiveMQtt.Test.HiveMQClient; public class PublishBuilderTest { + + private readonly byte[] payload = { 0x01, 0x02, 0x03 }; + [Fact] public async Task MostBasicPublishWithQoS0Async() { @@ -18,15 +20,15 @@ public async Task MostBasicPublishWithQoS0Async() var message = new PublishMessageBuilder() .WithTopic("tests/MostBasicPublishWithQoS0Async") - .WithPayload(new byte[] { 0x01, 0x02, 0x03 }) - .WithQualityOfService(MQTT5.Types.QualityOfService.AtMostOnceDelivery) + .WithPayload(this.payload) + .WithQualityOfService(QualityOfService.AtMostOnceDelivery) .Build(); var result = await client.PublishAsync(message).ConfigureAwait(false); Assert.IsType(result); Assert.Null(result.QoS1ReasonCode); Assert.Null(result.QoS2ReasonCode); - Assert.Equal(MQTT5.Types.QualityOfService.AtMostOnceDelivery, result.Message.QoS); + Assert.Equal(QualityOfService.AtMostOnceDelivery, result.Message.QoS); var disconnectResult = await client.DisconnectAsync().ConfigureAwait(false); Assert.True(disconnectResult); @@ -41,14 +43,14 @@ public async Task MostBasicPublishWithQoS1Async() var message = new PublishMessageBuilder() .WithTopic("tests/MostBasicPublishWithQoS1Async") - .WithPayload(new byte[] { 0x01, 0x02, 0x03 }) - .WithQualityOfService(MQTT5.Types.QualityOfService.AtLeastOnceDelivery) + .WithPayload(this.payload) + .WithQualityOfService(QualityOfService.AtLeastOnceDelivery) .Build(); var result = await client.PublishAsync(message).ConfigureAwait(false); Assert.IsType(result); Assert.NotNull(result.QoS1ReasonCode); Assert.Null(result.QoS2ReasonCode); - Assert.Equal(MQTT5.Types.QualityOfService.AtLeastOnceDelivery, result.Message.QoS); + Assert.Equal(QualityOfService.AtLeastOnceDelivery, result.Message.QoS); var disconnectResult = await client.DisconnectAsync().ConfigureAwait(false); Assert.True(disconnectResult); @@ -63,14 +65,14 @@ public async Task MostBasicPublishWithQoS2Async() var message = new PublishMessageBuilder() .WithTopic("tests/MostBasicPublishWithQoS1Async") - .WithPayload(new byte[] { 0x01, 0x02, 0x03 }) - .WithQualityOfService(MQTT5.Types.QualityOfService.ExactlyOnceDelivery) + .WithPayload(this.payload) + .WithQualityOfService(QualityOfService.ExactlyOnceDelivery) .Build(); var result = await client.PublishAsync(message).ConfigureAwait(false); Assert.IsType(result); Assert.NotNull(result.QoS2ReasonCode); Assert.Null(result.QoS1ReasonCode); - Assert.Equal(MQTT5.Types.QualityOfService.ExactlyOnceDelivery, result.Message.QoS); + Assert.Equal(QualityOfService.ExactlyOnceDelivery, result.Message.QoS); var disconnectResult = await client.DisconnectAsync().ConfigureAwait(false); Assert.True(disconnectResult); @@ -85,8 +87,8 @@ public async Task MultiPublishWithQoS0Async() var message = new PublishMessageBuilder() .WithTopic("tests/MultiPublishWithQoS0Async") - .WithPayload(new byte[] { 0x01, 0x02, 0x03 }) - .WithQualityOfService(MQTT5.Types.QualityOfService.AtMostOnceDelivery) + .WithPayload(this.payload) + .WithQualityOfService(QualityOfService.AtMostOnceDelivery) .Build(); Client.Results.PublishResult result; @@ -97,7 +99,7 @@ public async Task MultiPublishWithQoS0Async() Assert.IsType(result); Assert.Null(result.QoS1ReasonCode); Assert.Null(result.QoS2ReasonCode); - Assert.Equal(MQTT5.Types.QualityOfService.AtMostOnceDelivery, result.Message.QoS); + Assert.Equal(QualityOfService.AtMostOnceDelivery, result.Message.QoS); } var disconnectResult = await client.DisconnectAsync().ConfigureAwait(false); @@ -113,8 +115,8 @@ public async Task MultiPublishWithQoS1Async() var message = new PublishMessageBuilder() .WithTopic("tests/MultiPublishWithQoS1Async") - .WithPayload(new byte[] { 0x01, 0x02, 0x03 }) - .WithQualityOfService(MQTT5.Types.QualityOfService.AtLeastOnceDelivery) + .WithPayload(this.payload) + .WithQualityOfService(QualityOfService.AtLeastOnceDelivery) .Build(); Client.Results.PublishResult result; @@ -139,8 +141,8 @@ public async Task MultiPublishWithQoS2Async() var message = new PublishMessageBuilder() .WithTopic("tests/MultiPublishWithQoS2Async") - .WithPayload(new byte[] { 0x01, 0x02, 0x03 }) - .WithQualityOfService(MQTT5.Types.QualityOfService.ExactlyOnceDelivery) + .WithPayload(this.payload) + .WithQualityOfService(QualityOfService.ExactlyOnceDelivery) .Build(); Client.Results.PublishResult result; @@ -164,8 +166,8 @@ public async Task PublishWithOptionsAsync() var message = new PublishMessageBuilder() .WithTopic("tests/PublishWithOptionsAsync") - .WithPayload(new byte[] { 0x01, 0x02, 0x03 }) - .WithQualityOfService(MQTT5.Types.QualityOfService.AtMostOnceDelivery) + .WithPayload(this.payload) + .WithQualityOfService(QualityOfService.AtMostOnceDelivery) .WithUserProperty("test", "test") .Build(); @@ -189,8 +191,8 @@ public async Task PublishPayloadFormatIndicatorAsync() var message = new PublishMessageBuilder() .WithTopic("tests/PublishPayloadFormatIndicatorAsync") - .WithPayload(new byte[] { 0x01, 0x02, 0x03 }) - .WithQualityOfService(MQTT5.Types.QualityOfService.AtMostOnceDelivery) + .WithPayload(this.payload) + .WithQualityOfService(QualityOfService.AtMostOnceDelivery) .WithPayloadFormatIndicator(MQTT5PayloadFormatIndicator.UTF8Encoded) .Build(); diff --git a/Tests/HiveMQtt.Test/HiveMQClient/PublishTest.cs b/Tests/HiveMQtt.Test/HiveMQClient/PublishTest.cs index 6c11f63d..8efa7fac 100644 --- a/Tests/HiveMQtt.Test/HiveMQClient/PublishTest.cs +++ b/Tests/HiveMQtt.Test/HiveMQClient/PublishTest.cs @@ -221,7 +221,7 @@ async void Client2MessageHandler(object? sender, OnMessageReceivedEventArgs even // client 3 will receive the final message #pragma warning disable VSTHRD100 // Avoid async void methods - async void Client3MessageHandler(object? sender, OnMessageReceivedEventArgs eventArgs) + void Client3MessageHandler(object? sender, OnMessageReceivedEventArgs eventArgs) { Interlocked.Increment(ref client3MessageCount); Assert.NotNull(eventArgs.PublishMessage); diff --git a/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj b/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj index fdf8f425..9b0d61ee 100644 --- a/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj +++ b/Tests/HiveMQtt.Test/HiveMQtt.Test.csproj @@ -1,7 +1,7 @@ - net8.0 + net8.0; 0.1.0