mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15: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
+57
@@ -0,0 +1,57 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common.Filtering;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.DTO.Common.Filtering;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryFilterDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryFilterDtoTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void LibraryFilterDto_WhenConstructed_ShouldRequireLibraryId()
|
||||
{
|
||||
// Act
|
||||
LibraryFilterDto sut = new() { LibraryId = Guid.NewGuid(), SearchTerm = "test" };
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(Guid.Empty, sut.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingWithLibraryIdAndSearchTerm_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
LibraryFilterDto expected = new() { LibraryId = libraryId, SearchTerm = "fantasy" };
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
LibraryFilterDto? actual = JsonSerializer.Deserialize<LibraryFilterDto>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected.LibraryId, actual.LibraryId);
|
||||
Assert.Equal(expected.SearchTerm, actual.SearchTerm);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenDeserializingJsonWithoutLibraryId_ShouldThrowJsonException()
|
||||
{
|
||||
// Arrange
|
||||
string json = """{ "searchTerm": "fantasy" }""";
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonException>(() => JsonSerializer.Deserialize<LibraryFilterDto>(json, _jsonOptions));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GenreDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GenreDtoTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingGenre_ShouldPreserveName()
|
||||
{
|
||||
// Arrange
|
||||
GenreDto expected = new("Science Fiction");
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
GenreDto? actual = JsonSerializer.Deserialize<GenreDto>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
GenreDto first = new("Fantasy");
|
||||
GenreDto second = new("Fantasy");
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LanguageInfoDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LanguageInfoDtoTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingFullyPopulatedLanguageInfo_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto expected = new("en", "English", "English");
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
LanguageInfoDto? actual = JsonSerializer.Deserialize<LanguageInfoDto>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
LanguageInfoDto first = new("fr", "French", "Français");
|
||||
LanguageInfoDto second = new("fr", "French", "Français");
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common.Pagination;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.DTO.Common.Pagination;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="PaginationDataDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class PaginationDataDtoTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void CurrentPage_WhenNotSet_ShouldDefaultToOne()
|
||||
{
|
||||
// Arrange
|
||||
PaginationDataDto sut = new();
|
||||
|
||||
// Act
|
||||
int currentPage = sut.CurrentPage;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1, currentPage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PerPage_WhenNotSet_ShouldDefaultToTwoHundred()
|
||||
{
|
||||
// Arrange
|
||||
PaginationDataDto sut = new();
|
||||
|
||||
// Act
|
||||
int perPage = sut.PerPage;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(200, perPage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // zero is below the minimum
|
||||
[InlineData(-5)] // negative values are below the minimum
|
||||
public void CurrentPage_WhenSettingValueBelowOne_ShouldClampToOne(int value)
|
||||
{
|
||||
// Arrange
|
||||
PaginationDataDto sut = new();
|
||||
|
||||
// Act
|
||||
sut.CurrentPage = value;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1, sut.CurrentPage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // zero is below the minimum
|
||||
[InlineData(-10)] // negative values are below the minimum
|
||||
public void PerPage_WhenSettingValueBelowOne_ShouldClampToOne(int value)
|
||||
{
|
||||
// Arrange
|
||||
PaginationDataDto sut = new();
|
||||
|
||||
// Act
|
||||
sut.PerPage = value;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(1, sut.PerPage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CurrentPage_WhenSettingValueAboveOne_ShouldPreserveValue()
|
||||
{
|
||||
// Arrange
|
||||
PaginationDataDto sut = new();
|
||||
|
||||
// Act
|
||||
sut.CurrentPage = 5;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(5, sut.CurrentPage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PerPage_WhenSettingValueAboveOne_ShouldPreserveValue()
|
||||
{
|
||||
// Arrange
|
||||
PaginationDataDto sut = new();
|
||||
|
||||
// Act
|
||||
sut.PerPage = 25;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(25, sut.PerPage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingValidPaginationData_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
PaginationDataDto expected = new() { CurrentPage = 3, PerPage = 50 };
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
PaginationDataDto? actual = JsonSerializer.Deserialize<PaginationDataDto>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected.CurrentPage, actual.CurrentPage);
|
||||
Assert.Equal(expected.PerPage, actual.PerPage);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ReleaseInfoDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ReleaseInfoDtoTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingFullyPopulatedReleaseInfo_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
DateOnly originalReleaseDate = new(2005, 6, 15);
|
||||
DateOnly reReleaseDate = new(2015, 9, 1);
|
||||
ReleaseInfoDto expected = new(
|
||||
originalReleaseDate,
|
||||
2005,
|
||||
reReleaseDate,
|
||||
2015,
|
||||
"US",
|
||||
"Revised Edition"
|
||||
);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
ReleaseInfoDto? actual = JsonSerializer.Deserialize<ReleaseInfoDto>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingEmptyReleaseInfo_ShouldPreserveNullValues()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfoDto expected = new(null, null, null, null, null, null);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
ReleaseInfoDto? actual = JsonSerializer.Deserialize<ReleaseInfoDto>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfoDto first = new(new DateOnly(2005, 6, 15), 2005, null, null, "US", null);
|
||||
ReleaseInfoDto second = new(new DateOnly(2005, 6, 15), 2005, null, null, "US", null);
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.DTO.Common;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.DTO.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TagDto"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TagDtoTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingTag_ShouldPreserveName()
|
||||
{
|
||||
// Arrange
|
||||
TagDto expected = new("bestseller");
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
TagDto? actual = JsonSerializer.Deserialize<TagDto>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
TagDto first = new("award-winning");
|
||||
TagDto second = new("award-winning");
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user