mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 14:11:10 +00:00
Hardens test assertions and adds missing test coverage.
This commit is contained in:
1 parent
6b86fd5805
commit
1189bbaf36
489 files changed
+39982
-512
No files matched your search
+63
@@ -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);
|
||||
}
|
||||
}
|
||||
+68
@@ -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);
|
||||
}
|
||||
}
|
||||
+63
@@ -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);
|
||||
}
|
||||
}
|
||||
+67
@@ -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);
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AuthorizationResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AuthorizationResponseTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingAuthorizationResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
HashSet<AuthorizationPermission> permissions = [AuthorizationPermission.CanViewUsers, AuthorizationPermission.CanDeleteUsers];
|
||||
AuthorizationResponse expected = new(userId, "Admin", permissions);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains($"\"UserId\":\"{userId}\"", json, StringComparison.Ordinal);
|
||||
Assert.Contains("\"Role\":\"Admin\"", json, StringComparison.Ordinal);
|
||||
Assert.Contains("canViewUsers", json, StringComparison.Ordinal);
|
||||
Assert.Contains("canDeleteUsers", json, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingAuthorizationResponse_ShouldSerializePermissionsAsCamelCaseStrings()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
HashSet<AuthorizationPermission> permissions = [AuthorizationPermission.CanRegisterUsers];
|
||||
AuthorizationResponse sut = new(userId, "Admin", permissions);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("canRegisterUsers", json, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
HashSet<AuthorizationPermission> permissions = [AuthorizationPermission.None];
|
||||
AuthorizationResponse sut = new(userId, null, permissions);
|
||||
|
||||
// Act
|
||||
(Guid sutUserId, string? role, IReadOnlySet<AuthorizationPermission> sutPermissions) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.UserId, sutUserId);
|
||||
Assert.Equal(sut.Role, role);
|
||||
Assert.Equal(sut.Permissions, sutPermissions);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PermissionResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PermissionResponseTests
|
||||
{
|
||||
private readonly PermissionResponseFixture _permissionResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingPermissionResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PermissionResponse expected = _permissionResponseFixture.Create(permissionName: AuthorizationPermission.CanCreateLibraries);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PermissionResponse? actual = JsonSerializer.Deserialize<PermissionResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingPermissionResponse_ShouldSerializePermissionNameAsCamelCaseString()
|
||||
{
|
||||
// Arrange
|
||||
PermissionResponse sut = _permissionResponseFixture.Create(permissionName: AuthorizationPermission.CanCreateLibraries);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("\"PermissionName\":\"canCreateLibraries\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Authentication;
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Authorization;
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="RolePermissionsResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RolePermissionsResponseTests
|
||||
{
|
||||
private readonly RolePermissionsResponseFixture _rolePermissionsResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingRolePermissionsResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionsResponse expected = _rolePermissionsResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
RolePermissionsResponse? actual = JsonSerializer.Deserialize<RolePermissionsResponse>(json, _jsonOptions);
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equivalent(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingRolePermissionsResponse_ShouldSerializePermissionNameAsCamelCaseString()
|
||||
{
|
||||
// Arrange
|
||||
RolePermissionsResponse sut = _rolePermissionsResponseFixture.Create(permissions:
|
||||
[
|
||||
new PermissionDto(Guid.NewGuid(), AuthorizationPermission.CanDeleteUsers)
|
||||
]);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("canDeleteUsers", json, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.Authorization;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.Authorization;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="RoleResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class RoleResponseTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingRoleResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
RoleResponse expected = new(id, "Admin");
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
RoleResponse? actual = JsonSerializer.Deserialize<RoleResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
RoleResponse first = new(id, "Admin");
|
||||
RoleResponse second = new(id, "Admin");
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.Common;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PaginatedResponse{TData}"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PaginatedResponseTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void PaginatedResponse_WhenConstructed_ShouldRequireAllProperties()
|
||||
{
|
||||
// Act
|
||||
PaginatedResponse<int> sut = new()
|
||||
{
|
||||
Data = [1, 2, 3],
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 3,
|
||||
NumberOfPages = 1
|
||||
};
|
||||
|
||||
// Assert
|
||||
Assert.Equal([1, 2, 3], sut.Data);
|
||||
Assert.Equal(1, sut.CurrentPage);
|
||||
Assert.Equal(10, sut.PerPage);
|
||||
Assert.Equal(3, sut.Count);
|
||||
Assert.Equal(1, sut.NumberOfPages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingPaginatedResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PaginatedResponse<string> expected = new()
|
||||
{
|
||||
Data = ["book1", "book2"],
|
||||
CurrentPage = 2,
|
||||
PerPage = 20,
|
||||
Count = 2,
|
||||
NumberOfPages = 1
|
||||
};
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PaginatedResponse<string>? actual = JsonSerializer.Deserialize<PaginatedResponse<string>>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected.Data, actual.Data);
|
||||
Assert.Equal(expected.CurrentPage, actual.CurrentPage);
|
||||
Assert.Equal(expected.PerPage, actual.PerPage);
|
||||
Assert.Equal(expected.Count, actual.Count);
|
||||
Assert.Equal(expected.NumberOfPages, actual.NumberOfPages);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenDataIsMissing_ShouldThrowJsonException()
|
||||
{
|
||||
// Arrange
|
||||
string json = """{ "currentPage": 1, "perPage": 10, "count": 0, "numberOfPages": 0 }""";
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<PaginatedResponse<int>>(json, _jsonOptions));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
PaginatedResponse<int> first = new()
|
||||
{
|
||||
Data = [1, 2, 3],
|
||||
CurrentPage = 1,
|
||||
PerPage = 10,
|
||||
Count = 3,
|
||||
NumberOfPages = 1
|
||||
};
|
||||
PaginatedResponse<int> second = first with { };
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Common;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.FileSystemManagement.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileSystemTreeNodeResponse"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemTreeNodeResponseTests
|
||||
{
|
||||
private readonly FileSystemTreeNodeResponseFixture _fileSystemTreeNodeResponseFixture = new();
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenInstantiatingNode_ShouldInitializeEmptyChildren()
|
||||
{
|
||||
// Act
|
||||
FileSystemTreeNodeResponse sut = new();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(sut.Children);
|
||||
Assert.Empty(sut.Children);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalled_ShouldReturnValidTreeNode()
|
||||
{
|
||||
// Act
|
||||
FileSystemTreeNodeResponse sut = _fileSystemTreeNodeResponseFixture.Create();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(sut);
|
||||
Assert.False(string.IsNullOrWhiteSpace(sut.Path));
|
||||
Assert.False(string.IsNullOrWhiteSpace(sut.Name));
|
||||
Assert.Equal(FileSystemItemType.Directory, sut.ItemType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingTreeNode_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse expected = _fileSystemTreeNodeResponseFixture.Create(maxDepth: 1, maxChildren: 2);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
FileSystemTreeNodeResponse? actual = JsonSerializer.Deserialize<FileSystemTreeNodeResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected.Path, actual.Path);
|
||||
Assert.Equal(expected.Name, actual.Name);
|
||||
Assert.Equal(expected.ItemType, actual.ItemType);
|
||||
Assert.Equal(expected.Children.Count, actual.Children.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingTreeNode_ShouldSerializeItemTypeAsCamelCaseString()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTreeNodeResponse sut = new()
|
||||
{
|
||||
Path = @"C:\Media",
|
||||
Name = "Media",
|
||||
ItemType = FileSystemItemType.Directory,
|
||||
IsExpanded = false,
|
||||
ChildrenLoaded = true,
|
||||
Children = []
|
||||
};
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("\"ItemType\":\"directory\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Directories;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Directories;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.FileSystemManagement.Directories;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="DirectoryResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DirectoryResponseTests
|
||||
{
|
||||
private readonly DirectoryResponseFixture _directoryResponseFixture = new();
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalled_ShouldReturnValidDirectoryResponse()
|
||||
{
|
||||
// Act
|
||||
DirectoryResponse sut = _directoryResponseFixture.Create();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(sut);
|
||||
Assert.False(string.IsNullOrWhiteSpace(sut.Path));
|
||||
Assert.False(string.IsNullOrWhiteSpace(sut.Name));
|
||||
Assert.NotEmpty(sut.Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingDirectoryResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryResponse expected = _directoryResponseFixture.Create(itemCount: 2);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
DirectoryResponse? actual = JsonSerializer.Deserialize<DirectoryResponse>(json, _jsonOptions);
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equivalent(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
DirectoryResponse sut = _directoryResponseFixture.Create(itemCount: 1);
|
||||
|
||||
// Act
|
||||
(string path, string name, System.DateTime dateCreated, System.DateTime dateModified, System.Collections.Generic.List<Lumina.Contracts.DTO.FileSystemManagement.FileSystemItemDto> items) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.Path, path);
|
||||
Assert.Equal(sut.Name, name);
|
||||
Assert.Equal(sut.DateCreated, dateCreated);
|
||||
Assert.Equal(sut.DateModified, dateModified);
|
||||
Assert.Equal(sut.Items, items);
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.FileSystem;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.FileSystemManagement.FileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileSystemTypeResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileSystemTypeResponseTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingFileSystemTypeResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTypeResponse expected = new(PlatformType.Windows);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
FileSystemTypeResponse? actual = JsonSerializer.Deserialize<FileSystemTypeResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingFileSystemTypeResponse_ShouldSerializePlatformTypeAsCamelCaseString()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTypeResponse sut = new(PlatformType.Unix);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("\"PlatformType\":\"unix\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
FileSystemTypeResponse first = new(PlatformType.Windows);
|
||||
FileSystemTypeResponse second = new(PlatformType.Windows);
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Files;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Files;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.FileSystemManagement.Files;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="FileResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileResponseTests
|
||||
{
|
||||
private readonly FileResponseFixture _fileResponseFixture = new();
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalled_ShouldReturnValidFileResponse()
|
||||
{
|
||||
// Act
|
||||
FileResponse sut = _fileResponseFixture.Create();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(sut);
|
||||
Assert.False(string.IsNullOrWhiteSpace(sut.Path));
|
||||
Assert.False(string.IsNullOrWhiteSpace(sut.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingFileResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
FileResponse expected = _fileResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
FileResponse? actual = JsonSerializer.Deserialize<FileResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
FileResponse sut = _fileResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
(string path, string name, System.DateTime dateCreated, System.DateTime dateModified, long size) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.Path, path);
|
||||
Assert.Equal(sut.Name, name);
|
||||
Assert.Equal(sut.DateCreated, dateCreated);
|
||||
Assert.Equal(sut.DateModified, dateModified);
|
||||
Assert.Equal(sut.Size, size);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PathExistsResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathExistsResponseTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingPathExistsResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PathExistsResponse expected = new(true);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PathExistsResponse? actual = JsonSerializer.Deserialize<PathExistsResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
PathExistsResponse first = new(true);
|
||||
PathExistsResponse second = new(true);
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PathSegmentResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathSegmentResponseTests
|
||||
{
|
||||
private readonly PathSegmentResponseFixture _pathSegmentResponseFixture = new();
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalled_ShouldReturnValidPathSegmentResponse()
|
||||
{
|
||||
// Act
|
||||
PathSegmentResponse sut = _pathSegmentResponseFixture.Create();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(sut);
|
||||
Assert.False(string.IsNullOrWhiteSpace(sut.Path));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingPathSegmentResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PathSegmentResponse expected = _pathSegmentResponseFixture.Create(path: @"C:\Media");
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PathSegmentResponse? actual = JsonSerializer.Deserialize<PathSegmentResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
PathSegmentResponse first = _pathSegmentResponseFixture.Create(path: @"C:\Media\Books");
|
||||
PathSegmentResponse second = _pathSegmentResponseFixture.Create(path: @"C:\Media\Books");
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Path;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PathSeparatorResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathSeparatorResponseTests
|
||||
{
|
||||
private readonly PathSeparatorResponseFixture _pathSeparatorResponseFixture = new();
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalled_ShouldReturnValidPathSeparatorResponse()
|
||||
{
|
||||
// Act
|
||||
PathSeparatorResponse sut = _pathSeparatorResponseFixture.Create();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(sut);
|
||||
Assert.False(string.IsNullOrWhiteSpace(sut.Separator));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingPathSeparatorResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PathSeparatorResponse expected = _pathSeparatorResponseFixture.Create(separator: "\\");
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PathSeparatorResponse? actual = JsonSerializer.Deserialize<PathSeparatorResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
PathSeparatorResponse first = _pathSeparatorResponseFixture.Create(separator: "/");
|
||||
PathSeparatorResponse second = _pathSeparatorResponseFixture.Create(separator: "/");
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Path;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.FileSystemManagement.Path;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PathValidResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PathValidResponseTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingPathValidResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PathValidResponse expected = new(true);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PathValidResponse? actual = JsonSerializer.Deserialize<PathValidResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
PathValidResponse first = new(true);
|
||||
PathValidResponse second = new(true);
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Contracts.Responses.FileSystemManagement.Thumbnails;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.PhotoLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.FileSystemManagement.Thumbnails;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ThumbnailResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ThumbnailResponseTests
|
||||
{
|
||||
private readonly ThumbnailResponseFixture _thumbnailResponseFixture = new();
|
||||
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalled_ShouldReturnValidThumbnailResponse()
|
||||
{
|
||||
// Act
|
||||
ThumbnailResponse sut = _thumbnailResponseFixture.Create();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(sut);
|
||||
Assert.NotEmpty(sut.Bytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingThumbnailResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
ThumbnailResponse expected = _thumbnailResponseFixture.Create(type: ImageType.JPEG);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
ThumbnailResponse? actual = JsonSerializer.Deserialize<ThumbnailResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected.Type, actual.Type);
|
||||
Assert.Equal(expected.Bytes, actual.Bytes);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingThumbnailResponse_ShouldSerializeTypeAsCamelCaseString()
|
||||
{
|
||||
// Arrange
|
||||
ThumbnailResponse sut = _thumbnailResponseFixture.Create(type: ImageType.PNG);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("\"Type\":\"png\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryResponseTests
|
||||
{
|
||||
private readonly LibraryResponseFixture _libraryResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingLibraryResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
LibraryResponse expected = _libraryResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
LibraryResponse? actual = JsonSerializer.Deserialize<LibraryResponse>(json, _jsonOptions);
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equivalent(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingLibraryResponse_ShouldSerializeLibraryTypeAsCamelCaseString()
|
||||
{
|
||||
// Arrange
|
||||
LibraryResponse sut = _libraryResponseFixture.Create(libraryType: LibraryType.Movie);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("\"LibraryType\":\"movie\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
LibraryResponse sut = _libraryResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
(Guid id, Guid userId, string title, LibraryType libraryType, List<string> contentLocations, string? coverImage, bool isEnabled, bool isLocked, bool downloadMetadataFromWeb, bool shouldSaveMetadataInMediaDirectories, bool shouldSkipUnchangedDirectoriesDuringScan, DateTime createdOnUtc, DateTime? updatedOnUtc) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.Id, id);
|
||||
Assert.Equal(sut.UserId, userId);
|
||||
Assert.Equal(sut.Title, title);
|
||||
Assert.Equal(sut.LibraryType, libraryType);
|
||||
Assert.Equal(sut.ContentLocations, contentLocations);
|
||||
Assert.Equal(sut.CoverImage, coverImage);
|
||||
Assert.Equal(sut.IsEnabled, isEnabled);
|
||||
Assert.Equal(sut.IsLocked, isLocked);
|
||||
Assert.Equal(sut.DownloadMetadataFromWeb, downloadMetadataFromWeb);
|
||||
Assert.Equal(sut.ShouldSaveMetadataInMediaDirectories, shouldSaveMetadataInMediaDirectories);
|
||||
Assert.Equal(sut.ShouldSkipUnchangedDirectoriesDuringScan, shouldSkipUnchangedDirectoriesDuringScan);
|
||||
Assert.Equal(sut.CreatedOnUtc, createdOnUtc);
|
||||
Assert.Equal(sut.UpdatedOnUtc, updatedOnUtc);
|
||||
}
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanJobProgressResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanJobProgressResponseTests
|
||||
{
|
||||
private readonly MediaLibraryScanJobProgressResponseFixture _mediaLibraryScanJobProgressResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingMediaLibraryScanJobProgressResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanJobProgressResponse expected = _mediaLibraryScanJobProgressResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
MediaLibraryScanJobProgressResponse? actual = JsonSerializer.Deserialize<MediaLibraryScanJobProgressResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanJobProgressResponse sut = _mediaLibraryScanJobProgressResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
(int completedItems, int totalItems, string currentOperation, decimal progressPercentage) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.CompletedItems, completedItems);
|
||||
Assert.Equal(sut.TotalItems, totalItems);
|
||||
Assert.Equal(sut.CurrentOperation, currentOperation);
|
||||
Assert.Equal(sut.ProgressPercentage, progressPercentage);
|
||||
}
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.Management;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanProgressResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanProgressResponseTests
|
||||
{
|
||||
private readonly MediaLibraryScanProgressResponseFixture _mediaLibraryScanProgressResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingMediaLibraryScanProgressResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanProgressResponse expected = _mediaLibraryScanProgressResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
MediaLibraryScanProgressResponse? actual = JsonSerializer.Deserialize<MediaLibraryScanProgressResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingWithoutCurrentJobProgress_ShouldPreserveNull()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanProgressResponse expected = _mediaLibraryScanProgressResponseFixture.Create() with { CurrentJobProgress = null };
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
MediaLibraryScanProgressResponse? actual = JsonSerializer.Deserialize<MediaLibraryScanProgressResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Null(actual.CurrentJobProgress);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanProgressResponse sut = _mediaLibraryScanProgressResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
(Guid scanId, Guid userId, Guid libraryId, int totalJobs, int completedJobs, MediaLibraryScanJobProgressResponse? currentJobProgress, string status, decimal overallProgressPercentage) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.ScanId, scanId);
|
||||
Assert.Equal(sut.UserId, userId);
|
||||
Assert.Equal(sut.LibraryId, libraryId);
|
||||
Assert.Equal(sut.TotalJobs, totalJobs);
|
||||
Assert.Equal(sut.CompletedJobs, completedJobs);
|
||||
Assert.Equal(sut.CurrentJobProgress, currentJobProgress);
|
||||
Assert.Equal(sut.Status, status);
|
||||
Assert.Equal(sut.OverallProgressPercentage, overallProgressPercentage);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanResponseTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingMediaLibraryScanResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid scanId = Guid.NewGuid();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
MediaLibraryScanResponse expected = new(scanId, libraryId);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
MediaLibraryScanResponse? actual = JsonSerializer.Deserialize<MediaLibraryScanResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid scanId = Guid.NewGuid();
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
MediaLibraryScanResponse sut = new(scanId, libraryId);
|
||||
|
||||
// Act
|
||||
(Guid sutScanId, Guid sutLibraryId) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.ScanId, sutScanId);
|
||||
Assert.Equal(sut.LibraryId, sutLibraryId);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookLiteResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookLiteResponseTests
|
||||
{
|
||||
private readonly BookLiteResponseFixture _bookLiteResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingBookLiteResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
BookLiteResponse expected = _bookLiteResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
BookLiteResponse? actual = JsonSerializer.Deserialize<BookLiteResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingBookLiteResponseWithNullValues_ShouldPreserveNulls()
|
||||
{
|
||||
// Arrange
|
||||
BookLiteResponse expected = _bookLiteResponseFixture.Create() with { ReleaseYear = null, CoverPath = null };
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
BookLiteResponse? actual = JsonSerializer.Deserialize<BookLiteResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Null(actual.ReleaseYear);
|
||||
Assert.Null(actual.CoverPath);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
BookLiteResponse sut = _bookLiteResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
(Guid sutId, string title, int? releaseYear, string? coverPath) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.Id, sutId);
|
||||
Assert.Equal(sut.Title, title);
|
||||
Assert.Equal(sut.ReleaseYear, releaseYear);
|
||||
Assert.Equal(sut.CoverPath, coverPath);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Contracts.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.MediaLibrary.WrittenContentLibrary.BookLibrary.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookResponseTests
|
||||
{
|
||||
private readonly BookResponseFixture _bookResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingBookResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
BookResponse expected = _bookResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
BookResponse? actual = JsonSerializer.Deserialize<BookResponse>(json, _jsonOptions);
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equivalent(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingBookResponse_ShouldSerializeEnumsAsCamelCaseStrings()
|
||||
{
|
||||
// Arrange
|
||||
BookResponse sut = _bookResponseFixture.Create(
|
||||
format: BookFormat.Paperback,
|
||||
metadataStatus: MetadataStatus.Pending);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("\"Format\":\"paperback\"", json, StringComparison.Ordinal);
|
||||
Assert.Contains("\"MetadataStatus\":\"pending\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryMetadataProviderResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryMetadataProviderResponseTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingProviderResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
LibraryMetadataProviderResponse expected = new(pluginId, "OpenLibrary", true, 1);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
LibraryMetadataProviderResponse? actual = JsonSerializer.Deserialize<LibraryMetadataProviderResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid pluginId = Guid.NewGuid();
|
||||
LibraryMetadataProviderResponse sut = new(pluginId, "OpenLibrary", false, 2);
|
||||
|
||||
// Act
|
||||
(Guid sutPluginId, string name, bool isEnabled, int rank) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.PluginId, sutPluginId);
|
||||
Assert.Equal(sut.Name, name);
|
||||
Assert.Equal(sut.IsEnabled, isEnabled);
|
||||
Assert.Equal(sut.Rank, rank);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PluginResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginResponseTests
|
||||
{
|
||||
private readonly PluginResponseFixture _pluginResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingPluginResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PluginResponse expected = _pluginResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PluginResponse? actual = JsonSerializer.Deserialize<PluginResponse>(json, _jsonOptions);
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equivalent(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingFailedPluginResponse_ShouldPreserveLoadError()
|
||||
{
|
||||
// Arrange
|
||||
PluginResponse expected = _pluginResponseFixture.Create(
|
||||
loadStatus: PluginLoadStatus.FailedToLoad,
|
||||
loadError: "Missing dependency");
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PluginResponse? actual = JsonSerializer.Deserialize<PluginResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(PluginLoadStatus.FailedToLoad, actual.LoadStatus);
|
||||
Assert.Equal("Missing dependency", actual.LoadError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingPluginResponse_ShouldSerializeLoadStatusAsCamelCaseString()
|
||||
{
|
||||
// Arrange
|
||||
PluginResponse sut = _pluginResponseFixture.Create(loadStatus: PluginLoadStatus.Loaded);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("\"LoadStatus\":\"loaded\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.Plugins;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PluginSettingDescriptorResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginSettingDescriptorResponseTests
|
||||
{
|
||||
private readonly PluginSettingDescriptorResponseFixture _pluginSettingDescriptorResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) }
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingDescriptor_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingDescriptorResponse expected = _pluginSettingDescriptorResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PluginSettingDescriptorResponse? actual = JsonSerializer.Deserialize<PluginSettingDescriptorResponse>(json, _jsonOptions);
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equivalent(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingDescriptorWithoutOptionalValues_ShouldPreserveNulls()
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingDescriptorResponse expected = _pluginSettingDescriptorResponseFixture.Create() with { DefaultValue = null, AllowedValues = null };
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PluginSettingDescriptorResponse? actual = JsonSerializer.Deserialize<PluginSettingDescriptorResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Null(actual.DefaultValue);
|
||||
Assert.Null(actual.AllowedValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Serialize_WhenSerializingDescriptor_ShouldSerializeTypeAsCamelCaseString()
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingDescriptorResponse sut = _pluginSettingDescriptorResponseFixture.Create(type: PluginSettingType.Number);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(sut, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.Contains("\"Type\":\"number\"", json, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Fixtures.Core.Responses.Plugins;
|
||||
using Lumina.Contracts.Responses.Plugins;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Responses.Plugins;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PluginSettingsResponse"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PluginSettingsResponseTests
|
||||
{
|
||||
private readonly PluginSettingsResponseFixture _pluginSettingsResponseFixture = new();
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingPluginSettingsResponse_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingsResponse expected = _pluginSettingsResponseFixture.Create();
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PluginSettingsResponse? actual = JsonSerializer.Deserialize<PluginSettingsResponse>(json, _jsonOptions);
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equivalent(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingPluginSettingsResponseWithNullSettings_ShouldPreserveNull()
|
||||
{
|
||||
// Arrange
|
||||
PluginSettingsResponse expected = _pluginSettingsResponseFixture.Create() with { Settings = null };
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PluginSettingsResponse? actual = JsonSerializer.Deserialize<PluginSettingsResponse>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Null(actual.Settings);
|
||||
}
|
||||
}
|
||||
+63
@@ -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);
|
||||
}
|
||||
}
|
||||
+53
@@ -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);
|
||||
}
|
||||
}
|
||||
+69
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user