Преглед изворни кода

Add Unit Tests.

release/3.x.x
Christian пре 3 година
родитељ
комит
4f14373117
1 измењених фајлова са 37 додато и 2 уклоњено
  1. +37
    -2
      Tests/MQTTnet.Core.Tests/MqttClient_Tests.cs

+ 37
- 2
Tests/MQTTnet.Core.Tests/MqttClient_Tests.cs Прегледај датотеку

@@ -16,9 +16,8 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MQTTnet.Client.Receiving;
using MQTTnet.Diagnostics;
using MQTTnet.Extensions.ManagedClient;
using MQTTnet.Formatter;
using MQTTnet.Packets;

namespace MQTTnet.Tests
{
@@ -27,6 +26,42 @@ namespace MQTTnet.Tests
{
public TestContext TestContext { get; set; }

[TestMethod]
public async Task Ensure_Queue_Drain()
{
using (var testEnvironment = new TestEnvironment(TestContext))
{
var server = await testEnvironment.StartServerAsync();
var client = await testEnvironment.ConnectLowLevelClientAsync();

var i = 0;
server.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(c =>
{
i++;
});

await client.SendAsync(new MqttConnectPacket
{
ClientId = "Ensure_Queue_Drain_Test"
}, CancellationToken.None);

await client.SendAsync(new MqttPublishPacket
{
Topic = "Test"
}, CancellationToken.None);
await Task.Delay(1000);
// This will simulate a device which closes the connection directly
// after sending the data so do delay is added between send and dispose!
client.Dispose();
await Task.Delay(1000);

Assert.AreEqual(1, i);
}
}
[TestMethod]
public async Task Set_ClientWasConnected_On_ServerDisconnect()
{


Loading…
Откажи
Сачувај