TenantBasedService.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using qdr.fnd.core.test;
  2. using Quadarax.Application.QLiberace.Base.Repositories;
  3. using Quadarax.Application.QLiberace.Common.Domain;
  4. using Quadarax.Foundation.Core.Data.Interface.Repository;
  5. using Quadarax.Foundation.Core.Business;
  6. using Quadarax.Foundation.Core.Data.Domain;
  7. namespace Quadarax.Application.QLiberace.Base.Tests.Services.Base
  8. {
  9. public abstract class TenantBasedService<TService, TRepository> : ServiceDbContextTest<TService, TRepository, BaseInMemoryDbContext>
  10. where TService : AbstractRepositoryService<TRepository>
  11. where TRepository : IRepository
  12. {
  13. public const string TenantDefaultCode = "default";
  14. public const string TenantDefaultName = "Default system tenant";
  15. public const bool TenantDefaultIsLocked = false;
  16. public const string TenantOneCode = "one";
  17. public const string TenantOneName = "The one tenant";
  18. public const bool TenantOneIsLocked = false;
  19. protected QlbrcContext Context { get; private set; } = null!;
  20. protected override void OnSetup()
  21. {
  22. Context = new QlbrcContext(null, TenantDefaultCode, 1);
  23. base.OnSetup();
  24. var repoTenant = new RepoTenant(Uow.As<IDataDomain>(), Context);
  25. var tenant = repoTenant.New();
  26. tenant.Code = TenantDefaultCode;
  27. tenant.Name = TenantDefaultName;
  28. tenant.IsLocked = TenantDefaultIsLocked;
  29. tenant = repoTenant.New();
  30. tenant.Code = TenantOneCode;
  31. tenant.Name = TenantOneName;
  32. tenant.IsLocked = TenantOneIsLocked;
  33. repoTenant.Set(tenant);
  34. Uow.Commit();
  35. }
  36. }
  37. }