public async Task Dispatch_SingleEvent_ShouldInvokeCorrectHandler() { // Arrange var singleEvent = new EventB(); var fakeServiceScopeFactory = new FakeServiceScopeFactory(); var dispatcher = new EventDispatcher <object>(fakeServiceScopeFactory); // Act await dispatcher.Dispatch(new[] { singleEvent }, default); // Assert fakeServiceScopeFactory.EventAHandlerMock.Verify(x => x.Handle(It.IsAny <EventA>(), default), Times.Never); fakeServiceScopeFactory.EventBHandlerMock.Verify(x => x.Handle(It.IsAny <EventB>(), default), Times.Once); fakeServiceScopeFactory.EventBHandlerMock.Verify(x => x.Handle(singleEvent, default), Times.Once); }
public async Task Dispatch_MultipleEvents_ShouldInvokeCorrectHandlers() { // Arrange var eventA = new EventA(); var eventB = new EventB(); var fakeServiceScopeFactory = new FakeServiceScopeFactory(); var dispatcher = new EventDispatcher <object>(fakeServiceScopeFactory); // Act await dispatcher.Dispatch(new object[] { eventB, eventA }, default); // Assert fakeServiceScopeFactory.EventAHandlerMock.Verify(x => x.Handle(It.IsAny <EventA>(), default), Times.Once); fakeServiceScopeFactory.EventAHandlerMock.Verify(x => x.Handle(eventA, default), Times.Once); fakeServiceScopeFactory.EventBHandlerMock.Verify(x => x.Handle(It.IsAny <EventB>(), default), Times.Once); fakeServiceScopeFactory.EventBHandlerMock.Verify(x => x.Handle(eventB, default), Times.Once); }
public FakeServiceScope(FakeServiceScopeFactory factory) { _factory = factory; }