using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace NPin.Test; public class NPinTestBase : AbpTestBaseWithServiceProvider { public ILogger Logger { get; private set; } protected IServiceScope TestServiceScope { get; } public NPinTestBase() { IHost host = Host.CreateDefaultBuilder() .UseAutofac() .ConfigureServices((host, service) => { ConfigureServices(host, service); service.AddLogging(builder => builder.ClearProviders().AddConsole().AddDebug()); service.AddApplicationAsync().Wait(); }) .ConfigureAppConfiguration(ConfigureAppConfiguration) .Build(); ServiceProvider = host.Services; TestServiceScope = ServiceProvider.CreateScope(); Logger = (ILogger)ServiceProvider.GetRequiredService(typeof(ILogger<>).MakeGenericType(GetType())); host.InitializeAsync().Wait(); } public virtual void ConfigureServices(HostBuilderContext host, IServiceCollection service) { } protected virtual void ConfigureAppConfiguration(IConfigurationBuilder configurationBuilder) { configurationBuilder.AddJsonFile("appsettings.json"); } }