RepositoryDbContextTest.cs 981 B

12345678910111213141516171819202122232425262728
  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. protected DomainContextResolver<TDbContext>? _dbcResolver;
  9. protected UnitOfWork<TDbContext> Uow { get; private set; }
  10. protected override void OnSetup()
  11. {
  12. var context = new TDbContext();
  13. context.Database.EnsureCreated();
  14. _dbcResolver = new DomainContextResolver<TDbContext>(context);
  15. Uow = new UnitOfWork<TDbContext>(_dbcResolver);
  16. }
  17. protected override void OnTearDown()
  18. {
  19. _dbcResolver?.GetCurrent<TDbContext>().Dispose();
  20. _dbcResolver = null;
  21. }
  22. protected abstract TRepository GetRepository();
  23. }
  24. }