mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-27 00:40:01 +08:00
Refactoring
This commit is contained in:
@@ -55,7 +55,7 @@ namespace MQTTnet.Core.Tests
|
||||
{
|
||||
try
|
||||
{
|
||||
var r = await Task.Run(() =>
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var iis = new int[0];
|
||||
return iis[1];
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Core.Protocol;
|
||||
|
||||
namespace MQTTnet.Core.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class MqttApplicationMessageFactoryTests
|
||||
{
|
||||
[TestMethod]
|
||||
public void CreateApplicationMessage_TopicOnly()
|
||||
{
|
||||
var message = new MqttApplicationMessageFactory().CreateApplicationMessage("Abc", MqttQualityOfServiceLevel.AtLeastOnce);
|
||||
Assert.AreEqual("Abc", message.Topic);
|
||||
Assert.IsFalse(message.Retain);
|
||||
Assert.AreEqual(MqttQualityOfServiceLevel.AtLeastOnce, message.QualityOfServiceLevel);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void CreateApplicationMessage_TimeStampPayload()
|
||||
{
|
||||
var message = new MqttApplicationMessageFactory().CreateApplicationMessage("xyz", TimeSpan.FromSeconds(360));
|
||||
Assert.AreEqual("xyz", message.Topic);
|
||||
Assert.IsFalse(message.Retain);
|
||||
Assert.AreEqual(MqttQualityOfServiceLevel.AtMostOnce, message.QualityOfServiceLevel);
|
||||
Assert.AreEqual(Encoding.UTF8.GetString(message.Payload), "00:06:00");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ namespace MQTTnet.Core.Tests
|
||||
_adapter = adapter;
|
||||
}
|
||||
|
||||
public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(MqttClientOptions options)
|
||||
public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(IMqttClientOptions options)
|
||||
{
|
||||
return _adapter;
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using MQTTnet.Core.Adapter;
|
||||
using MQTTnet.Core.Channel;
|
||||
using MQTTnet.Core.Packets;
|
||||
using MQTTnet.Core.Protocol;
|
||||
using MQTTnet.Core.Serializer;
|
||||
@@ -387,45 +385,6 @@ namespace MQTTnet.Core.Tests
|
||||
DeserializeAndCompare(p, "sAIAew==");
|
||||
}
|
||||
|
||||
|
||||
public class TestChannel : IMqttCommunicationChannel
|
||||
{
|
||||
private readonly MemoryStream _stream = new MemoryStream();
|
||||
|
||||
public Stream ReceiveStream => _stream;
|
||||
|
||||
public Stream RawReceiveStream => _stream;
|
||||
|
||||
public Stream SendStream => _stream;
|
||||
|
||||
public bool IsConnected { get; } = true;
|
||||
|
||||
public TestChannel()
|
||||
{
|
||||
}
|
||||
|
||||
public TestChannel(byte[] initialData)
|
||||
{
|
||||
_stream.Write(initialData, 0, initialData.Length);
|
||||
_stream.Position = 0;
|
||||
}
|
||||
|
||||
public Task ConnectAsync()
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public Task DisconnectAsync()
|
||||
{
|
||||
return Task.FromResult(0);
|
||||
}
|
||||
|
||||
public byte[] ToArray()
|
||||
{
|
||||
return _stream.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private static void SerializeAndCompare(MqttBasePacket packet, string expectedBase64Value, MqttProtocolVersion protocolVersion = MqttProtocolVersion.V311)
|
||||
{
|
||||
var serializer = new MqttPacketSerializer { ProtocolVersion = protocolVersion };
|
||||
|
||||
Reference in New Issue
Block a user