public async Task ShouldUpdateValidationInvalid()
        {
            var expected  = "a description";
            var viewModel = new UpdateRoadmapViewModel {
                Summary = expected
            };
            var validationModel = new Mock <ISimpleResult>();

            validationModel.Setup(s => s.ToDictionary()).Returns(new Dictionary <string, string> {
                { "description", "maxLength" }
            });
            validationModel.Setup(s => s.IsValid).Returns(false);

            _mockMediator.Setup(m => m.Send(It.Is <UpdateRoadmapCommand>(q => q.SolutionId == SolutionId), It.IsAny <CancellationToken>())).ReturnsAsync(validationModel.Object);

            var result =
                (await _controller.Update(SolutionId, viewModel).ConfigureAwait(false)) as BadRequestObjectResult;

            result.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
            var resultValue = result.Value as Dictionary <string, string>;

            resultValue.Count.Should().Be(1);
            resultValue["description"].Should().Be("maxLength");

            _mockMediator.Verify(m => m.Send(It.Is <UpdateRoadmapCommand>(q => q.SolutionId == SolutionId && q.Summary == expected), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task ShouldUpdateValidationValid()
        {
            var expected  = "a description";
            var viewModel = new UpdateRoadmapViewModel {
                Summary = expected
            };
            var validationModel = new Mock <ISimpleResult>();

            validationModel.Setup(s => s.IsValid).Returns(true);

            _mockMediator.Setup(m => m.Send(It.Is <UpdateRoadmapCommand>(q => q.SolutionId == SolutionId && q.Summary == expected), It.IsAny <CancellationToken>())).ReturnsAsync(validationModel.Object);

            var result =
                (await _controller.Update(SolutionId, viewModel).ConfigureAwait(false)) as
                NoContentResult;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
            _mockMediator.Verify(m => m.Send(It.Is <UpdateRoadmapCommand>(q => q.SolutionId == SolutionId && q.Summary == expected), It.IsAny <CancellationToken>()), Times.Once);
        }
Beispiel #3
0
 public async Task <ActionResult> Update([FromRoute][Required] string id, [FromBody][Required] UpdateRoadmapViewModel viewModel) =>
 (await _mediator.Send(new UpdateRoadmapCommand(id, viewModel?.Summary)).ConfigureAwait(false)).ToActionResult();