public void Test_OnPost() { // Arrange Guid id = Guid.NewGuid(); ImpedimentoViewModel impedimentoMock = new ImpedimentoViewModel { }; _impedimentoAppService.Setup(x => x.Remover(id)); RemoverModel pageModel = new RemoverModel(_impedimentoAppService.Object) { Impedimento = new ImpedimentoViewModel { Id = id } }; PageModelTester <RemoverModel> pageTester = new PageModelTester <RemoverModel>(pageModel); // Act pageTester .Action(x => x.OnPost) // Assert .TestRedirectToPage("Listar"); }
public async Task <ImpedimentoViewModel> AddAsync(ImpedimentoViewModel viewModel) { ImpedimentoViewModel result = _mapper.Map <ImpedimentoViewModel>(await _unitOfWork.ImpedimentoRepository.AddAsync(_mapper.Map <Impedimento>(viewModel))); await _unitOfWork.SaveChangesAsync(); return(result); }
public ActionResult <ImpedimentoViewModel> Post([FromBody] ImpedimentoViewModel obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _impedimentoAppService.Incluir(obj); } catch (DbUpdateException) { if (ObjExists(obj.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtAction(nameof(Get), new { id = obj.Id }, obj)); }
public void Test_OnPost(string nome) { // Arrange Guid id = Guid.NewGuid(); ImpedimentoViewModel impedimentoMock = new ImpedimentoViewModel { Id = id, Nome = nome }; _impedimentoAppService.Setup(x => x.Alterar(impedimentoMock)); AlterarModel pageModel = new AlterarModel(_impedimentoAppService.Object); 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(impedimentoMock).ShouldReturn.NoErrors(); }
public void Test_OnPost(string nome) { // Arrange ImpedimentoViewModel impedimentoMock = new ImpedimentoViewModel { Nome = nome }; IncluirModel pageModel = new IncluirModel(_impedimentoAppService.Object) { PageContext = PageContextManager.CreatePageContext() }; _impedimentoAppService.Setup(x => x.Incluir(impedimentoMock)); PageModelTester <IncluirModel> pageTester = new PageModelTester <IncluirModel>(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(impedimentoMock).ShouldReturn.NoErrors(); }
public IActionResult Put(Guid id, [FromBody] ImpedimentoViewModel obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != obj.Id) { return(BadRequest()); } try { _impedimentoAppService.Alterar(obj); } catch (DbUpdateConcurrencyException) { if (!ObjExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task GetImpedimentoQuery_Handle() { // Arrange IUnitOfWork unitOfWork = DbContextHelper.GetContext(); IMapper mapper = AutoMapperHelper.GetMappings(); Guid impedimentoId = Guid.NewGuid(); await unitOfWork.ImpedimentoRepository.AddAsync(MockEntityHelper.GetNewImpedimento(impedimentoId)); await unitOfWork.SaveChangesAsync(); GetImpedimentoQuery request = new() { Id = impedimentoId }; // Act ImpedimentoHandler handler = new(unitOfWork, mapper); ImpedimentoViewModel response = await handler.Handle(request, CancellationToken.None); // Assert Assert.True(response != null); Assert.True(response.Id != Guid.Empty); Assert.True(response.DataInclusao.Ticks != 0); }
public ActionResult <ImpedimentoViewModel> Get(Guid id) { ImpedimentoViewModel impedimento = _impedimentoAppService.Consultar(id); if (impedimento == null) { return(NotFound()); } return(Ok(impedimento)); }
public IActionResult Delete(Guid id) { ImpedimentoViewModel obj = _impedimentoAppService.Consultar(id); if (obj == null) { return(NotFound()); } _impedimentoAppService.Remover(id); return(NoContent()); }
public async Task <IActionResult> OnGetAsync(Guid id) { try { Impedimento = await _cpnucleoApiService.GetAsync <ImpedimentoViewModel>("impedimento", Token, id); return(Page()); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(Page()); } }
public async Task <IActionResult> OnGetAsync(Guid id) { try { Impedimento = await _impedimentoApiService.ConsultarAsync(Token, id); return(Page()); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(Page()); } }
public void Test_OnGet() { // Arrange Guid id = Guid.NewGuid(); ImpedimentoViewModel impedimentoMock = new ImpedimentoViewModel { }; _impedimentoAppService.Setup(x => x.Consultar(id)).Returns(impedimentoMock); RemoverModel pageModel = new RemoverModel(_impedimentoAppService.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) { Impedimento = await _cpnucleoApiService.GetAsync <ImpedimentoViewModel>("impedimento", Token, Impedimento.Id); return(Page()); } await _cpnucleoApiService.PutAsync("impedimento", Token, Impedimento.Id, Impedimento); return(RedirectToPage("Listar")); } catch (Exception ex) { ModelState.AddModelError(string.Empty, ex.Message); return(Page()); } }
public async Task UpdateImpedimentoCommand_Handle() { // Arrange IUnitOfWork unitOfWork = DbContextHelper.GetContext(); IMapper mapper = AutoMapperHelper.GetMappings(); Guid impedimentoId = Guid.NewGuid(); DateTime dataInclusao = DateTime.Now; Impedimento impedimento = MockEntityHelper.GetNewImpedimento(impedimentoId); await unitOfWork.ImpedimentoRepository.AddAsync(impedimento); await unitOfWork.SaveChangesAsync(); unitOfWork.ImpedimentoRepository.Detatch(impedimento); UpdateImpedimentoCommand request = new() { Impedimento = MockViewModelHelper.GetNewImpedimento(impedimentoId, dataInclusao) }; GetImpedimentoQuery request2 = new() { Id = impedimentoId }; // Act ImpedimentoHandler handler = new(unitOfWork, mapper); OperationResult response = await handler.Handle(request, CancellationToken.None); ImpedimentoViewModel response2 = await handler.Handle(request2, CancellationToken.None); // Assert Assert.True(response == OperationResult.Success); Assert.True(response2 != null); Assert.True(response2.Id == impedimentoId); Assert.True(response2.DataInclusao.Ticks == dataInclusao.Ticks); } }
public IActionResult OnGet(Guid id) { Impedimento = _impedimentoAppService.Consultar(id); return(Page()); }
public async Task <IActionResult> OnGetAsync(Guid id) { Impedimento = await _impedimentoGrpcService.ConsultarAsync(id); return(Page()); }
public async Task UpdateAsync(ImpedimentoViewModel viewModel) { _unitOfWork.ImpedimentoRepository.Update(_mapper.Map <Impedimento>(viewModel)); await _unitOfWork.SaveChangesAsync(); }
public async Task <ImpedimentoViewModel> Handle(GetImpedimentoQuery request, CancellationToken cancellationToken) { ImpedimentoViewModel result = _mapper.Map <ImpedimentoViewModel>(await _unitOfWork.ImpedimentoRepository.GetAsync(request.Id)); return(result); }