|
|
@ -1,12 +1,9 @@ |
|
|
using System; |
|
|
using Lion.AbpPro.EntityFrameworkCore; |
|
|
using System.Linq; |
|
|
|
|
|
using Lion.AbpPro.EntityFrameworkCore; |
|
|
|
|
|
using Lion.AbpPro.FreeSqlRepository; |
|
|
using Lion.AbpPro.FreeSqlRepository; |
|
|
using Microsoft.Data.Sqlite; |
|
|
using Microsoft.Data.Sqlite; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore.Infrastructure; |
|
|
using Microsoft.EntityFrameworkCore.Infrastructure; |
|
|
using Microsoft.EntityFrameworkCore.Storage; |
|
|
using Microsoft.EntityFrameworkCore.Storage; |
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Volo.Abp; |
|
|
using Volo.Abp; |
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
using Volo.Abp.EntityFrameworkCore; |
|
|
@ -17,47 +14,51 @@ namespace Lion.AbpPro.FreeSqlReppsitory.Tests; |
|
|
|
|
|
|
|
|
[DependsOn( |
|
|
[DependsOn( |
|
|
typeof(AbpProTestBaseModule), |
|
|
typeof(AbpProTestBaseModule), |
|
|
typeof(AbpProEntityFrameworkCoreTestModule), |
|
|
typeof(AbpProEntityFrameworkCoreModule), |
|
|
|
|
|
typeof(AbpEntityFrameworkCoreSqliteModule), |
|
|
typeof(AbpProFreeSqlModule) |
|
|
typeof(AbpProFreeSqlModule) |
|
|
)] |
|
|
)] |
|
|
public class AbpProFreeSqlRepositoryTestModule : AbpModule |
|
|
public class AbpProFreeSqlRepositoryTestModule : AbpModule |
|
|
{ |
|
|
{ |
|
|
private const string ConnectionString = "Data Source=:memory:"; |
|
|
|
|
|
private SqliteConnection _sqliteConnection; |
|
|
private SqliteConnection _sqliteConnection; |
|
|
|
|
|
private const string ConnectionString = "Data Source=:memory:"; |
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
public override void ConfigureServices(ServiceConfigurationContext context) |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
var freeSql = new FreeSql.FreeSqlBuilder() |
|
|
var freeSql = new FreeSql.FreeSqlBuilder() |
|
|
.UseConnectionString(FreeSql.DataType.Sqlite, ConnectionString) |
|
|
.UseConnectionString(FreeSql.DataType.Sqlite, ConnectionString) |
|
|
.UseAutoSyncStructure(true) |
|
|
.UseAutoSyncStructure(true) |
|
|
.Build(); |
|
|
.Build(); |
|
|
context.Services.AddSingleton<IFreeSql>(freeSql); |
|
|
context.Services.AddSingleton<IFreeSql>(freeSql); |
|
|
var connection = new SqliteConnection(ConnectionString); |
|
|
ConfigureInMemorySqlite(context.Services,freeSql); |
|
|
ConfigureInMemorySqlite(context.Services, freeSql); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void ConfigureInMemorySqlite(IServiceCollection services, IFreeSql freeSql) |
|
|
private void ConfigureInMemorySqlite(IServiceCollection services,IFreeSql freeSql) |
|
|
{ |
|
|
{ |
|
|
_sqliteConnection = CreateDatabaseAndGetConnection(freeSql); |
|
|
_sqliteConnection = CreateDatabaseAndGetConnection(freeSql); |
|
|
|
|
|
|
|
|
//services.Configure<AbpDbContextOptions>(options =>
|
|
|
services.Configure<AbpDbContextOptions>(options => |
|
|
//{
|
|
|
{ |
|
|
// options.PreConfigure<AbpProDbContext>(options => { options.DbContextOptions.UseBatchEF_Sqlite(); });
|
|
|
options.PreConfigure<AbpProDbContext>(options => |
|
|
// options.Configure(context => { context.DbContextOptions.UseSqlite(_sqliteConnection); });
|
|
|
{ |
|
|
//});
|
|
|
options.DbContextOptions.UseBatchEF_Sqlite(); |
|
|
|
|
|
}); |
|
|
|
|
|
options.Configure(context => |
|
|
|
|
|
{ |
|
|
|
|
|
context.DbContextOptions.UseSqlite(_sqliteConnection); |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
|
|
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
|
|
{ |
|
|
{ |
|
|
// _sqliteConnection.Dispose();
|
|
|
_sqliteConnection.Dispose(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static SqliteConnection CreateDatabaseAndGetConnection(IFreeSql freeSql) |
|
|
private static SqliteConnection CreateDatabaseAndGetConnection(IFreeSql freeSql) |
|
|
{ |
|
|
{ |
|
|
var connection = new SqliteConnection(ConnectionString); |
|
|
var connection = new SqliteConnection(ConnectionString); |
|
|
//connection.Open();
|
|
|
connection.Open(); |
|
|
|
|
|
|
|
|
var options = new DbContextOptionsBuilder<AbpProDbContext>() |
|
|
var options = new DbContextOptionsBuilder<AbpProDbContext>() |
|
|
.UseSqlite(connection) |
|
|
.UseSqlite(connection) |
|
|
@ -69,10 +70,10 @@ public class AbpProFreeSqlRepositoryTestModule : AbpModule |
|
|
{ |
|
|
{ |
|
|
freeSql.CodeFirst.SyncStructure(entityType.ClrType, entityType.GetTableName(), true); |
|
|
freeSql.CodeFirst.SyncStructure(entityType.ClrType, entityType.GetTableName(), true); |
|
|
} |
|
|
} |
|
|
|
|
|
context.GetService<IRelationalDatabaseCreator>().CreateTables(); |
|
|
//context.GetService<IRelationalDatabaseCreator>().CreateTables();
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return connection; |
|
|
return connection; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |