예제 #1
0
        public void HandlerSubscribeTest()
        {
            IMetricsClient client = NSubstitute.Substitute.For <IMetricsClient>();

            IEventBus bus = new RabbitMQEventBus(new DATConfiguration(), client);

            MessageTest test = new MessageTest {
                Name = "Maikel"
            };

            bus.Publish("exchange.subscribe-test-handler", test);
            bus.Publish("exchange.subscribe-test-handler", test);
            bus.Publish("exchange.subscribe-test-handler", test);


            int index = 0;

            bus.Subscribe <MessageTest>("exchange.subscribe-test-handler", messageTest =>
            {
                Assert.Equal("Maikel", messageTest.Name);

                index++;

                return(true);
            });

            Thread.Sleep(500);

            Assert.Equal(3, index);
        }
예제 #2
0
        public void PublishTest()
        {
            IMetricsClient client = NSubstitute.Substitute.For <IMetricsClient>();

            IEventBus bus = new RabbitMQEventBus(new DATConfiguration(), client);

            MessageTest test = new MessageTest {
                Name = "Maikel"
            };

            bus.Publish("exchange.topic", test);
        }
예제 #3
0
        public void GetTest()
        {
            IMetricsClient client = NSubstitute.Substitute.For <IMetricsClient>();

            IEventBus bus = new RabbitMQEventBus(new DATConfiguration(), client);

            MessageTest test = new MessageTest {
                Name = "Maikel"
            };

            bus.Publish("exchange.topic-get", test);

            Option <MessageTest> returnMessage = bus.Get <MessageTest>("exchange.topic-get");

            Assert.True(returnMessage.HasValue);
            Assert.True(returnMessage.Exists(x => x.Name == "Maikel"));
        }
예제 #4
0
        public void ObservableSubscribeTest()
        {
            IMetricsClient client = NSubstitute.Substitute.For <IMetricsClient>();

            IEventBus bus = new RabbitMQEventBus(new DATConfiguration(), client);

            MessageTest test = new MessageTest {
                Name = "Maikel"
            };

            bus.Publish("exchange.subscribe-test", test);
            bus.Publish("exchange.subscribe-test", test);
            bus.Publish("exchange.subscribe-test", test);


            IObservable <MessageTest> subscription = bus.Subscribe <MessageTest>("exchange.subscribe-test");


            subscription.Do(messageTest => Assert.Equal("Maikel", messageTest.Name)).Subscribe();
        }