From 66ebdfd61a226b62feaa499020383b8441639101 Mon Sep 17 00:00:00 2001 From: Christian Kratky Date: Sun, 3 Jun 2018 22:04:43 +0200 Subject: [PATCH] Add test for simple server and client execution. --- Tests/MQTTnet.TestApp.NetCore/Program.cs | 5 ++++ .../ServerAndClientTest.cs | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Tests/MQTTnet.TestApp.NetCore/ServerAndClientTest.cs diff --git a/Tests/MQTTnet.TestApp.NetCore/Program.cs b/Tests/MQTTnet.TestApp.NetCore/Program.cs index 4032a17..270b16e 100644 --- a/Tests/MQTTnet.TestApp.NetCore/Program.cs +++ b/Tests/MQTTnet.TestApp.NetCore/Program.cs @@ -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); } diff --git a/Tests/MQTTnet.TestApp.NetCore/ServerAndClientTest.cs b/Tests/MQTTnet.TestApp.NetCore/ServerAndClientTest.cs new file mode 100644 index 0000000..30ba914 --- /dev/null +++ b/Tests/MQTTnet.TestApp.NetCore/ServerAndClientTest.cs @@ -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); + } + } +}