Ejemplo n.º 1
0
        public async Task ShouldUpdateValidationInvalid()
        {
            var featuresUpdateViewModel = new UpdateSolutionFeaturesViewModel()
            {
                Listing = new List <string>()
                {
                    new string('a', 200)
                }
            };

            var validationModel = new Mock <ISimpleResult>();

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

            _mockMediator.Setup(m => m.Send(It.Is <UpdateSolutionFeaturesCommand>(q => q.SolutionId == SolutionId && q.Data == featuresUpdateViewModel), It.IsAny <CancellationToken>())).ReturnsAsync(validationModel.Object);
            var result =
                (await _featuresController.UpdateFeaturesAsync(SolutionId, featuresUpdateViewModel).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["listing-1"].Should().Be("maxLength");

            _mockMediator.Verify(m => m.Send(It.Is <UpdateSolutionFeaturesCommand>(q => q.SolutionId == SolutionId && q.Data == featuresUpdateViewModel), It.IsAny <CancellationToken>()), Times.Once);
        }
Ejemplo n.º 2
0
        public async Task ShouldUpdateValidationValid()
        {
            var featuresUpdateModel = new UpdateSolutionFeaturesViewModel
            {
                Listing = new List <string> {
                    "test", "test2"
                },
            };

            var validationModel = new Mock <ISimpleResult>();

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

            mockMediator
            .Setup(m => m.Send(
                       It.Is <UpdateSolutionFeaturesCommand>(c => c.SolutionId == SolutionId && c.Data == featuresUpdateModel),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(validationModel.Object);

            var result = await featuresController.UpdateFeaturesAsync(SolutionId, featuresUpdateModel) as NoContentResult;

            Assert.NotNull(result);
            result.StatusCode.Should().Be(StatusCodes.Status204NoContent);

            mockMediator.Verify(m => m.Send(
                                    It.Is <UpdateSolutionFeaturesCommand>(c => c.SolutionId == SolutionId && c.Data == featuresUpdateModel),
                                    It.IsAny <CancellationToken>()));
        }
        public async Task ShouldUpdateValidationValid()
        {
            var featuresUpdateViewModel = new UpdateSolutionFeaturesViewModel()
            {
                Listing = new List <string>()
                {
                    "test", "test2"
                }
            };

            var validationModel = new MaxLengthResult();

            _mockMediator.Setup(m => m.Send(It.Is <UpdateSolutionFeaturesCommand>(q => q.SolutionId == SolutionId && q.UpdateSolutionFeaturesViewModel == featuresUpdateViewModel), It.IsAny <CancellationToken>())).ReturnsAsync(validationModel);
            var result =
                (await _featuresController.UpdateFeaturesAsync(SolutionId, featuresUpdateViewModel).ConfigureAwait(false)) as NoContentResult;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
            _mockMediator.Verify(m => m.Send(It.Is <UpdateSolutionFeaturesCommand>(q => q.SolutionId == SolutionId && q.UpdateSolutionFeaturesViewModel == featuresUpdateViewModel), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task ShouldUpdateValidationInvalid()
        {
            var featuresUpdateViewModel = new UpdateSolutionFeaturesViewModel()
            {
                Listing = new List <string>()
                {
                    new string('a', 200)
                }
            };

            var validationModel = new MaxLengthResult()
            {
                MaxLength = { "listing-1" }
            };

            _mockMediator.Setup(m => m.Send(It.Is <UpdateSolutionFeaturesCommand>(q => q.SolutionId == SolutionId && q.UpdateSolutionFeaturesViewModel == featuresUpdateViewModel), It.IsAny <CancellationToken>())).ReturnsAsync(validationModel);
            var result =
                (await _featuresController.UpdateFeaturesAsync(SolutionId, featuresUpdateViewModel).ConfigureAwait(false)) as
                BadRequestObjectResult;

            result.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
            (result.Value as UpdateFormMaxLengthResult).MaxLength.Should().BeEquivalentTo("listing-1");
            _mockMediator.Verify(m => m.Send(It.Is <UpdateSolutionFeaturesCommand>(q => q.SolutionId == SolutionId && q.UpdateSolutionFeaturesViewModel == featuresUpdateViewModel), It.IsAny <CancellationToken>()), Times.Once);
        }
 public async Task <ActionResult> UpdateFeaturesAsync([Required] string id, UpdateSolutionFeaturesViewModel model) =>
 (await mediator.Send(new UpdateSolutionFeaturesCommand(id, model))).ToActionResult();
 public async Task <ActionResult> UpdateFeaturesAsync([FromRoute][Required] string id, [FromBody][Required] UpdateSolutionFeaturesViewModel updateSolutionFeaturesViewModel) =>
 (await _mediator.Send(new UpdateSolutionFeaturesCommand(id, updateSolutionFeaturesViewModel)).ConfigureAwait(false)).ToActionResult();