Update tests to work with the now legacy WebHostBuilder

- I accidentally had the updated Program locally and that was why tests were working for me locally
This commit is contained in:
Justin Baur
2026-01-14 11:35:12 -05:00
parent 1c9ff89db1
commit 2ecdc13f2d
2 changed files with 26 additions and 19 deletions

View File

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