Exemplo n.º 1
0
        public void Adding_many_dynamic_and_removing_should_retain_dynamics()
        {
            var dynamicA = new FutureMessage <A>();
            var dynamicB = new FutureMessage <B>();
            var dynamicC = new FutureMessage <C>();
            var dynamicD = new FutureMessage <D>();

            UnsubscribeAction subscriptionA = RemoteBus.SubscribeHandler <A>(dynamicA.Set);
            UnsubscribeAction subscriptionB = RemoteBus.SubscribeHandler <B>(dynamicB.Set);
            UnsubscribeAction subscriptionC = RemoteBus.SubscribeHandler <C>(dynamicC.Set);
            UnsubscribeAction subscriptionD = RemoteBus.SubscribeHandler <D>(dynamicD.Set);

            LocalBus.HasSubscription <D>(8.Seconds()).Any().ShouldBeTrue("No D subscription");
            try
            {
                subscriptionA().ShouldBeFalse("A static not remaining");
                subscriptionB().ShouldBeFalse("B static not remaining");
                subscriptionC().ShouldBeFalse("C static not remaining");

                LocalBus.Publish(new A());
                LocalBus.Publish(new B());
                LocalBus.Publish(new C());
                LocalBus.Publish(new D());

                _receivedA.IsAvailable(8.Seconds()).ShouldBeTrue("A not received");
                _receivedB.IsAvailable(8.Seconds()).ShouldBeTrue("B not received");
                _receivedC.IsAvailable(8.Seconds()).ShouldBeTrue("C not received");
                dynamicD.IsAvailable(8.Seconds()).ShouldBeTrue("D should have been received");
            }
            finally
            {
                subscriptionD();
            }
        }
Exemplo n.º 2
0
        protected override void EstablishContext()
        {
            base.EstablishContext();

            LocalBus.HasSubscription <A>(8.Seconds()).Any().ShouldBeTrue("No subscription A found on local bus");
            LocalBus.HasSubscription <B>(8.Seconds()).Any().ShouldBeTrue("No subscription B found on local bus");
            LocalBus.HasSubscription <C>(8.Seconds()).Any().ShouldBeTrue("No subscription C found on local bus");
        }
Exemplo n.º 3
0
        public void Setup()
        {
            LocalBus  = CreateBus("local", x => { });
            RemoteBus = CreateBus("remote", x => x.Consumer <SomeConsumer>());

            Assert.IsTrue(LocalBus.HasSubscription <InvalidRequest>().Any());
            Assert.IsTrue(LocalBus.HasSubscription <ValidRequest>().Any());

            CompleteEvent.Reset();
        }
Exemplo n.º 4
0
        public void Should_be_possible()
        {
            LocalBus.HasSubscription <IBusinessCommand>(8.Seconds()).Any().ShouldBeTrue();
            RemoteBus.HasSubscription <ISecureCommand <IBusinessCommand> >(8.Seconds()).Any().ShouldBeTrue();

            RemoteBus.Publish(new BusinessCommand
            {
                SqlText = "DROP TABLE [Users]",
            });

            CommandHandler.CommandReceived.IsAvailable(8.Seconds()).ShouldBeTrue();
        }
Exemplo n.º 5
0
        void Publish <T>(T message)
            where T : class
        {
            LocalBus.HasSubscription <T>().Any()
            .ShouldBeTrue("Message subscription was not found");
            LocalBus.HasSubscription <WorkerAvailable <T> >().Any()
            .ShouldBeTrue("Worker available subscription was not found.");
            RemoteBus.HasSubscription <Distributed <T> >().Any()
            .ShouldBeTrue("Message subscription was not found");

            LocalBus.Endpoint.Send(message, context => { context.SendResponseTo(LocalBus); });
        }
        public void Should_recover_the_subscriptions_after_restarting()
        {
            Assert.IsTrue(LocalBus.HasSubscription <Hello>().Any(), "Initial subscription not found");

            RemoteBus.Dispose();
            RemoteBus = null;

            LocalBus.Dispose();
            LocalBus = null;

            // now we need to reload the local bus
            LocalBus = ServiceBusFactory.New(ConfigureLocalBus);

            Assert.IsTrue(LocalBus.HasSubscription <Hello>().Any(), "Subscription not found after restart");
        }
Exemplo n.º 7
0
        public void The_timeout_should_be_added_to_the_storage()
        {
            var timedOut = new FutureMessage <TimeoutExpired>();

            LocalBus.SubscribeHandler <TimeoutExpired>(timedOut.Set);

            LocalBus.HasSubscription <TimeoutExpired>(8.Seconds()).Any()
            .ShouldBeTrue("No subscription");

            LocalBus.Publish(new ScheduleTimeout(_correlationId, 2.Seconds()));

            Stopwatch watch = Stopwatch.StartNew();

            timedOut.IsAvailable(8.Seconds()).ShouldBeTrue("Did not get timeout message");

            watch.Stop();

            Debug.WriteLine(string.Format("Timeout took {0}ms", watch.ElapsedMilliseconds));
        }
        public void The_message_should_be_delivered_to_a_remote_subscriber_with_a_reply()
        {
            var updated        = new Future <UpdateMessage>();
            var updateAccepted = new Future <UpdateAcceptedMessage>();

            RemoteBus.SubscribeContextHandler <UpdateMessage>(context =>
            {
                updated.Complete(context.Message);

                context.Respond(new UpdateAcceptedMessage());
            });

            LocalBus.HasSubscription <UpdateMessage>().Count().ShouldBeGreaterThan(0);

            LocalBus.SubscribeHandler <UpdateAcceptedMessage>(updateAccepted.Complete);
            RemoteBus.HasSubscription <UpdateAcceptedMessage>().Count().ShouldBeGreaterThan(0);

            var um = new UpdateMessage();

            LocalBus.Publish(um);

            updated.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Update not received");
            updateAccepted.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Update accepted not received");
        }
Exemplo n.º 9
0
 public void Should_have_the_subscription_for_the_worker_availability_C()
 {
     LocalBus.HasSubscription <WorkerAvailable <C> >().Any()
     .ShouldBeTrue("Worker available subscription was not found.");
 }
Exemplo n.º 10
0
 public void Should_have_the_subscription_for_the_orchestrating()
 {
     LocalBus.HasSubscription <Distributed <B> >().Any()
     .ShouldBeTrue("Message subscription was not found");
 }
Exemplo n.º 11
0
 public void Should_have_the_subscription_for_the_observed()
 {
     LocalBus.HasSubscription <C>().Any()
     .ShouldBeTrue("Message subscription was not found");
 }
Exemplo n.º 12
0
 public void Should_not_have_a_subscription_for_the_second_consumer_message()
 {
     LocalBus.HasSubscription <AnotherMessageInterface>().Count()
     .ShouldEqual(0, "A subscription was found for AnotherMessageInterface and shouldn't have been.");
 }
Exemplo n.º 13
0
 public void Should_have_the_subscription_for_the_initiating()
 {
     LocalBus.HasSubscription <A>().Any()
     .ShouldBeTrue("Message subscription was not found");
 }
 public void Should_have_a_subscription_for_the_consumer_message_type()
 {
     LocalBus.HasSubscription <SimpleMessageInterface>().Count()
     .ShouldEqual(1, "No subscription for the SimpleMessageInterface was found.");
 }
 public void Should_have_a_subscription_for_the_nested_consumer_type()
 {
     LocalBus.HasSubscription <AnotherMessageInterface>().Count()
     .ShouldEqual(1, "Only one subscription should be registered for another consumer");
 }
Exemplo n.º 16
0
 public void Should_have_a_subscription_for_the_third_saga_message()
 {
     LocalBus.HasSubscription <ThirdSagaMessage>().Count()
     .ShouldEqual(1, "No subscription for the ThirdSagaMessage was found.");
 }
Exemplo n.º 17
0
 public void Should_have_the_subscription_for_the_context_consumer()
 {
     LocalBus.HasSubscription <Distributed <C> >().Any()
     .ShouldBeTrue("Message subscription was not found");
 }
Exemplo n.º 18
0
 public void Should_have_the_subscription_for_the_selected_consumer()
 {
     LocalBus.HasSubscription <B>().Any()
     .ShouldBeTrue("Message subscription was not found");
 }