2
2
using Abp . AspNetCore . TestBase ;
3
3
using Abp . Modules ;
4
4
using Abp . Reflection . Extensions ;
5
+ using AbpCompanyName . AbpProjectName . EntityFrameworkCore ;
5
6
using AbpCompanyName . AbpProjectName . Web . Startup ;
7
+ using Castle . MicroKernel . Registration ;
8
+ using Castle . Windsor . MsDependencyInjection ;
9
+ using Microsoft . EntityFrameworkCore ;
10
+ using Microsoft . Extensions . DependencyInjection ;
6
11
7
12
namespace AbpCompanyName . AbpProjectName . Web . Tests
8
13
{
@@ -12,9 +17,36 @@ namespace AbpCompanyName.AbpProjectName.Web.Tests
12
17
) ]
13
18
public class AbpProjectNameWebTestModule : AbpModule
14
19
{
20
+ public override void PreInitialize ( )
21
+ {
22
+ Configuration . UnitOfWork . IsTransactional = false ; //EF Core InMemory DB does not support transactions.
23
+ SetupInMemoryDb ( ) ;
24
+ }
25
+
15
26
public override void Initialize ( )
16
27
{
17
28
IocManager . RegisterAssemblyByConvention ( typeof ( AbpProjectNameWebTestModule ) . GetAssembly ( ) ) ;
18
29
}
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
+ }
19
51
}
20
52
}
0 commit comments