public void enqueue_an_oject_array()
        {
            var messages = new FubuTransportation.Runtime.Invocation.InvocationContext(new Envelope{Message = new Events.Message1()}, new HandlerChain());
            var m1 = new Events.Message1();
            var m2 = new Events.Message2();

            messages.EnqueueCascading(new object[]{m1, m2});

            messages.OutgoingMessages().ShouldHaveTheSameElementsAs(m1, m2);
        }
        public void create_and_send_with_timespan_delayed()
        {
            var message = new Events.Message1();
            var delayed = new FubuTransportation.Runtime.Cascading.DelayedResponse(message, 5.Minutes());

            var original = MockRepository.GenerateMock<Envelope>();
            var response = new Envelope();

            original.Stub(x => x.ForResponse(message)).Return(response);

            delayed.CreateEnvelope(original).ShouldBeTheSameAs(response);
            response.ExecutionTime.ShouldEqual(delayed.Time);
        }
        public void create_and_send_to_correct_destination()
        {
            var destination = new Uri("memory://blah");
            var message = new Events.Message1();
            var sendDirectlyTo = new SendDirectlyTo(destination, message);

            var original = MockRepository.GenerateMock<Envelope>();
            var response = new Envelope();

            original.Stub(x => x.ForSend(message)).Return(response);

            sendDirectlyTo.CreateEnvelope(original).ShouldBeTheSameAs(response);
            response.Destination.ShouldEqual(destination);
        }
        public void has_to_set_the_destination_header()
        {
            var message = new Events.Message1();
            var respondToSender = new RespondToSender(message);

            var original = MockRepository.GenerateMock<Envelope>();
            original.ReplyUri = new Uri("memory://me/reply");

            var response = new Envelope();

            original.Stub(x => x.ForResponse(message)).Return(response);

            respondToSender.CreateEnvelope(original).ShouldBeTheSameAs(response);
            response.Destination.ShouldEqual(original.ReplyUri);
        }
        public void SetUp()
        {
            theEvents = MockRepository.GenerateMock<IEventAggregator>();

            theListener = new ReplyListener<Events.Message1>(theEvents, correlationId, 10.Minutes());

            theMessage = new Events.Message1();

            var envelope = new EnvelopeToken
            {
                Message = theMessage
            };

            envelope.Headers[Envelope.ResponseIdKey] = correlationId;

            theListener.Handle(new EnvelopeReceived
            {
                Envelope = envelope
            });
        }
        public void do_not_set_destination_or_response_if_requested_header_does_not_exist_in_parent()
        {
            var parent = new Envelope
            {
                CorrelationId = Guid.NewGuid().ToString(),
                OriginalId = Guid.NewGuid().ToString(),
                Source = "foo://bar".ToUri()
            };

            parent.Headers.Has(Envelope.ReplyRequestedKey).ShouldBeFalse();

            var childMessage = new Events.Message1();

            var child = parent.ForResponse(childMessage);

            child.Headers.Has(Envelope.ResponseIdKey).ShouldBeFalse();
            child.Destination.ShouldBeNull();
        }
        public void parent_that_is_not_original_creating_child_envelope()
        {
            var parent = new Envelope
            {
                CorrelationId = Guid.NewGuid().ToString(),
                OriginalId = Guid.NewGuid().ToString()
            };

            var childMessage = new Events.Message1();

            var child = parent.ForResponse(childMessage);

            child.Message.ShouldBeTheSameAs(childMessage);

            child.OriginalId.ShouldEqual(parent.OriginalId);
            child.ParentId.ShouldEqual(parent.CorrelationId);
        }
        public void if_reply_requested_header_exists_in_parent_and_matches_the_message_type()
        {
            var parent = new Envelope
            {
                CorrelationId = Guid.NewGuid().ToString(),
                OriginalId = Guid.NewGuid().ToString(),
                ReplyUri = "foo://bar".ToUri(),
                ReplyRequested = typeof(Message1).Name
            };

            var childMessage = new Events.Message1();

            var child = parent.ForResponse(childMessage);

            child.Headers[Envelope.ResponseIdKey].ShouldEqual(parent.CorrelationId);
            child.Destination.ShouldEqual(parent.ReplyUri);
        }