将Abp的UnitTest中的InMemory改为SQLite in memory
Posted hahaxi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Abp的UnitTest中的InMemory改为SQLite in memory相关的知识,希望对你有一定的参考价值。
添加nuget包
Microsoft.EntityFrameworkCore.Sqlite
添加ServiceCollectionRegistrarSqlite
public static class ServiceCollectionRegistrarSqlite
public static void Register(IIocManager iocManager)
var services = new ServiceCollection();
IdentityRegistrar.Register(services);
services.AddEntityFrameworkSqlite();
var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(iocManager.IocContainer, services);
var builder = new DbContextOptionsBuilder<DeviceManageSystemDbContext>();
var inMemorySqlite = new SqliteConnection("Data Source=:memory:");
builder.UseSqlite(inMemorySqlite);
iocManager.IocContainer.Register(
Component
.For<DbContextOptions<DeviceManageSystemDbContext>>()
.Instance(builder.Options)
.LifestyleSingleton()
);
inMemorySqlite.Open();
new DeviceManageSystemDbContext(builder.Options).Database.EnsureCreated();
添加DeviceManageSystemTestModuleSqlite
复制DeviceManageSystemTestModule,修改
[DependsOn(
typeof(DeviceManageSystemApplicationModule),
typeof(DeviceManageSystemEntityFrameworkModule),
typeof(AbpTestBaseModule)
)]
public class DeviceManageSystemTestModuleSqlite : AbpModule
public override void Initialize()
ServiceCollectionRegistrarSqlite.Register(IocManager);
修改DeviceManageSystemTestBase
public abstract class DeviceManageSystemTestBase : AbpIntegratedTestBase<DeviceManageSystemTestModuleSqlite>
以上是关于将Abp的UnitTest中的InMemory改为SQLite in memory的主要内容,如果未能解决你的问题,请参考以下文章
apollo-cache-inmemory 的驱逐规则是啥?
何时使用 apollo-link-state 以及何时使用 apollo-cache-inmemory