public CommandProcessorCallTests()
        {
            _myRequest.RequestValue = "Hello World";

            _fakeMessageProducer = new FakeMessageProducer();

            var header = new MessageHeader(
                messageId: _myRequest.Id,
                topic: "MyRequest",
                messageType: MessageType.MT_COMMAND,
                correlationId: _myRequest.ReplyAddress.CorrelationId,
                replyTo: _myRequest.ReplyAddress.Topic);

            var json = new JObject(new JProperty("Id", _myRequest.Id), new JProperty("RequestValue", _myRequest.RequestValue));
            var body = new MessageBody(json.ToString());

            _message = new Message(header, body);

            var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory((type) =>
            {
                if (type == typeof(MyRequestMessageMapper))
                {
                    return(new MyRequestMessageMapper());
                }
                if (type == typeof(MyResponseMessageMapper))
                {
                    return(new MyResponseMessageMapper());
                }

                throw new ConfigurationException($"No mapper found for {type.Name}");
            }));

            messageMapperRegistry.Register <MyRequest, MyRequestMessageMapper>();
            messageMapperRegistry.Register <MyResponse, MyResponseMessageMapper>();

            var subscriberRegistry = new SubscriberRegistry();

            subscriberRegistry.Register <MyResponse, MyResponseHandler>();
            var handlerFactory = new TestHandlerFactory <MyResponse, MyResponseHandler>(() => new MyResponseHandler());

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .Retry();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreaker(1, TimeSpan.FromMilliseconds(1));

            InMemoryChannelFactory inMemoryChannelFactory = new InMemoryChannelFactory();

            //we need to seed the response as the fake producer does not actually send across the wire
            inMemoryChannelFactory.SeedChannel(new[] { _message });

            _commandProcessor = new CommandProcessor(
                subscriberRegistry,
                handlerFactory,
                new InMemoryRequestContextFactory(),
                new PolicyRegistry {
                { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy }
            },
                messageMapperRegistry,
                (IAmAMessageProducer)_fakeMessageProducer,
                responseChannelFactory: inMemoryChannelFactory);

            PipelineBuilder <MyRequest> .ClearPipelineCache();
        }
        public CommandProcessorCallTests()
        {
            _myRequest.RequestValue = "Hello World";

            _fakeMessageProducerWithPublishConfirmation = new FakeMessageProducerWithPublishConfirmation();

            const string topic  = "MyRequest";
            var          header = new MessageHeader(
                messageId: _myRequest.Id,
                topic: topic,
                messageType: MessageType.MT_COMMAND,
                correlationId: _myRequest.ReplyAddress.CorrelationId,
                replyTo: _myRequest.ReplyAddress.Topic);

            var body = new MessageBody(JsonSerializer.Serialize(new MyRequestDTO(_myRequest.Id.ToString(), _myRequest.RequestValue), JsonSerialisationOptions.Options));

            _message = new Message(header, body);

            var messageMapperRegistry = new MessageMapperRegistry(new SimpleMessageMapperFactory((type) =>
            {
                if (type == typeof(MyRequestMessageMapper))
                {
                    return(new MyRequestMessageMapper());
                }
                if (type == typeof(MyResponseMessageMapper))
                {
                    return(new MyResponseMessageMapper());
                }

                throw new ConfigurationException($"No mapper found for {type.Name}");
            }));

            messageMapperRegistry.Register <MyRequest, MyRequestMessageMapper>();
            messageMapperRegistry.Register <MyResponse, MyResponseMessageMapper>();

            var subscriberRegistry = new SubscriberRegistry();

            subscriberRegistry.Register <MyResponse, MyResponseHandler>();
            var handlerFactory = new TestHandlerFactorySync <MyResponse, MyResponseHandler>(() => new MyResponseHandler());

            var retryPolicy = Policy
                              .Handle <Exception>()
                              .Retry();

            var circuitBreakerPolicy = Policy
                                       .Handle <Exception>()
                                       .CircuitBreaker(1, TimeSpan.FromMilliseconds(1));

            InMemoryChannelFactory inMemoryChannelFactory = new InMemoryChannelFactory();

            //we need to seed the response as the fake producer does not actually send across the wire
            inMemoryChannelFactory.SeedChannel(new[] { _message });

            var replySubs = new List <Subscription>
            {
                new Subscription <MyResponse>()
            };

            _commandProcessor = new CommandProcessor(
                subscriberRegistry,
                handlerFactory,
                new InMemoryRequestContextFactory(),
                new PolicyRegistry {
                { CommandProcessor.RETRYPOLICY, retryPolicy }, { CommandProcessor.CIRCUITBREAKER, circuitBreakerPolicy }
            },
                messageMapperRegistry,
                new InMemoryOutbox(),
                new ProducerRegistry(new Dictionary <string, IAmAMessageProducer>()
            {
                { topic, _fakeMessageProducerWithPublishConfirmation },
            }),
                replySubs,
                responseChannelFactory: inMemoryChannelFactory);

            PipelineBuilder <MyRequest> .ClearPipelineCache();
        }