test(blogs): configure SiteSettings.Blog in MappedClaimsBlogsWebServerFixture
BlogSpotService's constructor throws InvalidOperationException
("SiteSettings.Blog is not configured.") when IOptions<SiteSettings>.Blog
is null, so every request to BlogApiController 500'd resolving the
service — all 3 BlogApiMappedClaimsTests were failing with
InternalServerError.
The mapped-claims fixture never configured SiteSettings (the main
BlogsWebServerFixture does, pointing Blog at a per-run temp dir).
Mirror that: Configure<SiteSettings>(s => s.Blog = <temp dir>)
before AddScoped<BlogSpotService>(). These tests are JSON-only
(AttachFiles short-circuits), but the service must be constructible.
Verified: BlogApiMappedClaimsTests 3/3 green; full Yavsc.Blogs.Tests
37/37 green.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2d8f92dde9
commit
a12830e49b
2 changed files with 13 additions and 1 deletions
|
|
@ -74,7 +74,7 @@ IClassFixture<MappedClaimsBlogsWebServerFixture>
|
||||||
var draft = new BlogPost
|
var draft = new BlogPost
|
||||||
{
|
{
|
||||||
Id = 0,
|
Id = 0,
|
||||||
Title = "Billet JWT remappe",
|
Title = "Billet JWT re-mappé",
|
||||||
AuthorId = "payload-attacker",
|
AuthorId = "payload-attacker",
|
||||||
Article = "Contenu de test.",
|
Article = "Contenu de test.",
|
||||||
DateCreated = DateTime.UtcNow,
|
DateCreated = DateTime.UtcNow,
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,18 @@ public sealed class MappedClaimsBlogsWebServerFixture : IDisposable, IBackendFix
|
||||||
opt.UseInMemoryDatabase("Yavsc.Blogs.Tests.MappedClaims", _inMemoryRoot));
|
opt.UseInMemoryDatabase("Yavsc.Blogs.Tests.MappedClaims", _inMemoryRoot));
|
||||||
|
|
||||||
builder.Services.AddSingleton<IFileSystemAuthManager>(new NoopFileSystemAuthManager());
|
builder.Services.AddSingleton<IFileSystemAuthManager>(new NoopFileSystemAuthManager());
|
||||||
|
|
||||||
|
// BlogSpotService's constructor throws InvalidOperationException
|
||||||
|
// ("SiteSettings.Blog is not configured.") when Blog is null, so
|
||||||
|
// every request hitting BlogApiController would 500 resolving the
|
||||||
|
// service. These tests never upload files (JSON-only POST/PUT), so
|
||||||
|
// AttachFiles short-circuits — but the service still has to be
|
||||||
|
// constructible. Point Blog at a per-run temp directory, mirroring
|
||||||
|
// BlogsWebServerFixture.
|
||||||
|
builder.Services.Configure<SiteSettings>(s =>
|
||||||
|
{
|
||||||
|
s.Blog = Path.Combine(Path.GetTempPath(), "postit-blogs-mappedclaims-" + Guid.NewGuid().ToString("N"));
|
||||||
|
});
|
||||||
builder.Services.AddScoped<BlogSpotService>();
|
builder.Services.AddScoped<BlogSpotService>();
|
||||||
builder.Services.AddScoped<IAuthorizationHandler, PermissionHandler>();
|
builder.Services.AddScoped<IAuthorizationHandler, PermissionHandler>();
|
||||||
builder.Services.AddControllers()
|
builder.Services.AddControllers()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue