mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 09: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
+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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user