コード例 #1
0
    public async Task UpdateProjetoCommand_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();
        DateTime dataInclusao = DateTime.Now;

        Projeto projeto = MockEntityHelper.GetNewProjeto(sistemaId, projetoId);

        await unitOfWork.ProjetoRepository.AddAsync(projeto);

        await unitOfWork.SaveChangesAsync();

        unitOfWork.ProjetoRepository.Detatch(projeto);

        UpdateProjetoCommand request = new()
        {
            Projeto = MockViewModelHelper.GetNewProjeto(sistemaId, projetoId, dataInclusao)
        };

        GetProjetoQuery request2 = new()
        {
            Id = projetoId
        };

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

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

        // Assert
        Assert.True(response == OperationResult.Success);
        Assert.True(response2 != null);
        Assert.True(response2.Id == projetoId);
        Assert.True(response2.DataInclusao.Ticks == dataInclusao.Ticks);
    }
}
コード例 #2
0
    public async Task CreateProjetoCommand_Handle()
    {
        // Arrange
        IUnitOfWork unitOfWork = DbContextHelper.GetContext();
        IMapper     mapper     = AutoMapperHelper.GetMappings();

        Guid sistemaId = Guid.NewGuid();

        await unitOfWork.SistemaRepository.AddAsync(MockEntityHelper.GetNewSistema(sistemaId));

        await unitOfWork.SaveChangesAsync();

        CreateProjetoCommand request = new()
        {
            Projeto = MockViewModelHelper.GetNewProjeto(sistemaId)
        };

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

        // Assert
        Assert.True(response == OperationResult.Success);
    }