Esempio n. 1
0
    public async Task UpdateImpedimentoTarefaCommand_Handle()
    {
        // Arrange
        IUnitOfWork unitOfWork = DbContextHelper.GetContext();
        IMapper     mapper     = AutoMapperHelper.GetMappings();

        Guid sistemaId = Guid.NewGuid();
        await unitOfWork.SistemaRepository.AddAsync(MockEntityHelper.GetNewSistema(sistemaId));

        Guid projetoId = Guid.NewGuid();
        await unitOfWork.ProjetoRepository.AddAsync(MockEntityHelper.GetNewProjeto(sistemaId, projetoId));

        Guid workflowId = Guid.NewGuid();
        await unitOfWork.WorkflowRepository.AddAsync(MockEntityHelper.GetNewWorkflow(workflowId));

        Guid recursoId = Guid.NewGuid();
        await unitOfWork.RecursoRepository.AddAsync(MockEntityHelper.GetNewRecurso(recursoId));

        Guid tipoTarefaId = Guid.NewGuid();
        await unitOfWork.TipoTarefaRepository.AddAsync(MockEntityHelper.GetNewTipoTarefa(tipoTarefaId));

        Guid tarefaId = Guid.NewGuid();
        await unitOfWork.TarefaRepository.AddAsync(MockEntityHelper.GetNewTarefa(projetoId, workflowId, recursoId, tipoTarefaId, tarefaId));

        Guid impedimentoId = Guid.NewGuid();
        await unitOfWork.ImpedimentoRepository.AddAsync(MockEntityHelper.GetNewImpedimento(impedimentoId));

        Guid              impedimentoTarefaId = Guid.NewGuid();
        DateTime          dataInclusao        = DateTime.Now;
        ImpedimentoTarefa impedimentoTarefa   = MockEntityHelper.GetNewImpedimentoTarefa(tarefaId, impedimentoId, impedimentoTarefaId);

        await unitOfWork.ImpedimentoTarefaRepository.AddAsync(impedimentoTarefa);

        await unitOfWork.SaveChangesAsync();

        unitOfWork.ImpedimentoTarefaRepository.Detatch(impedimentoTarefa);

        UpdateImpedimentoTarefaCommand request = new()
        {
            ImpedimentoTarefa = MockViewModelHelper.GetNewImpedimentoTarefa(tarefaId, impedimentoId, impedimentoTarefaId, dataInclusao)
        };

        GetImpedimentoTarefaQuery request2 = new()
        {
            Id = impedimentoTarefaId
        };

        // Act
        ImpedimentoTarefaHandler handler  = new(unitOfWork, mapper);
        OperationResult          response = await handler.Handle(request, CancellationToken.None);

        ImpedimentoTarefaViewModel response2 = await handler.Handle(request2, CancellationToken.None);

        // Assert
        Assert.True(response == OperationResult.Success);
        Assert.True(response2 != null);
        Assert.True(response2.Id == impedimentoTarefaId);
        Assert.True(response2.DataInclusao.Ticks == dataInclusao.Ticks);
    }
}
Esempio n. 2
0
    public async Task <ImpedimentoTarefaViewModel> AddAsync(ImpedimentoTarefaViewModel viewModel)
    {
        ImpedimentoTarefaViewModel result = _mapper.Map <ImpedimentoTarefaViewModel>(await _unitOfWork.ImpedimentoTarefaRepository.AddAsync(_mapper.Map <ImpedimentoTarefa>(viewModel)));
        await _unitOfWork.SaveChangesAsync();

        return(result);
    }
        public IActionResult Put(Guid id, [FromBody] ImpedimentoTarefaViewModel obj)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != obj.Id)
            {
                return(BadRequest());
            }

            try
            {
                _impedimentoTarefaAppService.Alterar(obj);
            }
            catch (Exception)
            {
                if (!ObjExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public ActionResult <ImpedimentoTarefaViewModel> Post([FromBody] ImpedimentoTarefaViewModel obj)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                obj.Id = _impedimentoTarefaAppService.Incluir(obj);
            }
            catch (Exception)
            {
                if (ObjExists(obj.Id))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetImpedimentoTarefa", new { id = obj.Id }, obj));
        }
Esempio n. 5
0
        public void Test_OnGet()
        {
            // Arrange
            Guid id       = Guid.NewGuid();
            Guid idTarefa = Guid.NewGuid();

            ImpedimentoTarefaViewModel impedimentoTarefaMock = new ImpedimentoTarefaViewModel {
            };
            List <ImpedimentoViewModel> listaMock            = new List <ImpedimentoViewModel> {
            };
            TarefaViewModel tarefaMock = new TarefaViewModel {
            };

            IncluirModel pageModel = new IncluirModel(_impedimentoTarefaAppService.Object, _impedimentoAppService.Object, _tarefaAppService.Object)
            {
                PageContext = PageContextManager.CreatePageContext()
            };

            _impedimentoTarefaAppService.Setup(x => x.Consultar(id)).Returns(impedimentoTarefaMock);
            _impedimentoAppService.Setup(x => x.Listar()).Returns(listaMock);
            _tarefaAppService.Setup(x => x.Consultar(idTarefa)).Returns(tarefaMock);

            PageModelTester <IncluirModel> pageTester = new PageModelTester <IncluirModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnGet(idTarefa))

            // Assert
            .TestPage();
        }
        public ActionResult <ImpedimentoTarefaViewModel> Get(Guid id)
        {
            ImpedimentoTarefaViewModel impedimentoTarefa = _impedimentoTarefaAppService.Consultar(id);

            if (impedimentoTarefa == null)
            {
                return(NotFound());
            }

            return(Ok(impedimentoTarefa));
        }
        public IActionResult Delete(Guid id)
        {
            ImpedimentoTarefaViewModel obj = _impedimentoTarefaAppService.Consultar(id);

            if (obj == null)
            {
                return(NotFound());
            }

            _impedimentoTarefaAppService.Remover(id);

            return(NoContent());
        }
    public async Task <IActionResult> OnGetAsync(Guid id)
    {
        try
        {
            ImpedimentoTarefa = await _cpnucleoApiService.GetAsync <ImpedimentoTarefaViewModel>("impedimentoTarefa", Token, id);

            return(Page());
        }
        catch (Exception ex)
        {
            ModelState.AddModelError(string.Empty, ex.Message);
            return(Page());
        }
    }
Esempio n. 9
0
        public async Task <IActionResult> OnGetAsync(Guid id)
        {
            try
            {
                ImpedimentoTarefa = await _impedimentoTarefaApiService.ConsultarAsync(Token, id);

                return(Page());
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(string.Empty, ex.Message);
                return(Page());
            }
        }
Esempio n. 10
0
    public async Task GetImpedimentoTarefaQuery_Handle()
    {
        // Arrange
        IUnitOfWork unitOfWork = DbContextHelper.GetContext();
        IMapper     mapper     = AutoMapperHelper.GetMappings();

        Guid sistemaId = Guid.NewGuid();
        await unitOfWork.SistemaRepository.AddAsync(MockEntityHelper.GetNewSistema(sistemaId));

        Guid projetoId = Guid.NewGuid();
        await unitOfWork.ProjetoRepository.AddAsync(MockEntityHelper.GetNewProjeto(sistemaId, projetoId));

        Guid workflowId = Guid.NewGuid();
        await unitOfWork.WorkflowRepository.AddAsync(MockEntityHelper.GetNewWorkflow(workflowId));

        Guid recursoId = Guid.NewGuid();
        await unitOfWork.RecursoRepository.AddAsync(MockEntityHelper.GetNewRecurso(recursoId));

        Guid tipoTarefaId = Guid.NewGuid();
        await unitOfWork.TipoTarefaRepository.AddAsync(MockEntityHelper.GetNewTipoTarefa(tipoTarefaId));

        Guid tarefaId = Guid.NewGuid();
        await unitOfWork.TarefaRepository.AddAsync(MockEntityHelper.GetNewTarefa(projetoId, workflowId, recursoId, tipoTarefaId, tarefaId));

        Guid impedimentoId = Guid.NewGuid();
        await unitOfWork.ImpedimentoRepository.AddAsync(MockEntityHelper.GetNewImpedimento(impedimentoId));

        Guid impedimentoTarefaId = Guid.NewGuid();
        await unitOfWork.ImpedimentoTarefaRepository.AddAsync(MockEntityHelper.GetNewImpedimentoTarefa(tarefaId, impedimentoId, impedimentoTarefaId));

        await unitOfWork.SaveChangesAsync();

        GetImpedimentoTarefaQuery request = new()
        {
            Id = impedimentoTarefaId
        };

        // Act
        ImpedimentoTarefaHandler   handler  = new(unitOfWork, mapper);
        ImpedimentoTarefaViewModel response = await handler.Handle(request, CancellationToken.None);

        // Assert
        Assert.True(response != null);
        Assert.True(response.Id != Guid.Empty);
        Assert.True(response.DataInclusao.Ticks != 0);
    }
Esempio n. 11
0
        public void Test_OnPost(string descricao)
        {
            // Arrange
            Guid id            = Guid.NewGuid();
            Guid idImpedimento = Guid.NewGuid();
            Guid idTarefa      = Guid.NewGuid();

            ImpedimentoTarefaViewModel impedimentoTarefaMock = new ImpedimentoTarefaViewModel {
                Id = id, IdImpedimento = idImpedimento, IdTarefa = idTarefa, Descricao = descricao
            };
            List <ImpedimentoViewModel> listaMock = new List <ImpedimentoViewModel> {
            };

            AlterarModel pageModel = new AlterarModel(_impedimentoTarefaAppService.Object, _impedimentoAppService.Object)
            {
                ImpedimentoTarefa = new ImpedimentoTarefaViewModel {
                    IdTarefa = idTarefa
                },
                PageContext = PageContextManager.CreatePageContext()
            };

            _impedimentoTarefaAppService.Setup(x => x.Alterar(impedimentoTarefaMock));
            _impedimentoAppService.Setup(x => x.Listar()).Returns(listaMock);

            PageModelTester <AlterarModel> pageTester = new PageModelTester <AlterarModel>(pageModel);

            // Act
            pageTester
            .Action(x => x.OnPost)

            // Assert
            .WhenModelStateIsValidEquals(false)
            .TestPage();

            // Act
            pageTester
            .Action(x => x.OnPost)

            // Assert
            .WhenModelStateIsValidEquals(true)
            .TestRedirectToPage("Listar");

            // Assert
            Validation.For(impedimentoTarefaMock).ShouldReturn.NoErrors();
        }
Esempio n. 12
0
        public void Test_OnGet()
        {
            // Arrange
            Guid id = Guid.NewGuid();

            ImpedimentoTarefaViewModel impedimentoTarefaMock = new ImpedimentoTarefaViewModel {
            };

            _impedimentoTarefaAppService.Setup(x => x.Consultar(id)).Returns(impedimentoTarefaMock);

            RemoverModel pageModel = new RemoverModel(_impedimentoTarefaAppService.Object);
            PageModelTester <RemoverModel> pageTester = new PageModelTester <RemoverModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnGet(id))

            // Assert
            .TestPage();
        }
    public async Task <IActionResult> OnPostAsync()
    {
        try
        {
            if (!ModelState.IsValid)
            {
                ImpedimentoTarefa = await _cpnucleoApiService.GetAsync <ImpedimentoTarefaViewModel>("impedimentoTarefa", Token, ImpedimentoTarefa.Id);

                return(Page());
            }

            await _cpnucleoApiService.DeleteAsync("impedimentoTarefa", Token, ImpedimentoTarefa.Id);

            return(RedirectToPage("Listar", new { idTarefa = ImpedimentoTarefa.IdTarefa }));
        }
        catch (Exception ex)
        {
            ModelState.AddModelError(string.Empty, ex.Message);
            return(Page());
        }
    }
Esempio n. 14
0
        public void Test_OnPost(string descricao)
        {
            // Arrange
            Guid id       = Guid.NewGuid();
            Guid idTarefa = Guid.NewGuid();

            ImpedimentoTarefaViewModel impedimentoTarefaMock = new ImpedimentoTarefaViewModel {
                Id = id, IdTarefa = idTarefa, Descricao = descricao
            };
            List <ImpedimentoViewModel> listaMock = new List <ImpedimentoViewModel> {
            };
            TarefaViewModel tarefaMock            = new TarefaViewModel {
            };

            _impedimentoTarefaAppService.Setup(x => x.Incluir(impedimentoTarefaMock));
            _impedimentoAppService.Setup(x => x.Listar()).Returns(listaMock);
            _tarefaAppService.Setup(x => x.Consultar(idTarefa)).Returns(tarefaMock);

            IncluirModel pageModel = new IncluirModel(_impedimentoTarefaAppService.Object, _impedimentoAppService.Object, _tarefaAppService.Object);
            PageModelTester <IncluirModel> pageTester = new PageModelTester <IncluirModel>(pageModel);

            // Act
            pageTester
            .Action(x => () => x.OnPost(idTarefa))

            // Assert
            .WhenModelStateIsValidEquals(false)
            .TestPage();

            // Act
            pageTester
            .Action(x => () => x.OnPost(idTarefa))

            // Assert
            .WhenModelStateIsValidEquals(true)
            .TestRedirectToPage("Listar");

            // Assert
            Validation.For(impedimentoTarefaMock).ShouldReturn.NoErrors();
        }
Esempio n. 15
0
        public async Task <IActionResult> OnGetAsync(Guid id)
        {
            ImpedimentoTarefa = await _impedimentoTarefaGrpcService.ConsultarAsync(id);

            return(Page());
        }
Esempio n. 16
0
        public IActionResult OnGet(Guid id)
        {
            ImpedimentoTarefa = _impedimentoTarefaAppService.Consultar(id);

            return(Page());
        }
Esempio n. 17
0
 public async Task UpdateAsync(ImpedimentoTarefaViewModel viewModel)
 {
     _unitOfWork.ImpedimentoTarefaRepository.Update(_mapper.Map <ImpedimentoTarefa>(viewModel));
     await _unitOfWork.SaveChangesAsync();
 }
        public async Task <bool> AlterarAsync(ImpedimentoTarefaViewModel obj)
        {
            BaseReply reply = await _client.AlterarAsync(_mapper.Map <ImpedimentoTarefaModel>(obj));

            return(reply.Sucesso);
        }
    public async Task <ImpedimentoTarefaViewModel> Handle(GetImpedimentoTarefaQuery request, CancellationToken cancellationToken)
    {
        ImpedimentoTarefaViewModel result = _mapper.Map <ImpedimentoTarefaViewModel>(await _unitOfWork.ImpedimentoTarefaRepository.GetAsync(request.Id));

        return(result);
    }