示例#1
0
        public async Task can_decorate_a_handler_without_response_to_return_default_response()
        {
            // given

            var handlerMock = new Mock <IHandler <RequestWithNoResponse> >();

            var builder = new ContainerBuilder();

            BuildRegistration.Instance(handlerMock.Object)
            .WithDefaultResponse()
            .RegisterAsHandlerIn(builder);

            builder.RegisterType <HandlerMediator>()
            .AsSelf();

            using (var container = builder.Build())
            {
                var request = new RequestWithNoResponse();

                // when

                var response = await container
                               .Resolve <HandlerMediator>()
                               .Handle(request);

                // then

                response.Should().BeSameAs(Nothing.Value);

                handlerMock.Verify(handler => handler.Handle(request), Times.Once);
            }
        }
示例#2
0
        public async Task mediator_handles_a_request_without_a_response_using_a_registered_handler()
        {
            // given

            var request = new RequestWithNoResponse();

            _handlerWithNoResponseMock.Setup(handler => handler.Handle(request))
            .Returns(Task.FromResult(Nothing.Value));

            // when

            var response = await _mediator.Handle(request);

            // then

            response.Should().Be(Nothing.Value);

            _handlerWithNoResponseMock.Verify(handler => handler.Handle(request), Times.Once);
        }