public async Task Test_MqSimpleSwitch()
        {
            MqttStringMessageWithState[] messages = new[]
            {
                new MqttStringMessageWithState
                {
                    Message = new MqttStringMessage()
                    {
                        Payload = "1",
                        Topic   = "/mqtt/on"
                    },
                    SensorState = new SensorState()
                }
            };

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            var messageProcessingPipeline =
                _messageProcessor.CreateMessageProcessingPipeline(cancellationTokenSource.Token,
                                                                  messages.ToObservable());

            cancellationTokenSource.Cancel();
            var result = await messageProcessingPipeline.SingleAsync();

            Assert.IsInstanceOf <SwitchDevice>(result);
            var switchAction = (SwitchDevice)result;

            Assert.AreEqual(1, switchAction.HueDevice.Id);
        }
        private async Task ExecuteTest(SensorState sensorState, MqttStringMessage[] inputMessages,
                                       Action <List <IActionMessage> > assertAction)
        {
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            var sensorStates   = new Subject <SensorState>();
            var stringMessages = new Subject <MqttStringMessage>();

            var messagesWithState  = MessageProcessor.CombineMqMessagesWithSensorState(stringMessages, sensorStates);
            var processingPipeline = _messageProcessor.CreateMessageProcessingPipeline(cancellationTokenSource.Token, messagesWithState);

            List <IActionMessage> actionMessages = new List <IActionMessage>();
            var subscription = processingPipeline.Subscribe(action =>
            {
                Console.WriteLine($"msg: {action}");
                actionMessages.Add(action);
            });

            sensorStates.OnNext(sensorState);
            foreach (var inputMessage in inputMessages)
            {
                stringMessages.OnNext(inputMessage);
            }

            stringMessages.OnCompleted();
            sensorStates.OnCompleted();
            cancellationTokenSource.Cancel();
            await processingPipeline.ToArray();

            subscription.Dispose();

            assertAction(actionMessages);
        }