Hardens test assertions and adds missing test coverage.

This commit is contained in:
BinaryAlley committed 2026-08-18 08:28:16 -07:00
1 parent 6b86fd5805
commit 1189bbaf36
489 files changed
+39982 -512

No files matched your search

@@ -0,0 +1,63 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.UsersManagement;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Contracts.UnitTests.Responses.UsersManagement;
/// <summary>
/// Contains unit tests for the <see cref="InitializationResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class InitializationResponseTests
{
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
[Fact]
public void RoundTrip_WhenSerializingInitializationResponse_ShouldPreserveValues()
{
// Arrange
InitializationResponse expected = new(true);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
InitializationResponse? actual = JsonSerializer.Deserialize<InitializationResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Equal(expected, actual);
}
[Fact]
public void RoundTrip_WhenSerializingFalseInitializationResponse_ShouldPreserveFalse()
{
// Arrange
InitializationResponse expected = new(false);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
InitializationResponse? actual = JsonSerializer.Deserialize<InitializationResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.False(actual.IsInitialized);
}
[Fact]
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
{
// Arrange
InitializationResponse first = new(true);
InitializationResponse second = new(true);
// Act
bool areEqual = first == second;
// Assert
Assert.True(areEqual);
}
}
@@ -0,0 +1,53 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.UsersManagement.Settings;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Contracts.UnitTests.Responses.UsersManagement.Settings;
/// <summary>
/// Contains unit tests for the <see cref="UserSettingsResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserSettingsResponseTests
{
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
[Fact]
public void RoundTrip_WhenSerializingUserSettingsResponse_ShouldPreserveValues()
{
// Arrange
Guid userId = Guid.NewGuid();
UserSettingsResponse expected = new(userId, true, 50, true);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
UserSettingsResponse? actual = JsonSerializer.Deserialize<UserSettingsResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Equal(expected, actual);
}
[Fact]
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
{
// Arrange
Guid userId = Guid.NewGuid();
UserSettingsResponse sut = new(userId, false, 25, false);
// Act
(Guid sutUserId, bool isPaginationEnabled, int itemsPerPage, bool ignoreThePrefixForAlphaPicker) = sut;
// Assert
Assert.Equal(sut.UserId, sutUserId);
Assert.Equal(sut.IsPaginationEnabled, isPaginationEnabled);
Assert.Equal(sut.ItemsPerPage, itemsPerPage);
Assert.Equal(sut.IgnoreThePrefixForAlphaPicker, ignoreThePrefixForAlphaPicker);
}
}
@@ -0,0 +1,69 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Fixtures.Core.Responses.UsersManagement.Users;
using Lumina.Contracts.Responses.UsersManagement.Users;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Contracts.UnitTests.Responses.UsersManagement.Users;
/// <summary>
/// Contains unit tests for the <see cref="UserResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class UserResponseTests
{
private readonly UserResponseFixture _userResponseFixture = new();
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
[Fact]
public void RoundTrip_WhenSerializingUserResponse_ShouldPreserveValues()
{
// Arrange
UserResponse expected = _userResponseFixture.Create();
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
UserResponse? actual = JsonSerializer.Deserialize<UserResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Equal(expected, actual);
}
[Fact]
public void RoundTrip_WhenSerializingUserResponseWithUpdatedOnUtc_ShouldPreserveValue()
{
// Arrange
DateTime updatedOnUtc = DateTime.UtcNow.AddDays(1);
UserResponse expected = _userResponseFixture.Create(updatedOnUtc: updatedOnUtc);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
UserResponse? actual = JsonSerializer.Deserialize<UserResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Equal(updatedOnUtc, actual.UpdatedOnUtc);
}
[Fact]
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
{
// Arrange
UserResponse sut = _userResponseFixture.Create();
// Act
(Guid sutId, string username, DateTime sutCreatedOnUtc, DateTime? sutUpdatedOnUtc) = sut;
// Assert
Assert.Equal(sut.Id, sutId);
Assert.Equal(sut.Username, username);
Assert.Equal(sut.CreatedOnUtc, sutCreatedOnUtc);
Assert.Equal(sut.UpdatedOnUtc, sutUpdatedOnUtc);
}
}