Exemplo n.º 1
0
        protected override void EstablishContext()
        {
            base.EstablishContext();

            RemoteBus.ShouldHaveSubscriptionFor <MyMessage>();

            LocalBus.Publish(new MyMessage());
        }
Exemplo n.º 2
0
        protected override void EstablishContext()
        {
            base.EstablishContext();

            AddFirstCommandInstance("A", "loopback://localhost/a");
            AddFirstCommandInstance("B", "loopback://localhost/b");
            AddFirstCommandInstance("C", "loopback://localhost/c");

            RemoteBus.ShouldHaveSubscriptionFor <Distributed <FirstCommand> >();
        }
Exemplo n.º 3
0
        public void Should_not_remove_any_existing_subscriptions()
        {
            RemoteBus.SubscribeHandler <A>(x => { });

            RemoteBus.ShouldHaveSubscriptionFor <A>();
            LocalBus.ShouldHaveRemoteSubscriptionFor <A>();

            RemoteBus.Dispose();

            ThreadUtil.Sleep(2.Seconds());
            LocalBus.ShouldHaveRemoteSubscriptionFor <A>();
        }
Exemplo n.º 4
0
        public void Publishing_to_a_remote_subscriber()
        {
            Consumer           = new ConsumerOf <SimpleMessage>();
            _unsubscribeAction = RemoteBus.SubscribeInstance(Consumer);

            RemoteBus.ShouldHaveSubscriptionFor <SimpleMessage>();

            LocalBus.ShouldHaveSubscriptionFor <SimpleMessage>();

            _message = new SimpleMessage();
            LocalBus.Publish(_message);
        }
Exemplo n.º 5
0
        public void A_consumer_type_should_be_created_to_receive_the_message()
        {
            var fm = new FutureMessage <PingMessage>();

            LocalBus.SubscribeConsumer <PingHandler>(() => new PingHandler(fm));
            RemoteBus.ShouldHaveSubscriptionFor <PingMessage>();

            int old = PingHandler.Pinged;

            RemoteBus.Publish(new PingMessage());
            fm.IsAvailable(1.Seconds());
            Assert.That(PingHandler.Pinged, Is.GreaterThan(old));
        }
Exemplo n.º 6
0
        public void Should_be_able_to_read_xml_when_using_json()
        {
            Assert.IsTrue(RemoteBus.ShouldHaveSubscriptionFor <B>().Any());
            Assert.IsTrue(LocalBus.ShouldHaveSubscriptionFor <A>().Any());

            LocalBus.GetEndpoint(RemoteUri).Send(new A {
                Key = "Hello"
            });

            _requestReceived.WaitUntilCompleted(8.Seconds()).ShouldBeTrue();

            _responseReceived.WaitUntilCompleted(8.Seconds()).ShouldBeTrue();
        }
Exemplo n.º 7
0
        public void Should_remove_any_previous_subscriptions()
        {
            RemoteBus.SubscribeHandler <A>(x => { });
            RemoteBus.ShouldHaveSubscriptionFor <A>();
            LocalBus.ShouldHaveRemoteSubscriptionFor <A>();

            RemoteBus.Dispose();

            ThreadUtil.Sleep(2.Seconds());

            SetupRemoteBus();

            LocalBus.ShouldNotHaveSubscriptionFor <A>();
        }
Exemplo n.º 8
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));
        }
Exemplo n.º 9
0
        public void Subscring_to_an_endpoint_should_accept_and_dispatch_messages()
        {
            FutureMessage <PingMessage> fm = new FutureMessage <PingMessage>();
            bool workDid = false;

            LocalBus.SubscribeHandler <PingMessage>(
                (msg) => { workDid = true; fm.Set(msg); },
                delegate { return(true); });

            RemoteBus.ShouldHaveSubscriptionFor <PingMessage>();

            RemoteBus.Publish(_message);
            fm.IsAvailable(1.Seconds());
            Assert.That(workDid, Is.True, "Lazy Test!");
        }
        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 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.");
            }
        }
Exemplo n.º 12
0
        protected override void EstablishContext()
        {
            base.EstablishContext();

            InMemorySagaRepository <RegisterUserSaga> sagaRepository = SetupSagaRepository <RegisterUserSaga>();

            // this just shows that you can easily respond to the message
            RemoteBus.SubscribeHandler <SendUserVerificationEmail>(
                x =>
            {
                RemoteBus.ShouldHaveSubscriptionFor <UserVerificationEmailSent>();
                RemoteBus.Publish(new UserVerificationEmailSent(x.CorrelationId, x.Email));
            });

            RemoteBus.SubscribeSaga(sagaRepository);

            LocalBus.ShouldHaveSubscriptionFor <RegisterUser>();
            LocalBus.ShouldHaveSubscriptionFor <UserVerificationEmailSent>();
            LocalBus.ShouldHaveSubscriptionFor <UserValidated>();
        }
        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);
        }
        protected override void EstablishContext()
        {
            base.EstablishContext();

            var sagaRepository = new InMemorySagaRepository <ClaimRequestSaga>();

            //these subscriptions are to replace the Timeout Service
            RemoteBus.SubscribeHandler <ScheduleTimeout>(
                x =>
            {
                RemoteBus.ShouldHaveSubscriptionFor <TimeoutScheduled>();
                RemoteBus.Publish(new TimeoutScheduled {
                    CorrelationId = x.CorrelationId, TimeoutAt = x.TimeoutAt
                });
            });

            RemoteBus.SubscribeHandler <CancelTimeout>(
                x =>
            {
                RemoteBus.ShouldHaveSubscriptionFor <TimeoutCancelled>();
                RemoteBus.Publish(new TimeoutCancelled {
                    CorrelationId = x.CorrelationId
                });
            }
                );

            //RemoteBus.SubscribeHandler<ClaimRequestCreatedPendingVerificationEvent>(x =>
            //    {
            //        Debug.WriteLine("Claim Created Pending Verification event received.");
            //    });

            RemoteBus.SubscribeSaga(sagaRepository);

            //event messages that the Saga is subscribed to
            LocalBus.ShouldHaveSubscriptionFor <ClaimRequestCreatedPendingVerificationEvent>();
            LocalBus.ShouldHaveSubscriptionFor <CardUseVerifiedEvent>();
            LocalBus.ShouldHaveSubscriptionFor <TimeoutExpired>();
        }
Exemplo n.º 16
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");
            }
        }