소스 검색

Add test for simple server and client execution.

release/3.x.x
Christian Kratky 6 년 전
부모
커밋
66ebdfd61a
2개의 변경된 파일32개의 추가작업 그리고 0개의 파일을 삭제
  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 파일 보기

@@ -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 파일 보기

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

불러오는 중...
취소
저장