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

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

            IActionResult result = await controller.ExecuteCommandProxy(command);

            OkResult castResult = (OkResult)result;

            Assert.Equal(200, castResult.StatusCode);
        }
예제 #2
0
        public async Task ExecuteCommandWithCommandResponseAndNoResultAndGenerateBadResultOnError()
        {
            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]);
        }
예제 #3
0
        public async Task ExecuteCommandWithCommandResponseAndNoResultAndGenerateBadResponse()
        {
            SimpleCommandCommandResponse command    = new SimpleCommandCommandResponse();
            Mock <ICommandDispatcher>    dispatcher = new Mock <ICommandDispatcher>();

            dispatcher.Setup(x => x.DispatchAsync(command, It.IsAny <CancellationToken>()))
            .ReturnsAsync(new CommandResult <CommandResponse>(CommandResponse.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]);
        }