async Task DispatchPacketAsync(IPacket packet)
        {
            IProtocolFlow flow = _flowProvider.GetFlow(packet.Type);

            if (flow != null)
            {
                try
                {
                    _packets.OnNext(packet);

                    await _flowRunner.Run(async() =>
                    {
                        Publish publish = packet as Publish;

                        if (publish == null)
                        {
                            _tracer.Info(ClientProperties.ClientPacketListener_DispatchingMessage(_clientId, packet.Type, flow.GetType().Name));
                        }
                        else
                        {
                            _tracer.Info(ClientProperties.ClientPacketListener_DispatchingPublish(_clientId, flow.GetType().Name, publish.Topic));
                        }

                        await flow.ExecuteAsync(_clientId, packet, _channel);
                    });
                }
                catch (Exception ex)
                {
                    NotifyError(ex);
                }
            }
        }
        public void when_getting_client_flow_from_valid_packet_type_then_succeeds(MqttPacketType packetType, Type flowType)
        {
            ClientProtocolFlowProvider flowProvider = new ClientProtocolFlowProvider(Mock.Of <IMqttTopicEvaluator>(), Mock.Of <IRepositoryProvider>(), new MqttConfiguration());

            IProtocolFlow flow = flowProvider.GetFlow(packetType);

            flowType.Should().Be(flow.GetType());
        }
        public void when_getting_server_flow_from_valid_packet_type_then_succeeds(MqttPacketType packetType, Type flowType)
        {
            IMqttAuthenticationProvider authenticationProvider = Mock.Of <IMqttAuthenticationProvider>(p => p.Authenticate(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()) == true);
            ServerProtocolFlowProvider  flowProvider           = new ServerProtocolFlowProvider(authenticationProvider, Mock.Of <IConnectionProvider>(), Mock.Of <IMqttTopicEvaluator>(),
                                                                                                Mock.Of <IRepositoryProvider>(), Mock.Of <IPacketIdProvider>(), Mock.Of <ISubject <MqttUndeliveredMessage> >(), new MqttConfiguration());

            IProtocolFlow flow = flowProvider.GetFlow(packetType);

            flowType.Should().Be(flow.GetType());
        }