public async Task ExecuteCommandWithResultAndGenerateOkResponse() { SimpleCommandWithResult command = new SimpleCommandWithResult(); Mock <ICommandDispatcher> dispatcher = new Mock <ICommandDispatcher>(); dispatcher.Setup(x => x.DispatchAsync(command, It.IsAny <CancellationToken>())).ReturnsAsync(new CommandResult <bool>(true, false)); TestSubjectController controller = new TestSubjectController(dispatcher.Object); IActionResult result = await controller.ExecuteCommandProxy(command); OkObjectResult castResult = (OkObjectResult)result; Assert.True((bool)castResult.Value); Assert.Equal(200, castResult.StatusCode); }
public async Task ExecuteCommandWithResultAndGenerateModelStateErrorOnDispatchErrorException() { SimpleCommandWithResult command = new SimpleCommandWithResult(); 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]); }