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>()); }
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>()); }
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); }
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); }
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); }
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); }
public Builder WithAsyncTopicHandler <TTopic>(AsyncTopicHandlerDelegate <TTopic> handler) { TopicDispatcher.Register(handler); return(this); }
public Builder WithTopicHandler <TTopic>(ITopicHandler <TTopic> handler) { TopicDispatcher.Register(handler); return(this); }