mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 07: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
+74
@@ -0,0 +1,74 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Requests.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AddLibraryRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AddLibraryRequestTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingAddLibraryRequest_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
AddLibraryRequest expected = new(
|
||||
"Books",
|
||||
"Book",
|
||||
[@"C:\Media\Books"],
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
AddLibraryRequest? actual = JsonSerializer.Deserialize<AddLibraryRequest>(json, _jsonOptions);
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equivalent(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
AddLibraryRequest sut = new(
|
||||
"Books",
|
||||
"Book",
|
||||
[@"C:\Media\Books"],
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
// Act
|
||||
(string? title, string? libraryType, string[]? contentLocations, string? coverImage, bool isEnabled, bool isLocked, bool downloadMetadataFromWeb, bool shouldSaveMetadataInMediaDirectories, bool shouldSkipUnchangedDirectoriesDuringScan) = sut;
|
||||
|
||||
// Assert
|
||||
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);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Requests.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="CancelLibraryScanRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class CancelLibraryScanRequestTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingCancelLibraryScanRequest_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid scanId = Guid.NewGuid();
|
||||
CancelLibraryScanRequest expected = new(libraryId, scanId);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
CancelLibraryScanRequest? actual = JsonSerializer.Deserialize<CancelLibraryScanRequest>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid scanId = Guid.NewGuid();
|
||||
CancelLibraryScanRequest first = new(libraryId, scanId);
|
||||
CancelLibraryScanRequest second = new(libraryId, scanId);
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Requests.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="DeleteLibraryRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DeleteLibraryRequestTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingDeleteLibraryRequest_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
DeleteLibraryRequest expected = new(id);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
DeleteLibraryRequest? actual = JsonSerializer.Deserialize<DeleteLibraryRequest>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
DeleteLibraryRequest first = new(id);
|
||||
DeleteLibraryRequest second = new(id);
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Requests.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetLibraryRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryRequestTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingGetLibraryRequest_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
GetLibraryRequest expected = new(id);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
GetLibraryRequest? actual = JsonSerializer.Deserialize<GetLibraryRequest>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
GetLibraryRequest first = new(id);
|
||||
GetLibraryRequest second = new(id);
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Requests.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="GetLibraryScanProgressRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class GetLibraryScanProgressRequestTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingGetLibraryScanProgressRequest_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid scanId = Guid.NewGuid();
|
||||
GetLibraryScanProgressRequest expected = new(libraryId, scanId);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
GetLibraryScanProgressRequest? actual = JsonSerializer.Deserialize<GetLibraryScanProgressRequest>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
Guid libraryId = Guid.NewGuid();
|
||||
Guid scanId = Guid.NewGuid();
|
||||
GetLibraryScanProgressRequest first = new(libraryId, scanId);
|
||||
GetLibraryScanProgressRequest second = new(libraryId, scanId);
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Requests.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ScanLibraryRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScanLibraryRequestTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingScanLibraryRequest_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
ScanLibraryRequest expected = new(id);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
ScanLibraryRequest? actual = JsonSerializer.Deserialize<ScanLibraryRequest>(json, _jsonOptions);
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equal(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equality_WhenTwoInstancesHaveSameValues_ShouldBeEqual()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
ScanLibraryRequest first = new(id);
|
||||
ScanLibraryRequest second = new(id);
|
||||
|
||||
// Act
|
||||
bool areEqual = first == second;
|
||||
|
||||
// Assert
|
||||
Assert.True(areEqual);
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text.Json;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Contracts.UnitTests.Requests.MediaLibrary.Management;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="UpdateLibraryRequest"/> record.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UpdateLibraryRequestTests
|
||||
{
|
||||
private readonly JsonSerializerOptions _jsonOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
[Fact]
|
||||
public void RoundTrip_WhenSerializingUpdateLibraryRequest_ShouldPreserveValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
Guid userId = Guid.NewGuid();
|
||||
UpdateLibraryRequest expected = new(
|
||||
id,
|
||||
userId,
|
||||
"Books",
|
||||
"Book",
|
||||
[@"C:\Media\Books"],
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
// Act
|
||||
string json = JsonSerializer.Serialize(expected, _jsonOptions);
|
||||
UpdateLibraryRequest? actual = JsonSerializer.Deserialize<UpdateLibraryRequest>(json, _jsonOptions);
|
||||
// Assert
|
||||
Assert.NotNull(actual);
|
||||
Assert.Equivalent(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deconstruct_WhenCalled_ShouldReturnAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
Guid userId = Guid.NewGuid();
|
||||
UpdateLibraryRequest sut = new(
|
||||
id,
|
||||
userId,
|
||||
"Books",
|
||||
"Book",
|
||||
[@"C:\Media\Books"],
|
||||
null,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
);
|
||||
|
||||
// Act
|
||||
(Guid sutId, Guid sutUserId, string? title, string? libraryType, string[]? contentLocations, string? coverImage, bool isEnabled, bool isLocked, bool downloadMetadataFromWeb, bool shouldSaveMetadataInMediaDirectories, bool shouldSkipUnchangedDirectoriesDuringScan) = sut;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(sut.Id, sutId);
|
||||
Assert.Equal(sut.UserId, sutUserId);
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user