using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; namespace Opsoft.NetCore.O3App.Test { [Xunit.Collection("TestCollection")] public class TestBase { protected readonly IServiceProvider ServiceProvider; protected readonly IConfiguration Configuration; public TestBase(TestStartupFixture fixture) { ServiceProvider = fixture.Services; this.Configuration = ServiceProvider.GetService(); } protected virtual T GetConfigSection(string key) { var targetSection = Configuration.GetSection(key); targetSection = targetSection ?? throw new ArgumentException($"Not Exists Config Key: {key}"); return targetSection.Get(); } protected virtual T GetService() { return ServiceProvider.GetService(); } } }