예제 #1
0
        public async Task ShouldUpdateValidationValid()
        {
            var solutionSummaryUpdateViewModel = new UpdateSolutionSummaryViewModel {
                Summary = "Summary"
            };
            var validationModel = new Mock <ISimpleResult>();

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

            mockMediator.Setup(m => m.Send(
                                   It.Is <UpdateSolutionSummaryCommand>(q => q.SolutionId == SolutionId && q.Data == solutionSummaryUpdateViewModel),
                                   It.IsAny <CancellationToken>()))
            .ReturnsAsync(validationModel.Object);

            var result = await solutionDescriptionController.UpdateAsync(
                SolutionId,
                solutionSummaryUpdateViewModel) as NoContentResult;

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

            mockMediator.Verify(m => m.Send(
                                    It.Is <UpdateSolutionSummaryCommand>(q => q.SolutionId == SolutionId && q.Data == solutionSummaryUpdateViewModel),
                                    It.IsAny <CancellationToken>()));
        }
        public async Task ShouldUpdateValidationInvalid()
        {
            var solutionSummaryUpdateViewModel = new UpdateSolutionSummaryViewModel()
            {
                Summary = string.Empty
            };

            var validationModel = new RequiredMaxLengthResult()
            {
                Required  = { "summary" },
                MaxLength = { "summary", "description", "link" }
            };

            _mockMediator.Setup(m => m.Send(It.Is <UpdateSolutionSummaryCommand>(q => q.SolutionId == SolutionId && q.UpdateSolutionSummaryViewModel == solutionSummaryUpdateViewModel), It.IsAny <CancellationToken>())).ReturnsAsync(validationModel);

            var result =
                (await _solutionDescriptionController.UpdateAsync(SolutionId, solutionSummaryUpdateViewModel).ConfigureAwait(false)) as BadRequestObjectResult;

            result.StatusCode.Should().Be((int)HttpStatusCode.BadRequest);
            var resultValue = result.Value as UpdateFormRequiredMaxLengthResult;

            resultValue.Required.Should().BeEquivalentTo(new[] { "summary" });
            resultValue.MaxLength.Should().BeEquivalentTo(new[] { "summary", "description", "link" });

            _mockMediator.Verify(m => m.Send(It.Is <UpdateSolutionSummaryCommand>(q => q.SolutionId == SolutionId && q.UpdateSolutionSummaryViewModel == solutionSummaryUpdateViewModel), It.IsAny <CancellationToken>()), Times.Once);
        }
예제 #3
0
        public void ShouldThrowWhenSolutionNotPresent()
        {
            Task UpdateSummary()
            {
                var summaryModel = new UpdateSolutionSummaryViewModel
                {
                    Description = "Description",
                    Link        = "Link",
                    Summary     = "Summary"
                };

                return(_context.UpdateSolutionSummaryHandler.Handle(
                           new UpdateSolutionSummaryCommand("Sln1", summaryModel),
                           new CancellationToken()));
            }

            Assert.ThrowsAsync <NotFoundException>(UpdateSummary);

            _context.MockSolutionRepository.Verify(r => r.ByIdAsync("Sln1", It.IsAny <CancellationToken>()), Times.Once());

            _context.MockSolutionDetailRepository.Verify(r => r.UpdateSummaryAsync(
                                                             It.IsAny <IUpdateSolutionSummaryRequest>(),
                                                             It.IsAny <CancellationToken>()),
                                                         Times.Never());
        }
예제 #4
0
        public async Task ShouldUpdateValidationInvalid()
        {
            var solutionSummaryUpdateViewModel = new UpdateSolutionSummaryViewModel()
            {
                Summary = string.Empty
            };

            var validationModel = new Mock <ISimpleResult>();

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

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

            var result =
                (await _solutionDescriptionController.UpdateAsync(SolutionId, solutionSummaryUpdateViewModel).ConfigureAwait(false)) as BadRequestObjectResult;

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

            resultValue.Count.Should().Be(3);
            resultValue["summary"].Should().Be("required");
            resultValue["description"].Should().Be("maxLength");
            resultValue["link"].Should().Be("maxLength");

            _mockMediator.Verify(m => m.Send(It.Is <UpdateSolutionSummaryCommand>(q => q.SolutionId == SolutionId && q.Data == solutionSummaryUpdateViewModel), It.IsAny <CancellationToken>()), Times.Once);
        }
        public async Task ShouldUpdateValidationValid()
        {
            var solutionSummaryUpdateViewModel = new UpdateSolutionSummaryViewModel {
                Summary = "Summary"
            };
            var validationModel = new RequiredMaxLengthResult();

            _mockMediator.Setup(m => m.Send(It.Is <UpdateSolutionSummaryCommand>(q => q.SolutionId == SolutionId && q.UpdateSolutionSummaryViewModel == solutionSummaryUpdateViewModel), It.IsAny <CancellationToken>())).ReturnsAsync(validationModel);

            var result =
                (await _solutionDescriptionController.UpdateAsync(SolutionId, solutionSummaryUpdateViewModel).ConfigureAwait(false)) as
                NoContentResult;

            result.StatusCode.Should().Be((int)HttpStatusCode.NoContent);
            _mockMediator.Verify(m => m.Send(It.Is <UpdateSolutionSummaryCommand>(q => q.SolutionId == SolutionId && q.UpdateSolutionSummaryViewModel == solutionSummaryUpdateViewModel), It.IsAny <CancellationToken>()), Times.Once);
        }
예제 #6
0
        public async Task ShouldUpdateValidationInvalid()
        {
            var solutionSummaryUpdateViewModel = new UpdateSolutionSummaryViewModel
            {
                Summary = string.Empty,
            };

            var validationErrors = new Dictionary <string, string>
            {
                { "description", "maxLength" },
                { "link", "maxLength" },
                { "summary", "required" },
            };

            var validationModel = new Mock <ISimpleResult>();

            validationModel.Setup(s => s.ToDictionary()).Returns(validationErrors);
            validationModel.Setup(s => s.IsValid).Returns(false);

            mockMediator
            .Setup(m => m.Send(
                       It.Is <UpdateSolutionSummaryCommand>(q => q.SolutionId == SolutionId && q.Data == solutionSummaryUpdateViewModel),
                       It.IsAny <CancellationToken>()))
            .ReturnsAsync(validationModel.Object);

            var result = await solutionDescriptionController.UpdateAsync(
                SolutionId,
                solutionSummaryUpdateViewModel) as BadRequestObjectResult;

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

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

            Assert.NotNull(resultValue);
            resultValue.Count.Should().Be(3);
            resultValue["summary"].Should().Be("required");
            resultValue["description"].Should().Be("maxLength");
            resultValue["link"].Should().Be("maxLength");

            mockMediator.Verify(m => m.Send(
                                    It.Is <UpdateSolutionSummaryCommand>(q => q.SolutionId == SolutionId && q.Data == solutionSummaryUpdateViewModel),
                                    It.IsAny <CancellationToken>()));
        }
        private async Task <ISimpleResult> UpdateSolutionDescriptionAsync(string summary = "Summary", string description = "Description", string link = "Link")
        {
            var existingSolution = new Mock <ISolutionResult>();

            existingSolution.Setup(s => s.Id).Returns("Sln1");

            context.MockSolutionRepository.Setup(r => r.ByIdAsync("Sln1", It.IsAny <CancellationToken>())).ReturnsAsync(existingSolution.Object);

            var updateSolutionSummaryModel = new UpdateSolutionSummaryViewModel
            {
                Description = description,
                Link        = link,
                Summary     = summary,
            };

            var validationResult = await context.UpdateSolutionSummaryHandler.Handle(
                new UpdateSolutionSummaryCommand("Sln1", updateSolutionSummaryModel),
                CancellationToken.None);

            return(validationResult);
        }
예제 #8
0
 public async Task <ActionResult> UpdateAsync([FromRoute][Required] string id, [FromBody][Required] UpdateSolutionSummaryViewModel updateSolutionSummaryViewModel) =>
 (await _mediator.Send(new UpdateSolutionSummaryCommand(id, updateSolutionSummaryViewModel)).ConfigureAwait(false)).ToActionResult();
 public async Task <ActionResult> UpdateAsync([Required] string id, UpdateSolutionSummaryViewModel model) =>
 (await mediator.Send(new UpdateSolutionSummaryCommand(id, model))).ToActionResult();