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>
    {
    
    }
    
  • 相关阅读:
    Pycharm中运行Python代码的几种方式
    Git同步Python代码
    抓包工具Charles的使用
    jmeter进行的接口测试和压力测试
    并发的HTTP请求,apache是如何响应的,以及如何调用php文件的
    http 请求头部解析
    display_errors","On");和error_reporting 区别和联系
    http
    curl
    正则 惰性和非惰性匹配
  • 原文地址:https://www.cnblogs.com/hahaxi/p/11135280.html
Copyright © 2011-2022 走看看