1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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 YGNT.Exam.EntityFrameworkCore;
- using YGNT.Exam.Tests.DependencyInjection;
- namespace YGNT.Exam.Tests
- {
- [DependsOn(
- typeof(ExamApplicationModule),
- typeof(ExamEntityFrameworkModule),
- typeof(AbpTestBaseModule)
- )]
- public class ExamTestModule : AbpModule
- {
- public ExamTestModule(ExamEntityFrameworkModule 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<ExamDbContext>>();
- 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()
- );
- }
- }
- }
|