zoukankan      html  css  js  c++  java
  • 将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>
    {
    
    }
    
  • 相关阅读:
    个人总结
    找水王
    nabcd需求分析
    四则运算最终篇-网页版四则运算
    第一次冲刺--个人工作总结02
    第一次冲刺--个人工作总结01
    组队APP功能点定点NABCD分析
    水王
    软件工程结对作业01
    个人工作总结06
  • 原文地址:https://www.cnblogs.com/hahaxi/p/11135280.html
Copyright © 2011-2022 走看看