示例#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();
        }