Example #1
0
        public void Register_WithAsyncTopicHandlerDelegate_WithUnserializableTopic_ThrowsUnserializableTypeException()
        {
            // Arrange
            var dispatcher = new TopicDispatcher();
            AsyncTopicHandlerDelegate <UnserializableTopic> handler = _ => Task.CompletedTask;

            // Act
            TestDelegate register = () => dispatcher.Register(handler);

            // Assert
            Assert.That(register, Throws.TypeOf <UnserializableTypeException>());
        }
Example #2
0
        public void Register_WithAsyncTopicHandler_WithUnserializableTopic_ThrowsUnserializableTypeException()
        {
            // Arrange
            var dispatcher = new TopicDispatcher();
            var handler    = new Mock <IAsyncTopicHandler <UnserializableTopic> >().Object;

            // Act
            TestDelegate register = () => dispatcher.Register(handler);

            // Assert
            Assert.That(register, Throws.TypeOf <UnserializableTypeException>());
        }
Example #3
0
        public void Handle_WithBaseClassHandlerRegistered_DoesNothing()
        {
            // Arrange
            var dispatcher = new TopicDispatcher();

            dispatcher.Register(handler);
            var message = new SubTopic();

            // Act
            dispatcher.Handle(subscriber, message);

            // Assert
            mockHandler.Verify(m => m.Handle(It.IsAny <Topic>()), Times.Never);
        }
Example #4
0
        public void Handle_WithAsyncHandlerRegistered_CallsHandler()
        {
            // Arrange
            var dispatcher = new TopicDispatcher();

            dispatcher.Register(asyncHandler);
            var message = new Topic();

            // Act
            dispatcher.Handle(subscriber, message);

            // Assert
            mockAsyncHandler.Verify(m => m.Handle(It.IsIn(message)), Times.Once);
        }
Example #5
0
        public void Handle_WithHandlerDelegateRegistered_CallsHandler()
        {
            // Arrange
            var handled    = false;
            var dispatcher = new TopicDispatcher();
            var message    = new Topic();

            dispatcher.Register <Topic>(e => { handled = true; });

            // Act
            dispatcher.Handle(subscriber, message);

            // Assert
            Assert.That(handled, Is.True);
        }
Example #6
0
        public void Handle_WithAsyncHandlerDelegateRegistered_CallsHandler()
        {
            // Arrange
            var handled    = false;
            var dispatcher = new TopicDispatcher();
            var message    = new Topic();
            var wait       = new ManualResetEvent(false);

            dispatcher.Register <Topic>(e => Task.Run(() => { handled = true; wait.Set(); }));

            // Act
            dispatcher.Handle(subscriber, message);

            wait.WaitOne();

            // Assert
            Assert.That(handled, Is.True);
        }
Example #7
0
 public Builder WithAsyncTopicHandler <TTopic>(AsyncTopicHandlerDelegate <TTopic> handler)
 {
     TopicDispatcher.Register(handler);
     return(this);
 }
Example #8
0
 public Builder WithTopicHandler <TTopic>(ITopicHandler <TTopic> handler)
 {
     TopicDispatcher.Register(handler);
     return(this);
 }