Esempio n. 1
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());
        }
Esempio n. 2
0
        public void A_subscription_should_be_added_for_a_selective_consumer()
        {
            var consumer = new TestSelectiveConsumer <PingMessage>();

            LocalBus.SubscribeInstance(consumer);

            _subscriptionService.AssertWasCalled(x => x.SubscribedTo <PingMessage>(LocalBus.Endpoint.Address.Uri));
        }
Esempio n. 3
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());
        }
Esempio n. 4
0
        public void Should_receive_a_fault_message()
        {
            var consumer = new SmartConsumer();

            LocalBus.SubscribeHandler <Hello>(delegate { throw new AccessViolationException("Crap!"); });

            LocalBus.SubscribeInstance(consumer);

            LocalBus.Publish(new Hello(), x => x.SendFaultTo(LocalBus));

            consumer.Fault.IsAvailable(30.Seconds()).ShouldBeTrue();
        }
Esempio n. 5
0
        public void A_consumer_object_should_receive_the_message()
        {
            FutureMessage <PingMessage> fm = new FutureMessage <PingMessage>();
            PingHandler handler            = new PingHandler(fm);

            LocalBus.SubscribeInstance(handler);
            RemoteBus.ShouldHaveSubscriptionFor <PingMessage>();

            int old = PingHandler.Pinged;

            RemoteBus.Publish(new PingMessage());
            fm.IsAvailable(1.Seconds());
            Assert.That(PingHandler.Pinged, Is.GreaterThan(old));
        }
Esempio n. 6
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());
        }
Esempio n. 7
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());
        }
Esempio n. 8
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 Should_properly_register_the_consumers_for_each_endpoint()
        {
            var firstComponent = new FirstComponent();

            LocalBus.SubscribeInstance(firstComponent);

            var secondComponent = new SecondComponent();

            LocalBus.SubscribeInstance(secondComponent);

            RemoteBus.ShouldHaveSubscriptionFor <IncomingMessage>();

            RemoteBus.ShouldHaveCorrelatedSubscriptionFor <IncomingMessage, string>(FirstCorrelationId);
            RemoteBus.ShouldHaveCorrelatedSubscriptionFor <IncomingMessage, string>(SecondCorrelationId);
        }
        public void The_exception_should_not_disrupt_the_flow_of_messages()
        {
            CrashingService service = new CrashingService();

            LocalBus.SubscribeInstance(service);

            LocalEndpoint.Send(new BogusMessage());

            CrashingService.Received.WaitOne(5.Seconds(), true).ShouldBeTrue("No message received");

            CrashingService.Received.Reset();

            LocalEndpoint.Send(new LegitMessage());

            CrashingService.LegitReceived.WaitOne(5.Seconds(), true).ShouldBeTrue("No message received");
        }
Esempio n. 11
0
        public void A_reply_should_be_received_by_the_requestor()
        {
            RemoteBus.ShouldHaveRemoteSubscriptionFor <PingMessage>();
            LocalBus.ShouldHaveRemoteSubscriptionFor <PingMessage>();

            var message = new PingMessage();

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

            LocalBus.SubscribeInstance(consumer);

            RemoteBus.ShouldHaveRemoteSubscriptionFor <PongMessage>();

            LocalBus.Publish(message);

            TestConsumerBase <PingMessage> .AnyShouldHaveReceivedMessage(message, _timeout);

            consumer.ShouldHaveReceivedMessage(new PongMessage(message.CorrelationId), _timeout);
        }
        public void Then_the_claim_is_rejected_when_no_verification_is_received_within_the_timeout()
        {
            var timer      = Stopwatch.StartNew();
            var controller = new ClaimRequestTestCoordinator(LocalBus, 1000);

            using (LocalBus.SubscribeInstance(controller).Disposable())
            {
                RemoteBus.ShouldHaveSubscriptionFor <ClaimRequestCreatedPendingVerificationEvent>();

                bool complete = controller.CreateClaimRequest(1200, "ClaimType", DateTime.Today.AddDays(-10), "provider", "reason");
                Assert.IsTrue(complete, "There should be a timeout scheduled for this claim request.");

                timer.Stop();
                Debug.WriteLine(string.Format("Time to handle message: {0}ms", timer.ElapsedMilliseconds));

                complete = controller.Timeout();
                Assert.IsTrue(complete, "The claim request timed out but the claim was not rejected.");
            }
        }
        public void Then_a_new_timeout_is_scheduled_and_cancelled_when_the_claim_is_verified()
        {
            var timer      = Stopwatch.StartNew();
            var controller = new ClaimRequestTestCoordinator(LocalBus, 4000);

            using (LocalBus.SubscribeInstance(controller).Disposable())
            {
                RemoteBus.ShouldHaveSubscriptionFor <ClaimRequestCreatedPendingVerificationEvent>();
                RemoteBus.ShouldHaveSubscriptionFor <CardUseVerifiedEvent>();

                bool complete = controller.CreateClaimRequest(1200, "ClaimType", DateTime.Today.AddDays(-10), "provider", "reason");
                Assert.IsTrue(complete, "No timeout scheduled message was received for this claim request.");

                timer.Stop();
                Debug.WriteLine(string.Format("Time to handle message: {0}ms", timer.ElapsedMilliseconds));

                complete = controller.VerifyCardUse();
                Assert.IsTrue(complete, "The timeout should have been cancelled and the saga should be complete.");
            }
        }
        public void It_should_not_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.ShouldHaveReceivedMessage(response, _timeout);
        }
Esempio n. 15
0
        public void The_user_should_be_pending()
        {
            Stopwatch timer = Stopwatch.StartNew();

            var controller = new RegisterUserController(LocalBus);

            using (IUnsubscribeAction unsubscribe = LocalBus.SubscribeInstance(controller).Disposable())
            {
                RemoteBus.ShouldHaveSubscriptionFor <UserRegistrationPending>();
                RemoteBus.ShouldHaveSubscriptionFor <UserRegistrationComplete>();

                bool complete = controller.RegisterUser("username", "password", "Display Name", "*****@*****.**");

                complete.ShouldBeTrue("The user should be pending");

                timer.Stop();
                Debug.WriteLine(string.Format("Time to handle message: {0}ms", timer.ElapsedMilliseconds));

                complete = controller.ValidateUser();

                complete.ShouldBeTrue("The user should be complete");
            }
        }
Esempio n. 16
0
 public void A_consumer_is_subscribed_to_a_message()
 {
     Consumer = new ConsumerOf <SimpleMessage>();
     LocalBus.SubscribeInstance(Consumer);
 }