Пример #1
0
        public async Task ShouldUpdateValidationInvalid()
        {
            var viewModel = new UpdateNativeMobileAdditionalInformationViewModel();

            var validationResult = new Mock <ISimpleResult>();

            validationResult.Setup(s => s.ToDictionary()).Returns(new Dictionary <string, string> {
                { "additional-information", "maxLength" }
            });
            validationResult.Setup(s => s.IsValid).Returns(false);

            _mockMediator
            .Setup(m => m.Send(
                       It.Is <UpdateSolutionNativeMobileAdditionalInformationCommand>(q =>
                                                                                      q.SolutionId == SolutionId && q.AdditionalInformation == viewModel.NativeMobileAdditionalInformation),
                       It.IsAny <CancellationToken>())).ReturnsAsync(validationResult.Object);

            var response = await _nativeMobileAdditionalInformationController.UpdateAdditionalInformationAsync(SolutionId, viewModel)
                           .ConfigureAwait(false) as BadRequestObjectResult;

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

            result.Count.Should().Be(1);
            result["additional-information"].Should().Be("maxLength");

            _mockMediator.Verify(
                m => m.Send(
                    It.Is <UpdateSolutionNativeMobileAdditionalInformationCommand>(q =>
                                                                                   q.SolutionId == SolutionId && q.AdditionalInformation ==
                                                                                   viewModel.NativeMobileAdditionalInformation), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task ShouldUpdateValidationValid()
        {
            var model = new UpdateNativeMobileAdditionalInformationViewModel();

            var validationResult = new Mock <ISimpleResult>();

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

            Expression <Func <UpdateSolutionNativeMobileAdditionalInformationCommand, bool> > match = c =>
                                                                                                      c.SolutionId == SolutionId &&
                                                                                                      c.AdditionalInformation == model.NativeMobileAdditionalInformation;

            mockMediator
            .Setup(m => m.Send(It.Is(match), It.IsAny <CancellationToken>()))
            .ReturnsAsync(validationResult.Object);

            var response = await nativeMobileAdditionalInformationController.UpdateAdditionalInformationAsync(
                SolutionId,
                model) as NoContentResult;

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

            mockMediator.Verify(m => m.Send(It.Is(match), It.IsAny <CancellationToken>()));
        }
Пример #3
0
        public async Task ShouldUpdateValidationValid()
        {
            var viewModel = new UpdateNativeMobileAdditionalInformationViewModel();

            var validationResult = new Mock <ISimpleResult>();

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

            _mockMediator
            .Setup(m => m.Send(
                       It.Is <UpdateSolutionNativeMobileAdditionalInformationCommand>(q =>
                                                                                      q.SolutionId == SolutionId && q.AdditionalInformation == viewModel.NativeMobileAdditionalInformation),
                       It.IsAny <CancellationToken>())).ReturnsAsync(validationResult.Object);

            var response = await _nativeMobileAdditionalInformationController.UpdateAdditionalInformationAsync(SolutionId, viewModel)
                           .ConfigureAwait(false) as NoContentResult;

            response.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
            _mockMediator.Verify(
                m => m.Send(
                    It.Is <UpdateSolutionNativeMobileAdditionalInformationCommand>(q =>
                                                                                   q.SolutionId == SolutionId && q.AdditionalInformation ==
                                                                                   viewModel.NativeMobileAdditionalInformation), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task ShouldUpdateValidationInvalid()
        {
            var model = new UpdateNativeMobileAdditionalInformationViewModel();

            var validationResult = new Mock <ISimpleResult>();

            validationResult.Setup(s => s.ToDictionary()).Returns(new Dictionary <string, string>
            {
                { "additional-information", "maxLength" },
            });

            validationResult.Setup(s => s.IsValid).Returns(false);

            Expression <Func <UpdateSolutionNativeMobileAdditionalInformationCommand, bool> > match = c =>
                                                                                                      c.SolutionId == SolutionId &&
                                                                                                      c.AdditionalInformation == model.NativeMobileAdditionalInformation;

            mockMediator
            .Setup(m => m.Send(It.Is(match), It.IsAny <CancellationToken>()))
            .ReturnsAsync(validationResult.Object);

            var response = await nativeMobileAdditionalInformationController.UpdateAdditionalInformationAsync(
                SolutionId,
                model) as BadRequestObjectResult;

            Assert.NotNull(response);
            response.StatusCode.Should().Be(StatusCodes.Status400BadRequest);

            var result = response.Value as Dictionary <string, string>;

            Assert.NotNull(result);
            result.Count.Should().Be(1);
            result["additional-information"].Should().Be("maxLength");

            mockMediator.Verify(m => m.Send(It.Is(match), It.IsAny <CancellationToken>()));
        }
Пример #5
0
 public async Task <ActionResult> UpdateAdditionalInformationAsync(
     [Required] string id,
     UpdateNativeMobileAdditionalInformationViewModel model) =>
 (await mediator.Send(new UpdateSolutionNativeMobileAdditionalInformationCommand(
                          id,
                          model?.NativeMobileAdditionalInformation))).ToActionResult();
Пример #6
0
 public async Task <ActionResult> UpdateAdditionalInformationAsync([FromRoute][Required] string id,
                                                                   [FromBody][Required]
                                                                   UpdateNativeMobileAdditionalInformationViewModel viewModel) =>
 (await _mediator.Send(new UpdateSolutionNativeMobileAdditionalInformationCommand(id, viewModel?.NativeMobileAdditionalInformation))
  .ConfigureAwait(false)).ToActionResult();