fix(test): resolve ContentRoot path in WebServerFixture
The previous code computed the path as Path.Combine(BaseDir, "../../src/Yavsc.Org") which from `bin/Debug/net10.0/` resolved to a non-existent `test/yavscTests/src/Yavsc.Org` (two levels up, not four). Kestrel logged: "The WebRootPath was not found: ... /wwwroot. Static files may be unavailable." The fix walks up the directory tree from BaseDir until it finds a directory that contains `src/Yavsc.Org`. This is robust against the test runner changing the current working directory (which it does: it runs from `test/yavscTests/bin/Debug/net10.0`, not the repo root). After this fix, UseStaticFiles correctly resolves the wwwroot, so static assets under `wwwroot/` are served. Note: this does NOT make the in-memory WebServerFixture fully functional. Two pre-existing issues remain: 1. _Layout.cshtml references `~/css/site.css` but the actual file is now at `~/css/main/site.css` (moved by commit 31906a78). The .cshtml was not updated. 2. HomeController.Index() throws NullReferenceException on an empty EF Core InMemory database (no Activities seeded). UseDeveloperExceptionPage returns a 500 page that gets caught and re-rendered as 404 by the test client. Both will be addressed in follow-up commits. Tested: dotnet test 11/11 green (existing tests use Services DI, not HTTP). UI tests not added yet (blocked by the issues above).
This commit is contained in:
parent
b18e60979a
commit
debb3231d3
1 changed files with 16 additions and 2 deletions
|
|
@ -119,9 +119,23 @@ namespace isnd.tests
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder();
|
var builder = WebApplication.CreateBuilder();
|
||||||
builder.Environment.EnvironmentName = "Development";
|
builder.Environment.EnvironmentName = "Development";
|
||||||
// Set ContentRoot to the Yavsc.Org project directory so WebRootPath resolves correctly
|
// Set ContentRoot to the Yavsc.Org project directory so WebRootPath resolves correctly.
|
||||||
|
// Walk up from BaseDir until we find a directory that contains src/Yavsc.Org. This is
|
||||||
|
// robust against the test runner changing the current working directory.
|
||||||
var testAssemblyLocation = AppDomain.CurrentDomain.BaseDirectory;
|
var testAssemblyLocation = AppDomain.CurrentDomain.BaseDirectory;
|
||||||
var yavscOrgPath = Path.GetFullPath(Path.Combine(testAssemblyLocation, "../../src/Yavsc.Org"));
|
string yavscOrgPath = "";
|
||||||
|
for (var d = new DirectoryInfo(testAssemblyLocation); d != null; d = d.Parent)
|
||||||
|
{
|
||||||
|
var candidate = Path.Combine(d.FullName, "src/Yavsc.Org");
|
||||||
|
if (Directory.Exists(candidate))
|
||||||
|
{
|
||||||
|
yavscOrgPath = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(yavscOrgPath))
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
$"Could not locate src/Yavsc.Org by walking up from {testAssemblyLocation}");
|
||||||
builder.Environment.ContentRootPath = yavscOrgPath;
|
builder.Environment.ContentRootPath = yavscOrgPath;
|
||||||
|
|
||||||
builder.Configuration
|
builder.Configuration
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue