Bläddra i källkod

Add test for simple server and client execution.

release/3.x.x
Christian Kratky 6 år sedan
förälder
incheckning
66ebdfd61a
2 ändrade filer med 32 tillägg och 0 borttagningar
  1. +5
    -0
      Tests/MQTTnet.TestApp.NetCore/Program.cs
  2. +27
    -0
      Tests/MQTTnet.TestApp.NetCore/ServerAndClientTest.cs

+ 5
- 0
Tests/MQTTnet.TestApp.NetCore/Program.cs Visa fil

@@ -20,6 +20,7 @@ namespace MQTTnet.TestApp.NetCore
Console.WriteLine("3 = Start performance test");
Console.WriteLine("4 = Start managed client");
Console.WriteLine("5 = Start public broker test");
Console.WriteLine("6 = Start server & client");

var pressedKey = Console.ReadKey(true);
if (pressedKey.KeyChar == '1')
@@ -42,6 +43,10 @@ namespace MQTTnet.TestApp.NetCore
{
Task.Run(PublicBrokerTest.RunAsync);
}
else if (pressedKey.KeyChar == '6')
{
Task.Run(ServerAndClientTest.RunAsync);
}

Thread.Sleep(Timeout.Infinite);
}


+ 27
- 0
Tests/MQTTnet.TestApp.NetCore/ServerAndClientTest.cs Visa fil

@@ -0,0 +1,27 @@
using System.Threading;
using System.Threading.Tasks;
using MQTTnet.Client;
using MQTTnet.Server;

namespace MQTTnet.TestApp.NetCore
{
public static class ServerAndClientTest
{
public static async Task RunAsync()
{
MqttNetConsoleLogger.ForwardToConsole();

var factory = new MqttFactory();
var server = factory.CreateMqttServer();
var client = factory.CreateMqttClient();

var serverOptions = new MqttServerOptionsBuilder().Build();
await server.StartAsync(serverOptions);

var clientOptions = new MqttClientOptionsBuilder().WithTcpServer("localhost").Build();
await client.ConnectAsync(clientOptions);

await Task.Delay(Timeout.Infinite);
}
}
}

Laddar…
Avbryt
Spara