Refactor package object model.

This commit is contained in:
Christian Kratky
2020-10-28 23:11:12 +01:00
parent adce5662eb
commit b7fb0c1002
71 changed files with 761 additions and 582 deletions
@@ -1,10 +1,12 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MQTTnet.Client.Options;
using MQTTnet.LowLevelClient;
using MQTTnet.Packets;
using MQTTnet.Protocol;
using MQTTnet.Tests.Mockups;
using System.Collections.Generic;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -34,7 +36,7 @@ namespace MQTTnet.Tests
{
using (var testEnvironment = new TestEnvironment(TestContext))
{
var server = await testEnvironment.StartServerAsync();
await testEnvironment.StartServerAsync();
var factory = new MqttFactory();
var lowLevelClient = factory.CreateLowLevelMqttClient();
@@ -50,7 +52,7 @@ namespace MQTTnet.Tests
{
using (var testEnvironment = new TestEnvironment(TestContext))
{
var server = await testEnvironment.StartServerAsync();
await testEnvironment.StartServerAsync();
var factory = new MqttFactory();
var lowLevelClient = factory.CreateLowLevelMqttClient();
@@ -71,7 +73,7 @@ namespace MQTTnet.Tests
{
using (var testEnvironment = new TestEnvironment(TestContext))
{
var server = await testEnvironment.StartServerAsync();
await testEnvironment.StartServerAsync();
var factory = new MqttFactory();
var lowLevelClient = factory.CreateLowLevelMqttClient();
@@ -89,6 +91,39 @@ namespace MQTTnet.Tests
}
}
[TestMethod]
public async Task Loose_Connection()
{
using (var testEnvironment = new TestEnvironment(TestContext))
{
testEnvironment.ServerPort = 8364;
var server = await testEnvironment.StartServerAsync();
var client = await testEnvironment.ConnectLowLevelClientAsync(o => o.WithCommunicationTimeout(TimeSpan.Zero));
await Authenticate(client).ConfigureAwait(false);
await server.StopAsync();
await Task.Delay(1000);
try
{
await client.SendAsync(MqttPingReqPacket.Instance, CancellationToken.None).ConfigureAwait(false);
}
catch (MqttCommunicationException exception)
{
Assert.IsTrue(exception.InnerException is SocketException);
return;
}
catch
{
Assert.Fail("Wrong exception type thrown.");
}
Assert.Fail("This MUST fail");
}
}
async Task<MqttConnAckPacket> Authenticate(ILowLevelMqttClient client)
{
await client.SendAsync(new MqttConnectPacket