Implements tests for commit b2d274f609

This commit is contained in:
BinaryAlley committed 2026-10-27 17:32:37 +02:00
1 parent d185c77999
commit 5c436fc13d
17 files changed
+2261 -6

No files matched your search

@@ -190,4 +190,57 @@ public class AddMediaLibraryRequestMappingTests
// Assert
Assert.Null(result.PathTemplateParts);
}
[Fact]
public void ToCommand_WhenConsumptionSettingsAreSupplied_ShouldMapThem()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 75);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.ShouldTrackConsumptionProgress);
Assert.True(result.ShouldTrackConsumptionProgress.Value);
Assert.Equal(75, result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenConsumptionSettingsAreAbsent_ShouldPreserveThemAsNull()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: null,
completionThresholdPercentage: null);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.Null(result.ShouldTrackConsumptionProgress);
Assert.Null(result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenProgressTrackingIsExplicitlyDisabled_ShouldPreserveTheDisabledFlagWithoutThreshold()
{
// Arrange
AddLibraryRequest request = _addLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: null);
// Act
AddLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.ShouldTrackConsumptionProgress);
Assert.False(result.ShouldTrackConsumptionProgress.Value);
Assert.Null(result.CompletionThresholdPercentage);
}
}
@@ -254,4 +254,145 @@ public class LibraryEntityMappingTests
Assert.True(result.IsFailure);
Assert.Equal(DomainErrors.Library.PathTemplateValuePartMustContainSinglePlaceholder, result.FirstError);
}
[Fact]
public void ToResponse_WhenProgressTrackingIsEnabled_ShouldMapTrackingAndThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 65);
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.True(result.ShouldTrackConsumptionProgress);
Assert.Equal(65, result.CompletionThresholdPercentage);
}
[Fact]
public void ToResponse_WhenProgressTrackingIsDisabled_ShouldMapTrackingOffWithoutThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: null);
// Act
LibraryResponse result = entity.ToResponse();
// Assert
Assert.False(result.ShouldTrackConsumptionProgress);
Assert.Null(result.CompletionThresholdPercentage);
}
[Fact]
public void ToDomainEntity_WhenProgressTrackingIsEnabled_ShouldMapConsumptionSettings()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 65);
// Act
Result<Library> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsFailure);
Assert.True(result.Value.ConsumptionSettings.ShouldTrackConsumptionProgress);
Assert.True(result.Value.ConsumptionSettings.CompletionThresholdPercentage.HasValue);
Assert.Equal(65, result.Value.ConsumptionSettings.CompletionThresholdPercentage.Value);
}
[Fact]
public void ToDomainEntity_WhenProgressTrackingIsEnabledWithoutThreshold_ShouldMapNoThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: null);
// Act
Result<Library> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsFailure);
Assert.True(result.Value.ConsumptionSettings.ShouldTrackConsumptionProgress);
Assert.False(result.Value.ConsumptionSettings.CompletionThresholdPercentage.HasValue);
}
[Fact]
public void ToDomainEntity_WhenProgressTrackingIsDisabledButStoredThresholdExists_ShouldNotRetainThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: 65);
// Act
Result<Library> result = entity.ToDomainEntity();
// Assert
Assert.False(result.IsFailure);
Assert.False(result.Value.ConsumptionSettings.ShouldTrackConsumptionProgress);
Assert.False(result.Value.ConsumptionSettings.CompletionThresholdPercentage.HasValue);
}
[Fact]
public void ToDomainValueObject_WhenProgressTrackingIsEnabled_ShouldMapTrackingAndThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 65);
// Act
LibraryConsumptionSettings result = entity.ToDomainValueObject();
// Assert
Assert.True(result.ShouldTrackConsumptionProgress);
Assert.True(result.CompletionThresholdPercentage.HasValue);
Assert.Equal(65, result.CompletionThresholdPercentage.Value);
}
[Fact]
public void ToDomainValueObject_WhenProgressTrackingIsDisabled_ShouldNotRetainThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: 65);
// Act
LibraryConsumptionSettings result = entity.ToDomainValueObject();
// Assert
Assert.False(result.ShouldTrackConsumptionProgress);
Assert.False(result.CompletionThresholdPercentage.HasValue);
}
[Fact]
public void ToDomainValueObject_WhenProgressTrackingIsEnabledWithoutThreshold_ShouldMapNoThreshold()
{
// Arrange
LibraryEntity entity = _libraryEntityFixture.Create(
libraryType: LibraryType.Book,
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: null);
// Act
LibraryConsumptionSettings result = entity.ToDomainValueObject();
// Assert
Assert.True(result.ShouldTrackConsumptionProgress);
Assert.False(result.CompletionThresholdPercentage.HasValue);
}
}
@@ -25,6 +25,7 @@ public class LibraryMappingTests
private readonly LibraryFixture _libraryFixture = new();
private readonly LibraryPathPartFixture _libraryPathPartFixture = new();
private readonly LibraryPathTemplateFixture _libraryPathTemplateFixture = new();
private readonly LibraryConsumptionSettingsFixture _libraryConsumptionSettingsFixture = new();
[Fact]
public void ToRepositoryEntity_WhenMappingValidLibrary_ShouldMapCorrectly()
@@ -244,4 +245,46 @@ public class LibraryMappingTests
// Assert
Assert.Empty(result.PathTemplateParts);
}
[Fact]
public void ToRepositoryEntity_WhenProgressTrackingIsEnabled_ShouldMapTrackingAndThreshold()
{
// Arrange
LibraryConsumptionSettings consumptionSettings = _libraryConsumptionSettingsFixture.Create(
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 70);
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
consumptionSettings: consumptionSettings);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.True(result.ShouldTrackConsumptionProgress);
Assert.Equal(70, result.CompletionThresholdPercentage);
}
[Fact]
public void ToRepositoryEntity_WhenProgressTrackingIsDisabled_ShouldMapTrackingOffWithoutThreshold()
{
// Arrange
LibraryConsumptionSettings consumptionSettings = _libraryConsumptionSettingsFixture.Create(
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: 70);
Library library = _libraryFixture.Create(
title: "Test Library",
libraryType: LibraryType.Book,
contentLocations: ["C:/Books"],
consumptionSettings: consumptionSettings);
// Act
LibraryEntity result = library.ToRepositoryEntity();
// Assert
Assert.False(result.ShouldTrackConsumptionProgress);
Assert.Null(result.CompletionThresholdPercentage);
}
}
@@ -93,4 +93,57 @@ public class UpdateLibraryRequestMappingTests
// Assert
Assert.Null(result.PathTemplateParts);
}
[Fact]
public void ToCommand_WhenConsumptionSettingsAreSupplied_ShouldMapThem()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: true,
completionThresholdPercentage: 75);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.ShouldTrackConsumptionProgress);
Assert.True(result.ShouldTrackConsumptionProgress.Value);
Assert.Equal(75, result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenConsumptionSettingsAreAbsent_ShouldPreserveThemAsNull()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: null,
completionThresholdPercentage: null);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.Null(result.ShouldTrackConsumptionProgress);
Assert.Null(result.CompletionThresholdPercentage);
}
[Fact]
public void ToCommand_WhenProgressTrackingIsExplicitlyDisabled_ShouldPreserveTheDisabledFlagWithoutThreshold()
{
// Arrange
UpdateLibraryRequest request = _updateLibraryRequestFixture.Create(
libraryType: "Book",
shouldTrackConsumptionProgress: false,
completionThresholdPercentage: null);
// Act
UpdateLibraryCommand result = request.ToCommand();
// Assert
Assert.NotNull(result.ShouldTrackConsumptionProgress);
Assert.False(result.ShouldTrackConsumptionProgress.Value);
Assert.Null(result.CompletionThresholdPercentage);
}
}