Refactoring

This commit is contained in:
Christian Kratky
2017-11-09 13:26:03 +01:00
parent 587622af81
commit c01edb192f
5 changed files with 14 additions and 25 deletions
+3 -1
View File
@@ -53,6 +53,7 @@ namespace MQTTnet.Core.Tests
public async Task MqttServer_WillMessage()
{
var serverAdapter = new TestMqttServerAdapter();
var services = new ServiceCollection()
.AddLogging()
.AddMqttServer()
@@ -70,7 +71,7 @@ namespace MQTTnet.Core.Tests
var c2 = await serverAdapter.ConnectTestClient(s, "c2", willMessage);
c1.ApplicationMessageReceived += (_, __) => receivedMessagesCount++;
await c1.SubscribeAsync(new TopicFilter("#", MqttQualityOfServiceLevel.AtMostOnce));
await c1.SubscribeAsync(new TopicFilter("#"));
await c2.DisconnectAsync();
@@ -80,6 +81,7 @@ namespace MQTTnet.Core.Tests
{
await s.StopAsync();
}
Assert.AreEqual(1, receivedMessagesCount);
}
@@ -33,7 +33,7 @@ namespace MQTTnet.Core.Tests
foreach (var packet in packets)
{
Partner.SendPacketInternal(packet);
Partner.EnqueuePacketInternal(packet);
}
return Task.FromResult(0);
@@ -46,7 +46,7 @@ namespace MQTTnet.Core.Tests
return Task.Run(() => _incomingPackets.Take(), cancellationToken);
}
private void SendPacketInternal(MqttBasePacket packet)
private void EnqueuePacketInternal(MqttBasePacket packet)
{
if (packet == null) throw new ArgumentNullException(nameof(packet));
@@ -4,11 +4,11 @@ using MQTTnet.Core.Client;
namespace MQTTnet.Core.Tests
{
public class MqttCommunicationAdapterFactory : IMqttCommunicationAdapterFactory
public class TestMqttCommunicationAdapterFactory : IMqttCommunicationAdapterFactory
{
private readonly IMqttCommunicationAdapter _adapter;
public MqttCommunicationAdapterFactory(IMqttCommunicationAdapter adapter)
public TestMqttCommunicationAdapterFactory(IMqttCommunicationAdapter adapter)
{
_adapter = adapter;
}
@@ -17,7 +17,11 @@ namespace MQTTnet.Core.Tests
adapterA.Partner = adapterB;
adapterB.Partner = adapterA;
var client = new MqttClient(new MqttCommunicationAdapterFactory(adapterA), new TestLogger<MqttClient>(), new MqttPacketDispatcher(new TestLogger<MqttPacketDispatcher>()));
var client = new MqttClient(
new TestMqttCommunicationAdapterFactory(adapterA),
new TestLogger<MqttClient>(),
new MqttPacketDispatcher(new TestLogger<MqttPacketDispatcher>()));
var connected = WaitForClientToConnect(server, clientId);
FireClientAcceptedEvent(adapterB);
@@ -29,8 +33,6 @@ namespace MQTTnet.Core.Tests
ChannelOptions = new MqttClientTcpOptions()
};
options.ChannelOptions = new MqttClientTcpOptions();
await client.ConnectAsync(options);
await connected;