Ejemplo n.º 1
0
		public void A_response_should_be_sent_directly_if_a_reply_address_is_specified()
		{
			PingMessage ping = new PingMessage();

			TestMessageConsumer<PongMessage> otherConsumer = new TestMessageConsumer<PongMessage>();
			RemoteBus.Subscribe(otherConsumer);

			TestCorrelatedConsumer<PongMessage, Guid> consumer = new TestCorrelatedConsumer<PongMessage, Guid>(ping.CorrelationId);
			LocalBus.Subscribe(consumer);

			FutureMessage<PongMessage> pong = new FutureMessage<PongMessage>();

			RemoteBus.Subscribe<PingMessage>(message =>
				{
					pong.Set(new PongMessage(message.CorrelationId));

					CurrentMessage.Respond(pong.Message);
				});

			LocalBus.Publish(ping, context => context.SendResponseTo(LocalBus));

			Assert.IsTrue(pong.IsAvailable(3.Seconds()), "No pong generated");

			consumer.ShouldHaveReceivedMessage(pong.Message, 3.Seconds());
			otherConsumer.ShouldNotHaveReceivedMessage(pong.Message, 1.Seconds());
		}
Ejemplo n.º 2
0
        public void A_response_should_be_sent_directly_if_a_reply_address_is_specified()
        {
            var ping = new PingMessage();

            var otherConsumer = new TestMessageConsumer <PongMessage>();

            RemoteBus.SubscribeInstance(otherConsumer);

            var consumer = new TestCorrelatedConsumer <PongMessage, Guid>(ping.CorrelationId);

            LocalBus.SubscribeInstance(consumer);

            var pong = new FutureMessage <PongMessage>();

            RemoteBus.SubscribeHandler <PingMessage>(message =>
            {
                pong.Set(new PongMessage(message.CorrelationId));

                RemoteBus.Context().Respond(pong.Message);
            });

            RemoteBus.ShouldHaveRemoteSubscriptionFor <PongMessage>();
            LocalBus.ShouldHaveRemoteSubscriptionFor <PongMessage>();
            LocalBus.ShouldHaveRemoteSubscriptionFor <PingMessage>();

            LocalBus.Publish(ping, context => context.SendResponseTo(LocalBus));

            Assert.IsTrue(pong.IsAvailable(8.Seconds()), "No pong generated");

            consumer.ShouldHaveReceivedMessage(pong.Message, 8.Seconds());
            otherConsumer.ShouldNotHaveReceivedMessage(pong.Message, 1.Seconds());
        }
Ejemplo n.º 3
0
		public void A_filter_should_be_nameable()
		{
			var consumer = new TestMessageConsumer<PingMessage>();

			_pipeline.Filter<PingMessage>("Message Blocker", x => false);

			_pipeline.Subscribe(consumer);

			var message = new PingMessage();

			_pipeline.Dispatch(message);

			consumer.ShouldNotHaveReceivedMessage(message);

			PipelineViewer.Trace(_pipeline);
		}
Ejemplo n.º 4
0
        public void A_filtered_message_should_not_be_received()
        {
            TestMessageConsumer <PingMessage> consumer = new TestMessageConsumer <PingMessage>();

            _pipeline.Filter <PingMessage>(x => false);

            _pipeline.Subscribe(consumer);

            PingMessage message = new PingMessage();

            _pipeline.Dispatch(message);

            consumer.ShouldNotHaveReceivedMessage(message);

            PipelineViewer.Trace(_pipeline);
        }
Ejemplo n.º 5
0
        public void A_filter_should_be_nameable()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            _pipeline.Filter <PingMessage>("Message Blocker", x => false);

            _pipeline.Subscribe(consumer);

            var message = new PingMessage();

            _pipeline.Dispatch(message);

            consumer.ShouldNotHaveReceivedMessage(message);

            PipelineViewer.Trace(_pipeline);
        }
Ejemplo n.º 6
0
        public void It_should_not_be_received_by_an_uninterested_consumer()
        {
            TestMessageConsumer <PingMessage> messageConsumer = new TestMessageConsumer <PingMessage>();

            RemoteBus.Subscribe <PingMessage>(messageConsumer.MessageHandler, x => false);

            TestMessageConsumer <PingMessage> consumer = new TestMessageConsumer <PingMessage>();

            RemoteBus.Subscribe(consumer);

            PingMessage message = new PingMessage();

            LocalBus.Publish(message);

            consumer.ShouldHaveReceivedMessage(message, _timeout);
            messageConsumer.ShouldNotHaveReceivedMessage(message, TimeSpan.FromSeconds(1));
        }
Ejemplo n.º 7
0
		public void A_filter_should_be_removable()
		{
			var consumer = new TestMessageConsumer<PingMessage>();

			var f = _pipeline.Filter<PingMessage>(x => false);
			PipelineViewer.Trace(_pipeline);

			var message = new PingMessage();
			_pipeline.Dispatch(message);

			consumer.ShouldNotHaveReceivedMessage(message);

			f();
			PipelineViewer.Trace(_pipeline);

			message = new PingMessage();
			_pipeline.Dispatch(message);

			consumer.ShouldHaveReceivedMessage(message);
		}
        public void It_should_rollback_a_send_if_an_exception_is_thrown()
        {
            var consumer = new TestMessageConsumer <PongMessage>();

            LocalBus.SubscribeInstance(consumer);

            var message  = new PingMessage();
            var response = new PongMessage(message.CorrelationId);

            RemoteBus.SubscribeHandler <PingMessage>(m =>
            {
                RemoteBus.Publish(response);
                throw new ApplicationException("Boing!");
            });

            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();
            RemoteBus.ShouldHaveSubscriptionFor <PongMessage>();
            LocalBus.Publish(message);

            consumer.ShouldNotHaveReceivedMessage(response, _timeout);
        }
Ejemplo n.º 9
0
        public void A_filter_should_be_removable()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            var f = _pipeline.Filter <PingMessage>(x => false);

            PipelineViewer.Trace(_pipeline);

            var message = new PingMessage();

            _pipeline.Dispatch(message);

            consumer.ShouldNotHaveReceivedMessage(message);

            f();
            PipelineViewer.Trace(_pipeline);

            message = new PingMessage();
            _pipeline.Dispatch(message);

            consumer.ShouldHaveReceivedMessage(message);
        }
Ejemplo n.º 10
0
		public void A_filtered_message_should_not_be_received()
		{
			TestMessageConsumer<PingMessage> consumer = new TestMessageConsumer<PingMessage>();

			_pipeline.Filter<PingMessage>(x => false);

			_pipeline.Subscribe(consumer);

			PingMessage message = new PingMessage();

			_pipeline.Dispatch(message);

			consumer.ShouldNotHaveReceivedMessage(message);

			PipelineViewer.Trace(_pipeline);
		}
Ejemplo n.º 11
0
		public void It_should_not_be_received_by_an_uninterested_consumer()
		{
			TestMessageConsumer<PingMessage> messageConsumer = new TestMessageConsumer<PingMessage>();
			RemoteBus.SubscribeHandler<PingMessage>(messageConsumer.MessageHandler, x => false);

			TestMessageConsumer<PingMessage> consumer = new TestMessageConsumer<PingMessage>();
			RemoteBus.SubscribeInstance(consumer);

			PingMessage message = new PingMessage();
			LocalBus.Publish(message);

			consumer.ShouldHaveReceivedMessage(message, _timeout);
			messageConsumer.ShouldNotHaveReceivedMessage(message, TimeSpan.FromSeconds(1));
		}