mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-27 08:42:37 +08:00
Refactor namespaces.
This commit is contained in:
@@ -8,12 +8,13 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Source\MQTTnet.AspnetCore\MQTTnet.AspNetCore.csproj" />
|
||||
<ProjectReference Include="..\..\Source\MQTTnet\MQTTnet.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
#if NETCOREAPP
|
||||
using System.Buffers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.AspNetCore;
|
||||
using MQTTnet.Formatter;
|
||||
using MQTTnet.Formatter.V311;
|
||||
using MQTTnet.Packets;
|
||||
|
||||
namespace MQTTnet.AspNetCore.Tests
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Benchmarks
|
||||
|
||||
@@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||
using MQTTnet.Server;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.AspNetCore.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
|
||||
namespace MQTTnet.Benchmarks
|
||||
{
|
||||
|
||||
@@ -6,6 +6,7 @@ using MQTTnet.Implementations;
|
||||
using MQTTnet.Server;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client.Options;
|
||||
|
||||
namespace MQTTnet.Benchmarks
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Channel;
|
||||
using MQTTnet.Formatter;
|
||||
using MQTTnet.Formatter.V311;
|
||||
using MQTTnet.Formatter.V3;
|
||||
|
||||
namespace MQTTnet.Benchmarks
|
||||
{
|
||||
@@ -56,7 +56,7 @@ namespace MQTTnet.Benchmarks
|
||||
|
||||
var receivedPacket = new ReceivedMqttPacket(
|
||||
header.Flags,
|
||||
new MqttPacketBodyReader(_serializedPacket.Array, (ulong)(_serializedPacket.Count - header.RemainingLength), (ulong)_serializedPacket.Array.Length));
|
||||
new MqttPacketBodyReader(_serializedPacket.Array, (ulong)(_serializedPacket.Count - header.RemainingLength), (ulong)_serializedPacket.Array.Length), 0);
|
||||
|
||||
_serializer.Decode(receivedPacket);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Internal;
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Internal;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
// Inspired from the vs-threading tests (https://github.com/Microsoft/vs-threading/blob/master/src/Microsoft.VisualStudio.Threading.Tests/AsyncAutoResetEventTests.cs)
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Internal;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class AsyncLockTests
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Internal;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class BlockingQueueTests
|
||||
|
||||
@@ -5,7 +5,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Exceptions;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class ExtensionTests
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -0,0 +1,245 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Client.Publishing;
|
||||
using MQTTnet.Client.Subscribing;
|
||||
using MQTTnet.Client.Unsubscribing;
|
||||
using MQTTnet.Formatter;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Tests.MQTTv5
|
||||
{
|
||||
[TestClass]
|
||||
public class Client_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task Client_Connect()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
var client = new MqttFactory().CreateMqttClient();
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Client_Connect_And_Disconnect()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
var client = new MqttFactory().CreateMqttClient();
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
|
||||
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
await client.DisconnectAsync();
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Client_Subscribe()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
var client = new MqttFactory().CreateMqttClient();
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
|
||||
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
var result = await client.SubscribeAsync("a", MqttQualityOfServiceLevel.AtLeastOnce);
|
||||
await client.DisconnectAsync();
|
||||
|
||||
Assert.AreEqual(1, result.Items.Count);
|
||||
Assert.AreEqual(MqttClientSubscribeResultCode.GrantedQoS1, result.Items[0].ResultCode);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Client_Unsubscribe()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
var client = new MqttFactory().CreateMqttClient();
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
|
||||
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
await client.SubscribeAsync("a");
|
||||
var result = await client.UnsubscribeAsync("a");
|
||||
await client.DisconnectAsync();
|
||||
|
||||
Assert.AreEqual(1, result.Items.Count);
|
||||
Assert.AreEqual(MqttClientUnsubscribeResultCode.Success, result.Items[0].ReasonCode);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Client_Publish_QoS0()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
var client = new MqttFactory().CreateMqttClient();
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
|
||||
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
var result = await client.PublishAsync("a", "b");
|
||||
await client.DisconnectAsync();
|
||||
|
||||
Assert.AreEqual(MqttClientPublishReasonCode.Success, result.ReasonCode);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Client_Publish_QoS1()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
var client = new MqttFactory().CreateMqttClient();
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
|
||||
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
var result = await client.PublishAsync("a", "b", MqttQualityOfServiceLevel.AtLeastOnce);
|
||||
await client.DisconnectAsync();
|
||||
|
||||
Assert.AreEqual(MqttClientPublishReasonCode.Success, result.ReasonCode);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Client_Publish_QoS2()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
var client = new MqttFactory().CreateMqttClient();
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
|
||||
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
var result = await client.PublishAsync("a", "b", MqttQualityOfServiceLevel.ExactlyOnce);
|
||||
await client.DisconnectAsync();
|
||||
|
||||
Assert.AreEqual(MqttClientPublishReasonCode.Success, result.ReasonCode);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Client_Publish_With_Properties()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
var client = new MqttFactory().CreateMqttClient();
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
|
||||
var applicationMessage = new MqttApplicationMessageBuilder()
|
||||
.WithTopic("Hello")
|
||||
.WithPayload("World")
|
||||
.WithAtMostOnceQoS()
|
||||
.WithUserProperty("x", "1")
|
||||
.WithUserProperty("y", "2")
|
||||
.WithResponseTopic("response")
|
||||
.WithContentType("text")
|
||||
.WithMessageExpiryInterval(50)
|
||||
.WithCorrelationData(new byte[12])
|
||||
.WithTopicAlias(2)
|
||||
.Build();
|
||||
|
||||
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
var result = await client.PublishAsync(applicationMessage);
|
||||
await client.DisconnectAsync();
|
||||
|
||||
Assert.AreEqual(MqttClientPublishReasonCode.Success, result.ReasonCode);
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task Subscribe_And_Publish()
|
||||
{
|
||||
var server = new MqttFactory().CreateMqttServer();
|
||||
var client1 = new MqttFactory().CreateMqttClient();
|
||||
var client2 = new MqttFactory().CreateMqttClient();
|
||||
|
||||
try
|
||||
{
|
||||
await server.StartAsync(new MqttServerOptions());
|
||||
|
||||
var receivedMessages = new List<MqttApplicationMessageReceivedEventArgs>();
|
||||
|
||||
await client1.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithClientId("client1").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
client1.ApplicationMessageReceived += (s, e) =>
|
||||
{
|
||||
lock (receivedMessages)
|
||||
{
|
||||
receivedMessages.Add(e);
|
||||
}
|
||||
};
|
||||
|
||||
await client1.SubscribeAsync("a");
|
||||
|
||||
await client2.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("127.0.0.1").WithClientId("client2").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
await client2.PublishAsync("a", "b");
|
||||
|
||||
await Task.Delay(500);
|
||||
|
||||
await client2.DisconnectAsync();
|
||||
await client1.DisconnectAsync();
|
||||
|
||||
Assert.AreEqual(1, receivedMessages.Count);
|
||||
Assert.AreEqual("client1", receivedMessages[0].ClientId);
|
||||
Assert.AreEqual("a", receivedMessages[0].ApplicationMessage.Topic);
|
||||
Assert.AreEqual("b", receivedMessages[0].ApplicationMessage.ConvertPayloadToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using MQTTnet.Extensions.ManagedClient;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Extensions.ManagedClient;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class ManagedMqttClientTests
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Protocol;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttApplicationMessageBuilderTests
|
||||
|
||||
@@ -2,17 +2,14 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Exceptions;
|
||||
using MQTTnet.Packets;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttClientTests
|
||||
@@ -128,39 +125,39 @@ namespace MQTTnet.Core.Tests
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
[TestMethod]
|
||||
public async Task Client_Cleanup_On_Authentification_Fails()
|
||||
{
|
||||
var channel = new TestMqttCommunicationAdapter();
|
||||
var channel2 = new TestMqttCommunicationAdapter();
|
||||
channel.Partner = channel2;
|
||||
channel2.Partner = channel;
|
||||
//#if DEBUG
|
||||
// [TestMethod]
|
||||
// public async Task Client_Cleanup_On_Authentification_Fails()
|
||||
// {
|
||||
// var channel = new TestMqttCommunicationAdapter();
|
||||
// var channel2 = new TestMqttCommunicationAdapter();
|
||||
// channel.Partner = channel2;
|
||||
// channel2.Partner = channel;
|
||||
|
||||
Task.Run(async () => {
|
||||
var connect = await channel2.ReceivePacketAsync(TimeSpan.Zero, CancellationToken.None);
|
||||
await channel2.SendPacketAsync(new MqttConnAckPacket
|
||||
{
|
||||
ConnectReturnCode = Protocol.MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
}, CancellationToken.None);
|
||||
});
|
||||
// Task.Run(async () => {
|
||||
// var connect = await channel2.ReceivePacketAsync(TimeSpan.Zero, CancellationToken.None);
|
||||
// await channel2.SendPacketAsync(new MqttConnAckPacket
|
||||
// {
|
||||
// ConnectReturnCode = Protocol.MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
// }, CancellationToken.None);
|
||||
// });
|
||||
|
||||
var fake = new TestMqttCommunicationAdapterFactory(channel);
|
||||
// var fake = new TestMqttCommunicationAdapterFactory(channel);
|
||||
|
||||
var client = new MqttClient(fake, new MqttNetLogger());
|
||||
// var client = new MqttClient(fake, new MqttNetLogger());
|
||||
|
||||
try
|
||||
{
|
||||
await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("any-server").Build());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Assert.IsInstanceOfType(ex, typeof(MqttConnectingFailedException));
|
||||
}
|
||||
// try
|
||||
// {
|
||||
// await client.ConnectAsync(new MqttClientOptionsBuilder().WithTcpServer("any-server").Build());
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// Assert.IsInstanceOfType(ex, typeof(MqttConnectingFailedException));
|
||||
// }
|
||||
|
||||
Assert.IsTrue(client._packetReceiverTask == null || client._packetReceiverTask.IsCompleted, "receive loop not completed");
|
||||
Assert.IsTrue(client._keepAliveMessageSenderTask == null || client._keepAliveMessageSenderTask.IsCompleted, "keepalive loop not completed");
|
||||
}
|
||||
#endif
|
||||
// Assert.IsTrue(client._packetReceiverTask == null || client._packetReceiverTask.IsCompleted, "receive loop not completed");
|
||||
// Assert.IsTrue(client._keepAliveMessageSenderTask == null || client._keepAliveMessageSenderTask.IsCompleted, "keepalive loop not completed");
|
||||
// }
|
||||
//#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Packets;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttKeepAliveMonitorTests
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.VisualStudio.TestTools .UnitTesting;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Client;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttPacketIdentifierProviderTests
|
||||
|
||||
@@ -5,7 +5,7 @@ using MQTTnet.Exceptions;
|
||||
using MQTTnet.Formatter;
|
||||
using MQTTnet.Internal;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttPacketReaderTests
|
||||
|
||||
@@ -6,13 +6,12 @@ using System.Threading;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Formatter;
|
||||
using MQTTnet.Formatter.V310;
|
||||
using MQTTnet.Formatter.V311;
|
||||
using MQTTnet.Formatter.V3;
|
||||
using MQTTnet.Internal;
|
||||
using MQTTnet.Packets;
|
||||
using MQTTnet.Protocol;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttPacketSerializerTests
|
||||
@@ -112,7 +111,7 @@ namespace MQTTnet.Core.Tests
|
||||
var p = new MqttConnAckPacket
|
||||
{
|
||||
IsSessionPresent = true,
|
||||
ConnectReturnCode = MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
ReturnCode = MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
};
|
||||
|
||||
SerializeAndCompare(p, "IAIBBQ==");
|
||||
@@ -123,7 +122,7 @@ namespace MQTTnet.Core.Tests
|
||||
{
|
||||
var p = new MqttConnAckPacket
|
||||
{
|
||||
ConnectReturnCode = MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
ReturnCode = MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
};
|
||||
|
||||
SerializeAndCompare(p, "IAIABQ==", MqttProtocolVersion.V310);
|
||||
@@ -135,7 +134,7 @@ namespace MQTTnet.Core.Tests
|
||||
var p = new MqttConnAckPacket
|
||||
{
|
||||
IsSessionPresent = true,
|
||||
ConnectReturnCode = MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
ReturnCode = MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
};
|
||||
|
||||
DeserializeAndCompare(p, "IAIBBQ==");
|
||||
@@ -146,7 +145,7 @@ namespace MQTTnet.Core.Tests
|
||||
{
|
||||
var p = new MqttConnAckPacket
|
||||
{
|
||||
ConnectReturnCode = MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
ReturnCode = MqttConnectReturnCode.ConnectionRefusedNotAuthorized
|
||||
};
|
||||
|
||||
DeserializeAndCompare(p, "IAIABQ==", MqttProtocolVersion.V310);
|
||||
@@ -189,7 +188,8 @@ namespace MQTTnet.Core.Tests
|
||||
|
||||
var receivedPacket = new ReceivedMqttPacket(
|
||||
header.Flags,
|
||||
new MqttPacketBodyReader(buffer.Array, (uint)eof - header.RemainingLength, (uint)(buffer.Count + buffer.Offset)));
|
||||
new MqttPacketBodyReader(buffer.Array, eof - header.RemainingLength, buffer.Count + buffer.Offset),
|
||||
0);
|
||||
|
||||
var packet = (MqttPublishPacket)serializer.Decode(receivedPacket);
|
||||
|
||||
@@ -401,9 +401,9 @@ namespace MQTTnet.Core.Tests
|
||||
PacketIdentifier = 123
|
||||
};
|
||||
|
||||
p.TopicFilters.Add(new TopicFilter("A/B/C", MqttQualityOfServiceLevel.ExactlyOnce));
|
||||
p.TopicFilters.Add(new TopicFilter("1/2/3", MqttQualityOfServiceLevel.AtLeastOnce));
|
||||
p.TopicFilters.Add(new TopicFilter("x/y/z", MqttQualityOfServiceLevel.AtMostOnce));
|
||||
p.TopicFilters.Add(new TopicFilter { Topic = "A/B/C", QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce });
|
||||
p.TopicFilters.Add(new TopicFilter { Topic = "1/2/3", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce });
|
||||
p.TopicFilters.Add(new TopicFilter { Topic = "x/y/z", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||
|
||||
SerializeAndCompare(p, "ghoAewAFQS9CL0MCAAUxLzIvMwEABXgveS96AA==");
|
||||
}
|
||||
@@ -416,9 +416,9 @@ namespace MQTTnet.Core.Tests
|
||||
PacketIdentifier = 123
|
||||
};
|
||||
|
||||
p.TopicFilters.Add(new TopicFilter("A/B/C", MqttQualityOfServiceLevel.ExactlyOnce));
|
||||
p.TopicFilters.Add(new TopicFilter("1/2/3", MqttQualityOfServiceLevel.AtLeastOnce));
|
||||
p.TopicFilters.Add(new TopicFilter("x/y/z", MqttQualityOfServiceLevel.AtMostOnce));
|
||||
p.TopicFilters.Add(new TopicFilter { Topic = "A/B/C", QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce });
|
||||
p.TopicFilters.Add(new TopicFilter { Topic = "1/2/3", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce });
|
||||
p.TopicFilters.Add(new TopicFilter { Topic = "x/y/z", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||
|
||||
DeserializeAndCompare(p, "ghoAewAFQS9CL0MCAAUxLzIvMwEABXgveS96AA==");
|
||||
}
|
||||
@@ -431,10 +431,10 @@ namespace MQTTnet.Core.Tests
|
||||
PacketIdentifier = 123
|
||||
};
|
||||
|
||||
p.SubscribeReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS0);
|
||||
p.SubscribeReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS1);
|
||||
p.SubscribeReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS2);
|
||||
p.SubscribeReturnCodes.Add(MqttSubscribeReturnCode.Failure);
|
||||
p.ReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS0);
|
||||
p.ReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS1);
|
||||
p.ReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS2);
|
||||
p.ReturnCodes.Add(MqttSubscribeReturnCode.Failure);
|
||||
|
||||
SerializeAndCompare(p, "kAYAewABAoA=");
|
||||
}
|
||||
@@ -447,10 +447,10 @@ namespace MQTTnet.Core.Tests
|
||||
PacketIdentifier = 123
|
||||
};
|
||||
|
||||
p.SubscribeReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS0);
|
||||
p.SubscribeReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS1);
|
||||
p.SubscribeReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS2);
|
||||
p.SubscribeReturnCodes.Add(MqttSubscribeReturnCode.Failure);
|
||||
p.ReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS0);
|
||||
p.ReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS1);
|
||||
p.ReturnCodes.Add(MqttSubscribeReturnCode.SuccessMaximumQoS2);
|
||||
p.ReturnCodes.Add(MqttSubscribeReturnCode.Failure);
|
||||
|
||||
DeserializeAndCompare(p, "kAYAewABAoA=");
|
||||
}
|
||||
@@ -552,9 +552,9 @@ namespace MQTTnet.Core.Tests
|
||||
var fixedHeader = new byte[2];
|
||||
var header = new MqttPacketReader(channel).ReadFixedHeaderAsync(fixedHeader, CancellationToken.None).GetAwaiter().GetResult();
|
||||
|
||||
using (var bodyStream = new MemoryStream(Join(buffer1), (int)headerStream.Position, (int)header.RemainingLength))
|
||||
using (var bodyStream = new MemoryStream(Join(buffer1), (int)headerStream.Position, header.RemainingLength))
|
||||
{
|
||||
var deserializedPacket = serializer.Decode(new ReceivedMqttPacket(header.Flags, new MqttPacketBodyReader(bodyStream.ToArray(), 0, (int)bodyStream.Length)));
|
||||
var deserializedPacket = serializer.Decode(new ReceivedMqttPacket(header.Flags, new MqttPacketBodyReader(bodyStream.ToArray(), 0, (int)bodyStream.Length), 0));
|
||||
var buffer2 = serializer.Encode(deserializedPacket);
|
||||
|
||||
Assert.AreEqual(expectedBase64Value, Convert.ToBase64String(Join(buffer2)));
|
||||
@@ -590,7 +590,7 @@ namespace MQTTnet.Core.Tests
|
||||
|
||||
using (var bodyStream = new MemoryStream(Join(buffer1), (int)headerStream.Position, (int)header.RemainingLength))
|
||||
{
|
||||
return (T)serializer.Decode(new ReceivedMqttPacket(header.Flags, new MqttPacketBodyReader(bodyStream.ToArray(), 0, (int)bodyStream.Length)));
|
||||
return (T)serializer.Decode(new ReceivedMqttPacket(header.Flags, new MqttPacketBodyReader(bodyStream.ToArray(), 0, (int)bodyStream.Length), 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Formatter;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttPacketWriterTests
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Server;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Implementations;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttServerTests
|
||||
@@ -111,7 +111,7 @@ namespace MQTTnet.Core.Tests
|
||||
subscribeEventCalled = e.TopicFilter.Topic == "a" && e.ClientId == "c1";
|
||||
};
|
||||
|
||||
await c1.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce));
|
||||
await c1.SubscribeAsync(new TopicFilter { Topic = "a", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce });
|
||||
await Task.Delay(500);
|
||||
Assert.IsTrue(subscribeEventCalled, "Subscribe event not called.");
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace MQTTnet.Core.Tests
|
||||
c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++;
|
||||
|
||||
var message = new MqttApplicationMessageBuilder().WithTopic("a").WithAtLeastOnceQoS().Build();
|
||||
await c1.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce));
|
||||
await c1.SubscribeAsync(new TopicFilter { Topic = "a", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce });
|
||||
|
||||
await s.PublishAsync(message);
|
||||
await Task.Delay(500);
|
||||
@@ -213,8 +213,8 @@ namespace MQTTnet.Core.Tests
|
||||
};
|
||||
|
||||
var message = new MqttApplicationMessageBuilder().WithTopic("a").WithAtLeastOnceQoS().Build();
|
||||
await c1.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce));
|
||||
await c2.SubscribeAsync(new TopicFilter("a", MqttQualityOfServiceLevel.AtLeastOnce));
|
||||
await c1.SubscribeAsync(new TopicFilter { Topic = "a", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce });
|
||||
await c2.SubscribeAsync(new TopicFilter { Topic = "a", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce });
|
||||
|
||||
//await Task.WhenAll(Publish(c1, message), Publish(c2, message));
|
||||
await Publish(c1, message);
|
||||
@@ -228,7 +228,7 @@ namespace MQTTnet.Core.Tests
|
||||
|
||||
Assert.AreEqual(2000, receivedMessagesCount);
|
||||
}
|
||||
|
||||
|
||||
[TestMethod]
|
||||
public async Task MqttServer_SessionTakeover()
|
||||
{
|
||||
@@ -373,7 +373,7 @@ namespace MQTTnet.Core.Tests
|
||||
{
|
||||
await server.StopAsync();
|
||||
}
|
||||
|
||||
|
||||
Assert.IsTrue(clientWasConnected);
|
||||
Assert.AreEqual(0, errors);
|
||||
}
|
||||
@@ -554,7 +554,7 @@ namespace MQTTnet.Core.Tests
|
||||
c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++;
|
||||
|
||||
await Task.Delay(200);
|
||||
await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce));
|
||||
await c2.SubscribeAsync(new TopicFilter { Topic = "retained", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||
await Task.Delay(500);
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -3,7 +3,7 @@ using MQTTnet.Packets;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttSubscriptionsManagerTests
|
||||
@@ -29,7 +29,7 @@ namespace MQTTnet.Core.Tests
|
||||
var sm = new MqttClientSubscriptionsManager("", new MqttServerOptions(), new MqttServerEventDispatcher());
|
||||
|
||||
var sp = new MqttSubscribePacket();
|
||||
sp.TopicFilters.Add(new TopicFilter("A/B/C", MqttQualityOfServiceLevel.AtMostOnce));
|
||||
sp.TopicFilters.Add(new TopicFilter { Topic = "A/B/C", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||
|
||||
sm.Subscribe(sp);
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace MQTTnet.Core.Tests
|
||||
var sm = new MqttClientSubscriptionsManager("", new MqttServerOptions(), new MqttServerEventDispatcher());
|
||||
|
||||
var sp = new MqttSubscribePacket();
|
||||
sp.TopicFilters.Add(new TopicFilter("#", MqttQualityOfServiceLevel.AtMostOnce));
|
||||
sp.TopicFilters.Add(new TopicFilter("A/B/C", MqttQualityOfServiceLevel.AtLeastOnce));
|
||||
sp.TopicFilters.Add(new TopicFilter { Topic = "#", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||
sp.TopicFilters.Add(new TopicFilter { Topic = "A/B/C", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtLeastOnce });
|
||||
|
||||
sm.Subscribe(sp);
|
||||
|
||||
|
||||
@@ -4,9 +4,10 @@ using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class RoundtripTimeTests
|
||||
|
||||
@@ -6,7 +6,7 @@ using MQTTnet.Adapter;
|
||||
using MQTTnet.Formatter;
|
||||
using MQTTnet.Packets;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
public class TestMqttCommunicationAdapter : IMqttChannelAdapter
|
||||
{
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Diagnostics;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
public class TestMqttCommunicationAdapterFactory : IMqttClientAdapterFactory
|
||||
{
|
||||
|
||||
@@ -3,10 +3,11 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Adapter;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
public class TestMqttServerAdapter : IMqttServerAdapter
|
||||
{
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
using MQTTnet.Client;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Server;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
public static class TestServerExtensions
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
namespace MQTTnet.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class TopicFilterComparerTests
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
|
||||
namespace MQTTnet.TestApp.NetCore
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Protocol;
|
||||
|
||||
namespace MQTTnet.TestApp.NetCore
|
||||
@@ -23,7 +24,7 @@ namespace MQTTnet.TestApp.NetCore
|
||||
Server = "127.0.0.1"
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
client.ApplicationMessageReceived += (s, e) =>
|
||||
{
|
||||
Console.WriteLine("### RECEIVED APPLICATION MESSAGE ###");
|
||||
@@ -73,14 +74,14 @@ namespace MQTTnet.TestApp.NetCore
|
||||
{
|
||||
Console.ReadLine();
|
||||
|
||||
await client.SubscribeAsync(new TopicFilter("test", MqttQualityOfServiceLevel.AtMostOnce));
|
||||
await client.SubscribeAsync(new TopicFilter { Topic = "test", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||
|
||||
var applicationMessage = new MqttApplicationMessageBuilder()
|
||||
.WithTopic("A/B/C")
|
||||
.WithPayload("Hello World")
|
||||
.WithAtLeastOnceQoS()
|
||||
.Build();
|
||||
|
||||
|
||||
await client.PublishAsync(applicationMessage);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Extensions.ManagedClient;
|
||||
using MQTTnet.Protocol;
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace MQTTnet.TestApp.NetCore
|
||||
public static async Task RunAsync()
|
||||
{
|
||||
var ms = new ClientRetainedMessageHandler();
|
||||
|
||||
|
||||
var options = new ManagedMqttClientOptions
|
||||
{
|
||||
ClientOptions = new MqttClientOptions
|
||||
@@ -44,9 +44,9 @@ namespace MQTTnet.TestApp.NetCore
|
||||
|
||||
await managedClient.StartAsync(options);
|
||||
|
||||
await managedClient.SubscribeAsync(new TopicFilter("xyz", MqttQualityOfServiceLevel.AtMostOnce));
|
||||
await managedClient.SubscribeAsync(new TopicFilter("abc", MqttQualityOfServiceLevel.AtMostOnce));
|
||||
|
||||
await managedClient.SubscribeAsync(new TopicFilter { Topic = "xyz", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||
await managedClient.SubscribeAsync(new TopicFilter { Topic = "abc", QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce });
|
||||
|
||||
await managedClient.PublishAsync(builder => builder.WithTopic("Step").WithPayload("3"));
|
||||
|
||||
Console.WriteLine("Managed client started.");
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Server;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Server;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -3,7 +3,8 @@ using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Formatter;
|
||||
using MQTTnet.Protocol;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
@@ -17,37 +18,37 @@ namespace MQTTnet.TestApp.NetCore
|
||||
|
||||
// iot.eclipse.org
|
||||
await ExecuteTestAsync("iot.eclipse.org TCP",
|
||||
new MqttClientOptionsBuilder().WithTcpServer("iot.eclipse.org", 1883).Build());
|
||||
new MqttClientOptionsBuilder().WithTcpServer("iot.eclipse.org", 1883).WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
|
||||
await ExecuteTestAsync("iot.eclipse.org WS",
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("iot.eclipse.org:80/mqtt").Build());
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("iot.eclipse.org:80/mqtt").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
|
||||
await ExecuteTestAsync("iot.eclipse.org WS TLS",
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("iot.eclipse.org:443/mqtt").WithTls().Build());
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("iot.eclipse.org:443/mqtt").WithProtocolVersion(MqttProtocolVersion.V500).WithTls().Build());
|
||||
|
||||
// test.mosquitto.org
|
||||
await ExecuteTestAsync("test.mosquitto.org TCP",
|
||||
new MqttClientOptionsBuilder().WithTcpServer("test.mosquitto.org", 1883).Build());
|
||||
new MqttClientOptionsBuilder().WithTcpServer("test.mosquitto.org", 1883).WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
|
||||
await ExecuteTestAsync("test.mosquitto.org TCP TLS",
|
||||
new MqttClientOptionsBuilder().WithTcpServer("test.mosquitto.org", 8883).WithTls().Build());
|
||||
new MqttClientOptionsBuilder().WithTcpServer("test.mosquitto.org", 8883).WithProtocolVersion(MqttProtocolVersion.V500).WithTls().Build());
|
||||
|
||||
await ExecuteTestAsync("test.mosquitto.org WS",
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("test.mosquitto.org:8080/mqtt").Build());
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("test.mosquitto.org:8080/mqtt").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
|
||||
await ExecuteTestAsync("test.mosquitto.org WS TLS",
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("test.mosquitto.org:8081/mqtt").WithTls().Build());
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("test.mosquitto.org:8081/mqtt").WithProtocolVersion(MqttProtocolVersion.V500).WithTls().Build());
|
||||
|
||||
// broker.hivemq.com
|
||||
await ExecuteTestAsync("broker.hivemq.com TCP",
|
||||
new MqttClientOptionsBuilder().WithTcpServer("broker.hivemq.com", 1883).Build());
|
||||
new MqttClientOptionsBuilder().WithTcpServer("broker.hivemq.com", 1883).WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
|
||||
await ExecuteTestAsync("broker.hivemq.com WS",
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("broker.hivemq.com:8000/mqtt").Build());
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer("broker.hivemq.com:8000/mqtt").WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
|
||||
// mqtt.swifitch.cz
|
||||
await ExecuteTestAsync("mqtt.swifitch.cz",
|
||||
new MqttClientOptionsBuilder().WithTcpServer("mqtt.swifitch.cz", 1883).Build());
|
||||
new MqttClientOptionsBuilder().WithTcpServer("mqtt.swifitch.cz", 1883).WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
|
||||
// CloudMQTT
|
||||
var configFile = Path.Combine("E:\\CloudMqttTestConfig.json");
|
||||
@@ -56,13 +57,13 @@ namespace MQTTnet.TestApp.NetCore
|
||||
var config = JsonConvert.DeserializeObject<MqttConfig>(File.ReadAllText(configFile));
|
||||
|
||||
await ExecuteTestAsync("CloudMQTT TCP",
|
||||
new MqttClientOptionsBuilder().WithTcpServer(config.Server, config.Port).WithCredentials(config.Username, config.Password).Build());
|
||||
new MqttClientOptionsBuilder().WithTcpServer(config.Server, config.Port).WithCredentials(config.Username, config.Password).WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
|
||||
await ExecuteTestAsync("CloudMQTT TCP TLS",
|
||||
new MqttClientOptionsBuilder().WithTcpServer(config.Server, config.SslPort).WithCredentials(config.Username, config.Password).WithTls().Build());
|
||||
new MqttClientOptionsBuilder().WithTcpServer(config.Server, config.SslPort).WithCredentials(config.Username, config.Password).WithTls().WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
|
||||
await ExecuteTestAsync("CloudMQTT WS TLS",
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer(config.Server + ":" + config.SslWebSocketPort + "/mqtt").WithCredentials(config.Username, config.Password).WithTls().Build());
|
||||
new MqttClientOptionsBuilder().WithWebSocketServer(config.Server + ":" + config.SslWebSocketPort + "/mqtt").WithCredentials(config.Username, config.Password).WithTls().WithProtocolVersion(MqttProtocolVersion.V500).Build());
|
||||
}
|
||||
|
||||
Write("Finished.", ConsoleColor.White);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Server;
|
||||
|
||||
namespace MQTTnet.TestApp.NetCore
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WindowsXamlEnableOverview>true</WindowsXamlEnableOverview>
|
||||
<PackageCertificateKeyFile>MQTTnet.TestApp.UniversalWindows_TemporaryKey.pfx</PackageCertificateKeyFile>
|
||||
<PackageCertificateThumbprint>05F70CAF1426E296BE2F7396F0B654070D72B930</PackageCertificateThumbprint>
|
||||
<PackageCertificateThumbprint>6B99AEE2D6C4A05C2FC9162A71D02388D66DFEEF</PackageCertificateThumbprint>
|
||||
<RuntimeIdentifiers>win10;win10-arm;win10-arm-aot;win10-x86;win10-x86-aot;win10-x64;win10-x64-aot</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||
|
||||
BIN
Binary file not shown.
@@ -101,26 +101,35 @@
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
<RowDefinition></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="0">Topic:</TextBlock>
|
||||
<TextBox Grid.Column="1" Grid.Row="0" x:Name="Topic"></TextBox>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="1">Payload:</TextBlock>
|
||||
<TextBox Grid.Column="1" Grid.Row="1" x:Name="Payload"></TextBox>
|
||||
<TextBlock Grid.Column="0" Grid.Row="1">Content type:</TextBlock>
|
||||
<TextBox Grid.Column="1" Grid.Row="1" x:Name="ContentType"></TextBox>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="2">Payload format:</TextBlock>
|
||||
<StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal">
|
||||
<TextBlock Grid.Column="0" Grid.Row="2">Payload:</TextBlock>
|
||||
<TextBox Grid.Column="1" Grid.Row="2" x:Name="Payload"></TextBox>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="3">Payload format:</TextBlock>
|
||||
<StackPanel Grid.Column="1" Grid.Row="3" Orientation="Horizontal">
|
||||
<RadioButton Margin="0,0,10,0" x:Name="PlainText" IsChecked="True" GroupName="payload">Plain text</RadioButton>
|
||||
<RadioButton Margin="0,0,10,0" x:Name="Base64" GroupName="payload">Base64 string</RadioButton>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="3">QoS level:</TextBlock>
|
||||
<StackPanel Grid.Column="1" Grid.Row="3" Orientation="Horizontal">
|
||||
<TextBlock Grid.Column="0" Grid.Row="4">QoS level:</TextBlock>
|
||||
<StackPanel Grid.Column="1" Grid.Row="4" Orientation="Horizontal">
|
||||
<RadioButton Margin="0,0,10,0" IsChecked="True" GroupName="qos">0 (At most once)</RadioButton>
|
||||
<RadioButton Margin="0,0,10,0" x:Name="QoS1" GroupName="qos">1 (At least once)</RadioButton>
|
||||
<RadioButton Margin="0,0,10,0" x:Name="QoS2" GroupName="qos">2 (Exactly once)</RadioButton>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Grid.Column="0" Grid.Row="5">Response topic:</TextBlock>
|
||||
<TextBox Grid.Column="1" Grid.Row="5" x:Name="ResponseTopic"></TextBox>
|
||||
</Grid>
|
||||
|
||||
<CheckBox x:Name="Retain">Retain</CheckBox>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Security.Cryptography.Certificates;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
using MQTTnet.Client;
|
||||
using MQTTnet.Client.Options;
|
||||
using MQTTnet.Diagnostics;
|
||||
using MQTTnet.Exceptions;
|
||||
using MQTTnet.Extensions.ManagedClient;
|
||||
@@ -16,8 +16,8 @@ using MQTTnet.Formatter;
|
||||
using MQTTnet.Implementations;
|
||||
using MQTTnet.Protocol;
|
||||
using MQTTnet.Server;
|
||||
using MqttClientConnectedEventArgs = MQTTnet.Client.MqttClientConnectedEventArgs;
|
||||
using MqttClientDisconnectedEventArgs = MQTTnet.Client.MqttClientDisconnectedEventArgs;
|
||||
using MqttClientConnectedEventArgs = MQTTnet.Client.Connecting.MqttClientConnectedEventArgs;
|
||||
using MqttClientDisconnectedEventArgs = MQTTnet.Client.Disconnecting.MqttClientDisconnectedEventArgs;
|
||||
|
||||
namespace MQTTnet.TestApp.UniversalWindows
|
||||
{
|
||||
@@ -234,6 +234,8 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
}
|
||||
|
||||
var message = new MqttApplicationMessageBuilder()
|
||||
.WithContentType(ContentType.Text)
|
||||
.WithResponseTopic(ResponseTopic.Text)
|
||||
.WithTopic(Topic.Text)
|
||||
.WithPayload(payload)
|
||||
.WithQualityOfServiceLevel(qos)
|
||||
@@ -266,7 +268,7 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
_mqttClient.Dispose();
|
||||
_mqttClient = null;
|
||||
}
|
||||
|
||||
|
||||
if (_managedMqttClient != null)
|
||||
{
|
||||
await _managedMqttClient.StopAsync();
|
||||
@@ -305,14 +307,16 @@ namespace MQTTnet.TestApp.UniversalWindows
|
||||
qos = MqttQualityOfServiceLevel.ExactlyOnce;
|
||||
}
|
||||
|
||||
var topicFilter = new TopicFilter { Topic = SubscribeTopic.Text, QualityOfServiceLevel = qos };
|
||||
|
||||
if (_mqttClient != null)
|
||||
{
|
||||
await _mqttClient.SubscribeAsync(new TopicFilter(SubscribeTopic.Text, qos));
|
||||
await _mqttClient.SubscribeAsync(topicFilter);
|
||||
}
|
||||
|
||||
if (_managedMqttClient != null)
|
||||
{
|
||||
await _managedMqttClient.SubscribeAsync(new TopicFilter(SubscribeTopic.Text, qos));
|
||||
await _managedMqttClient.SubscribeAsync(topicFilter);
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10" xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest" xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10" xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3" IgnorableNamespaces="uap mp uap3">
|
||||
<Identity Name="4fa21172-9128-4e84-8a6d-74b9acde4d58" Publisher="CN=test" Version="1.0.0.0" />
|
||||
<Identity Name="4fa21172-9128-4e84-8a6d-74b9acde4d58" Publisher="CN=chris" Version="1.0.0.0" />
|
||||
<mp:PhoneIdentity PhoneProductId="4fa21172-9128-4e84-8a6d-74b9acde4d58" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
|
||||
<Properties>
|
||||
<DisplayName>MQTTnet.TestApp.UniversalWindows</DisplayName>
|
||||
|
||||
Reference in New Issue
Block a user