public void A_response_should_be_published_if_no_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);

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

			consumer.ShouldHaveReceivedMessage(pong.Message, 3.Seconds());
			otherConsumer.ShouldHaveReceivedMessage(pong.Message, 1.Seconds());
		}
		public void A_response_should_be_published_if_no_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);
				});

			LocalBus.Publish(ping);

			pong.IsAvailable(8.Seconds()).ShouldBeTrue("No pong generated");

			consumer.ShouldHaveReceivedMessage(pong.Message, 8.Seconds());
			otherConsumer.ShouldHaveReceivedMessage(pong.Message, 8.Seconds());
		}
        public void A_response_should_be_published_if_no_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);

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

            consumer.ShouldHaveReceivedMessage(pong.Message, 3.Seconds());
            otherConsumer.ShouldHaveReceivedMessage(pong.Message, 1.Seconds());
        }
        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());
        }
        public static IContainer Init()
        {
            ObjectFactory.Initialize(x =>
                                     	{
                                     		var consumer = new TestMessageConsumer();

                                            var serviceBus = ServiceBusFactory.New(sbc =>
                                            {
                                                sbc.UseMulticastSubscriptionClient();
                                                sbc.SetNetwork("localhost");

                                                sbc.UseMsmq();
                                                sbc.VerifyMsmqConfiguration();
                                                sbc.ReceiveFrom("msmq://localhost/test_consumer");

                                                sbc.UseControlBus();

                                                sbc.ImplementDistributorWorker<TestMessage>(msg => consumer.Consume, 1, 1);

                                                sbc.UseLog4Net();
                                            });

                                     		consumer.ServiceBus = serviceBus;

                                     		x.For<TestMessageConsumer>()
                                     			.Singleton()
                                     			.Use(consumer);
                                     	});

            return ObjectFactory.Container;
        }
Beispiel #6
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());
        }
Beispiel #7
0
        public void A_subscription_should_be_added_for_a_consumer()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            LocalBus.SubscribeInstance(consumer);

            _subscriptionService.AssertWasCalled(x => x.SubscribedTo <PingMessage>(LocalBus.Endpoint.Address.Uri));
        }
Beispiel #8
0
		public void It_should_be_received_by_one_subscribed_consumer_on_the_same_bus()
		{
			var consumer = new TestMessageConsumer<PingMessage>();
			LocalBus.Subscribe(consumer);

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

			consumer.ShouldHaveReceivedMessage(message, _timeout);
		}
		public void It_should_be_received_by_one_subscribed_consumer()
		{
			TestMessageConsumer<PingMessage> consumer = new TestMessageConsumer<PingMessage>();
			RemoteBus.SubscribeInstance(consumer);

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

			consumer.ShouldHaveReceivedMessage(message, _timeout);
		}
		public void A_simple_bus_should_be_able_to_subscribe_and_publish()
		{
			TestMessageConsumer<PingMessage> consumer = new TestMessageConsumer<PingMessage>();
			LocalBus.Subscribe(consumer);

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

			consumer.ShouldHaveReceivedMessage(message, 500.Milliseconds());
		}
        public void A_simple_bus_should_be_able_to_subscribe_and_publish()
        {
            var consumer = new TestMessageConsumer<PingMessage>();
            LocalBus.SubscribeInstance(consumer);

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

            consumer.ShouldHaveReceivedMessage(message, 8.Seconds());
        }
        public void It_should_be_received_by_one_subscribed_consumer_on_the_same_bus()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            LocalBus.Subscribe(consumer);

            var message = new PingMessage();

            LocalBus.Publish(message);

            consumer.ShouldHaveReceivedMessage(message, _timeout);
        }
Beispiel #13
0
        public void A_simple_bus_should_be_able_to_subscribe_and_publish()
        {
            TestMessageConsumer <PingMessage> consumer = new TestMessageConsumer <PingMessage>();

            LocalBus.SubscribeInstance(consumer);

            PingMessage message = new PingMessage();

            LocalBus.Publish(message);

            consumer.ShouldHaveReceivedMessage(message, 500.Milliseconds());
        }
        public void An_unfiltered_message_should_be_received()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            _pipeline.Subscribe(consumer);

            var message = new PingMessage();

            _pipeline.Dispatch(message);

            consumer.ShouldHaveReceivedMessage(message);
        }
        public void Should_accept_the_type_specified_with_context()
        {
            var consumer = new TestMessageConsumer<PingMessage>();
            LocalBus.SubscribeInstance(consumer);

            var message = new PingMessage();

            object unknownMessage = message;
            LocalBus.Publish(unknownMessage, typeof(PingMessage), x => x.SetRequestId("27"));

            consumer.ShouldHaveReceivedMessage(message, 8.Seconds());
        }
        public void Should_receive_the_proper_message()
        {
            var consumer = new TestMessageConsumer<PingMessage>();
            LocalBus.SubscribeInstance(consumer);

            var message = new PingMessage();

            object unknownMessage = message;
            LocalBus.Publish(unknownMessage);

            consumer.ShouldHaveReceivedMessage(message, 8.Seconds());
        }
        public void It_should_be_received_by_one_subscribed_message_handler()
        {
            TestMessageConsumer <PingMessage> messageConsumer = new TestMessageConsumer <PingMessage>();

            RemoteBus.Subscribe <PingMessage>(messageConsumer.MessageHandler);

            PingMessage message = new PingMessage();

            LocalBus.Publish(message);

            messageConsumer.ShouldHaveReceivedMessage(message, _timeout);
        }
        public void It_should_be_received_by_one_subscribed_consumer()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            RemoteBus.SubscribeInstance(consumer);

            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();
            var message = new PingMessage();

            LocalBus.Publish(message);

            consumer.ShouldHaveReceivedMessage(message, _timeout);
        }
Beispiel #19
0
        public void Should_receive_the_proper_message()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            LocalBus.SubscribeInstance(consumer);

            var message = new PingMessage();

            object unknownMessage = message;

            LocalBus.Endpoint.Send(unknownMessage);

            consumer.ShouldHaveReceivedMessage(message, 8.Seconds());
        }
Beispiel #20
0
        public void Should_accept_the_type_specified_with_context()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            LocalBus.SubscribeInstance(consumer);

            var message = new PingMessage();

            object unknownMessage = message;

            LocalBus.Publish(unknownMessage, typeof(PingMessage), x => x.SetRequestId("27"));

            consumer.ShouldHaveReceivedMessage(message, 8.Seconds());
        }
Beispiel #21
0
        public void Should_accept_the_type_specified()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            LocalBus.SubscribeInstance(consumer);

            var message = new PingMessage();

            object unknownMessage = message;

            LocalBus.Endpoint.Send(unknownMessage, typeof(PingMessage));

            consumer.ShouldHaveReceivedMessage(message, 8.Seconds());
        }
		public void It_should_be_received_by_multiple_subscribed_consumers()
		{
			TestMessageConsumer<PingMessage> consumer = new TestMessageConsumer<PingMessage>();
			RemoteBus.Subscribe(consumer);

			TestMessageConsumer<PingMessage> messageConsumer = new TestMessageConsumer<PingMessage>();
			RemoteBus.Subscribe<PingMessage>(messageConsumer.MessageHandler);

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

			consumer.ShouldHaveReceivedMessage(message, _timeout);
			messageConsumer.ShouldHaveReceivedMessage(message, _timeout);
		}
Beispiel #23
0
		public void It_should_leave_the_message_in_the_queue_if_an_exception_is_thrown()
		{
			var consumer = new TestSelectiveConsumer<PingMessage>(x => false);
			RemoteBus.Subscribe(consumer);

			var realConsumer = new TestMessageConsumer<PingMessage>();
			LocalBus.Subscribe(realConsumer);

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

			realConsumer.ShouldHaveReceivedMessage(message, _timeout);
			consumer.ShouldNotHaveReceivedMessage(message, _timeout);
		}
        public void A_subscription_should_be_added_for_a_consumer()
        {
            using (Record())
            {
//                _mockSubscriptionCache.Add(_subscription);
            }

            using (Playback())
            {
                var consumer = new TestMessageConsumer<PingMessage>();

                _serviceBus.Subscribe(consumer);
            }
        }
Beispiel #25
0
		public void It_should_be_received_by_multiple_subscribed_consumers()
		{
			var localConsumer = new TestMessageConsumer<PingMessage>();
			LocalBus.Subscribe(localConsumer);

			var remoteConsumer = new TestMessageConsumer<PingMessage>();
			RemoteBus.Subscribe(remoteConsumer);

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

			localConsumer.ShouldHaveReceivedMessage(message, _timeout);
			remoteConsumer.ShouldHaveReceivedMessage(message, _timeout);
		}
        public void It_should_be_received_by_one_subscribed_consumer()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            RemoteBus.Subscribe(consumer);

            Thread.Sleep(5.Seconds());

            var message = new PingMessage();

            LocalBus.Publish(message);

            consumer.ShouldHaveReceivedMessage(message, _timeout);
        }
Beispiel #27
0
        public void A_subscription_should_be_added_for_a_consumer()
        {
            using (Record())
            {
//                _mockSubscriptionCache.Add(_subscription);
            }

            using (Playback())
            {
                var consumer = new TestMessageConsumer <PingMessage>();

                _serviceBus.Subscribe(consumer);
            }
        }
Beispiel #28
0
        public void for_regular_subscriptions()
        {
            _subscriptionEvent.Expect(x => x.SubscribedTo <PingMessage>()).Return(() =>
            {
                _unsubscribe();
                return(true);
            });

            var consumer = new TestMessageConsumer <PingMessage>();

            _pipeline.Subscribe(consumer);

            _subscriptionEvent.VerifyAllExpectations();
        }
Beispiel #29
0
        public void The_system_should_be_ready_to_use_before_getting_underway()
        {
            var consumer          = new TestMessageConsumer <PingMessage>();
            var unsubscribeAction = RemoteBus.SubscribeInstance(consumer);

            LocalBus.ShouldHaveRemoteSubscriptionFor <PingMessage>();

            var message = new PingMessage();

            LocalBus.Publish(message);

            consumer.ShouldHaveReceivedMessage(message, 8.Seconds());

            unsubscribeAction();
        }
Beispiel #30
0
        public void A_component_should_be_subscribed_to_the_pipeline()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

            _pipeline.ConnectConsumer <TestMessageConsumer <PingMessage> >(() => consumer);

            PipelineViewer.Trace(_pipeline);

            var message = new PingMessage();

            _pipeline.ShouldHaveSubscriptionFor <PingMessage>();

            _pipeline.Dispatch(message);

            TestMessageConsumer <PingMessage> .AnyShouldHaveReceivedMessage(message, 1.Seconds());
        }
		public void A_component_should_be_subscribed_to_the_pipeline()
		{
			TestMessageConsumer<PingMessage> consumer = new TestMessageConsumer<PingMessage>();

			_pipeline.ConnectConsumer<TestMessageConsumer<PingMessage>>(() => consumer);

			PipelineViewer.Trace(_pipeline);

			PingMessage message = new PingMessage();

			_pipeline.ShouldHaveSubscriptionFor<PingMessage>();

			_pipeline.Dispatch(message);

			TestMessageConsumer<PingMessage>.AnyShouldHaveReceivedMessage(message, 1.Seconds());
		}
Beispiel #32
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);
		}
        public void for_regular_subscriptions()
        {
            _subscriptionEvent.Expect(x => x.SubscribedTo <PingMessage>()).Return(() =>
            {
                _unsubscribe();
                return(true);
            });

            var consumer = new TestMessageConsumer <PingMessage>();
            var token    = _pipeline.ConnectInstance(consumer);

            token();

            _subscriptionEvent.VerifyAllExpectations();
            _unsubscribe.AssertWasCalled(x => x());
        }
Beispiel #34
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);
		}
        public void A_message_should_fall_throuh_happy_filters()
        {
            var consumer = new TestMessageConsumer <PingMessage>();

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

            _pipeline.Subscribe(consumer);

            var message = new PingMessage();

            _pipeline.Dispatch(message);

            consumer.ShouldHaveReceivedMessage(message);

            PipelineViewer.Trace(_pipeline);
        }
        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);
        }
        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);
        }
        public void An_object_filter_should_pass_the_message_if_allowed()
        {
            var consumer = new TestMessageConsumer <object>();

            _pipeline.Filter <object>("Message Passer", x => true);

            _pipeline.Subscribe(consumer);

            var message = new PingMessage();

            _pipeline.Dispatch(message);

            consumer.ShouldHaveReceivedMessage(message);

            PipelineViewer.Trace(_pipeline);
        }
Beispiel #39
0
		public void It_should_be_received_after_the_deferral_period_elapses()
		{
			TestMessageConsumer<PingMessage> consumer = new TestMessageConsumer<PingMessage>();
			LocalBus.Subscribe(consumer);

			Stopwatch watch = Stopwatch.StartNew();

			var message = new PingMessage();

			LocalBus.Publish(new DeferMessage(_correlationId, 1.Seconds(), message));

			consumer.ShouldHaveReceivedMessage(message, 3.Seconds());

			watch.Stop();

			Debug.WriteLine(string.Format("Timeout took {0}ms", watch.ElapsedMilliseconds));
		}
Beispiel #40
0
        public void It_should_leave_the_message_in_the_queue_if_an_exception_is_thrown()
        {
            var consumer = new TestSelectiveConsumer <PingMessage>(x => false);

            RemoteBus.Subscribe(consumer);

            var realConsumer = new TestMessageConsumer <PingMessage>();

            LocalBus.Subscribe(realConsumer);

            var message = new PingMessage();

            LocalBus.Publish(message);

            realConsumer.ShouldHaveReceivedMessage(message, _timeout);
            consumer.ShouldNotHaveReceivedMessage(message, _timeout);
        }
        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));
        }
        public void The_system_should_be_ready_to_use_before_getting_underway()
        {
            var consumer          = new TestMessageConsumer <PingMessage>();
            var unsubscribeAction = RemoteBus.Subscribe(consumer);

            Thread.Sleep(1000);

            DumpPipelines();

            var message = new PingMessage();

            LocalBus.Publish(message);

            consumer.ShouldHaveReceivedMessage(message, 500.Milliseconds());

            unsubscribeAction();
        }
        public void It_should_be_received_by_multiple_subscribed_consumers()
        {
            var localConsumer = new TestMessageConsumer <PingMessage>();

            LocalBus.Subscribe(localConsumer);

            var remoteConsumer = new TestMessageConsumer <PingMessage>();

            RemoteBus.Subscribe(remoteConsumer);

            PingMessage message = new PingMessage();

            LocalBus.Publish(message);

            localConsumer.ShouldHaveReceivedMessage(message, _timeout);
            remoteConsumer.ShouldHaveReceivedMessage(message, _timeout);
        }
Beispiel #44
0
		public void Echo_reply_should_work()
		{
			var echoConsumer = new TestMessageConsumer<PingMessage>();
			RemoteBus.Subscribe(echoConsumer);

			var replyConsumer = new TestMessageConsumer<PongMessage>();
			LocalBus.Subscribe(replyConsumer);

			var echoMessage = new PingMessage();
			LocalBus.Publish(echoMessage);

			echoConsumer.ShouldHaveReceivedMessage(echoMessage, _timeout);

			PongMessage replyMessage = new PongMessage(echoMessage.CorrelationId);
			RemoteBus.Publish(replyMessage);

			replyConsumer.ShouldHaveReceivedMessage(replyMessage, _timeout);
		}
Beispiel #45
0
//        [ExpectedException(typeof(SemaphoreFullException))] //TODO: Bad Exception
        public void The_batch_should_throw_an_error()
        {
            _batchSize = 1;

            var timeoutConsumer = new TestMessageConsumer <BatchTimeout <IndividualBatchMessage, Guid> >();

            RemoteBus.Subscribe(timeoutConsumer);

            var batchConsumer = new TestBatchConsumer <IndividualBatchMessage, Guid>();

            RemoteBus.Subscribe(batchConsumer);

            Guid batchId = Guid.NewGuid();
            IndividualBatchMessage message = new IndividualBatchMessage(batchId, _batchSize);

            LocalBus.Publish(message);
            LocalBus.Publish(message);
        }
Beispiel #46
0
        public void Should_dispatch_an_interface_via_the_pipeline()
        {
            var pipeline = InboundPipelineConfigurator.CreateDefault(null);

            var consumer = new TestMessageConsumer <IComplaintAdded>();

            pipeline.ConnectInstance(consumer);

            var             user      = new User("Chris", "*****@*****.**");
            IComplaintAdded complaint = new ComplaintAdded(user, "No toilet paper", BusinessArea.Appearance)
            {
                Body = "There was no toilet paper in the stall, forcing me to use my treasured issue of .NET Developer magazine."
            };

            pipeline.Dispatch(complaint);

            consumer.ShouldHaveReceivedMessage(complaint);
        }
        public void It_should_be_received_after_the_deferral_period_elapses()
        {
            TestMessageConsumer <PingMessage> consumer = new TestMessageConsumer <PingMessage>();

            LocalBus.Subscribe(consumer);

            Stopwatch watch = Stopwatch.StartNew();

            var message = new PingMessage();

            LocalBus.Publish(new DeferMessage(_correlationId, 1.Seconds(), message));

            consumer.ShouldHaveReceivedMessage(message, 3.Seconds());

            watch.Stop();

            Debug.WriteLine(string.Format("Timeout took {0}ms", watch.ElapsedMilliseconds));
        }
        public void It_should_not_rollback_a_send_if_an_exception_is_thrown()
        {
            var consumer = new TestMessageConsumer <PongMessage>();

            LocalBus.Subscribe(consumer);

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

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

            LocalBus.Publish(message);

            consumer.ShouldHaveReceivedMessage(response, _timeout);
        }
        public void It_should_be_received_by_multiple_subscribed_consumers()
        {
            TestMessageConsumer <PingMessage> consumer = new TestMessageConsumer <PingMessage>();

            RemoteBus.SubscribeInstance(consumer);

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

            RemoteBus.SubscribeHandler <PingMessage>(messageConsumer.MessageHandler);

            LocalBus.ShouldHaveSubscriptionFor <PingMessage>();

            PingMessage message = new PingMessage();

            LocalBus.Publish(message);

            consumer.ShouldHaveReceivedMessage(message, _timeout);
            messageConsumer.ShouldHaveReceivedMessage(message, _timeout);
        }
Beispiel #50
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);
		}
Beispiel #51
0
		public void Should_dispatch_an_interface_via_the_pipeline()
		{
			var builder = MockRepository.GenerateMock<IObjectBuilder>();
			var pipeline = MessagePipelineConfigurator.CreateDefault(builder, null);

			var consumer = new TestMessageConsumer<ComplaintAdded>();

			var unsubscribeAction = pipeline.Subscribe(consumer);

			var user = new UserImpl("Chris", "*****@*****.**");
			ComplaintAdded complaint = new ComplaintAddedImpl(user, "No toilet paper", BusinessArea.Appearance)
				{
					Body = "There was no toilet paper in the stall, forcing me to use my treasured issue of .NET Developer magazine."
				};

			pipeline.Dispatch(complaint);

			PipelineViewer.Trace(pipeline);

			consumer.ShouldHaveReceivedMessage(complaint);
		}
Beispiel #52
0
		public void The_batch_should_throw_an_exception_that_the_timeout_occurred()
		{
			_batchSize = 2;

			var timeoutConsumer = new TestMessageConsumer<BatchTimeout<IndividualBatchMessage, Guid>>();
			RemoteBus.Subscribe(timeoutConsumer);

			var batchConsumer = new TestBatchConsumer<IndividualBatchMessage, Guid>();

			RemoteBus.Subscribe(batchConsumer);

			Guid batchId = Guid.NewGuid();
			IndividualBatchMessage message = new IndividualBatchMessage(batchId, _batchSize);

			LocalBus.Publish(message);

			timeoutConsumer.ShouldHaveReceivedMessage(new BatchTimeout<IndividualBatchMessage, Guid>(batchId), _timeout);

			batchConsumer.ShouldNotHaveCompletedBatch(TimeSpan.Zero);
		}
Beispiel #53
0
	    public void An_object_filter_should_pass_the_message_if_allowed()
	    {
            var consumer = new TestMessageConsumer<object>();

            _pipeline.Filter<object>("Message Passer", x => true);

            _pipeline.Subscribe(consumer);
 
            var message = new PingMessage();

            _pipeline.Dispatch(message);

            consumer.ShouldHaveReceivedMessage(message);

            PipelineViewer.Trace(_pipeline);
	    }
Beispiel #54
0
		public void An_unfiltered_message_should_be_received()
		{
			var consumer = new TestMessageConsumer<PingMessage>();

			_pipeline.Subscribe(consumer);

			var message = new PingMessage();

			_pipeline.Dispatch(message);

			consumer.ShouldHaveReceivedMessage(message);
		}
		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));
		}
		public void It_should_be_received_by_one_subscribed_message_handler()
		{
			TestMessageConsumer<PingMessage> messageConsumer = new TestMessageConsumer<PingMessage>();
			RemoteBus.SubscribeHandler<PingMessage>(messageConsumer.MessageHandler);

			LocalBus.ShouldHaveSubscriptionFor<PingMessage>();
			
			PingMessage message = new PingMessage();
			LocalBus.Publish(message);

			messageConsumer.ShouldHaveReceivedMessage(message, _timeout);
		}
Beispiel #57
0
//        [ExpectedException(typeof(SemaphoreFullException))] //TODO: Bad Exception
		public void The_batch_should_throw_an_error()
		{
			_batchSize = 1;

			var timeoutConsumer = new TestMessageConsumer<BatchTimeout<IndividualBatchMessage, Guid>>();
			RemoteBus.Subscribe(timeoutConsumer);

			var batchConsumer = new TestBatchConsumer<IndividualBatchMessage, Guid>();
			RemoteBus.Subscribe(batchConsumer);

			Guid batchId = Guid.NewGuid();
			IndividualBatchMessage message = new IndividualBatchMessage(batchId, _batchSize);

			LocalBus.Publish(message);
			LocalBus.Publish(message);
		}
		public void for_regular_subscriptions()
		{
			_subscriptionEvent.Expect(x => x.SubscribedTo<PingMessage>()).Return(() =>
				{
					_unsubscribe();
					return true;
				});

			var consumer = new TestMessageConsumer<PingMessage>();
			_pipeline.ConnectInstance(consumer);

			_subscriptionEvent.VerifyAllExpectations();
		}
Beispiel #59
0
		public void A_message_should_fall_throuh_happy_filters()
		{
			var consumer = new TestMessageConsumer<PingMessage>();

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

			_pipeline.Subscribe(consumer);

			var message = new PingMessage();

			_pipeline.Dispatch(message);

			consumer.ShouldHaveReceivedMessage(message);

			PipelineViewer.Trace(_pipeline);
		}
		public void for_regular_subscriptions()
		{
			_subscriptionEvent.Expect(x => x.SubscribedTo<PingMessage>()).Return(() =>
				{
					_unsubscribe();
					return true;
				});

			var consumer = new TestMessageConsumer<PingMessage>();
			var token = _pipeline.Subscribe(consumer);

			token();

			_subscriptionEvent.VerifyAllExpectations();
			_unsubscribe.AssertWasCalled(x => x());
		}