Asoka.Wang 21f044712c 1
2025-08-27 18:39:19 +08:00

35 lines
833 B
C#

using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc.Testing;
using System;
using System.Net.Http;
namespace NPP.SmartSchedue.Tests;
/// <summary>
/// 测试基础
/// </summary>
public class BaseTest
{
protected TestServer Server { get; }
protected HttpClient Client { get; }
protected IServiceProvider ServiceProvider { get; }
protected BaseTest()
{
var application = new WebApplicationFactory<Program>();
Client = application.CreateClient();
Server = application.Server;
ServiceProvider = Server.Services;
}
public T GetService<T>()
{
return ServiceProvider.GetService<T>();
}
public T GetRequiredService<T>()
{
return ServiceProvider.GetRequiredService<T>();
}
}