From c4a82ac350f20cadd4cfeecb89e3d8854c37f662 Mon Sep 17 00:00:00 2001 From: Peter Giacomo Lombardo Date: Tue, 26 Mar 2024 09:22:48 +0100 Subject: [PATCH] More Test & Client Validations (#138) --- .../HiveMQtt.Test/HiveMQClient/ConnectTest.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Tests/HiveMQtt.Test/HiveMQClient/ConnectTest.cs b/Tests/HiveMQtt.Test/HiveMQClient/ConnectTest.cs index 7c8c7c5c..5877f47f 100644 --- a/Tests/HiveMQtt.Test/HiveMQClient/ConnectTest.cs +++ b/Tests/HiveMQtt.Test/HiveMQClient/ConnectTest.cs @@ -4,6 +4,7 @@ namespace HiveMQtt.Test.HiveMQClient; using System.Threading.Tasks; using HiveMQtt.Client; using HiveMQtt.Client.Events; +using HiveMQtt.Client.Exceptions; using HiveMQtt.Client.Options; using HiveMQtt.MQTT5.ReasonCodes; using Xunit; @@ -11,7 +12,7 @@ namespace HiveMQtt.Test.HiveMQClient; public class ConnectTest { [Fact] - public async Task Basic_Connect_And_Disconnect_Async() + public async Task BasicConnectAndDisconnectAsync() { var client = new HiveMQClient(); Assert.NotNull(client); @@ -30,7 +31,20 @@ public async Task Basic_Connect_And_Disconnect_Async() } [Fact] - public async Task Test_Connect_Events_Async() + public async Task RaiseOnFailureToConnectAsync() + { + // Bad port number + var clientOptions = new HiveMQClientOptionsBuilder().WithPort(0).Build(); + var client = new HiveMQClient(clientOptions); + + await Assert.ThrowsAsync(async () => + { + await client.ConnectAsync().ConfigureAwait(false); + }).ConfigureAwait(false); + } + + [Fact] + public async Task TestConnectEventsAsync() { var client = new HiveMQClient();