Skip to content

Commit

Permalink
Improve unit tests and samples
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Nov 1, 2023
1 parent 00be43e commit 29194fe
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 3 additions & 1 deletion Samples/Client/Client_Subscribe_Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static void ConcurrentProcessingDisableAutoAcknowledge(CancellationToken shutdow
* This sample shows how to achieve concurrent processing and not have message AutoAcknowledged
* This to have a proper QoS1 (at-least-once) experience for what at least MQTT specification can provide
*/
mqttClient.ApplicationMessageReceivedAsync += async ea =>
mqttClient.ApplicationMessageReceivedAsync += ea =>
{
ea.AutoAcknowledge = false;

Expand All @@ -201,6 +201,8 @@ async Task ProcessAsync()
}

_ = Task.Run(ProcessAsync, shutdownToken);

return Task.CompletedTask;
};
}

Expand Down
2 changes: 1 addition & 1 deletion Source/MQTTnet.Tests/MQTTv5/Client_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public async Task Publish_And_Receive_New_Properties()
Assert.AreEqual(applicationMessage.ResponseTopic, receivedMessage.ResponseTopic);
Assert.AreEqual(applicationMessage.MessageExpiryInterval, receivedMessage.MessageExpiryInterval);
CollectionAssert.AreEqual(applicationMessage.CorrelationData, receivedMessage.CorrelationData);
CollectionAssert.AreEqual(applicationMessage.Payload, receivedMessage.Payload);
CollectionAssert.AreEqual(applicationMessage.PayloadSegment.ToArray(), receivedMessage.PayloadSegment.ToArray());
CollectionAssert.AreEqual(applicationMessage.UserProperties, receivedMessage.UserProperties);
}
}
Expand Down
19 changes: 8 additions & 11 deletions Source/MQTTnet.Tests/MqttApplicationMessageTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CS0618 // Type or member is obsolete

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
Expand All @@ -8,7 +10,7 @@
namespace MQTTnet.Tests
{
[TestClass]
public class MqttApplicationMessageTest
public sealed class MqttApplicationMessageTest
{
[TestMethod]
public void PayloadSegment()
Expand All @@ -17,32 +19,27 @@ public void PayloadSegment()
Assert.AreEqual(0, message.Payload.Length);
Assert.AreEqual(0, message.PayloadSegment.Count);

Assert.IsTrue(object.ReferenceEquals(message.Payload, message.Payload));
Assert.IsTrue(object.ReferenceEquals(message.Payload, message.PayloadSegment.Array));
Assert.IsTrue(ReferenceEquals(message.Payload, message.PayloadSegment.Array));

message.Payload = new byte[] { 1, 2 };
Assert.AreEqual(2, message.Payload.Length);
Assert.AreEqual(2, message.PayloadSegment.Count);
Assert.IsTrue(object.ReferenceEquals(message.Payload, message.Payload));
Assert.IsTrue(object.ReferenceEquals(message.Payload, message.PayloadSegment.Array));
Assert.IsTrue(ReferenceEquals(message.Payload, message.PayloadSegment.Array));

message.Payload = new byte[] { 1, 2, 3 };
Assert.AreEqual(3, message.Payload.Length);
Assert.AreEqual(3, message.PayloadSegment.Count);
Assert.IsTrue(object.ReferenceEquals(message.Payload, message.Payload));
Assert.IsTrue(object.ReferenceEquals(message.Payload, message.PayloadSegment.Array));
Assert.IsTrue(ReferenceEquals(message.Payload, message.PayloadSegment.Array));

message.PayloadSegment = new ArraySegment<byte>(new byte[] { 1, 2, 3 });
Assert.AreEqual(3, message.Payload.Length);
Assert.AreEqual(3, message.PayloadSegment.Count);
Assert.IsTrue(object.ReferenceEquals(message.Payload, message.Payload));
Assert.IsTrue(object.ReferenceEquals(message.Payload, message.PayloadSegment.Array));
Assert.IsTrue(ReferenceEquals(message.Payload, message.PayloadSegment.Array));

message.PayloadSegment = new ArraySegment<byte>(new byte[] { 1, 2, 3 }, 1, 1);
Assert.AreEqual(1, message.Payload.Length);
Assert.AreEqual(1, message.PayloadSegment.Count);
Assert.IsTrue(object.ReferenceEquals(message.Payload, message.Payload));
Assert.IsFalse(object.ReferenceEquals(message.Payload, message.PayloadSegment.Array));
Assert.IsFalse(ReferenceEquals(message.Payload, message.PayloadSegment.Array));
}
}
}
4 changes: 3 additions & 1 deletion Source/MQTTnet/Client/Options/MqttClientOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#pragma warning disable CS0612 // Type or member is obsolete

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -37,7 +39,7 @@ public MqttClientOptions Build()
// on the order of called methods from the builder).
// The builder prefers the explicitly set TLS options!
var tlsOptions = _tlsOptions ?? _tcpOptions?.TlsOptions;

if (_tlsParameters != null)
{
if (_tlsParameters?.UseTls == true)
Expand Down

0 comments on commit 29194fe

Please sign in to comment.