|
|
- using System;
- using Castle.MicroKernel.Registration;
- using NSubstitute;
- using Abp.AutoMapper;
- using Abp.Dependency;
- using Abp.Modules;
- using Abp.Configuration.Startup;
- using Abp.Net.Mail;
- using Abp.TestBase;
- using Abp.Zero.Configuration;
- using Abp.Zero.EntityFrameworkCore;
- using BCS.BMC.EntityFrameworkCore;
- using BCS.BMC.Tests.DependencyInjection;
-
- namespace BCS.BMC.Tests
- {
- [DependsOn(
- typeof(BMCApplicationModule),
- typeof(BMCEntityFrameworkModule),
- typeof(AbpTestBaseModule)
- )]
- public class BMCTestModule : AbpModule
- {
- public BMCTestModule(BMCEntityFrameworkModule abpProjectNameEntityFrameworkModule)
- {
- abpProjectNameEntityFrameworkModule.SkipDbContextRegistration = true;
- abpProjectNameEntityFrameworkModule.SkipDbSeed = true;
- }
-
- public override void PreInitialize()
- {
- Configuration.UnitOfWork.Timeout = TimeSpan.FromMinutes(30);
- Configuration.UnitOfWork.IsTransactional = false;
-
- // Disable static mapper usage since it breaks unit tests (see https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2052)
- Configuration.Modules.AbpAutoMapper().UseStaticMapper = false;
-
- Configuration.BackgroundJobs.IsJobExecutionEnabled = false;
-
- // Use database for language management
- Configuration.Modules.Zero().LanguageManagement.EnableDbLocalization();
-
- RegisterFakeService<AbpZeroDbMigrator<BMCDbContext>>();
-
- Configuration.ReplaceService<IEmailSender, NullEmailSender>(DependencyLifeStyle.Transient);
- }
-
- public override void Initialize()
- {
- ServiceCollectionRegistrar.Register(IocManager);
- }
-
- private void RegisterFakeService<TService>() where TService : class
- {
- IocManager.IocContainer.Register(
- Component.For<TService>()
- .UsingFactoryMethod(() => Substitute.For<TService>())
- .LifestyleSingleton()
- );
- }
- }
- }
|