Caches JsonSerializerOptions instances in tests

This commit is contained in:
BinaryAlley committed 2026-08-22 00:43:58 -07:00
1 parent c2e00242cc
commit b2b6f554b7
3 files changed
+6 -8

No files matched your search

@@ -26,6 +26,7 @@ public class GetRolesEndpointTests
private readonly IApiHttpClient _mockApiHttpClient;
private readonly GetRolesEndpoint _sut;
private readonly RoleDtoFixture _roleDtoFixture = new();
private readonly JsonSerializerOptions _jsonOptions = new() { PropertyNameCaseInsensitive = true };
/// <summary>
/// Initializes a new instance of the <see cref="GetRolesEndpointTests"/> class.
@@ -51,15 +52,10 @@ public class GetRolesEndpointTests
// Assert
using JsonDocument jsonDocument = JsonDocument.Parse(body);
Assert.True(jsonDocument.RootElement.GetProperty("success").GetBoolean());
RoleDto[]? returnedRoles = jsonDocument.RootElement.GetProperty("data").Deserialize<RoleDto[]>(CreateCaseInsensitiveOptions());
RoleDto[]? returnedRoles = jsonDocument.RootElement.GetProperty("data").Deserialize<RoleDto[]>(_jsonOptions);
Assert.Equal(expectedRoles.Select(role => role.RoleName), returnedRoles!.Select(role => role.RoleName));
}
private static JsonSerializerOptions CreateCaseInsensitiveOptions()
{
return new JsonSerializerOptions { PropertyNameCaseInsensitive = true };
}
[Fact]
public async Task ExecuteAsync_WhenCalled_ShouldRequestRolesFromApi()
{