Esempio n. 1
0
        public void async_execution_of_handlers_will_not_block_message_sender()
        {
            //Arrange
            var ping_logger  = new MessageLogger();
            var ping_handler = new PingHandler(ping_logger.add);

            Bus.Instance.Register(ping_handler);

            //Act
            Bus.Instance.SendMessageAsync(new Ping());

            //Assert
            Assert.AreEqual(0, ping_logger.messages.Count());
        }
Esempio n. 2
0
        public void will_publish_once_to_single_handler()
        {
            //Arrange
            var ping_logger  = new MessageLogger();
            var ping_handler = new PingHandler(ping_logger.add);

            Bus.Instance.Register(ping_handler);

            //Act
            Bus.Instance.SendMessage(new Ping());

            //Assert
            Assert.AreEqual(1, ping_logger.messages.Count());
        }
Esempio n. 3
0
        public void will_publish_one_of_each_message_to_double_handler()
        {
            //Arrange
            var ping_pong_logger  = new MessageLogger();
            var ping_pong_handler = new PingPongHandler(ping_pong_logger.add, ping_pong_logger.add);

            Bus.Instance.Register(ping_pong_handler);

            //Act
            Bus.Instance.SendMessage(new Ping());
            Bus.Instance.SendMessage(new Pong());

            //Assert
            Assert.AreEqual(2, ping_pong_logger.messages.Count());
            Assert.AreEqual(1, ping_pong_logger.get_messages_of_type <Ping>().Count());
            Assert.AreEqual(1, ping_pong_logger.get_messages_of_type <Pong>().Count());
        }
Esempio n. 4
0
        public void exception_in_one_handler_will_not_halt_execution_of_other_handlers()
        {
            //Arrange
            var ping_logger  = new MessageLogger();
            var ping_handler = new PingHandler(m => { throw new System.Exception(); });

            var ping_logger2  = new MessageLogger();
            var ping_handler2 = new PingHandler(ping_logger2.add);

            Bus.Instance.Register(ping_handler);
            Bus.Instance.Register(ping_handler2);

            //Act
            Bus.Instance.SendMessage(new Ping());

            //Assert
            Assert.AreEqual(1, ping_logger2.messages.Count());
        }
Esempio n. 5
0
        public void will_publish_manytimes_to_single_handler()
        {
            //Arrange
            var ping_logger  = new MessageLogger();
            var ping_handler = new PingHandler(ping_logger.add);

            Bus.Instance.Register(ping_handler);

            //Act
            Enumerable
            .Range(0, 5)
            .ToList()
            .ForEach(i =>
            {
                Bus.Instance.SendMessage(new Ping());
            });


            //Assert
            Assert.AreEqual(5, ping_logger.messages.Count());
        }