Update to IHostBuilder style

This commit is contained in:
Justin Baur
2026-01-14 13:32:52 -05:00
parent a5f1b3f815
commit 753c702ccc
2 changed files with 30 additions and 39 deletions

View File

@@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
namespace Bit.Server.IntegrationTest;
@@ -12,34 +12,27 @@ public class Server : WebApplicationFactory<Program>
public bool? WebVault { get; set; }
public string? AppIdLocation { get; set; }
protected override IWebHostBuilder? CreateWebHostBuilder()
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
var args = new List<string>
base.ConfigureWebHost(builder);
var config = new Dictionary<string, string?>
{
"/contentRoot",
ContentRoot ?? "",
"/webRoot",
WebRoot ?? "",
"/serveUnknown",
ServeUnknown.ToString().ToLowerInvariant(),
{"contentRoot", ContentRoot},
{"webRoot", WebRoot},
{"serveUnknown", ServeUnknown.ToString().ToLowerInvariant()},
};
if (WebVault.HasValue)
{
args.Add("/webVault");
args.Add(WebVault.Value.ToString().ToLowerInvariant());
config["webVault"] = WebVault.Value.ToString().ToLowerInvariant();
}
if (!string.IsNullOrEmpty(AppIdLocation))
{
args.Add("/appIdLocation");
args.Add(AppIdLocation);
config["appIdLocation"] = AppIdLocation;
}
var builder = WebHostBuilderFactory.CreateFromTypesAssemblyEntryPoint<Program>([.. args])
?? throw new InvalidProgramException("Could not create builder from assembly.");
builder.UseSetting("TEST_CONTENTROOT_SERVER", ContentRoot);
return builder;
builder.UseConfiguration(new ConfigurationBuilder().AddInMemoryCollection(config).Build());
}
}