Refactors the integration tests to deserialize problem details and to use collection expressions.

This commit is contained in:
BinaryAlley committed 2026-10-13 13:27:51 +03:00
1 parent 5a5042bea7
commit 34199cc35b
22 files changed
+167 -100

No files matched your search

@@ -12,6 +12,7 @@ using Lumina.Presentation.Api.Core.Endpoints.Library.AudioLibrary.MusicLibrary.T
using Lumina.Presentation.Api.IntegrationTests.Common.Setup; using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
@@ -203,10 +204,12 @@ public class GetTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert // Assert
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
using JsonDocument problemDetails = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); string content = await response.Content.ReadAsStringAsync();
Assert.Equal("General.Unauthorized", problemDetails.RootElement.GetProperty("title").GetString()); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("NotAuthorized", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.NotNull(problemDetails);
Assert.DoesNotContain("Exception", problemDetails.RootElement.GetRawText(), StringComparison.Ordinal); Assert.Equal("General.Unauthorized", problemDetails!["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.DoesNotContain("Exception", content, StringComparison.Ordinal);
} }
[Fact] [Fact]
@@ -232,8 +235,9 @@ public class GetTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// The route value is kept as a raw string, so the unparseable Id reaches the query validator, which reports a clean validation error instead of failing the request binding. // The route value is kept as a raw string, so the unparseable Id reaches the query validator, which reports a clean validation error instead of failing the request binding.
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -246,8 +250,9 @@ public class GetTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert // Assert
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("ArtistIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("ArtistIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -260,8 +265,9 @@ public class GetTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert // Assert
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("AlbumIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("AlbumIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -274,8 +280,9 @@ public class GetTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Assert // Assert
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("TrackIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("TrackIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -197,9 +197,10 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
// Assert // Assert
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Unauthorized", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("NotAuthorized", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.Equal("General.Unauthorized", problemDetails!["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
} }
[Fact] [Fact]
@@ -1032,13 +1033,14 @@ public class UpdateTrackEndpointTests : IClassFixture<AuthenticatedLuminaApiFact
/// </summary> /// </summary>
/// <param name="response">The HTTP response to assert.</param> /// <param name="response">The HTTP response to assert.</param>
/// <param name="expectedDetail">The expected detail of the problem details.</param> /// <param name="expectedDetail">The expected detail of the problem details.</param>
private static async Task AssertNotFoundAsync(HttpResponseMessage response, string expectedDetail) private async Task AssertNotFoundAsync(HttpResponseMessage response, string expectedDetail)
{ {
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.NotFound", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal(expectedDetail, problemDetails.RootElement.GetProperty("detail").GetString()); Assert.Equal("General.NotFound", problemDetails!["title"].GetString());
Assert.Equal(expectedDetail, problemDetails["detail"].GetString());
} }
/// <summary> /// <summary>
@@ -1745,8 +1745,9 @@ public class AddBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
// command validator reports a clean validation error instead of failing the request binding. // command validator reports a clean validation error instead of failing the request binding.
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -13,6 +13,7 @@ using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
@@ -130,10 +131,12 @@ public class GetBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
// Assert // Assert
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
using JsonDocument problemDetails = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); string content = await response.Content.ReadAsStringAsync();
Assert.Equal("General.Unauthorized", problemDetails.RootElement.GetProperty("title").GetString()); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("NotAuthorized", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.NotNull(problemDetails);
Assert.DoesNotContain("Exception", problemDetails.RootElement.GetRawText(), StringComparison.Ordinal); Assert.Equal("General.Unauthorized", problemDetails!["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.DoesNotContain("Exception", content, StringComparison.Ordinal);
} }
[Fact] [Fact]
@@ -160,8 +163,9 @@ public class GetBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
// validation error instead of failing the request binding. // validation error instead of failing the request binding.
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -176,8 +180,9 @@ public class GetBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory>
// validation error instead of failing the request binding. // validation error instead of failing the request binding.
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("BookIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("BookIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -14,6 +14,7 @@ using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
@@ -262,11 +263,11 @@ public class GetBooksEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
Assert.NotNull(paginatedBooks); Assert.NotNull(paginatedBooks);
BookResponse book = Assert.Single(paginatedBooks!.Data); BookResponse book = Assert.Single(paginatedBooks!.Data);
Assert.Equal(seededBook.Title, book.Metadata.Title); Assert.Equal(seededBook.Title, book.Metadata.Title);
Assert.Equal(seededBook.Tags.Select(tag => tag.Name), book.Metadata.Tags.Select(tag => tag.Name)); Assert.Equal(seededBook.Tags.Select(tag => tag.Name), book?.Metadata?.Tags?.Select(tag => tag.Name));
Assert.Equal(seededBook.Genres.Select(genre => genre.Name), book.Metadata.Genres.Select(genre => genre.Name)); Assert.Equal(seededBook.Genres.Select(genre => genre.Name), book?.Metadata?.Genres?.Select(genre => genre.Name));
Assert.Equal(seededBook.ISBNs.Select(isbn => isbn.Value), book.ISBNs.Select(isbn => isbn.Value)); Assert.Equal(seededBook.ISBNs.Select(isbn => isbn.Value), book?.ISBNs?.Select(isbn => isbn.Value));
Assert.Equal(seededBook.Ratings.Select(rating => rating.Value), book.Ratings.Select(rating => rating.Value)); Assert.Equal(seededBook.Ratings.Select(rating => rating.Value), book?.Ratings?.Select(rating => rating.Value));
Assert.Equal(seededBook.Ratings.Single().Source, book.Ratings.Single().Source); Assert.Equal(seededBook.Ratings.Single().Source, book?.Ratings?.Single().Source);
} }
[Fact] [Fact]
@@ -280,8 +281,9 @@ public class GetBooksEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// validation error instead of failing the request binding. // validation error instead of failing the request binding.
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -303,7 +305,7 @@ public class GetBooksEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
PaginatedResponse<BookResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookResponse>>(_jsonOptions); PaginatedResponse<BookResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookResponse>>(_jsonOptions);
Assert.NotNull(paginatedBooks); Assert.NotNull(paginatedBooks);
Assert.Equal(new[] { "Book A", "Book B", "Book C" }, paginatedBooks!.Data.Select(book => book.Metadata.Title)); Assert.Equal(["Book A", "Book B", "Book C"], paginatedBooks!.Data.Select(book => book.Metadata.Title));
} }
[Fact] [Fact]
@@ -324,7 +326,7 @@ public class GetBooksEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
PaginatedResponse<BookResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookResponse>>(_jsonOptions); PaginatedResponse<BookResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookResponse>>(_jsonOptions);
Assert.NotNull(paginatedBooks); Assert.NotNull(paginatedBooks);
Assert.Equal(new[] { "Book C", "Book B", "Book A" }, paginatedBooks!.Data.Select(book => book.Metadata.Title)); Assert.Equal(["Book C", "Book B", "Book A"], paginatedBooks!.Data.Select(book => book.Metadata.Title));
} }
[Fact] [Fact]
@@ -410,7 +412,7 @@ public class GetBooksEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
PaginatedResponse<BookResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookResponse>>(_jsonOptions); PaginatedResponse<BookResponse>? paginatedBooks = await response.Content.ReadFromJsonAsync<PaginatedResponse<BookResponse>>(_jsonOptions);
Assert.NotNull(paginatedBooks); Assert.NotNull(paginatedBooks);
Assert.Equal(new[] { "Book A", "Book B", "Book C" }, paginatedBooks!.Data.Select(book => book.Metadata.Title)); Assert.Equal(["Book A", "Book B", "Book C"], paginatedBooks!.Data.Select(book => book.Metadata.Title));
} }
[Fact] [Fact]
@@ -11,6 +11,7 @@ using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
@@ -351,8 +352,9 @@ public class GetBooksLiteEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
// validation error instead of failing the request binding. // validation error instead of failing the request binding.
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("LibraryIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -10,6 +10,7 @@ using Lumina.DataAccess.Core.UoW;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup; using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
@@ -105,10 +106,12 @@ public class GetReadingAvailabilityEndpointTests : IClassFixture<AuthenticatedLu
// Assert // Assert
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
using JsonDocument problemDetails = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); string content = await response.Content.ReadAsStringAsync();
Assert.Equal("General.Unauthorized", problemDetails.RootElement.GetProperty("title").GetString()); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("NotAuthorized", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.NotNull(problemDetails);
Assert.DoesNotContain("Exception", problemDetails.RootElement.GetRawText(), StringComparison.Ordinal); Assert.Equal("General.Unauthorized", problemDetails!["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.DoesNotContain("Exception", content, StringComparison.Ordinal);
} }
[Fact] [Fact]
@@ -9,11 +9,13 @@ using Lumina.DataAccess.Core.UoW;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup; using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
@@ -27,6 +29,11 @@ public class GetReadingManifestEndpointTests : IClassFixture<AuthenticatedLumina
{ {
private HttpClient _client; private HttpClient _client;
private readonly AuthenticatedLuminaApiFactory _apiFactory; private readonly AuthenticatedLuminaApiFactory _apiFactory;
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
};
private readonly LibraryEntityFixture _libraryEntityFixture = new(); private readonly LibraryEntityFixture _libraryEntityFixture = new();
private readonly BookEntityFixture _bookEntityFixture = new(); private readonly BookEntityFixture _bookEntityFixture = new();
private readonly UserEntityFixture _userEntityFixture = new(); private readonly UserEntityFixture _userEntityFixture = new();
@@ -74,10 +81,12 @@ public class GetReadingManifestEndpointTests : IClassFixture<AuthenticatedLumina
// Assert // Assert
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
using JsonDocument problemDetails = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); string content = await response.Content.ReadAsStringAsync();
Assert.Equal("General.Unauthorized", problemDetails.RootElement.GetProperty("title").GetString()); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("NotAuthorized", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.NotNull(problemDetails);
Assert.DoesNotContain("Exception", problemDetails.RootElement.GetRawText(), StringComparison.Ordinal); Assert.Equal("General.Unauthorized", problemDetails!["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.DoesNotContain("Exception", content, StringComparison.Ordinal);
} }
[Fact] [Fact]
@@ -9,11 +9,13 @@ using Lumina.DataAccess.Core.UoW;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup; using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
@@ -27,6 +29,11 @@ public class GetReadingResourceEndpointTests : IClassFixture<AuthenticatedLumina
{ {
private HttpClient _client; private HttpClient _client;
private readonly AuthenticatedLuminaApiFactory _apiFactory; private readonly AuthenticatedLuminaApiFactory _apiFactory;
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
};
private readonly LibraryEntityFixture _libraryEntityFixture = new(); private readonly LibraryEntityFixture _libraryEntityFixture = new();
private readonly BookEntityFixture _bookEntityFixture = new(); private readonly BookEntityFixture _bookEntityFixture = new();
private readonly UserEntityFixture _userEntityFixture = new(); private readonly UserEntityFixture _userEntityFixture = new();
@@ -74,10 +81,12 @@ public class GetReadingResourceEndpointTests : IClassFixture<AuthenticatedLumina
// Assert // Assert
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
using JsonDocument problemDetails = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); string content = await response.Content.ReadAsStringAsync();
Assert.Equal("General.Unauthorized", problemDetails.RootElement.GetProperty("title").GetString()); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("NotAuthorized", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.NotNull(problemDetails);
Assert.DoesNotContain("Exception", problemDetails.RootElement.GetRawText(), StringComparison.Ordinal); Assert.Equal("General.Unauthorized", problemDetails!["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.DoesNotContain("Exception", content, StringComparison.Ordinal);
} }
[Fact] [Fact]
@@ -9,11 +9,13 @@ using Lumina.DataAccess.Core.UoW;
using Lumina.Presentation.Api.IntegrationTests.Common.Setup; using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
@@ -27,6 +29,11 @@ public class GetReadingSectionEndpointTests : IClassFixture<AuthenticatedLuminaA
{ {
private HttpClient _client; private HttpClient _client;
private readonly AuthenticatedLuminaApiFactory _apiFactory; private readonly AuthenticatedLuminaApiFactory _apiFactory;
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
};
private readonly LibraryEntityFixture _libraryEntityFixture = new(); private readonly LibraryEntityFixture _libraryEntityFixture = new();
private readonly BookEntityFixture _bookEntityFixture = new(); private readonly BookEntityFixture _bookEntityFixture = new();
private readonly UserEntityFixture _userEntityFixture = new(); private readonly UserEntityFixture _userEntityFixture = new();
@@ -74,10 +81,12 @@ public class GetReadingSectionEndpointTests : IClassFixture<AuthenticatedLuminaA
// Assert // Assert
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
using JsonDocument problemDetails = JsonDocument.Parse(await response.Content.ReadAsStringAsync()); string content = await response.Content.ReadAsStringAsync();
Assert.Equal("General.Unauthorized", problemDetails.RootElement.GetProperty("title").GetString()); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("NotAuthorized", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.NotNull(problemDetails);
Assert.DoesNotContain("Exception", problemDetails.RootElement.GetRawText(), StringComparison.Ordinal); Assert.Equal("General.Unauthorized", problemDetails!["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
Assert.DoesNotContain("Exception", content, StringComparison.Ordinal);
} }
[Fact] [Fact]
@@ -181,8 +181,9 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
// command validator reports a clean validation error instead of failing the request binding. // command validator reports a clean validation error instead of failing the request binding.
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("BookIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("BookIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -199,9 +200,10 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
// Assert // Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.NotFound", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("BookNotFound", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.Equal("General.NotFound", problemDetails!["title"].GetString());
Assert.Equal("BookNotFound", problemDetails["detail"].GetString());
} }
[Fact] [Fact]
@@ -218,9 +220,10 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
// Assert // Assert
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Unauthorized", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("NotAuthorized", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.Equal("General.Unauthorized", problemDetails!["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
} }
[Fact] [Fact]
@@ -237,8 +240,9 @@ public class UpdateBookEndpointTests : IClassFixture<AuthenticatedLuminaApiFacto
// Assert // Assert
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("TitleCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("TitleCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -14,12 +14,14 @@ using Lumina.Presentation.Api.Core.Endpoints.Library.WrittenContentLibrary.BookL
using Lumina.Presentation.Api.IntegrationTests.Common.Setup; using Lumina.Presentation.Api.IntegrationTests.Common.Setup;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using System.Net.Http; using System.Net.Http;
using System.Net.Http.Headers; using System.Net.Http.Headers;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks; using System.Threading.Tasks;
#endregion #endregion
@@ -33,6 +35,11 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
{ {
private HttpClient _client; private HttpClient _client;
private readonly AuthenticatedLuminaApiFactory _apiFactory; private readonly AuthenticatedLuminaApiFactory _apiFactory;
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true,
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
};
private readonly BookEntityFixture _bookEntityFixture = new(); private readonly BookEntityFixture _bookEntityFixture = new();
private readonly BookArtworkEntityFixture _bookArtworkEntityFixture = new(); private readonly BookArtworkEntityFixture _bookArtworkEntityFixture = new();
private readonly LibraryEntityFixture _libraryEntityFixture = new(); private readonly LibraryEntityFixture _libraryEntityFixture = new();
@@ -69,7 +76,7 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert // Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
string storedPath = JsonSerializer.Deserialize<UpdateBookCoverResponse>(content, new JsonSerializerOptions { PropertyNameCaseInsensitive = true })!.CoverPath; string storedPath = JsonSerializer.Deserialize<UpdateBookCoverResponse>(content, _jsonOptions)!.CoverPath;
Assert.False(string.IsNullOrWhiteSpace(storedPath)); Assert.False(string.IsNullOrWhiteSpace(storedPath));
Assert.Contains("cover.png", storedPath, StringComparison.OrdinalIgnoreCase); Assert.Contains("cover.png", storedPath, StringComparison.OrdinalIgnoreCase);
@@ -95,7 +102,7 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert // Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
string storedPath = JsonSerializer.Deserialize<UpdateBookCoverResponse>(content, new JsonSerializerOptions { PropertyNameCaseInsensitive = true })!.CoverPath; string storedPath = JsonSerializer.Deserialize<UpdateBookCoverResponse>(content, _jsonOptions)!.CoverPath;
Assert.False(string.IsNullOrWhiteSpace(storedPath)); Assert.False(string.IsNullOrWhiteSpace(storedPath));
using IServiceScope scope = _apiFactory.Services.CreateScope(); using IServiceScope scope = _apiFactory.Services.CreateScope();
@@ -115,9 +122,10 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert // Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.NotFound", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("BookNotFound", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.Equal("General.NotFound", problemDetails!["title"].GetString());
Assert.Equal("BookNotFound", problemDetails["detail"].GetString());
} }
[Fact] [Fact]
@@ -129,8 +137,9 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert // Assert
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("BookIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("BookIdCannotBeEmpty", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -147,9 +156,10 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert // Assert
Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode); Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Unauthorized", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("NotAuthorized", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.Equal("General.Unauthorized", problemDetails!["title"].GetString());
Assert.Equal("NotAuthorized", problemDetails["detail"].GetString());
} }
[Fact] [Fact]
@@ -166,9 +176,10 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert // Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.NotFound", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("BookNotFound", problemDetails.RootElement.GetProperty("detail").GetString()); Assert.Equal("General.NotFound", problemDetails!["title"].GetString());
Assert.Equal("BookNotFound", problemDetails["detail"].GetString());
} }
[Fact] [Fact]
@@ -197,8 +208,9 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert // Assert
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("BookCoverCannotBeNull", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("BookCoverCannotBeNull", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -216,8 +228,9 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert // Assert
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("CoverFileMustBeAnImage", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("CoverFileMustBeAnImage", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -245,8 +258,9 @@ public class UpdateBookCoverEndpointTests : IClassFixture<AuthenticatedLuminaApi
// Assert // Assert
Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode); Assert.Equal(HttpStatusCode.UnprocessableEntity, response.StatusCode);
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
using JsonDocument problemDetails = JsonDocument.Parse(content); Dictionary<string, JsonElement>? problemDetails = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(content, _jsonOptions);
Assert.Equal("General.Validation", problemDetails.RootElement.GetProperty("title").GetString()); Assert.NotNull(problemDetails);
Assert.Equal("General.Validation", problemDetails!["title"].GetString());
Assert.Contains("FileTooLarge", content, StringComparison.OrdinalIgnoreCase); Assert.Contains("FileTooLarge", content, StringComparison.OrdinalIgnoreCase);
} }
@@ -63,7 +63,7 @@ public class CancelLibrariesScanEndpointTests : IClassFixture<LuminaWebFactory>
{ {
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
cancelRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); cancelRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
cancelRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); cancelRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return cancelRequest; return cancelRequest;
@@ -66,7 +66,7 @@ public class CancelLibraryScanEndpointTests : IClassFixture<LuminaWebFactory>
{ {
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
cancelRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); cancelRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
cancelRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); cancelRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return cancelRequest; return cancelRequest;
@@ -63,10 +63,10 @@ public class DeleteLibraryEndpointTests : IClassFixture<LuminaWebFactory>
{ {
HttpRequestMessage deleteRequest = new(HttpMethod.Delete, $"/en-us/libraries/manage/api-item/{libraryId}") HttpRequestMessage deleteRequest = new(HttpMethod.Delete, $"/en-us/libraries/manage/api-item/{libraryId}")
{ {
// the front-end sends the JSON content type even for DELETE requests, which triggers the antiforgery validation // The front-end sends the JSON content type even for DELETE requests, which triggers the antiforgery validation.
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
deleteRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); deleteRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
deleteRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); deleteRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return deleteRequest; return deleteRequest;
@@ -73,7 +73,7 @@ public class ScanLibrariesEndpointTests : IClassFixture<LuminaWebFactory>
{ {
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
scanRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); scanRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
scanRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); scanRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return scanRequest; return scanRequest;
@@ -70,7 +70,7 @@ public class ScanLibraryEndpointTests : IClassFixture<LuminaWebFactory>
{ {
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
scanRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); scanRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
scanRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); scanRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return scanRequest; return scanRequest;
@@ -72,7 +72,7 @@ public class CancelLibrariesScanEndpointTests : IClassFixture<LuminaWebFactory>
{ {
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
cancelRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); cancelRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
cancelRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); cancelRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return cancelRequest; return cancelRequest;
@@ -77,7 +77,7 @@ public class CancelLibraryScanEndpointTests : IClassFixture<LuminaWebFactory>
{ {
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
cancelRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); cancelRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
cancelRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); cancelRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return cancelRequest; return cancelRequest;
@@ -73,10 +73,10 @@ public class DeleteLibraryEndpointTests : IClassFixture<LuminaWebFactory>
{ {
HttpRequestMessage deleteRequest = new(HttpMethod.Delete, $"/en-us/libraries/manage/api-item/{libraryId}") HttpRequestMessage deleteRequest = new(HttpMethod.Delete, $"/en-us/libraries/manage/api-item/{libraryId}")
{ {
// the front-end sends the JSON content type even for DELETE requests, which triggers the antiforgery validation // The front-end sends the JSON content type even for DELETE requests, which triggers the antiforgery validation.
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
deleteRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); deleteRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
deleteRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); deleteRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return deleteRequest; return deleteRequest;
@@ -72,7 +72,7 @@ public class ScanLibrariesEndpointTests : IClassFixture<LuminaWebFactory>
{ {
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
scanRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); scanRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
scanRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); scanRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return scanRequest; return scanRequest;
@@ -81,8 +81,8 @@ public class ScanLibraryEndpointTests : IClassFixture<LuminaWebFactory>
string content = await response.Content.ReadAsStringAsync(); string content = await response.Content.ReadAsStringAsync();
// Assert // Assert
// note: the {id} route parameter is Guid-typed, so the malicious value fails model binding and never reaches // Note: the {id} route parameter is Guid-typed, so the malicious value fails model binding and never reaches
// the handler; the Web application reports the binding failure as a 200 response carrying success=false // the handler; the Web application reports the binding failure as a 200 response carrying success=false.
using JsonDocument json = JsonDocument.Parse(content); using JsonDocument json = JsonDocument.Parse(content);
Assert.False(json.RootElement.GetProperty("success").GetBoolean()); Assert.False(json.RootElement.GetProperty("success").GetBoolean());
Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase); Assert.DoesNotContain("Exception", content, StringComparison.OrdinalIgnoreCase);
@@ -105,7 +105,7 @@ public class ScanLibraryEndpointTests : IClassFixture<LuminaWebFactory>
{ {
Content = new StringContent("{}", Encoding.UTF8, "application/json") Content = new StringContent("{}", Encoding.UTF8, "application/json")
}; };
// the antiforgery middleware matches the content type exactly, so the charset suffix must be omitted // The antiforgery middleware matches the content type exactly, so the charset suffix must be omitted.
scanRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json"); scanRequest.Content!.Headers.ContentType = new MediaTypeHeaderValue("application/json");
scanRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); scanRequest.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
return scanRequest; return scanRequest;