public async Task UseTransactionAsync_Success_Should_WriteChangesInDatabase() { var expCount = 1; var aggregateRep = Mock.Of <IRepositoryAsync <TestAggregateRoot, Guid> >(); ITestUnitOfWork unitOfWork = new TestUnitOfWork(_Context, aggregateRep); var aggregateRoot = new TestAggregateRoot("testing"); await unitOfWork.UseTransactionAsync(async() => { _Context.Add(aggregateRoot); await unitOfWork.SaveChangesAsync(); }); _Context.TestAggregateRoots.Should().HaveCount(expCount); }
public async Task UseTransactionAsync_WithReturn_Success_Should_RollBackChanges() { var expCount = 0; var aggregateRep = Mock.Of <IRepositoryAsync <TestAggregateRoot, Guid> >(); ITestUnitOfWork unitOfWork = new TestUnitOfWork(_Context, aggregateRep); var aggregateRoot = new TestAggregateRoot("testing"); Func <Task> act = () => unitOfWork.UseTransactionAsync <TestAggregateRoot>(async() => { _Context.Add(aggregateRoot); await unitOfWork.SaveChangesAsync(); throw new Exception(); }); await act.Should().ThrowExactlyAsync <Exception>(); _Context.TestAggregateRoots.Should().HaveCount(expCount); }