示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
 public FakeServiceScope(FakeServiceScopeFactory factory)
 {
     _factory = factory;
 }