public async void ValidarFiltroNomeResponsavel()
        {
            // Arrange
            var query = new ObterProcessosQuery {
                NomeResponsavel = "kelvin"
            };

            query.ConfigurarPaginacao(1, 10);

            mockValidator
            .Setup(v => v.ValidateModelAsync(query))
            .Returns(Task.FromResult(true));

            mockProcessoRepository
            .Setup(p => p.Query())
            .Returns(processos.AsQueryable());

            // Act
            var response = await sut.Handle(query, default);

            // Assert
            response.Success.Should().BeTrue();
            response.Value.Should().HaveCount(2);
            response.Value[0].Id.Should().Be(1);
            response.Value[1].Id.Should().Be(3);
        }
        public async void ValidarFiltroData()
        {
            // Arrange
            var query = new ObterProcessosQuery
            {
                DataDistribuicaoInicio = new DateTimeOffset(2022, 4, 1, 0, 0, 0, TimeSpan.Zero),
                DataDistribuicaoFim    = new DateTimeOffset(2022, 6, 1, 0, 0, 0, TimeSpan.Zero)
            };

            query.ConfigurarPaginacao(1, 10);

            mockValidator
            .Setup(v => v.ValidateModelAsync(query))
            .Returns(Task.FromResult(true));

            mockProcessoRepository
            .Setup(p => p.Query())
            .Returns(processos.AsQueryable());

            // Act
            var response = await sut.Handle(query, default);

            // Assert
            response.Success.Should().BeTrue();
            response.Value.Should().HaveCount(1);
            response.Value[0].Id.Should().Be(3);
        }
Esempio n. 3
0
        public Task <IActionResult> ObterProcessosAsync([FromBody] ObterProcessosQuery query, [FromQuery] ObterProcessosParameter parameters)
        {
            query.ConfigurarPaginacao(parameters.PageNumber, parameters.PageSize);

            return(this.ExecAndHandleAsync(
                       action: () => this.processoService.ObterProcessosAsync(query),
                       onSuccessActionResultHandler: (result) =>
            {
                this.EnsurePaginationMetadata(result, ObterProcessosRouteName);
                return this.Ok(result);
            }));
        }
        public async void ValidarFalhaValidação()
        {
            // Arrange
            var query = new ObterProcessosQuery();

            query.ConfigurarPaginacao(1, 10);

            mockValidator
            .Setup(pv => pv.ValidateModelAsync(query))
            .Returns(Task.FromResult(false));

            // Act
            var response = await sut.Handle(query, default);

            // Assert
            mockValidator.Verify(pv => pv.ValidateModelAsync(query), Times.Once);
            response.Success.Should().BeFalse();
        }
        public async void ValidarObterProcessos()
        {
            // Arrange
            var query = new ObterProcessosQuery
            {
                NumeroProcesso = "987515-88-15"
            };
            var processos = PagedList <ProcessoDto> .Create(new List <ProcessoDto>
            {
                new ProcessoDto
                {
                    Id = 1,
                    DataDistribuicao   = DateTimeOffset.Now,
                    Descricao          = "Descrição",
                    NumeroProcesso     = "NumeroProcesso",
                    PastaFisicaCliente = "PastaFisicaCliente",
                    SegredoJustica     = true,
                    SituacaoProcessoId = 1
                },
                new ProcessoDto
                {
                    Id = 1,
                    DataDistribuicao   = DateTimeOffset.Now,
                    Descricao          = "Descrição",
                    NumeroProcesso     = "NumeroProcesso",
                    PastaFisicaCliente = "PastaFisicaCliente",
                    SegredoJustica     = true,
                    SituacaoProcessoId = 1
                }
            }.AsQueryable(),
                                                            pageNumber : 1,
                                                            pageSize : 30);

            this.mockMediator
            .Setup(m => m.Send(query, default))
            .Returns(Task.FromResult(new RequestResponseWrapper <PagedList <ProcessoDto> >(true, processos)));

            // Act
            var response = await this.sut.ObterProcessosAsync(query);

            // Assert
            response.Should().BeEquivalentTo(processos);
        }
        public async void ValidarRetornoPaginado(int pageNumber, int pageSize, int expectedItemsCount, int expectedTotalPages, int expectedTotalCount)
        {
            // Arrange
            var query = new ObterProcessosQuery();

            query.ConfigurarPaginacao(pageNumber, pageSize);

            mockValidator
            .Setup(v => v.ValidateModelAsync(query))
            .Returns(Task.FromResult(true));

            mockProcessoRepository
            .Setup(p => p.Query())
            .Returns(processos.AsQueryable());

            // Act
            var response = await sut.Handle(query, default);

            // Assert
            response.Success.Should().BeTrue();
            response.Value.Should().HaveCount(expectedItemsCount);
            response.Value.TotalPages.Should().Be(expectedTotalPages);
            response.Value.TotalCount.Should().Be(expectedTotalCount);
        }
        public async Task <PagedList <ProcessoDto> > ObterProcessosAsync(ObterProcessosQuery query)
        {
            var result = await this.mediator.Send(query, default);

            return(result.Value);
        }