Browse Source

Add test for simple server and client execution.

release/3.x.x
Christian Kratky 6 years ago
parent
commit
66ebdfd61a
2 changed files with 32 additions and 0 deletions
  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 View File

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


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


Thread.Sleep(Timeout.Infinite); Thread.Sleep(Timeout.Infinite);
} }


+ 27
- 0
Tests/MQTTnet.TestApp.NetCore/ServerAndClientTest.cs View File

@@ -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);
}
}
}

Loading…
Cancel
Save