コード例 #1
0
ファイル: NybusHostTests.cs プロジェクト: simgu/Nybus
        public void ExecuteCommandHandlerAsync_throws_if_handler_is_not_registered([Frozen] IServiceProvider serviceProvider, NybusHost sut, IDispatcher dispatcher, ICommandContext <FirstTestCommand> commandContext, IServiceScopeFactory scopeFactory)
        {
            var handlerType = typeof(FirstTestCommandHandler);

            Mock.Get(serviceProvider).Setup(p => p.GetService(typeof(IServiceScopeFactory))).Returns(scopeFactory);

            Mock.Get(serviceProvider).Setup(p => p.GetService(handlerType)).Returns(null as FirstTestCommandHandler);

            Assert.ThrowsAsync <MissingHandlerException>(() => sut.ExecuteCommandHandlerAsync(dispatcher, commandContext, handlerType));
        }
コード例 #2
0
ファイル: NybusHostTests.cs プロジェクト: simgu/Nybus
        public async Task ExecuteCommandHandler_executes_handler([Frozen] IServiceProvider serviceProvider, NybusHost sut, IDispatcher dispatcher, ICommandContext <FirstTestCommand> commandContext, IServiceScopeFactory scopeFactory, ICommandHandler <FirstTestCommand> handler)
        {
            var handlerType = handler.GetType();

            Mock.Get(serviceProvider).Setup(p => p.GetService(typeof(IServiceScopeFactory))).Returns(scopeFactory);

            Mock.Get(serviceProvider).Setup(p => p.GetService(handlerType)).Returns(handler);

            await sut.ExecuteCommandHandlerAsync(dispatcher, commandContext, handlerType);

            Mock.Get(handler).Verify(p => p.HandleAsync(dispatcher, commandContext), Times.Once);
        }
コード例 #3
0
ファイル: NybusHostTests.cs プロジェクト: simgu/Nybus
        public async Task ExecuteCommandHandlerAsync_notifies_engine_on_success([Frozen] IServiceProvider serviceProvider, [Frozen] IBusEngine engine, NybusHost sut, IDispatcher dispatcher, CommandMessage <FirstTestCommand> commandMessage, IServiceScopeFactory scopeFactory, ICommandHandler <FirstTestCommand> handler)
        {
            var handlerType = handler.GetType();

            var context = new NybusCommandContext <FirstTestCommand>(commandMessage);

            Mock.Get(serviceProvider).Setup(p => p.GetService(typeof(IServiceScopeFactory))).Returns(scopeFactory);

            Mock.Get(serviceProvider).Setup(p => p.GetService(handlerType)).Returns(handler);

            await sut.ExecuteCommandHandlerAsync(dispatcher, context, handlerType);

            Mock.Get(engine).Verify(p => p.NotifySuccessAsync(context.Message));
        }
コード例 #4
0
ファイル: NybusHostTests.cs プロジェクト: simgu/Nybus
        public async Task ExecuteCommandHandlerAsync_executes_error_filter_on_fail([Frozen] IServiceProvider serviceProvider, [Frozen] IBusEngine engine, [Frozen] INybusConfiguration configuration, NybusHost sut, IDispatcher dispatcher, CommandMessage <FirstTestCommand> commandMessage, IServiceScopeFactory scopeFactory, ICommandHandler <FirstTestCommand> handler, Exception error, IErrorFilter errorFilter)
        {
            configuration.CommandErrorFilters = new[] { errorFilter };

            var handlerType = handler.GetType();

            var context = new NybusCommandContext <FirstTestCommand>(commandMessage);

            Mock.Get(serviceProvider).Setup(p => p.GetService(typeof(IServiceScopeFactory))).Returns(scopeFactory);

            Mock.Get(serviceProvider).Setup(p => p.GetService(handlerType)).Returns(handler);

            Mock.Get(handler).Setup(p => p.HandleAsync(It.IsAny <IDispatcher>(), It.IsAny <ICommandContext <FirstTestCommand> >())).Throws(error);

            await sut.ExecuteCommandHandlerAsync(dispatcher, context, handlerType);

            Mock.Get(errorFilter).Verify(p => p.HandleErrorAsync(context, error, It.IsAny <CommandErrorDelegate <FirstTestCommand> >()));
        }