public static void ConfigureDatabase(this IHost host)
    {
        using IServiceScope scope = host.Services.CreateScope();

        ILogger        logger         = scope.ServiceProvider.GetRequiredService <ILogger <TenantsContext> >();
        TenantsContext tenantsContext = scope.ServiceProvider.GetRequiredService <TenantsContext>();

        CreateDatabase(tenantsContext, logger);
        SeedDatabase(tenantsContext, logger);
    }
    public async Task Add_New_Will_Update_Created_Time(TenantsContext context, Tenant tenant)
    {
        tenant.CreatedTime = null;

        await context.AddAsync(tenant);

        await context.SaveChangesAsync();

        Assert.NotNull(tenant.CreatedTime);
    }
 private static void CreateDatabase(TenantsContext tenantsContext, ILogger logger)
 {
     try
     {
         /////////////////////////////////////////////////////////////////////////////////////////
         // In a production environment, use EF tools to apply migrations during deployment
         // This is here to simplify the demo application
         ////////////////////////////////////////////////////////////////////////////////////////
         tenantsContext.Database.Migrate();
     }
     catch (Exception ex)
     {
         logger.LogCritical(ex, "Unable to create the database");
         throw;
     }
 }
    private static void SeedDatabase(TenantsContext tenantsContext, ILogger logger)
    {
        try
        {
            if (tenantsContext.Tenants.Any())
            {
                return;   // DB has been seeded
            }

            //Add any code required to seed the database here
        }
        catch (Exception ex)
        {
            logger.LogCritical(ex, "Error while seeding the database");
            throw;
        }
    }
Exemple #5
0
        public async Task Will_throw_if_tenenent_Not_Found2([Frozen] TenantsContext tenantsContext, TenantService tenantService, Tenant[] tenants)
        {
            await tenantsContext.Tenants.AddRangeAsync(tenants);

            Guid      id     = tenants[^ 1].Id;
Exemple #6
0
        public async Task Will_throw_if_tenenent_Not_Found([Frozen] TenantsContext tenantsContext, TenantService tenantService, Guid tenantId)
        {
            Assert.Null(await tenantsContext.Tenants.FindAsync(tenantId));

            await Assert.ThrowsAsync <ItemNotFoundExcepton>(() => tenantService.GetTenantAsync(tenantId));
        }
Exemple #7
0
 public TenantsRepository(TenantsContext tenantsContext)
 {
     this.tenantsContext = tenantsContext;
 }
Exemple #8
0
 public TenantsSteps(ITenantsApi tenantsApi, IFixture autoFixture, TenantsContext tenantsContext)
 {
     _tenantsApi     = tenantsApi;
     _autoFixture    = autoFixture;
     _tenantsContext = tenantsContext;
 }
Exemple #9
0
 public TenantService(TenantsContext tenantContext, IPermissionService permissionService, ILogger <TenantService> logger)
 {
     _context           = tenantContext;
     _permissionService = permissionService;
     _logger            = logger;
 }
Exemple #10
0
        public TenantProvider(IHttpContextAccessor accessor, TenantsContext context)
        {
            var host = accessor.HttpContext.Request.Host.Value;

            _tenantId = context.GetTenantId(host);
        }