testing
Some checks failed
Dotnet build and test / log-the-inputs (push) Failing after 2s
Dotnet build and test / build (push) Failing after 1s

This commit is contained in:
Paul Schneider
2025-07-14 18:58:04 +01:00
parent 0a270c9218
commit 62e863e343
20 changed files with 233 additions and 266 deletions

View File

@ -1,5 +1,6 @@
using System.Net;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
@ -13,6 +14,8 @@ using Yavsc;
using Yavsc.Models;
using Yavsc.Services;
using yavscTests.Settings;
using Yavsc.Extensions;
using Microsoft.EntityFrameworkCore;
namespace isnd.tests
{
@ -20,12 +23,14 @@ namespace isnd.tests
[CollectionDefinition("Web server collection")]
public class WebServerFixture : IDisposable
{
public IWebHost Host { get; private set;}
public List<string> Addresses { get; private set; } = new List<string>();
public Microsoft.Extensions.Logging.ILogger Logger { get; internal set; }
private SiteSettings siteSettings;
public IConfigurationRoot Configuration { get; private set; }
private WebApplication app;
public string TestingUserName { get; private set; }
public string ProtectedTestingApiKey { get; internal set; }
@ -38,34 +43,41 @@ namespace isnd.tests
public WebServerFixture()
{
SetupHost();
SetupHost().Wait();
}
public void Dispose()
{
Host.StopAsync().Wait();
Host.Dispose();
if (app!=null)
app.StopAsync().Wait();
}
public void SetupHost()
public async Task SetupHost()
{
var builder = WebHost.CreateDefaultBuilder(new string[0]);
var builder = WebApplication.CreateBuilder();
Configuration = builder.Configuration
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables()
.Build();
// .UseContentRoot("../../../../../src/isnd")
builder.UseStartup(typeof(Startup))
.ConfigureAppConfiguration((builderContext, config) =>
this.app = builder.ConfigureWebAppServices();
using (var migrationScope = app.Services.CreateScope())
{
config.AddJsonFile("appsettings.json", true);
config.AddJsonFile("appsettings.Development.json", false);
});
var db = migrationScope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
await db.Database.MigrateAsync();
}
await app.ConfigurePipeline();
app.UseSession();
await app.StartAsync();
Host = builder.Build();
var logFactory = Host.Services.GetRequiredService<ILoggerFactory>();
var logFactory = app.Services.GetRequiredService<ILoggerFactory>();
Logger = logFactory.CreateLogger<WebServerFixture>();
Host.Start(); //Starts listening on the configured addresses.
var server = Host.Services.GetRequiredService<IServer>();
var server = app.Services.GetRequiredService<IServer>();
var addressFeatures = server.Features.Get<IServerAddressesFeature>();
@ -73,12 +85,13 @@ namespace isnd.tests
{
Addresses.Add(address);
}
SiteSettings = Host.Services.GetRequiredService<IOptions<SiteSettings>>().Value;
SiteSettings = app.Services.GetRequiredService<IOptions<SiteSettings>>().Value;
using IServiceScope scope = Host.Services.CreateScope();
using IServiceScope scope = app.Services.CreateScope();
ApplicationDbContext dbContext =
scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
//dbContext.Database.EnsureCreated();
dbContext.Database.Migrate();
TestingUserName = "Tester";
TestingUser = dbContext.Users.FirstOrDefault(u => u.UserName == TestingUserName);
@ -93,7 +106,7 @@ namespace isnd.tests
{
if (TestingUser == null)
{
using IServiceScope scope = Host.Services.CreateScope();
using IServiceScope scope = app.Services.CreateScope();
var userManager =
scope.ServiceProvider.GetRequiredService<UserManager<ApplicationUser>>();
@ -114,19 +127,6 @@ namespace isnd.tests
}
}
internal void DropTestDb()
{
throw new NotImplementedException();
}
internal bool EnsureTestDb()
{
throw new NotImplementedException();
}
internal int UpgradeDb()
{
throw new NotImplementedException();
}
}
}