33 lines
957 B
C#
Executable File
33 lines
957 B
C#
Executable File
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<IConfiguration>();
|
|
}
|
|
|
|
protected virtual T GetConfigSection<T>(string key)
|
|
{
|
|
var targetSection = Configuration.GetSection(key);
|
|
targetSection = targetSection ?? throw new ArgumentException($"Not Exists Config Key: {key}");
|
|
return targetSection.Get<T>();
|
|
}
|
|
|
|
protected virtual T GetService<T>()
|
|
{
|
|
return ServiceProvider.GetService<T>();
|
|
}
|
|
}
|
|
}
|