Exemplo n.º 1
0
    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);
    }
Exemplo n.º 2
0
    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);
    }
Exemplo n.º 3
0
 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;
     }
 }
Exemplo n.º 4
0
    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;
        }
    }
Exemplo n.º 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;
Exemplo n.º 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));
        }
Exemplo n.º 7
0
 public TenantsRepository(TenantsContext tenantsContext)
 {
     this.tenantsContext = tenantsContext;
 }
Exemplo n.º 8
0
 public TenantsSteps(ITenantsApi tenantsApi, IFixture autoFixture, TenantsContext tenantsContext)
 {
     _tenantsApi     = tenantsApi;
     _autoFixture    = autoFixture;
     _tenantsContext = tenantsContext;
 }
Exemplo n.º 9
0
 public TenantService(TenantsContext tenantContext, IPermissionService permissionService, ILogger <TenantService> logger)
 {
     _context           = tenantContext;
     _permissionService = permissionService;
     _logger            = logger;
 }
Exemplo n.º 10
0
        public TenantProvider(IHttpContextAccessor accessor, TenantsContext context)
        {
            var host = accessor.HttpContext.Request.Host.Value;

            _tenantId = context.GetTenantId(host);
        }