From eda51cf6e29d38e8abcaa9ae8476aa2bfffa65af Mon Sep 17 00:00:00 2001 From: Jonas Hansen Date: Tue, 10 Oct 2023 07:22:44 +0200 Subject: [PATCH] Fix test --- .../ToMqttNet.Test.Unit/MqttConnectionServiceTests.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/test/ToMqttNet.Test.Unit/MqttConnectionServiceTests.cs b/test/ToMqttNet.Test.Unit/MqttConnectionServiceTests.cs index 13ecbb1..7ef2e95 100644 --- a/test/ToMqttNet.Test.Unit/MqttConnectionServiceTests.cs +++ b/test/ToMqttNet.Test.Unit/MqttConnectionServiceTests.cs @@ -55,8 +55,9 @@ public async Task ShouldSetConnectionsToOne() var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10)); // Act + _clientStub.IsConnected = true; await _sut.StartAsync(cancellationTokenSource.Token); - await _clientStub.CallConnectedAsync(new MqttClientConnectedEventArgs(new MqttClientConnectResult())); + await _clientStub.CallConnectionStateChangedAsync(new MqttClientConnectedEventArgs(new MqttClientConnectResult())); // Assert listener.RecordObservableInstruments(); @@ -87,7 +88,7 @@ public async Task ShouldIncreaseMessagesSent() var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10)); await _sut.StartAsync(cancellationTokenSource.Token); - await _clientStub.CallConnectedAsync(new MqttClientConnectedEventArgs(new MqttClientConnectResult())); + await _clientStub.CallConnectionStateChangedAsync(new MqttClientConnectedEventArgs(new MqttClientConnectResult())); var message = new MqttApplicationMessageBuilder() .WithTopic("my-topic") @@ -106,7 +107,7 @@ public class MqttClientStub : IManagedMqttClient { public IMqttClient InternalClient => throw new NotImplementedException(); - public bool IsConnected => throw new NotImplementedException(); + public bool IsConnected { get; set; } public bool IsStarted => throw new NotImplementedException(); @@ -126,6 +127,10 @@ public Task CallConnectedAsync(MqttClientConnectedEventArgs args) public event Func ConnectingFailedAsync = null!; public event Func ConnectionStateChangedAsync = null!; + public Task CallConnectionStateChangedAsync(EventArgs args) + { + return ConnectionStateChangedAsync.Invoke(args); + } public event Func DisconnectedAsync = null!; public Task CallDisconnectedAsync(MqttClientDisconnectedEventArgs args) {