예제 #1
0
        public void ShouldNotDeliverMessagesToSubscriberAfterSubscriptionDisposed()
        {
            FakeServiceEndpoint serviceEndpoint1 = new FakeServiceEndpoint(typeof(ITestServiceMessage1));
            FakeServiceEndpoint serviceEndpoint2 = new FakeServiceEndpoint(typeof(ITestServiceMessage2));

            IServiceBus serviceBus = ServiceBus.Configure()
                .WithEndpoint((IServiceEndpointClient) serviceEndpoint1)
                .WithEndpoint((IServiceEndpoint)serviceEndpoint1)
                .WithEndpoint((IServiceEndpointClient) serviceEndpoint2)
                .WithEndpoint((IServiceEndpoint)serviceEndpoint2)
                .UsingConsoleLogging().Create();

            var subscriber = new FakeSubscriber();
            var testScheduler = new TestScheduler();
            var subscription = serviceBus.Subscribe(subscriber, testScheduler);

            serviceEndpoint1.Messages.OnNext(new TestServiceEvent1());
            testScheduler.AdvanceBy(1);

            subscription.Dispose();

            serviceEndpoint1.Messages.OnNext(new TestServiceEvent2());
            testScheduler.AdvanceBy(1);

            Assert.That(subscriber.Received.Count(), Is.EqualTo(1));
            Assert.That(subscriber.Received[0].GetType(), Is.EqualTo(typeof(TestServiceEvent1)));
        }
예제 #2
0
        public void ShouldThrowExceptionIfAlreadySubscribed()
        {
            FakeServiceEndpoint serviceEndpoint1 = new FakeServiceEndpoint(typeof(ITestServiceMessage1));
            FakeServiceEndpoint serviceEndpoint2 = new FakeServiceEndpoint(typeof(ITestServiceMessage2));

            IServiceBus serviceBus = ServiceBus.Configure()
                .WithEndpoint((IServiceEndpointClient) serviceEndpoint1)
                .WithEndpoint((IServiceEndpoint)serviceEndpoint1)
                .WithEndpoint((IServiceEndpointClient) serviceEndpoint2)
                .WithEndpoint((IServiceEndpoint)serviceEndpoint2)
                .UsingConsoleLogging().Create();

            FakeSubscriber subscriber = new FakeSubscriber();

            serviceBus.Subscribe(subscriber);
            serviceBus.Subscribe(subscriber);
        }
예제 #3
0
        public void ShouldEmitSubscriberExceptionsOnExceptionObservable()
        {
            FakeServiceEndpoint serviceEndpoint1 = new FakeServiceEndpoint(typeof(ITestServiceMessage1));
            FakeServiceEndpoint serviceEndpoint2 = new FakeServiceEndpoint(typeof(ITestServiceMessage2));

            IServiceBus serviceBus = ServiceBus.Configure()
                .WithEndpoint((IServiceEndpointClient) serviceEndpoint1)
                .WithEndpoint((IServiceEndpoint)serviceEndpoint1)
                .WithEndpoint((IServiceEndpointClient) serviceEndpoint2)
                .WithEndpoint((IServiceEndpoint)serviceEndpoint2)
                .UsingConsoleLogging().Create();

            ConcurrentBag<Exception> exceptions = new ConcurrentBag<Exception>();
            serviceBus.Exceptions.Subscribe(exceptions.Add);

            FakeSubscriber subscriber = new FakeSubscriber();

            var testScheduler = new TestScheduler();
            var subscription = serviceBus.Subscribe(subscriber, testScheduler);

            subscriber.ThrowExceptions = true;
            serviceBus.PublishAsync(new TestServiceEvent1());
            testScheduler.AdvanceBy(1);

            serviceBus.PublishAsync(new TestServiceEvent2());
            testScheduler.AdvanceBy(1);

            serviceBus.SendAsync(new TestServiceCommand1());
            testScheduler.AdvanceBy(1);

            serviceBus.SendAsync(new TestServiceCommand2());
            testScheduler.AdvanceBy(1);

            subscription.Dispose();

            Assert.That(exceptions.Count(), Is.EqualTo(4));
            Assert.That(subscriber.Received.Count(), Is.EqualTo(0));
        }
예제 #4
0
        public void ShouldSendAllMessagesToSubscribers()
        {
            FakeServiceEndpoint serviceEndpoint1 = new FakeServiceEndpoint(typeof(ITestServiceMessage1));
            FakeServiceEndpoint serviceEndpoint2 = new FakeServiceEndpoint(typeof(ITestServiceMessage2));

            IServiceBus serviceBus = ServiceBus.Configure()
                .WithEndpoint((IServiceEndpointClient) serviceEndpoint1)
                .WithEndpoint((IServiceEndpoint)serviceEndpoint1)
                .WithEndpoint((IServiceEndpointClient) serviceEndpoint2)
                .WithEndpoint((IServiceEndpoint)serviceEndpoint2)
                .UsingConsoleLogging()
                .Create();

            ConcurrentBag<Exception> exceptions = new ConcurrentBag<Exception>();
            serviceBus.Exceptions.Subscribe(exceptions.Add);

            FakeSubscriber subscriber = new FakeSubscriber();
            FakeSubscriber2 subscriber2 = new FakeSubscriber2();

            var testScheduler = new TestScheduler();
            var subscription = serviceBus.Subscribe(subscriber, testScheduler);
            var subscription2 = serviceBus.Subscribe(subscriber2, testScheduler);

            serviceBus.PublishAsync(new TestServiceEvent1());
            testScheduler.AdvanceBy(1);

            serviceBus.PublishAsync(new TestServiceEvent2());
            testScheduler.AdvanceBy(1);

            serviceBus.SendAsync(new TestServiceCommand1());
            testScheduler.AdvanceBy(1);

            serviceBus.SendAsync(new TestServiceCommand2());
            testScheduler.AdvanceBy(1);

            serviceEndpoint1.Messages.OnNext(new TestServiceRequest1());
            testScheduler.AdvanceBy(1);

            subscription.Dispose();
            subscription2.Dispose();

            Assert.That(exceptions.Count(), Is.EqualTo(0));
            Assert.That(subscriber.Received.Count(), Is.EqualTo(5));
            Assert.That(subscriber.Received[0].GetType(), Is.EqualTo(typeof(TestServiceEvent1)));
            Assert.That(subscriber.Received[1].GetType(), Is.EqualTo(typeof(TestServiceEvent2)));
            Assert.That(subscriber.Received[2].GetType(), Is.EqualTo(typeof(TestServiceCommand1)));
            Assert.That(subscriber.Received[3].GetType(), Is.EqualTo(typeof(TestServiceCommand2)));
            Assert.That(subscriber.Received[4].GetType(), Is.EqualTo(typeof(TestServiceRequest1)));

            Assert.That(subscriber2.Received.Count(), Is.EqualTo(5));
            Assert.That(subscriber2.Received[0].GetType(), Is.EqualTo(typeof(TestServiceEvent1)));
            Assert.That(subscriber2.Received[1].GetType(), Is.EqualTo(typeof(TestServiceEvent2)));
            Assert.That(subscriber2.Received[2].GetType(), Is.EqualTo(typeof(TestServiceCommand1)));
            Assert.That(subscriber2.Received[3].GetType(), Is.EqualTo(typeof(TestServiceCommand2)));
            Assert.That(subscriber2.Received[4].GetType(), Is.EqualTo(typeof(TestServiceRequest1)));
        }