RepositoryDbContextTest.cs 1.0 KB

1234567891011121314151617181920212223242526272829
  1. using Quadarax.Foundation.Core.Data.Domain;
  2. using Quadarax.Foundation.Core.Data.Interface.Repository;
  3. namespace qdr.fnd.core.test
  4. {
  5. public abstract class RepositoryDbContextTest<TRepository, TDbContext> : BaseTest where TDbContext : DataDomain, new()
  6. where TRepository : IRepository
  7. {
  8. // ReSharper disable once InconsistentNaming
  9. protected DomainContextResolver<TDbContext>? _dbcResolver;
  10. protected UnitOfWork<TDbContext> Uow { get; private set; } = null!;
  11. protected override void OnSetup()
  12. {
  13. var context = new TDbContext();
  14. context.Database.EnsureCreated();
  15. _dbcResolver = new DomainContextResolver<TDbContext>(context);
  16. Uow = new UnitOfWork<TDbContext>(_dbcResolver);
  17. }
  18. protected override void OnTearDown()
  19. {
  20. _dbcResolver?.GetCurrent<TDbContext>().Dispose();
  21. _dbcResolver = null;
  22. }
  23. protected abstract TRepository GetRepository();
  24. }
  25. }