Exemple #1
0
        public async Task ShouldUpdateValidationInvalid()
        {
            var model = new UpdateNativeDesktopAdditionalInformationViewModel();

            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 <UpdateNativeDesktopAdditionalInformationCommand, bool> > match = c =>
                                                                                               c.SolutionId == SolutionId &&
                                                                                               c.AdditionalInformation == model.NativeDesktopAdditionalInformation;

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

            var response = await nativeDesktopAdditionalInformationController.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>()));
        }
        public async Task ShouldUpdateValidationValid()
        {
            var viewModel = new UpdateNativeDesktopAdditionalInformationViewModel();

            var validationResult = new Mock <ISimpleResult>();

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

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

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

            response.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
            _mockMediator.Verify(
                m => m.Send(
                    It.Is <UpdateNativeDesktopAdditionalInformationCommand>(q =>
                                                                            q.SolutionId == SolutionId && q.AdditionalInformation ==
                                                                            viewModel.NativeDesktopAdditionalInformation), It.IsAny <CancellationToken>()), Times.Once);
        }