Ejemplo n.º 1
0
        public void Should_throw_exeception_if_Property_Type_is_not_equal_to_deserialized_message_type_string()
        {
            // Arrange
            Global.DefaultTypeNameSerializer = new TypeNameSerializer();
            var property     = Substitute.For <IBasicProperties>();
            var errorHanlder = Substitute.For <IConsumerErrorHandler>();
            var handler      = new DefaultMessageHandlerForTest <Customer>("SubscriptionName", Substitute.For <Action <Customer, MessageDeliverEventArgs> >(), errorHanlder, Substitute.For <ISerializer>(), Substitute.For <IRabbitWatcher>());

            // Action
            handler.PublicCheckMessageType(property);
        }
Ejemplo n.º 2
0
        public void Should_catch_all_exception()
        {
            // Arrange
            var watcher      = Substitute.For <IRabbitWatcher>();
            var errorHanlder = Substitute.For <IConsumerErrorHandler>();
            var handler      = new DefaultMessageHandlerForTest <Customer>(
                "SubscriptionName",
                Substitute.For <Action <Customer, MessageDeliverEventArgs> >(),
                errorHanlder,
                Substitute.For <ISerializer>(),
                watcher);

            // Action
            handler.CleanUp(new BasicDeliverEventArgs(), true);

            // Assert
            watcher.Received(1).Error(Arg.Is <Exception>(e => e.Message == "HandlingCompleteException"));
            watcher.Received(1).Error(Arg.Is <Exception>(e => e.Message == "AfterHandlingMessageException"));
        }
Ejemplo n.º 3
0
        public void Should_fire_event_MessageWasNotHandled_if_msg_was_not_handled()
        {
            // Arrange
            var waitHandler  = new AutoResetEvent(false);
            var watcher      = Substitute.For <IRabbitWatcher>();
            var errorHanlder = Substitute.For <IConsumerErrorHandler>();
            var handler      = new DefaultMessageHandlerForTest <Customer>(
                "SubscriptionName",
                Substitute.For <Action <Customer, MessageDeliverEventArgs> >(),
                errorHanlder,
                Substitute.For <ISerializer>(),
                watcher);

            handler.MessageWasNotHandled += x => waitHandler.Set();

            // Action
            handler.CleanUp(new BasicDeliverEventArgs(), false);
            Assert.IsTrue(waitHandler.WaitOne(1000));

            // Assert
            watcher.DidNotReceive().ErrorFormat(Arg.Is <string>(e => e == "There is an error when trying to fire MessageWasNotDelivered event"), Arg.Any <object[]>());
        }
Ejemplo n.º 4
0
        public void Should_catch_all_exception_when_firing_event_MessageWasNotHandled()
        {
            // Arrange
            var waitHandler  = new AutoResetEvent(false);
            var watcher      = Substitute.For <IRabbitWatcher>();
            var errorHanlder = Substitute.For <IConsumerErrorHandler>();
            var handler      = new DefaultMessageHandlerForTest <Customer>(
                "SubscriptionName",
                Substitute.For <Action <Customer, MessageDeliverEventArgs> >(),
                errorHanlder,
                Substitute.For <ISerializer>(),
                watcher);

            handler.MessageWasNotHandled += x => { waitHandler.Set(); throw new Exception("Error firing event MessageWasNotHandled"); };

            // Action
            handler.CleanUp(new BasicDeliverEventArgs(), false);
            Assert.IsTrue(waitHandler.WaitOne(1000));

            // Assert
            watcher.Received(1).ErrorFormat(Arg.Is <string>(e => e == "There is an error when trying to fire MessageWasNotDelivered event"), Arg.Any <object[]>());
            watcher.Received(1).Error(Arg.Is <Exception>(e => e.Message == "Error firing event MessageWasNotHandled"));
        }