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.Authentication;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Contracts.UnitTests.Responses.Authentication;
/// <summary>
/// Contains unit tests for the <see cref="ChangePasswordResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class ChangePasswordResponseTests
{
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
[Fact]
public void RoundTrip_WhenSerializingChangePasswordResponse_ShouldPreserveValues()
{
// Arrange
ChangePasswordResponse expected = new(true);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
ChangePasswordResponse? actual = JsonSerializer.Deserialize<ChangePasswordResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Equal(expected, actual);
}
[Fact]
public void RoundTrip_WhenSerializingFalseChangePasswordResponse_ShouldPreserveFalse()
{
// Arrange
ChangePasswordResponse expected = new(false);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
ChangePasswordResponse? actual = JsonSerializer.Deserialize<ChangePasswordResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.False(actual.IsPasswordChanged);
}
[Fact]
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
{
// Arrange
ChangePasswordResponse first = new(true);
ChangePasswordResponse second = new(true);
// Act
bool areEqual = first == second;
// Assert
Assert.True(areEqual);
}
}
@@ -0,0 +1,68 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.Authentication;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Contracts.UnitTests.Responses.Authentication;
/// <summary>
/// Contains unit tests for the <see cref="LoginResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class LoginResponseTests
{
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
[Fact]
public void RoundTrip_WhenSerializingLoginResponse_ShouldPreserveValues()
{
// Arrange
Guid id = Guid.NewGuid();
LoginResponse expected = new(id, "testUser", "jwt_token", true);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
LoginResponse? actual = JsonSerializer.Deserialize<LoginResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Equal(expected, actual);
}
[Fact]
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
{
// Arrange
Guid id = Guid.NewGuid();
LoginResponse first = new(id, "testUser", "jwt_token", false);
LoginResponse second = new(id, "testUser", "jwt_token", false);
// Act
bool areEqual = first == second;
// Assert
Assert.True(areEqual);
}
[Fact]
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
{
// Arrange
Guid id = Guid.NewGuid();
LoginResponse sut = new(id, "testUser", "jwt_token", true);
// Act
(Guid sutId, string username, string token, bool usesTotp) = sut;
// Assert
Assert.Equal(sut.Id, sutId);
Assert.Equal(sut.Username, username);
Assert.Equal(sut.Token, token);
Assert.Equal(sut.UsesTotp, usesTotp);
}
}
@@ -0,0 +1,63 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Responses.Authentication;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Contracts.UnitTests.Responses.Authentication;
/// <summary>
/// Contains unit tests for the <see cref="RecoverPasswordResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class RecoverPasswordResponseTests
{
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
[Fact]
public void RoundTrip_WhenSerializingRecoverPasswordResponse_ShouldPreserveValues()
{
// Arrange
RecoverPasswordResponse expected = new(true);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
RecoverPasswordResponse? actual = JsonSerializer.Deserialize<RecoverPasswordResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Equal(expected, actual);
}
[Fact]
public void RoundTrip_WhenSerializingFalseRecoverPasswordResponse_ShouldPreserveFalse()
{
// Arrange
RecoverPasswordResponse expected = new(false);
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
RecoverPasswordResponse? actual = JsonSerializer.Deserialize<RecoverPasswordResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.False(actual.IsPasswordReset);
}
[Fact]
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
{
// Arrange
RecoverPasswordResponse first = new(true);
RecoverPasswordResponse second = new(true);
// Act
bool areEqual = first == second;
// Assert
Assert.True(areEqual);
}
}
@@ -0,0 +1,67 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Contracts.Fixtures.Core.Responses.Authentication;
using Lumina.Contracts.Responses.Authentication;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json;
#endregion
namespace Lumina.Contracts.UnitTests.Responses.Authentication;
/// <summary>
/// Contains unit tests for the <see cref="RegistrationResponse"/> record.
/// </summary>
[ExcludeFromCodeCoverage]
public class RegistrationResponseTests
{
private readonly RegistrationResponseFixture _registrationResponseFixture = new();
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
[Fact]
public void RoundTrip_WhenSerializingRegistrationResponse_ShouldPreserveValues()
{
// Arrange
RegistrationResponse expected = _registrationResponseFixture.Create();
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
RegistrationResponse? actual = JsonSerializer.Deserialize<RegistrationResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Equal(expected, actual);
}
[Fact]
public void RoundTrip_WhenSerializingRegistrationResponseWithNullTotpSecret_ShouldPreserveNull()
{
// Arrange
RegistrationResponse expected = _registrationResponseFixture.Create() with { TotpSecret = null };
// Act
string json = JsonSerializer.Serialize(expected, _jsonOptions);
RegistrationResponse? actual = JsonSerializer.Deserialize<RegistrationResponse>(json, _jsonOptions);
// Assert
Assert.NotNull(actual);
Assert.Null(actual.TotpSecret);
}
[Fact]
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
{
// Arrange
RegistrationResponse sut = _registrationResponseFixture.Create();
// Act
(Guid sutId, string username, string? totpSecret) = sut;
// Assert
Assert.Equal(sut.Id, sutId);
Assert.Equal(sut.Username, username);
Assert.Equal(sut.TotpSecret, totpSecret);
}
}