/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Middleware/Diagnostics/test/FunctionalTests/TestFixture.cs
48 строк
1 KB
William Godbe
Rename Microsoft.Aspnetcore.Testing to Microsoft.AspNetCore.InternalTesting (#51713)
02 ноя 2023, 03:15
Не верифицирован
02 ноя 2023, 03:15
fc8deca
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.TestHost; using Microsoft.AspNetCore.InternalTesting; using Microsoft.Extensions.Hosting; namespace Microsoft.AspNetCore.Diagnostics.FunctionalTests; public class TestFixture<TStartup> : IDisposable { private readonly TestServer _server; private readonly IHost _host; public TestFixture() { // RequestLocalizationOptions saves the current culture when constructed, potentially changing response // localization i.e. RequestLocalizationMiddleware behavior. Ensure the saved culture // (DefaultRequestCulture) is consistent regardless of system configuration or personal preferences. using (new CultureReplacer()) { _host = new HostBuilder() .ConfigureWebHost(webHostBuilder => { webHostBuilder .UseTestServer() .UseStartup(typeof(TStartup)); }).Build(); _host.Start(); _server = _host.GetTestServer(); } Client = _server.CreateClient(); Client.BaseAddress = new Uri("http://localhost"); } public HttpClient Client { get; } public void Dispose() { Client.Dispose(); _server.Dispose(); _host.Dispose(); } }