using Abp.AspNetCore;
using Abp.AspNetCore.TestBase;
using Abp.Modules;
using Abp.Reflection.Extensions;
using YGNT.Exam.EntityFrameworkCore;
using YGNT.Exam.Web.Startup;
using Microsoft.AspNetCore.Mvc.ApplicationParts;

namespace YGNT.Exam.Web.Tests
{
    [DependsOn(
        typeof(ExamWebMvcModule),
        typeof(AbpAspNetCoreTestBaseModule)
    )]
    public class ExamWebTestModule : AbpModule
    {
        public ExamWebTestModule(ExamEntityFrameworkModule abpProjectNameEntityFrameworkModule)
        {
            abpProjectNameEntityFrameworkModule.SkipDbContextRegistration = true;
        } 
        
        public override void PreInitialize()
        {
            Configuration.UnitOfWork.IsTransactional = false; //EF Core InMemory DB does not support transactions.
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(ExamWebTestModule).GetAssembly());
        }
        
        public override void PostInitialize()
        {
            IocManager.Resolve<ApplicationPartManager>()
                .AddApplicationPartsIfNotAddedBefore(typeof(ExamWebMvcModule).Assembly);
        }
    }
}