public async Task GetTipoTarefaQuery_Handle() { // Arrange IUnitOfWork unitOfWork = DbContextHelper.GetContext(); IMapper mapper = AutoMapperHelper.GetMappings(); Guid tipoTarefaId = Guid.NewGuid(); await unitOfWork.TipoTarefaRepository.AddAsync(MockEntityHelper.GetNewTipoTarefa(tipoTarefaId)); await unitOfWork.SaveChangesAsync(); GetTipoTarefaQuery request = new() { Id = tipoTarefaId }; // Act TipoTarefaHandler handler = new(unitOfWork, mapper); TipoTarefaViewModel 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 async Task <TipoTarefaViewModel> AddAsync(TipoTarefaViewModel viewModel) { TipoTarefaViewModel result = _mapper.Map <TipoTarefaViewModel>(await _unitOfWork.TipoTarefaRepository.AddAsync(_mapper.Map <TipoTarefa>(viewModel))); await _unitOfWork.SaveChangesAsync(); return(result); }
public ActionResult <TipoTarefaViewModel> Post([FromBody] TipoTarefaViewModel obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { _tipoTarefaAppService.Incluir(obj); } catch (Exception) { if (ObjExists(obj.Id)) { return(Conflict()); } else { throw; } } return(CreatedAtAction(nameof(Get), new { id = obj.Id }, obj)); }
public IActionResult Put(Guid id, [FromBody] TipoTarefaViewModel obj) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != obj.Id) { return(BadRequest()); } try { _tipoTarefaAppService.Alterar(obj); } catch (Exception) { if (!ObjExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult <TipoTarefaViewModel> Get(Guid id) { TipoTarefaViewModel tipoTarefa = _tipoTarefaAppService.Consultar(id); if (tipoTarefa == null) { return(NotFound()); } return(Ok(tipoTarefa)); }
public IActionResult Delete(Guid id) { TipoTarefaViewModel obj = _tipoTarefaAppService.Consultar(id); if (obj == null) { return(NotFound()); } _tipoTarefaAppService.Remover(id); return(NoContent()); }
public async Task UpdateTipoTarefaCommand_Handle() { // Arrange IUnitOfWork unitOfWork = DbContextHelper.GetContext(); IMapper mapper = AutoMapperHelper.GetMappings(); Guid tipoTarefaId = Guid.NewGuid(); DateTime dataInclusao = DateTime.Now; TipoTarefa tipoTarefa = MockEntityHelper.GetNewTipoTarefa(tipoTarefaId); await unitOfWork.TipoTarefaRepository.AddAsync(tipoTarefa); await unitOfWork.SaveChangesAsync(); unitOfWork.TipoTarefaRepository.Detatch(tipoTarefa); UpdateTipoTarefaCommand request = new() { TipoTarefa = MockViewModelHelper.GetNewTipoTarefa(tipoTarefaId, dataInclusao) }; GetTipoTarefaQuery request2 = new() { Id = tipoTarefaId }; // Act TipoTarefaHandler handler = new(unitOfWork, mapper); OperationResult response = await handler.Handle(request, CancellationToken.None); TipoTarefaViewModel response2 = await handler.Handle(request2, CancellationToken.None); // Assert Assert.True(response == OperationResult.Success); Assert.True(response2 != null); Assert.True(response2.Id == tipoTarefaId); Assert.True(response2.DataInclusao.Ticks == dataInclusao.Ticks); } }
public async Task <TipoTarefaViewModel> Handle(GetTipoTarefaQuery request, CancellationToken cancellationToken) { TipoTarefaViewModel result = _mapper.Map <TipoTarefaViewModel>(await _unitOfWork.TipoTarefaRepository.GetAsync(request.Id)); return(result); }
public async Task UpdateAsync(TipoTarefaViewModel viewModel) { _unitOfWork.TipoTarefaRepository.Update(_mapper.Map <TipoTarefa>(viewModel)); await _unitOfWork.SaveChangesAsync(); }