コード例 #1
0
    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);
    }
コード例 #2
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);
    }
コード例 #3
0
        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));
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        public ActionResult <TipoTarefaViewModel> Get(Guid id)
        {
            TipoTarefaViewModel tipoTarefa = _tipoTarefaAppService.Consultar(id);

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

            return(Ok(tipoTarefa));
        }
コード例 #6
0
        public IActionResult Delete(Guid id)
        {
            TipoTarefaViewModel obj = _tipoTarefaAppService.Consultar(id);

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

            _tipoTarefaAppService.Remover(id);

            return(NoContent());
        }
コード例 #7
0
    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);
    }
}
コード例 #8
0
    public async Task <TipoTarefaViewModel> Handle(GetTipoTarefaQuery request, CancellationToken cancellationToken)
    {
        TipoTarefaViewModel result = _mapper.Map <TipoTarefaViewModel>(await _unitOfWork.TipoTarefaRepository.GetAsync(request.Id));

        return(result);
    }
コード例 #9
0
 public async Task UpdateAsync(TipoTarefaViewModel viewModel)
 {
     _unitOfWork.TipoTarefaRepository.Update(_mapper.Map <TipoTarefa>(viewModel));
     await _unitOfWork.SaveChangesAsync();
 }