예제 #1
0
        public async Task ExecuteCommandWithCommandResponseWithResultGeneratesBadResponse()
        {
            SimpleCommandCommandResponseResult command    = new SimpleCommandCommandResponseResult();
            Mock <ICommandDispatcher>          dispatcher = new Mock <ICommandDispatcher>();

            dispatcher.Setup(x => x.DispatchAsync(command, It.IsAny <CancellationToken>()))
            .ReturnsAsync(new CommandResult <CommandResponse <bool> >(CommandResponse <bool> .WithError("went wrong"), false));
            TestSubjectController controller = new TestSubjectController(dispatcher.Object);

            IActionResult result = await controller.ExecuteCommandProxy(command);

            BadRequestObjectResult castResult = (BadRequestObjectResult)result;

            Assert.Equal(400, castResult.StatusCode);
            Assert.Equal("went wrong", ((string[])((SerializableError)castResult.Value)[""])[0]);
        }
예제 #2
0
        public async Task ExecuteCommandWithCommandResponseThrowsExceptionAndGeneratesBadResponse()
        {
            SimpleCommandCommandResponse command    = new SimpleCommandCommandResponse();
            Mock <ICommandDispatcher>    dispatcher = new Mock <ICommandDispatcher>();

            dispatcher.Setup(x => x.DispatchAsync(command, It.IsAny <CancellationToken>()))
            .Throws(new DispatcherException("An error occurred", new Exception()));
            TestSubjectController controller = new TestSubjectController(dispatcher.Object);

            IActionResult result = await controller.ExecuteCommandProxy(command);

            BadRequestObjectResult castResult = (BadRequestObjectResult)result;

            Assert.Equal(400, castResult.StatusCode);
            Assert.Equal("An error occurred", ((string[])((SerializableError)castResult.Value)[""])[0]);
        }