public void Should_wrap_error_messages_correctly()
        {
            var typeNameSerializer = bus.Advanced.Container.Resolve <ITypeNameSerializer>();
            var serializer         = bus.Advanced.Container.Resolve <ISerializer>();
            var conventions        = bus.Advanced.Container.Resolve <IConventions>();

            var errorQueue = new Queue(conventions.ErrorQueueNamingConvention(), false);

            bus.Advanced.QueuePurge(errorQueue);

            var typeName = typeNameSerializer.Serialize(typeof(MyErrorTestMessage));
            var exchange = this.bus.Advanced.ExchangeDeclare(typeName, ExchangeType.Topic);

            bus.Subscribe <MyErrorTestMessage>("exceptionTest", _ =>
            {
                throw new Exception("Hello Error Handler!");
            });

            // give the subscription a chance to complete
            Thread.Sleep(500);

            var message = new MyErrorTestMessage {
                Id = 444, Name = "I cause an error. Naughty me!"
            };
            var headers = new Dictionary <string, object>()
            {
                { "AString", "ThisIsAString" },
                { "AnInt", 123 }
            };
            var correlationId = Guid.NewGuid().ToString();

            var props = new MessageProperties()
            {
                Type          = typeName,
                Headers       = headers,
                CorrelationId = correlationId
            };

            bus.Advanced.Publish(exchange, typeNameSerializer.Serialize(typeof(MyErrorTestMessage)), true, props, serializer.MessageToBytes(message));

            // give the publish a chance to get to rabbit and back
            // also allow the DefaultConsumerErrorStrategy time to spin up its connection
            Thread.Sleep(1000);

            var errorMessage = this.bus.Advanced.Get <Error>(errorQueue);

            errorMessage.MessageAvailable.Should().BeTrue();

            var error = errorMessage.Message.Body;

            Console.WriteLine(error.ToString());


            error.BasicProperties.Type.Should().Be(typeNameSerializer.Serialize(typeof(MyErrorTestMessage)));
            error.BasicProperties.CorrelationId.Should().Be(correlationId);
            error.BasicProperties.Headers.Should().BeEquivalentTo(headers);
            error.BasicProperties.Headers["AString"].Should().Be("ThisIsAString");
            error.BasicProperties.Headers["AnInt"].Should().Be(123);
        }
        public void Should_wrap_error_messages_correctly()
        {
            var typeNameSerializer = bus.Advanced.Container.Resolve<ITypeNameSerializer>();
            var serializer = bus.Advanced.Container.Resolve<ISerializer>();
            var conventions = bus.Advanced.Container.Resolve<IConventions>();

            var errorQueue = new Queue(conventions.ErrorQueueNamingConvention(), false);
            bus.Advanced.QueuePurge(errorQueue);

            var typeName = typeNameSerializer.Serialize(typeof(MyErrorTestMessage));
            var exchange = this.bus.Advanced.ExchangeDeclare(typeName, ExchangeType.Topic);

            bus.Subscribe<MyErrorTestMessage>("exceptionTest", _ =>
            {
                throw new Exception("Hello Error Handler!");
            });

            // give the subscription a chance to complete
            Thread.Sleep(500);

            var message = new MyErrorTestMessage { Id = 444, Name = "I cause an error. Naughty me!" };
            var headers = new Dictionary<string, object>()
                          {
                              { "AString", "ThisIsAString" },
                              { "AnInt", 123 }
                          };
            var correlationId = Guid.NewGuid().ToString();

            var props = new MessageProperties()
            {
                Type = typeName,
                Headers = headers,
                CorrelationId = correlationId
            };

             bus.Advanced.Publish(exchange, typeNameSerializer.Serialize(typeof(MyErrorTestMessage)), true, props, serializer.MessageToBytes(message));

            // give the publish a chance to get to rabbit and back
            // also allow the DefaultConsumerErrorStrategy time to spin up its connection
            Thread.Sleep(1000);

            var errorMessage = this.bus.Advanced.Get<Error>(errorQueue);
            errorMessage.MessageAvailable.ShouldBeTrue();

            var error = errorMessage.Message.Body;
            Console.WriteLine(error.ToString());

            error.BasicProperties.Type.ShouldEqual(typeNameSerializer.Serialize(typeof(MyErrorTestMessage)));
            error.BasicProperties.CorrelationId.ShouldEqual(correlationId);
            error.BasicProperties.Headers.ShouldEqual(headers);
            error.BasicProperties.Headers["AString"].ShouldEqual("ThisIsAString");
            error.BasicProperties.Headers["AnInt"].ShouldEqual(123);
        }