mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-15 00:15:15 +08:00
* Add support for binary user properties in MQTT 5.0 * Optimize byte array reversal in SubscriptionTopicHashTests * Use InvariantCulture for topic string conversion in Load_Tests * switched to `Microsoft.Testing.Platform` * Refactor CI workflow to separate signed and unsigned package builds * Add condition to sign job to prevent execution on external pull requests * Remove fallback to value as string in MqttUserProperty * Refactor MqttUserProperty handling to use byte arrays for improved performance and add deprecation warnings for legacy methods
59 lines
2.4 KiB
C#
59 lines
2.4 KiB
C#
using System.Text;
|
|
using MQTTnet.Formatter;
|
|
|
|
namespace MQTTnet.Tests.Server;
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
[TestClass]
|
|
public sealed class Cross_Version_Tests : BaseTestClass
|
|
{
|
|
[TestMethod]
|
|
public async Task Send_V311_Receive_V500()
|
|
{
|
|
using var testEnvironment = CreateTestEnvironment();
|
|
await testEnvironment.StartServer();
|
|
|
|
var receiver = await testEnvironment.ConnectClient(o => o.WithProtocolVersion(MqttProtocolVersion.V500));
|
|
var receivedApplicationMessages = testEnvironment.CreateApplicationMessageHandler(receiver);
|
|
await receiver.SubscribeAsync("#");
|
|
|
|
var sender = await testEnvironment.ConnectClient();
|
|
|
|
var applicationMessage = new MqttApplicationMessageBuilder().WithTopic("My/Message").WithPayload("My_Payload").Build();
|
|
await sender.PublishAsync(applicationMessage);
|
|
|
|
await LongTestDelay();
|
|
|
|
Assert.HasCount(1, receivedApplicationMessages.ReceivedEventArgs);
|
|
Assert.AreEqual("My/Message", receivedApplicationMessages.ReceivedEventArgs[0].ApplicationMessage.Topic);
|
|
Assert.AreEqual("My_Payload", receivedApplicationMessages.ReceivedEventArgs[0].ApplicationMessage.ConvertPayloadToString());
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task Send_V500_Receive_V311()
|
|
{
|
|
using var testEnvironment = CreateTestEnvironment(MqttProtocolVersion.V500);
|
|
await testEnvironment.StartServer();
|
|
|
|
var receiver = await testEnvironment.ConnectClient(o => o.WithProtocolVersion(MqttProtocolVersion.V311));
|
|
var receivedApplicationMessages = testEnvironment.CreateApplicationMessageHandler(receiver);
|
|
await receiver.SubscribeAsync("#");
|
|
|
|
var sender = await testEnvironment.ConnectClient();
|
|
|
|
var applicationMessage = new MqttApplicationMessageBuilder().WithTopic("My/Message")
|
|
.WithPayload("My_Payload")
|
|
.WithUserProperty("A", Encoding.UTF8.GetBytes("B"))
|
|
.WithResponseTopic("Response")
|
|
.WithCorrelationData(Encoding.UTF8.GetBytes("Correlation"))
|
|
.Build();
|
|
|
|
await sender.PublishAsync(applicationMessage);
|
|
|
|
await LongTestDelay();
|
|
|
|
Assert.HasCount(1, receivedApplicationMessages.ReceivedEventArgs);
|
|
Assert.AreEqual("My/Message", receivedApplicationMessages.ReceivedEventArgs[0].ApplicationMessage.Topic);
|
|
Assert.AreEqual("My_Payload", receivedApplicationMessages.ReceivedEventArgs[0].ApplicationMessage.ConvertPayloadToString());
|
|
}
|
|
} |