Skip to content

Commit

Permalink
Fixed unit tests. All are working now. Persistence unit of work is no…
Browse files Browse the repository at this point in the history
…w cleaned up and persistence no longer requires RCommon unit of work pattern - a simple TransactionScope can now be used instead. Decoupled event producing from unit of work pattern so we let the developer decide when to publish events.
  • Loading branch information
jasonmwebb-lv committed Jun 4, 2024
1 parent 980ddc0 commit 193d673
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected override void OnBuildInitialized()
{
Log.Information("Generating NuGet packages for projects in solution");
int commitNum = 0;
string NuGetVersionCustom = "2.0.0.881";
string NuGetVersionCustom = "2.0.0.882";
//if it's not a tagged release - append the commit number to the package version
Expand Down
4 changes: 0 additions & 4 deletions Src/RCommon.Dapper/DapperPersistenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,10 @@ public IDapperBuilder AddDbConnection<TDbConnection>(string dataStoreName, Actio
Guard.Against<RDbConnectionException>(options == null, "You must configure the options for the RDbConnection for it to be useful");

var dbContext = typeof(TDbConnection).AssemblyQualifiedName;
//this._services.AddTransient(Type.GetType(dbContext), Type.GetType(dbContext));

this._services.TryAddTransient<IDataStoreFactory, DataStoreFactory>();
this._services.TryAddTransient(Type.GetType(dbContext));
this._services.Configure<DataStoreFactoryOptions>(options => options.Register<TDbConnection>(dataStoreName));

//var dbContext = typeof(TDbConnection).AssemblyQualifiedName;
//this._services.AddTransient(Type.GetType(dbContext), Type.GetType(dbContext));
this._services.Configure(options);

return this;
Expand Down
1 change: 0 additions & 1 deletion Src/RCommon.EfCore/EFCorePerisistenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public IEFCorePersistenceBuilder AddDbContext<TDbContext>(string dataStoreName,
Guard.Against<UnsupportedDataStoreException>(dataStoreName.IsNullOrEmpty(), "You must set a name for the Data Store");

this._services.TryAddTransient<IDataStoreFactory, DataStoreFactory>();
//this._services.TryAddTransient<TDbContext>();
this._services.Configure<DataStoreFactoryOptions>(options => options.Register<TDbContext>(dataStoreName));
this._services.AddDbContext<TDbContext>(options, ServiceLifetime.Scoped);

Expand Down
4 changes: 1 addition & 3 deletions Src/RCommon.Linq2Db/Linq2DbPersistenceBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ public ILinq2DbPersistenceBuilder AddDataConnection<TDataConnection>(string data
Guard.Against<UnsupportedDataStoreException>(options == null, "You must set options to a value in order for them to be useful");

this._services.TryAddTransient<IDataStoreFactory, DataStoreFactory>();
this._services.TryAddTransient<TDataConnection>();
this._services.Configure<DataStoreFactoryOptions>(options => options.Register<TDataConnection>(dataStoreName));

_services.AddLinqToDBContext<TDataConnection>(options);
this._services.AddLinqToDBContext<TDataConnection>(options);
return this;
}

Expand Down
3 changes: 1 addition & 2 deletions Src/RCommon.Linq2Db/RCommonDataConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ namespace RCommon.Persistence.Linq2Db
{
public class RCommonDataConnection : DataConnection, IDataStore
{
private readonly IEntityEventTracker _eventTracker;

public RCommonDataConnection(IEntityEventTracker eventTracker, DataOptions linq2DbOptions)
public RCommonDataConnection(DataOptions linq2DbOptions)
:base(linq2DbOptions)
{

Expand Down
3 changes: 1 addition & 2 deletions Src/RCommon.Persistence/Transactions/UnitOfWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public UnitOfWork(ILogger<UnitOfWork> logger, IGuidGenerator guidGenerator, IOpt
_state = UnitOfWorkState.Created;
_transactionScope = TransactionScopeHelper.CreateScope(_logger, this);
}
public UnitOfWork(ILogger<UnitOfWork> logger, IGuidGenerator guidGenerator, TransactionMode transactionMode, IsolationLevel isolationLevel,
IEventBus eventBus)
public UnitOfWork(ILogger<UnitOfWork> logger, IGuidGenerator guidGenerator, TransactionMode transactionMode, IsolationLevel isolationLevel)
{
_logger = logger;
_guidGenerator = guidGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ public async Task UnitOfWork_Nested_Rollback_Works()
Order savedOrder = null;
savedCustomer = await repo.Context.Set<Customer>().AsNoTracking().FirstOrDefaultAsync(x => x.Id == customer.Id);
savedOrder = await repo.Context.Set<Order>().AsNoTracking().FirstOrDefaultAsync(x => x.Id == order.Id);
Assert.That(savedCustomer != null);
Assert.That(savedOrder != null);
Assert.That(savedCustomer == null);
Assert.That(savedOrder == null);
}

[Test]
Expand Down Expand Up @@ -437,8 +437,8 @@ public async Task UnitOfWork_Can_Rollback_Multipe_Db_Operations()
savedCustomer = await repo.Context.Set<Customer>().AsNoTracking().FirstOrDefaultAsync(x => x.Id == customer.Id);
savedSalesPerson = await repo.Context.Set<SalesPerson>().AsNoTracking().FirstOrDefaultAsync(x => x.Id == salesPerson.Id);

Assert.That(savedCustomer != null);
Assert.That(savedSalesPerson != null);
Assert.That(savedCustomer == null);
Assert.That(savedSalesPerson == null);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ public async Task UnitOfWork_Nested_Rollback_Works()
Order savedOrder = null;
savedCustomer = await repo.Context.Set<Customer>().AsNoTracking().FirstOrDefaultAsync(x => x.Id == customer.Id);
savedOrder = await repo.Context.Set<Order>().AsNoTracking().FirstOrDefaultAsync(x=>x.Id == order.Id);
Assert.That(savedCustomer != null);
Assert.That(savedOrder != null);
Assert.That(savedCustomer == null);
Assert.That(savedOrder == null);
}

[Test]
Expand Down
4 changes: 2 additions & 2 deletions Tests/RCommon.Persistence.Linq2Db.Tests/TestDataConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace RCommon.Persistence.Linq2Db.Tests
{
public class TestDataConnection : RCommonDataConnection
{
public TestDataConnection(IEntityEventTracker eventTracker, DataOptions linq2DbOptions)
: base(eventTracker, linq2DbOptions)
public TestDataConnection(DataOptions linq2DbOptions)
: base(linq2DbOptions)
{
}

Expand Down

0 comments on commit 193d673

Please sign in to comment.