public async Task NewMessageIsProcessed() { // 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); 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.HandleApplicationMessageReceivedAsync(new MqttApplicationMessageReceivedEventArgs("ClientId", DefaultMessage)); // Assert messageProcessor.Verify(x => x.OnMessage(It.Is <MqttMessageReceivedEventArgs>(y => y.Message.Topic == DefaultMessage.Topic))); messageProcessor.Verify(x => x.OnMessage(It.Is <MqttMessageReceivedEventArgs>(y => y.Message.Retain == DefaultMessage.Retain))); messageProcessor.Verify(x => x.OnMessage(It.Is <MqttMessageReceivedEventArgs>(y => y.Message.QosLevel.ToString() == DefaultMessage.QualityOfServiceLevel.ToString()))); messageProcessor.Verify(x => x.OnMessage(It.Is <MqttMessageReceivedEventArgs>(y => y.Message.GetMessage() == DefaultMessage.Payload))); }