Refactor options

This commit is contained in:
Christian Kratky
2017-10-04 13:58:51 +02:00
parent d23ab88add
commit 67267c05fd
40 changed files with 291 additions and 197 deletions
@@ -0,0 +1,20 @@
using MQTTnet.Core.Adapter;
using MQTTnet.Core.Client;
namespace MQTTnet.Core.Tests
{
public class MqttCommunicationAdapterFactory : IMqttCommunicationAdapterFactory
{
private readonly IMqttCommunicationAdapter _adapter;
public MqttCommunicationAdapterFactory(IMqttCommunicationAdapter adapter)
{
_adapter = adapter;
}
public IMqttCommunicationAdapter CreateMqttCommunicationAdapter(MqttClientOptions options)
{
return _adapter;
}
}
}
@@ -6,7 +6,6 @@ using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Core.Adapter;
using MQTTnet.Core.Channel;
using MQTTnet.Core.Client;
using MQTTnet.Core.Packets;
using MQTTnet.Core.Protocol;
using MQTTnet.Core.Serializer;
@@ -411,7 +410,7 @@ namespace MQTTnet.Core.Tests
_stream.Position = 0;
}
public Task ConnectAsync(MqttClientOptions options)
public Task ConnectAsync()
{
return Task.FromResult(0);
}
@@ -6,7 +6,6 @@ using MQTTnet.Core.Client;
using MQTTnet.Core.Packets;
using MQTTnet.Core.Protocol;
using MQTTnet.Core.Server;
using System;
namespace MQTTnet.Core.Tests
{
@@ -4,7 +4,6 @@ using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MQTTnet.Core.Adapter;
using MQTTnet.Core.Client;
using MQTTnet.Core.Packets;
using MQTTnet.Core.Serializer;
@@ -18,7 +17,7 @@ namespace MQTTnet.Core.Tests
public IMqttPacketSerializer PacketSerializer { get; } = new MqttPacketSerializer();
public Task ConnectAsync(TimeSpan timeout, MqttClientOptions options)
public Task ConnectAsync(TimeSpan timeout)
{
return Task.FromResult(0);
}
@@ -17,10 +17,11 @@ namespace MQTTnet.Core.Tests
adapterA.Partner = adapterB;
adapterB.Partner = adapterA;
var client = new MqttClient(new MqttClientOptions() { ClientId = clientId }, adapterA);
var client = new MqttClient(new MqttCommunicationAdapterFactory(adapterA));
var connected = WaitForClientToConnect(server, clientId);
FireClientAcceptedEvent(adapterB);
await client.ConnectAsync(willMessage);
await client.ConnectAsync(new MqttClientTcpOptions { ClientId = clientId, WillMessage = willMessage });
await connected;
return client;
@@ -30,17 +31,16 @@ namespace MQTTnet.Core.Tests
{
var tcs = new TaskCompletionSource<object>();
EventHandler<MqttClientConnectedEventArgs> handler = null;
handler = (sender, args) =>
void Handler(object sender, MqttClientConnectedEventArgs args)
{
if (args.Client.ClientId == clientId)
{
s.ClientConnected -= handler;
s.ClientConnected -= Handler;
tcs.SetResult(null);
}
};
}
s.ClientConnected += handler;
s.ClientConnected += Handler;
return tcs.Task;
}