Strip comments and dedupe normalized literals in backend tests

- Remove all // and /// comments from the backend test suite.
- Replace hardcoded normalized-form string literals (e.g. NormalizedTitle/
  NormalizedName duplicating a title/name in upper case) with a variable
  plus .ToUpperInvariant(), so the two values can't drift apart.
This commit is contained in:
2026-09-10 02:45:11 +02:00
parent 5658dd24ff
commit c418844178
14 changed files with 29 additions and 110 deletions
@@ -8,8 +8,6 @@ namespace Musify.Api.Tests.Extensions
{
public sealed class ErrorOrHttpExtensionsTests
{
// The concrete IResult types (NoContent, UnauthorizedHttpResult, ...) resolve logging/problem-
// details services from HttpContext.RequestServices when they execute, so it can't be empty.
private static readonly IServiceProvider Services = new ServiceCollection().AddLogging().AddProblemDetails().BuildServiceProvider();
private static async Task<(int StatusCode, string Body)> ExecuteAsync(IResult result)
@@ -12,11 +12,6 @@ namespace Musify.Api.Tests.Filters
{
public sealed record Payload(string Name);
// EndpointFilterInvocationContext.Create has no (HttpContext, object[]) overload — only
// Create<T0>, Create<T0,T1>, etc. Passing an object[] to a params-object[] call site binds
// to Create<T0> with T0 inferred as object[] itself, so .Arguments ends up with one element
// (the array, boxed) instead of the array's contents — OfType<Payload>() then never matches
// and the filter silently falls through to "no argument, skip validation" for every case.
private static EndpointFilterInvocationContext CreateContext<T>(T argument) =>
EndpointFilterInvocationContext.Create(new DefaultHttpContext(), argument);
@@ -13,14 +13,6 @@ using Xunit;
namespace Musify.Api.Tests.TestSupport
{
/// <summary>
/// Boots the real <c>Musify.Api</c> host — real routing, real auth/authorization pipeline,
/// real validators, real Mediator handlers — against a private Postgres container (so EF
/// queries behave like production, not like a stand-in). The services this API talks to over
/// the network (object storage, YouTube, the message bus, stream-ticket signing) are replaced
/// with NSubstitute fakes: they are Infrastructure's job to verify against the real thing (see
/// Musify.Infrastructure.Tests), not the HTTP layer's.
/// </summary>
public sealed class ApiTestFixture : WebApplicationFactory<Program>, IAsyncLifetime
{
private readonly PostgreSqlContainer postgres = new PostgreSqlBuilder("postgres:17-alpine")
@@ -46,20 +38,14 @@ namespace Musify.Api.Tests.TestSupport
await database.Database.MigrateAsync();
}
// xUnit v3's IAsyncLifetime IS System.IAsyncDisposable (rather than declaring its own
// Task-returning DisposeAsync as in v2), so there is a single DisposeAsync slot to fill —
// override the one WebApplicationFactory already provides instead of implementing the
// interface explicitly alongside it.
public override async ValueTask DisposeAsync()
{
await base.DisposeAsync();
await postgres.DisposeAsync();
}
/// <summary>An <see cref="HttpClient"/> with no auth header — every protected endpoint answers 401.</summary>
public HttpClient CreateAnonymousClient() => CreateClient();
/// <summary>An <see cref="HttpClient"/> authenticated as the given user id (see <see cref="FakeAuthenticationHandler"/>).</summary>
public HttpClient CreateAuthenticatedClient(long userId, string userName = "test-user")
{
var client = CreateClient();
@@ -105,8 +91,6 @@ namespace Musify.Api.Tests.TestSupport
services.Replace(ServiceDescriptor.Singleton(YouTubeMusicService));
services.Replace(ServiceDescriptor.Singleton(StreamTicketService));
// Overrides the real JwtBearer scheme as the default, so requests authenticate via
// FakeAuthenticationHandler instead of needing a real token and a reachable IdP.
services
.AddAuthentication(FakeAuthenticationHandler.SchemeName)
.AddScheme<AuthenticationSchemeOptions, FakeAuthenticationHandler>(FakeAuthenticationHandler.SchemeName, _ => { });
@@ -6,12 +6,6 @@ using Microsoft.Extensions.Options;
namespace Musify.Api.Tests.TestSupport
{
/// <summary>
/// Replaces the real JwtBearer handler in the test host: a request carrying the
/// <see cref="UserIdHeader"/> header authenticates as that user id, with no real token,
/// issuer or JWKS endpoint involved. A request without the header stays anonymous, so
/// endpoints under <c>.RequireAuthorization()</c> correctly answer 401.
/// </summary>
public sealed class FakeAuthenticationHandler(
IOptionsMonitor<AuthenticationSchemeOptions> options,
ILoggerFactory logger,