Ejemplo n.º 1
0
		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());
		}
Ejemplo n.º 3
0
        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());
        }
Ejemplo n.º 4
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.º 5
0
        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;
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
		}
Ejemplo n.º 9
0
		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);
		}
Ejemplo n.º 10
0
		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());
		}
Ejemplo n.º 11
0
        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());
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 14
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);
        }
Ejemplo n.º 15
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());
        }
Ejemplo n.º 16
0
        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());
        }
Ejemplo n.º 17
0
        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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 22
0
		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);
		}
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 31
0
		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());
		}
Ejemplo n.º 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);
		}
Ejemplo n.º 33
0
        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());
        }
Ejemplo n.º 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);
		}
Ejemplo n.º 35
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);
        }
Ejemplo n.º 36
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.º 37
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.º 38
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);
        }
Ejemplo n.º 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));
		}
Ejemplo n.º 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);
        }
Ejemplo n.º 41
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));
        }
        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();
        }
Ejemplo n.º 43
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);
        }
Ejemplo n.º 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);
		}
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 47
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));
        }
        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);
        }
Ejemplo n.º 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);
		}
Ejemplo n.º 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);
		}
Ejemplo n.º 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);
		}
Ejemplo n.º 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);
	    }
Ejemplo n.º 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);
		}
Ejemplo n.º 55
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));
		}
Ejemplo n.º 56
0
		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);
		}
Ejemplo n.º 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);
		}
Ejemplo n.º 58
0
		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();
		}
Ejemplo n.º 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);
		}
Ejemplo n.º 60
0
		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());
		}