Beispiel #1
0
    public async Task CreateImpedimentoCommand_Handle()
    {
        // Arrange
        IUnitOfWork unitOfWork = DbContextHelper.GetContext();
        IMapper     mapper     = AutoMapperHelper.GetMappings();

        CreateImpedimentoCommand request = new()
        {
            Impedimento = MockViewModelHelper.GetNewImpedimento()
        };

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

        // Assert
        Assert.True(response == OperationResult.Success);
    }
Beispiel #2
0
    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);
    }
}