public async Task StartAsyncSubscribesToTopics() { // Arrange var mockManagedMqttClient = new Mock <IManagedMqttClient>(); var mockManagedMqttClientOptions = new Mock <IManagedMqttClientOptions>(); var mockMqttClientFactory = new Mock <IManagedMqttClientFactory>(); var messageProcessor = new Mock <IProcesMqttMessage>(); mockMqttClientFactory .Setup(m => m.CreateManagedMqttClient()) .Returns(mockManagedMqttClient.Object); mockManagedMqttClient .Setup(m => m.StartAsync(It.Is <IManagedMqttClientOptions>(y => y == mockManagedMqttClientOptions.Object))) .Returns(Task.CompletedTask); messageProcessor.Setup(x => x.OnMessage(It.IsAny <MqttMessageReceivedEventArgs>())).Returns(Task.CompletedTask); var config = new MqttConfiguration("CustomConfig", mockManagedMqttClientOptions.Object); var mqttConnection = new MqttConnection(mockMqttClientFactory.Object, config, _mockLogger.Object); // Act await mqttConnection.StartAsync(messageProcessor.Object); await mqttConnection.HandleConnectedAsync(new MqttClientConnectedEventArgs(new MqttClientAuthenticateResult { IsSessionPresent = true, ResultCode = MqttClientConnectResultCode.Success })); // Assert Assert.Equal(ConnectionState.Connected, mqttConnection.ConnectionState); mockMqttClientFactory.VerifyAll(); mockManagedMqttClient.VerifyAll(); }