22using Abp . AspNetCore . TestBase ;
33using Abp . Modules ;
44using Abp . Reflection . Extensions ;
5+ using AbpCompanyName . AbpProjectName . EntityFrameworkCore ;
56using AbpCompanyName . AbpProjectName . Web . Startup ;
7+ using Castle . MicroKernel . Registration ;
8+ using Castle . Windsor . MsDependencyInjection ;
9+ using Microsoft . EntityFrameworkCore ;
10+ using Microsoft . Extensions . DependencyInjection ;
611
712namespace AbpCompanyName . AbpProjectName . Web . Tests
813{
@@ -12,9 +17,36 @@ namespace AbpCompanyName.AbpProjectName.Web.Tests
1217 ) ]
1318 public class AbpProjectNameWebTestModule : AbpModule
1419 {
20+ public override void PreInitialize ( )
21+ {
22+ Configuration . UnitOfWork . IsTransactional = false ; //EF Core InMemory DB does not support transactions.
23+ SetupInMemoryDb ( ) ;
24+ }
25+
1526 public override void Initialize ( )
1627 {
1728 IocManager . RegisterAssemblyByConvention ( typeof ( AbpProjectNameWebTestModule ) . GetAssembly ( ) ) ;
1829 }
30+
31+ private void SetupInMemoryDb ( )
32+ {
33+ var services = new ServiceCollection ( )
34+ . AddEntityFrameworkInMemoryDatabase ( ) ;
35+
36+ var serviceProvider = WindsorRegistrationHelper . CreateServiceProvider (
37+ IocManager . IocContainer ,
38+ services
39+ ) ;
40+
41+ var builder = new DbContextOptionsBuilder < AbpProjectNameDbContext > ( ) ;
42+ builder . UseInMemoryDatabase ( ) . UseInternalServiceProvider ( serviceProvider ) ;
43+
44+ IocManager . IocContainer . Register (
45+ Component
46+ . For < DbContextOptions < AbpProjectNameDbContext > > ( )
47+ . Instance ( builder . Options )
48+ . LifestyleSingleton ( )
49+ ) ;
50+ }
1951 }
2052}
0 commit comments