Add nuget support

This commit is contained in:
Christian Kratky
2017-04-01 21:51:36 +02:00
parent ee25228c0b
commit 8bfad437cf
27 changed files with 589 additions and 335 deletions
+3 -53
View File
@@ -1,8 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Core.Adapter;
using MQTTnet.Core.Client;
using MQTTnet.Core.Packets;
using MQTTnet.Core.Protocol;
@@ -71,8 +68,8 @@ namespace MQTTnet.Core.Tests
private MqttClient ConnectTestClient(string clientId, MqttApplicationMessage willMessage, MqttServer server)
{
var adapterA = new TestMqttClientAdapter();
var adapterB = new TestMqttClientAdapter();
var adapterA = new TestMqttCommunicationAdapter();
var adapterB = new TestMqttCommunicationAdapter();
adapterA.Partner = adapterB;
adapterB.Partner = adapterA;
@@ -111,51 +108,4 @@ namespace MQTTnet.Core.Tests
Assert.AreEqual(expectedReceivedMessagesCount, receivedMessagesCount);
}
}
public class TestMqttClientAdapter : IMqttCommunicationAdapter
{
private readonly BlockingCollection<MqttBasePacket> _incomingPackets = new BlockingCollection<MqttBasePacket>();
public TestMqttClientAdapter Partner { get; set; }
public async Task ConnectAsync(MqttClientOptions options, TimeSpan timeout)
{
await Task.FromResult(0);
}
public async Task DisconnectAsync()
{
await Task.FromResult(0);
}
public async Task SendPacketAsync(MqttBasePacket packet, TimeSpan timeout)
{
ThrowIfPartnerIsNull();
Partner.SendPacketInternal(packet);
await Task.FromResult(0);
}
public async Task<MqttBasePacket> ReceivePacketAsync(TimeSpan timeout)
{
ThrowIfPartnerIsNull();
return await Task.Run(() => _incomingPackets.Take());
}
private void SendPacketInternal(MqttBasePacket packet)
{
if (packet == null) throw new ArgumentNullException(nameof(packet));
_incomingPackets.Add(packet);
}
private void ThrowIfPartnerIsNull()
{
if (Partner == null)
{
throw new InvalidOperationException("Partner is not set.");
}
}
}
}