|
|
@ -1,36 +1,62 @@ |
|
|
using System; |
|
|
using System.Threading.Tasks; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure; |
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Storage; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
|
|
|
using Volo.Abp.EntityFrameworkCore.Sqlite; |
|
|
using Volo.Abp.Modularity; |
|
|
using Volo.Abp.Modularity; |
|
|
using Volo.Abp.Threading; |
|
|
using Volo.Abp.Threading; |
|
|
using Volo.Abp.Uow; |
|
|
using Volo.Abp.Uow; |
|
|
|
|
|
using Microsoft.Data.Sqlite; |
|
|
|
|
|
|
|
|
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore; |
|
|
namespace Volo.Abp.PermissionManagement.EntityFrameworkCore; |
|
|
|
|
|
|
|
|
[DependsOn( |
|
|
[DependsOn( |
|
|
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
|
|
typeof(AbpPermissionManagementEntityFrameworkCoreModule), |
|
|
typeof(AbpPermissionManagementTestBaseModule))] |
|
|
typeof(AbpPermissionManagementTestBaseModule), |
|
|
|
|
|
typeof(AbpEntityFrameworkCoreSqliteModule) |
|
|
|
|
|
)] |
|
|
public class AbpPermissionManagementEntityFrameworkCoreTestModule : AbpModule |
|
|
public class AbpPermissionManagementEntityFrameworkCoreTestModule : AbpModule |
|
|
{ |
|
|
{ |
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
public override void PreConfigureServices(ServiceConfigurationContext context) |
|
|
{ |
|
|
{ |
|
|
context.Services.AddEntityFrameworkInMemoryDatabase(); |
|
|
PreConfigure<AbpSqliteOptions>(x => x.BusyTimeout = null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var databaseName = Guid.NewGuid().ToString(); |
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
var sqliteConnection = CreateDatabaseAndGetConnection(); |
|
|
|
|
|
|
|
|
Configure<AbpDbContextOptions>(options => |
|
|
Configure<AbpDbContextOptions>(options => |
|
|
{ |
|
|
{ |
|
|
options.Configure(abpDbContextConfigurationContext => |
|
|
options.Configure(abpDbContextConfigurationContext => |
|
|
{ |
|
|
{ |
|
|
abpDbContextConfigurationContext.DbContextOptions.UseInMemoryDatabase(databaseName); |
|
|
abpDbContextConfigurationContext.DbContextOptions.UseSqlite(sqliteConnection); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
Configure<AbpUnitOfWorkDefaultOptions>(options => |
|
|
|
|
|
{ |
|
|
|
|
|
options.TransactionBehavior = UnitOfWorkTransactionBehavior.Disabled; //EF in-memory database does not support transactions
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
context.Services.AddAlwaysDisableUnitOfWorkTransaction(); |
|
|
context.Services.AddAlwaysDisableUnitOfWorkTransaction(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static SqliteConnection CreateDatabaseAndGetConnection() |
|
|
|
|
|
{ |
|
|
|
|
|
var connection = new AbpUnitTestSqliteConnection("Data Source=:memory:"); |
|
|
|
|
|
connection.Open(); |
|
|
|
|
|
|
|
|
|
|
|
new PermissionManagementDbContext( |
|
|
|
|
|
new DbContextOptionsBuilder<PermissionManagementDbContext>().UseSqlite(connection).Options |
|
|
|
|
|
).GetService<IRelationalDatabaseCreator>().CreateTables(); |
|
|
|
|
|
|
|
|
|
|
|
return connection; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
|
public override void OnApplicationInitialization(ApplicationInitializationContext context) |
|
|
{ |
|
|
{ |
|
|
var task = context.ServiceProvider.GetRequiredService<AbpPermissionManagementDomainModule>().GetInitializeDynamicPermissionsTask(); |
|
|
var task = context.ServiceProvider.GetRequiredService<AbpPermissionManagementDomainModule>().GetInitializeDynamicPermissionsTask(); |
|
|
|