mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 15:11:10 +00:00
Adds the test suites for the library path templates and centralizes their resolution in the domain service
This commit is contained in:
1 parent
ca4f308b0a
commit
7ed6f05632
52 files changed
+4724
-40
No files matched your search
+163
@@ -0,0 +1,163 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Services.PathTemplate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.Services.PathTemplate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicLibraryPathPartCatalog"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicLibraryPathPartCatalogTests
|
||||
{
|
||||
private readonly MusicLibraryPathPartCatalog _sut = new();
|
||||
|
||||
[Fact]
|
||||
public void SupportedLibraryType_WhenCalled_ShouldReturnMusic()
|
||||
{
|
||||
// Act
|
||||
LibraryType result = _sut.SupportedLibraryType;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(LibraryType.Music, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPartDefinitions_WhenCalled_ShouldReturnTheExpectedDefinitions()
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<LibraryPathPartDefinition> result = _sut.GetPartDefinitions();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(10, result.Count);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[0].Kind);
|
||||
Assert.Equal(LibraryPathValueType.None, result[0].ValueType);
|
||||
Assert.Equal(string.Empty, result[0].DefaultRepresentation);
|
||||
Assert.False(result[0].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[1].Kind);
|
||||
Assert.Equal(LibraryPathValueType.None, result[1].ValueType);
|
||||
Assert.Equal(string.Empty, result[1].DefaultRepresentation);
|
||||
Assert.False(result[1].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Artist, result[2].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[2].ValueType);
|
||||
Assert.Equal("{0}", result[2].DefaultRepresentation);
|
||||
Assert.False(result[2].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.ReleaseType, result[3].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Enum, result[3].ValueType);
|
||||
Assert.Equal("{0}", result[3].DefaultRepresentation);
|
||||
Assert.False(result[3].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.ReleaseYear, result[4].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Year, result[4].ValueType);
|
||||
Assert.Equal("{0}", result[4].DefaultRepresentation);
|
||||
Assert.False(result[4].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.ReleaseName, result[5].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[5].ValueType);
|
||||
Assert.Equal("{0}", result[5].DefaultRepresentation);
|
||||
Assert.False(result[5].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.TrackNumber, result[6].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Integer, result[6].ValueType);
|
||||
Assert.Equal("{0:00}", result[6].DefaultRepresentation);
|
||||
Assert.False(result[6].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.TrackName, result[7].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[7].ValueType);
|
||||
Assert.Equal("{0}", result[7].DefaultRepresentation);
|
||||
Assert.False(result[7].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Extension, result[8].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[8].ValueType);
|
||||
Assert.Equal("{0}", result[8].DefaultRepresentation);
|
||||
Assert.False(result[8].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.DiscNumber, result[9].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Integer, result[9].ValueType);
|
||||
Assert.Equal("{0:00}", result[9].DefaultRepresentation);
|
||||
Assert.True(result[9].IsOptionalByDefault);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultTemplate_WhenCalled_ShouldReturnTheExpectedParts()
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<LibraryPathPart> result = _sut.GetDefaultTemplate().Parts;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(16, result.Count);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Artist, result[0].Kind);
|
||||
Assert.Equal("{0}", result[0].Representation);
|
||||
Assert.False(result[0].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[1].Kind);
|
||||
Assert.Equal(string.Empty, result[1].Representation);
|
||||
Assert.False(result[1].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.ReleaseType, result[2].Kind);
|
||||
Assert.Equal("{0}", result[2].Representation);
|
||||
Assert.False(result[2].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[3].Kind);
|
||||
Assert.Equal(string.Empty, result[3].Representation);
|
||||
Assert.False(result[3].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.ReleaseYear, result[4].Kind);
|
||||
Assert.Equal("{0}", result[4].Representation);
|
||||
Assert.False(result[4].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[5].Kind);
|
||||
Assert.Equal(" - ", result[5].Representation);
|
||||
Assert.False(result[5].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.ReleaseName, result[6].Kind);
|
||||
Assert.Equal("{0}", result[6].Representation);
|
||||
Assert.False(result[6].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[7].Kind);
|
||||
Assert.Equal(string.Empty, result[7].Representation);
|
||||
Assert.True(result[7].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[8].Kind);
|
||||
Assert.Equal("Disk ", result[8].Representation);
|
||||
Assert.True(result[8].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.DiscNumber, result[9].Kind);
|
||||
Assert.Equal("{0:00}", result[9].Representation);
|
||||
Assert.True(result[9].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[10].Kind);
|
||||
Assert.Equal(string.Empty, result[10].Representation);
|
||||
Assert.False(result[10].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.TrackNumber, result[11].Kind);
|
||||
Assert.Equal("{0:00}", result[11].Representation);
|
||||
Assert.False(result[11].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[12].Kind);
|
||||
Assert.Equal(" - ", result[12].Representation);
|
||||
Assert.False(result[12].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.TrackName, result[13].Kind);
|
||||
Assert.Equal("{0}", result[13].Representation);
|
||||
Assert.False(result[13].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[14].Kind);
|
||||
Assert.Equal(".", result[14].Representation);
|
||||
Assert.False(result[14].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Extension, result[15].Kind);
|
||||
Assert.Equal("{0}", result[15].Representation);
|
||||
Assert.False(result[15].IsOptional);
|
||||
}
|
||||
}
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.AudioLibrary;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.AudioLibraryBoundedContext.MusicLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MusicLibraryPathMetadata"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MusicLibraryPathMetadataTests
|
||||
{
|
||||
private readonly MusicLibraryPathMetadataFixture _musicLibraryPathMetadataFixture = new();
|
||||
private readonly ParsedLibraryPathFixture _parsedLibraryPathFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void FromParsedLibraryPath_WhenAllValuesAreCaptured_ShouldMapAllFields()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Queen",
|
||||
[LibraryPathPartKind.ReleaseType] = "Album",
|
||||
[LibraryPathPartKind.ReleaseYear] = "1975",
|
||||
[LibraryPathPartKind.ReleaseName] = "A Night at the Opera",
|
||||
[LibraryPathPartKind.TrackNumber] = "11",
|
||||
[LibraryPathPartKind.DiscNumber] = "1",
|
||||
[LibraryPathPartKind.TrackName] = "Bohemian Rhapsody"
|
||||
});
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata result = MusicLibraryPathMetadata.FromParsedLibraryPath(parsedPath);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Queen", result.ArtistName.Value);
|
||||
Assert.Equal(MusicReleaseType.Album, result.ReleaseType.Value);
|
||||
Assert.Equal(1975, result.ReleaseYear.Value);
|
||||
Assert.Equal("A Night at the Opera", result.ReleaseName.Value);
|
||||
Assert.Equal(11, result.TrackNumber.Value);
|
||||
Assert.Equal(1, result.DiscNumber.Value);
|
||||
Assert.Equal("Bohemian Rhapsody", result.TrackTitle.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromParsedLibraryPath_WhenReleaseTypeIsRecognized_ShouldParseItCaseInsensitively()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.ReleaseType] = "album"
|
||||
});
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata result = MusicLibraryPathMetadata.FromParsedLibraryPath(parsedPath);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.ReleaseType.HasValue);
|
||||
Assert.Equal(MusicReleaseType.Album, result.ReleaseType.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromParsedLibraryPath_WhenReleaseTypeIsNotRecognized_ShouldFallBackToOther()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.ReleaseType] = "not a release type"
|
||||
});
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata result = MusicLibraryPathMetadata.FromParsedLibraryPath(parsedPath);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.ReleaseType.HasValue);
|
||||
Assert.Equal(MusicReleaseType.Other, result.ReleaseType.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromParsedLibraryPath_WhenReleaseTypeIsAbsent_ShouldLeaveItUnset()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Queen"
|
||||
});
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata result = MusicLibraryPathMetadata.FromParsedLibraryPath(parsedPath);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.ReleaseType.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FromParsedLibraryPath_WhenValuesAreAbsent_ShouldLeaveThemUnset()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(includeValues: false);
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata result = MusicLibraryPathMetadata.FromParsedLibraryPath(parsedPath);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.ArtistName.HasValue);
|
||||
Assert.False(result.ReleaseType.HasValue);
|
||||
Assert.False(result.ReleaseYear.HasValue);
|
||||
Assert.False(result.ReleaseName.HasValue);
|
||||
Assert.False(result.TrackNumber.HasValue);
|
||||
Assert.False(result.DiscNumber.HasValue);
|
||||
Assert.False(result.TrackTitle.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
MusicLibraryPathMetadata firstMetadata = _musicLibraryPathMetadataFixture.Create();
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata secondMetadata = _musicLibraryPathMetadataFixture.Create(
|
||||
artistName: firstMetadata.ArtistName.Value,
|
||||
releaseType: firstMetadata.ReleaseType.Value,
|
||||
releaseYear: firstMetadata.ReleaseYear.Value,
|
||||
releaseName: firstMetadata.ReleaseName.Value,
|
||||
trackNumber: firstMetadata.TrackNumber.Value,
|
||||
discNumber: firstMetadata.DiscNumber.Value,
|
||||
trackTitle: firstMetadata.TrackTitle.Value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstMetadata, secondMetadata);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentArtistName_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicLibraryPathMetadata firstMetadata = _musicLibraryPathMetadataFixture.Create(artistName: "Queen");
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata secondMetadata = _musicLibraryPathMetadataFixture.Create(artistName: "Pink Floyd");
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstMetadata, secondMetadata);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentReleaseType_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicLibraryPathMetadata firstMetadata = _musicLibraryPathMetadataFixture.Create(releaseType: MusicReleaseType.Album);
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata secondMetadata = _musicLibraryPathMetadataFixture.Create(releaseType: MusicReleaseType.Single);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstMetadata, secondMetadata);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentReleaseYear_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicLibraryPathMetadata firstMetadata = _musicLibraryPathMetadataFixture.Create(releaseYear: 1975);
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata secondMetadata = _musicLibraryPathMetadataFixture.Create(releaseYear: 1980);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstMetadata, secondMetadata);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentReleaseName_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicLibraryPathMetadata firstMetadata = _musicLibraryPathMetadataFixture.Create(releaseName: "A Night at the Opera");
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata secondMetadata = _musicLibraryPathMetadataFixture.Create(releaseName: "The Game");
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstMetadata, secondMetadata);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentTrackNumber_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicLibraryPathMetadata firstMetadata = _musicLibraryPathMetadataFixture.Create(trackNumber: 11);
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata secondMetadata = _musicLibraryPathMetadataFixture.Create(trackNumber: 12);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstMetadata, secondMetadata);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentDiscNumber_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicLibraryPathMetadata firstMetadata = _musicLibraryPathMetadataFixture.Create(discNumber: 1);
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata secondMetadata = _musicLibraryPathMetadataFixture.Create(discNumber: 2);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstMetadata, secondMetadata);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentTrackTitle_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MusicLibraryPathMetadata firstMetadata = _musicLibraryPathMetadataFixture.Create(trackTitle: "Bohemian Rhapsody");
|
||||
|
||||
// Act
|
||||
MusicLibraryPathMetadata secondMetadata = _musicLibraryPathMetadataFixture.Create(trackTitle: "Love of My Life");
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstMetadata, secondMetadata);
|
||||
}
|
||||
}
|
||||
+155
@@ -0,0 +1,155 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryPathPart"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryPathPartTests
|
||||
{
|
||||
private readonly LibraryPathPartFixture _libraryPathPartFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenKindIsSeparator_ShouldCreateSeparatorWithoutRepresentation()
|
||||
{
|
||||
// Act
|
||||
Result<LibraryPathPart> result = LibraryPathPart.Create(LibraryPathPartKind.Separator, "/", isOptional: false);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result.Value.Kind);
|
||||
Assert.Equal(string.Empty, result.Value.Representation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenKindIsLiteralWithText_ShouldCreateLiteralWithThatRepresentation()
|
||||
{
|
||||
// Act
|
||||
Result<LibraryPathPart> result = LibraryPathPart.Create(LibraryPathPartKind.Literal, " - ", isOptional: false);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result.Value.Kind);
|
||||
Assert.Equal(" - ", result.Value.Representation);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // the representation is absent
|
||||
[InlineData("")] // the representation is empty
|
||||
[InlineData(" ")] // the representation is whitespace
|
||||
public void Create_WhenKindIsNotSeparatorAndRepresentationIsEmpty_ShouldReturnLiteralCannotBeEmptyError(string? representation)
|
||||
{
|
||||
// Act
|
||||
Result<LibraryPathPart> result = LibraryPathPart.Create(LibraryPathPartKind.Literal, representation, isOptional: false);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Lumina.Domain.Common.Errors.Errors.Library.PathTemplateLiteralCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenTypedPartContainsSinglePlaceholder_ShouldCreateThePart()
|
||||
{
|
||||
// Act
|
||||
Result<LibraryPathPart> result = LibraryPathPart.Create(LibraryPathPartKind.Artist, "{0}", isOptional: false);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("{0}", result.Value.Representation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenTypedPartContainsFixedWidthPlaceholder_ShouldCreateThePart()
|
||||
{
|
||||
// Act
|
||||
Result<LibraryPathPart> result = LibraryPathPart.Create(LibraryPathPartKind.TrackNumber, "Disc {0:00}", isOptional: true);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Disc {0:00}", result.Value.Representation);
|
||||
Assert.True(result.Value.IsOptional);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("no placeholder")] // the mask carries no value placeholder
|
||||
[InlineData("{0} {0}")] // the mask carries more than one value placeholder
|
||||
public void Create_WhenTypedPartDoesNotContainExactlyOnePlaceholder_ShouldReturnError(string representation)
|
||||
{
|
||||
// Act
|
||||
Result<LibraryPathPart> result = LibraryPathPart.Create(LibraryPathPartKind.Artist, representation, isOptional: false);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Lumina.Domain.Common.Errors.Errors.Library.PathTemplateValuePartMustContainSinglePlaceholder, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenLiteralContainsNoPlaceholder_ShouldCreateThePart()
|
||||
{
|
||||
// Act
|
||||
Result<LibraryPathPart> result = LibraryPathPart.Create(LibraryPathPartKind.Literal, "Disk ", isOptional: false);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Disk ", result.Value.Representation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPart firstPart = _libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}", isOptional: true);
|
||||
|
||||
// Act
|
||||
LibraryPathPart secondPart = _libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}", isOptional: true);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstPart, secondPart);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentKind_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPart firstPart = _libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}", isOptional: false);
|
||||
|
||||
// Act
|
||||
LibraryPathPart secondPart = _libraryPathPartFixture.Create(kind: LibraryPathPartKind.ReleaseName, representation: "{0}", isOptional: false);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstPart, secondPart);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentRepresentation_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPart firstPart = _libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}", isOptional: false);
|
||||
|
||||
// Act
|
||||
LibraryPathPart secondPart = _libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "Artist: {0}", isOptional: false);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstPart, secondPart);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentIsOptional_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPart firstPart = _libraryPathPartFixture.Create(kind: LibraryPathPartKind.DiscNumber, representation: "{0:00}", isOptional: false);
|
||||
|
||||
// Act
|
||||
LibraryPathPart secondPart = _libraryPathPartFixture.Create(kind: LibraryPathPartKind.DiscNumber, representation: "{0:00}", isOptional: true);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstPart, secondPart);
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryPathTemplate"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryPathTemplateTests
|
||||
{
|
||||
private readonly LibraryPathTemplateFixture _libraryPathTemplateFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithParts_ShouldCreateTemplateWithThoseParts()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathTemplate template = _libraryPathTemplateFixture.Create();
|
||||
|
||||
// Act
|
||||
LibraryPathTemplate result = LibraryPathTemplate.Create(template.Parts);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(template.Parts, result.Parts);
|
||||
Assert.False(result.IsEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Empty_WhenCalled_ShouldCreateTemplateWithoutParts()
|
||||
{
|
||||
// Act
|
||||
LibraryPathTemplate result = LibraryPathTemplate.Empty();
|
||||
|
||||
// Assert
|
||||
Assert.Empty(result.Parts);
|
||||
Assert.True(result.IsEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenSourceCollectionIsLaterModified_ShouldNotAffectTheTemplate()
|
||||
{
|
||||
// Arrange
|
||||
List<LibraryPathPart> sourceParts = [.. _libraryPathTemplateFixture.Create().Parts];
|
||||
int originalCount = sourceParts.Count;
|
||||
|
||||
// Act
|
||||
LibraryPathTemplate template = LibraryPathTemplate.Create(sourceParts);
|
||||
sourceParts.Clear();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(originalCount, template.Parts.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathTemplate firstTemplate = _libraryPathTemplateFixture.Create();
|
||||
|
||||
// Act
|
||||
LibraryPathTemplate secondTemplate = LibraryPathTemplate.Create(firstTemplate.Parts);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstTemplate, secondTemplate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentParts_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathTemplate firstTemplate = _libraryPathTemplateFixture.Create();
|
||||
|
||||
// Act
|
||||
LibraryPathTemplate secondTemplate = _libraryPathTemplateFixture.Create();
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstTemplate, secondTemplate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WhenBothTemplatesAreEmpty_ShouldReturnTrue()
|
||||
{
|
||||
// Act
|
||||
LibraryPathTemplate firstTemplate = LibraryPathTemplate.Empty();
|
||||
LibraryPathTemplate secondTemplate = LibraryPathTemplate.Empty();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstTemplate, secondTemplate);
|
||||
}
|
||||
}
|
||||
+497
@@ -0,0 +1,497 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using NSubstitute;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.PathTemplate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryPathTemplateService"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryPathTemplateServiceTests
|
||||
{
|
||||
private readonly ILibraryPathPartCatalog _mockCatalog = Substitute.For<ILibraryPathPartCatalog>();
|
||||
private readonly LibraryPathTemplateService _sut;
|
||||
private readonly LibraryPathPartFixture _libraryPathPartFixture = new();
|
||||
private readonly LibraryPathTemplateFixture _libraryPathTemplateFixture = new();
|
||||
private readonly LibraryPathPartDefinitionFixture _libraryPathPartDefinitionFixture = new();
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LibraryPathTemplateServiceTests"/> class.
|
||||
/// </summary>
|
||||
public LibraryPathTemplateServiceTests()
|
||||
{
|
||||
_mockCatalog.SupportedLibraryType.Returns(LibraryType.Music);
|
||||
_sut = new LibraryPathTemplateService([_mockCatalog]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultTemplate_WhenCatalogExists_ShouldReturnTheCatalogDefaultTemplate()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathTemplate defaultTemplate = _libraryPathTemplateFixture.Create();
|
||||
_mockCatalog.GetDefaultTemplate().Returns(defaultTemplate);
|
||||
|
||||
// Act
|
||||
LibraryPathTemplate result = _sut.GetDefaultTemplate(LibraryType.Music);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(defaultTemplate, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultTemplate_WhenNoCatalogExistsForTheLibraryType_ShouldReturnAnEmptyTemplate()
|
||||
{
|
||||
// Act
|
||||
LibraryPathTemplate result = _sut.GetDefaultTemplate(LibraryType.Book);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveTemplate_WhenProvidedPartsAreEmpty_ShouldReturnTheCatalogDefaultTemplate()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog();
|
||||
LibraryPathTemplate defaultTemplate = CreateMusicTemplate();
|
||||
_mockCatalog.GetDefaultTemplate().Returns(defaultTemplate);
|
||||
|
||||
// Act
|
||||
Result<LibraryPathTemplate> result = _sut.ResolveTemplate(LibraryType.Music, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(defaultTemplate, result.Value);
|
||||
_mockCatalog.Received(1).GetDefaultTemplate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveTemplate_WhenProvidedPartsAreEmptyAndNoCatalogExists_ShouldReturnAnEmptyTemplate()
|
||||
{
|
||||
// Act
|
||||
Result<LibraryPathTemplate> result = _sut.ResolveTemplate(LibraryType.Book, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.True(result.Value.IsEmpty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveTemplate_WhenProvidedPartsAreNotEmpty_ShouldReturnATemplateWithThoseParts()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog();
|
||||
LibraryPathPart providedPart = _libraryPathPartFixture.Create(
|
||||
kind: LibraryPathPartKind.Artist,
|
||||
representation: "{0}",
|
||||
isOptional: false);
|
||||
|
||||
// Act
|
||||
Result<LibraryPathTemplate> result = _sut.ResolveTemplate(LibraryType.Music, [providedPart]);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
LibraryPathPart pathPart = Assert.Single(result.Value.Parts);
|
||||
Assert.Equal(LibraryPathPartKind.Artist, pathPart.Kind);
|
||||
Assert.Equal("{0}", pathPart.Representation);
|
||||
Assert.False(pathPart.IsOptional);
|
||||
_mockCatalog.DidNotReceive().GetDefaultTemplate();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveTemplate_WhenProvidedPartsAreNotSupportedByTheCatalog_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog(
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Artist, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Separator, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty)
|
||||
]);
|
||||
LibraryPathPart releaseNamePart = _libraryPathPartFixture.Create(
|
||||
kind: LibraryPathPartKind.ReleaseName,
|
||||
representation: "{0}",
|
||||
isOptional: false);
|
||||
|
||||
// Act
|
||||
Result<LibraryPathTemplate> result = _sut.ResolveTemplate(LibraryType.Music, [releaseNamePart]);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Library.PathTemplatePartKindNotSupportedForLibraryType, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResolveTemplate_WhenNoCatalogExistsForTheLibraryTypeAndPartsAreProvided_ShouldReturnNotSupportedError()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPart artistPart = _libraryPathPartFixture.Create(
|
||||
kind: LibraryPathPartKind.Artist,
|
||||
representation: "{0}",
|
||||
isOptional: false);
|
||||
|
||||
// Act
|
||||
Result<LibraryPathTemplate> result = _sut.ResolveTemplate(LibraryType.Book, [artistPart]);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Library.PathTemplateIsNotSupportedForLibraryType, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenTemplateIsEmpty_ShouldReturnSuccess()
|
||||
{
|
||||
// Act
|
||||
Result<Success> result = _sut.Validate(LibraryType.Music, LibraryPathTemplate.Empty());
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenTemplateIsEmptyAndNoCatalogExists_ShouldReturnSuccess()
|
||||
{
|
||||
// Act
|
||||
Result<Success> result = _sut.Validate(LibraryType.Book, LibraryPathTemplate.Empty());
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenNoCatalogExistsForTheLibraryType_ShouldReturnNotSupportedError()
|
||||
{
|
||||
// Act
|
||||
Result<Success> result = _sut.Validate(LibraryType.Book, CreateMusicTemplate());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Library.PathTemplateIsNotSupportedForLibraryType, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenPartKindIsNotSupportedByTheCatalog_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog(definitions:
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Artist, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Separator, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.TrackName, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}")
|
||||
]);
|
||||
LibraryPathTemplate template = _libraryPathTemplateFixture.Create(
|
||||
[
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Separator, representation: string.Empty),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.ReleaseName, representation: "{0}")
|
||||
]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = _sut.Validate(LibraryType.Music, template);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Library.PathTemplatePartKindNotSupportedForLibraryType, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_WhenAllPartKindsAreSupportedByTheCatalog_ShouldReturnSuccess()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog();
|
||||
LibraryPathTemplate template = CreateMusicTemplate();
|
||||
|
||||
// Act
|
||||
Result<Success> result = _sut.Validate(LibraryType.Music, template);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")] // the relative path is empty
|
||||
[InlineData(" ")] // the relative path is whitespace
|
||||
public void Parse_WhenRelativePathIsEmpty_ShouldReturnNull(string relativePath)
|
||||
{
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, CreateMusicTemplate(), relativePath, '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenTemplateIsEmpty_ShouldReturnNull()
|
||||
{
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, LibraryPathTemplate.Empty(), "Pink Floyd/1973 - Time.mp3", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenTemplateIsNotSupportedForTheLibraryType_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Book, CreateMusicTemplate(), "Pink Floyd/1973 - Time.mp3", '/');
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.Library.PathTemplateIsNotSupportedForLibraryType, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenPathMatchesTheTemplate_ShouldReturnTheCapturedValues()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog();
|
||||
LibraryPathTemplate template = CreateMusicTemplate();
|
||||
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, template, "Pink Floyd/1973 - Time.mp3", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
ParsedLibraryPath parsedPath = result.Value!;
|
||||
Assert.Equal("Pink Floyd", parsedPath.GetString(LibraryPathPartKind.Artist).Value);
|
||||
Assert.Equal(1973, parsedPath.GetInt(LibraryPathPartKind.ReleaseYear).Value);
|
||||
Assert.Equal("Time", parsedPath.GetString(LibraryPathPartKind.TrackName).Value);
|
||||
Assert.Equal("mp3", parsedPath.GetString(LibraryPathPartKind.Extension).Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenPathDoesNotMatchTheTemplate_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog();
|
||||
LibraryPathTemplate template = CreateMusicTemplate();
|
||||
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, template, "Pink Floyd/no year/Time.mp3", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenIntegerPartHasAFixedWidth_ShouldCaptureIt()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog(
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Artist, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Separator, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.TrackNumber, valueType: LibraryPathValueType.Integer, defaultRepresentation: "{0:00}")
|
||||
]);
|
||||
LibraryPathTemplate template = _libraryPathTemplateFixture.Create(
|
||||
[
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Separator, representation: string.Empty),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.TrackNumber, representation: "{0:00}")
|
||||
]);
|
||||
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, template, "Pink Floyd/07", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(7, result.Value!.GetInt(LibraryPathPartKind.TrackNumber).Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenIntegerPartDoesNotMatchTheFixedWidth_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog(
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Artist, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Separator, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.TrackNumber, valueType: LibraryPathValueType.Integer, defaultRepresentation: "{0:00}")
|
||||
]);
|
||||
LibraryPathTemplate template = _libraryPathTemplateFixture.Create(
|
||||
[
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Separator, representation: string.Empty),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.TrackNumber, representation: "{0:00}")
|
||||
]);
|
||||
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, template, "Pink Floyd/007", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenYearPartHasAFourDigitValue_ShouldCaptureIt()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog(
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.ReleaseYear, valueType: LibraryPathValueType.Year, defaultRepresentation: "{0}")
|
||||
]);
|
||||
LibraryPathTemplate template = _libraryPathTemplateFixture.Create(
|
||||
[
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.ReleaseYear, representation: "{0}")
|
||||
]);
|
||||
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, template, "1973", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(1973, result.Value!.GetInt(LibraryPathPartKind.ReleaseYear).Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenYearPartDoesNotHaveAFourDigitValue_ShouldReturnNull()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog(
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.ReleaseYear, valueType: LibraryPathValueType.Year, defaultRepresentation: "{0}")
|
||||
]);
|
||||
LibraryPathTemplate template = _libraryPathTemplateFixture.Create(
|
||||
[
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.ReleaseYear, representation: "{0}")
|
||||
]);
|
||||
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, template, "73", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Null(result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenAnOptionalRunIsAbsent_ShouldStillMatchThePath()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog(
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Artist, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Separator, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.DiscNumber, valueType: LibraryPathValueType.Integer, defaultRepresentation: "{0:00}")
|
||||
]);
|
||||
LibraryPathTemplate template = _libraryPathTemplateFixture.Create(
|
||||
[
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Separator, representation: string.Empty),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.DiscNumber, representation: "{0:00}", isOptional: true)
|
||||
]);
|
||||
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, template, "Pink Floyd/", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Pink Floyd", result.Value!.GetString(LibraryPathPartKind.Artist).Value);
|
||||
Assert.False(result.Value.GetInt(LibraryPathPartKind.DiscNumber).HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenAnOptionalRunIsPresent_ShouldCaptureIt()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog(
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Artist, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Separator, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.DiscNumber, valueType: LibraryPathValueType.Integer, defaultRepresentation: "{0:00}")
|
||||
]);
|
||||
LibraryPathTemplate template = _libraryPathTemplateFixture.Create(
|
||||
[
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Separator, representation: string.Empty),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.DiscNumber, representation: "{0:00}", isOptional: true)
|
||||
]);
|
||||
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, template, "Pink Floyd/02", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Pink Floyd", result.Value!.GetString(LibraryPathPartKind.Artist).Value);
|
||||
Assert.Equal(2, result.Value.GetInt(LibraryPathPartKind.DiscNumber).Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_WhenTheSameKindAppearsMoreThanOnce_ShouldKeepTheFirstCapture()
|
||||
{
|
||||
// Arrange
|
||||
SetupCatalog(
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Author, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Separator, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Title, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Literal, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty)
|
||||
]);
|
||||
LibraryPathTemplate template = _libraryPathTemplateFixture.Create(
|
||||
[
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Author, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Separator, representation: string.Empty),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Title, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Literal, representation: " - "),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Author, representation: "{0}")
|
||||
]);
|
||||
|
||||
// Act
|
||||
Result<ParsedLibraryPath?> result = _sut.Parse(LibraryType.Music, template, "Tolkien/The Lord of the Rings - J.R.R. Tolkien", '/');
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Tolkien", result.Value!.GetString(LibraryPathPartKind.Author).Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up the mock catalog to return a music-like set of part definitions and a default template.
|
||||
/// </summary>
|
||||
/// <param name="definitions">Optional. The part definitions the catalog returns. When omitted, a standard music set is used.</param>
|
||||
private void SetupCatalog(IReadOnlyList<LibraryPathPartDefinition>? definitions = null)
|
||||
{
|
||||
_mockCatalog.GetPartDefinitions().Returns(definitions ??
|
||||
[
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Literal, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Artist, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Separator, valueType: LibraryPathValueType.None, defaultRepresentation: string.Empty),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.ReleaseYear, valueType: LibraryPathValueType.Year, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.TrackNumber, valueType: LibraryPathValueType.Integer, defaultRepresentation: "{0:00}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.TrackName, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}"),
|
||||
_libraryPathPartDefinitionFixture.Create(kind: LibraryPathPartKind.Extension, valueType: LibraryPathValueType.Text, defaultRepresentation: "{0}")
|
||||
]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a music-like path template whose parts are all supported by the standard music set of definitions.
|
||||
/// </summary>
|
||||
/// <returns>The created path template.</returns>
|
||||
private LibraryPathTemplate CreateMusicTemplate()
|
||||
{
|
||||
return _libraryPathTemplateFixture.Create(
|
||||
[
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Artist, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Separator, representation: string.Empty),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.ReleaseYear, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Literal, representation: " - "),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.TrackName, representation: "{0}"),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Literal, representation: "."),
|
||||
_libraryPathPartFixture.Create(kind: LibraryPathPartKind.Extension, representation: "{0}")
|
||||
]);
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryPathPartDefinition"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryPathPartDefinitionTests
|
||||
{
|
||||
private readonly LibraryPathPartDefinitionFixture _libraryPathPartDefinitionFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Act
|
||||
LibraryPathPartDefinition definition = new(LibraryPathPartKind.TrackNumber, LibraryPathValueType.Integer, "{0:00}", isOptionalByDefault: true);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(LibraryPathPartKind.TrackNumber, definition.Kind);
|
||||
Assert.Equal(LibraryPathValueType.Integer, definition.ValueType);
|
||||
Assert.Equal("{0:00}", definition.DefaultRepresentation);
|
||||
Assert.True(definition.IsOptionalByDefault);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPartDefinition firstDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.Artist,
|
||||
valueType: LibraryPathValueType.Text,
|
||||
defaultRepresentation: "{0}",
|
||||
isOptionalByDefault: false);
|
||||
|
||||
// Act
|
||||
LibraryPathPartDefinition secondDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.Artist,
|
||||
valueType: LibraryPathValueType.Text,
|
||||
defaultRepresentation: "{0}",
|
||||
isOptionalByDefault: false);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstDefinition, secondDefinition);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentKind_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPartDefinition firstDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.Artist,
|
||||
valueType: LibraryPathValueType.Text,
|
||||
defaultRepresentation: "{0}");
|
||||
|
||||
// Act
|
||||
LibraryPathPartDefinition secondDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.ReleaseName,
|
||||
valueType: LibraryPathValueType.Text,
|
||||
defaultRepresentation: "{0}");
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstDefinition, secondDefinition);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValueType_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPartDefinition firstDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.TrackNumber,
|
||||
valueType: LibraryPathValueType.Integer,
|
||||
defaultRepresentation: "{0}");
|
||||
|
||||
// Act
|
||||
LibraryPathPartDefinition secondDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.TrackNumber,
|
||||
valueType: LibraryPathValueType.Text,
|
||||
defaultRepresentation: "{0}");
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstDefinition, secondDefinition);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentDefaultRepresentation_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPartDefinition firstDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.ReleaseYear,
|
||||
valueType: LibraryPathValueType.Year,
|
||||
defaultRepresentation: "{0}");
|
||||
|
||||
// Act
|
||||
LibraryPathPartDefinition secondDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.ReleaseYear,
|
||||
valueType: LibraryPathValueType.Year,
|
||||
defaultRepresentation: "Year {0}");
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstDefinition, secondDefinition);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentIsOptionalByDefault_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
LibraryPathPartDefinition firstDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.DiscNumber,
|
||||
valueType: LibraryPathValueType.Integer,
|
||||
defaultRepresentation: "{0:00}",
|
||||
isOptionalByDefault: false);
|
||||
|
||||
// Act
|
||||
LibraryPathPartDefinition secondDefinition = _libraryPathPartDefinitionFixture.Create(
|
||||
kind: LibraryPathPartKind.DiscNumber,
|
||||
valueType: LibraryPathValueType.Integer,
|
||||
defaultRepresentation: "{0:00}",
|
||||
isOptionalByDefault: true);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstDefinition, secondDefinition);
|
||||
}
|
||||
}
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ParsedLibraryPath"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ParsedLibraryPathTests
|
||||
{
|
||||
private readonly ParsedLibraryPathFixture _parsedLibraryPathFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValues_ShouldExposeThoseValues()
|
||||
{
|
||||
// Arrange
|
||||
Dictionary<LibraryPathPartKind, string> values = new()
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Pink Floyd",
|
||||
[LibraryPathPartKind.TrackName] = "Time"
|
||||
};
|
||||
|
||||
// Act
|
||||
ParsedLibraryPath result = ParsedLibraryPath.Create(values);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(2, result.Values.Count);
|
||||
Assert.Equal("Pink Floyd", result.Values[LibraryPathPartKind.Artist]);
|
||||
Assert.Equal("Time", result.Values[LibraryPathPartKind.TrackName]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetString_WhenKindIsCaptured_ShouldReturnTheTrimmedValue()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = " Pink Floyd "
|
||||
});
|
||||
|
||||
// Act
|
||||
Optional<string> result = parsedPath.GetString(LibraryPathPartKind.Artist);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.HasValue);
|
||||
Assert.Equal("Pink Floyd", result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetString_WhenKindIsNotCaptured_ShouldReturnNoValue()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Pink Floyd"
|
||||
});
|
||||
|
||||
// Act
|
||||
Optional<string> result = parsedPath.GetString(LibraryPathPartKind.TrackName);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetString_WhenCapturedValueIsWhitespace_ShouldReturnNoValue()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = " "
|
||||
});
|
||||
|
||||
// Act
|
||||
Optional<string> result = parsedPath.GetString(LibraryPathPartKind.Artist);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInt_WhenKindIsCapturedWithAnInteger_ShouldReturnTheValue()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.ReleaseYear] = "1973"
|
||||
});
|
||||
|
||||
// Act
|
||||
Optional<int> result = parsedPath.GetInt(LibraryPathPartKind.ReleaseYear);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.HasValue);
|
||||
Assert.Equal(1973, result.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInt_WhenKindIsNotCaptured_ShouldReturnNoValue()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Pink Floyd"
|
||||
});
|
||||
|
||||
// Act
|
||||
Optional<int> result = parsedPath.GetInt(LibraryPathPartKind.ReleaseYear);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetInt_WhenCapturedValueIsNotAnInteger_ShouldReturnNoValue()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.ReleaseYear] = "not a year"
|
||||
});
|
||||
|
||||
// Act
|
||||
Optional<int> result = parsedPath.GetInt(LibraryPathPartKind.ReleaseYear);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDictionary_WhenCalled_ShouldReturnAllCapturedValues()
|
||||
{
|
||||
// Arrange
|
||||
Dictionary<LibraryPathPartKind, string> values = new()
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Pink Floyd",
|
||||
[LibraryPathPartKind.TrackName] = "Time"
|
||||
};
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(values);
|
||||
|
||||
// Act
|
||||
IReadOnlyDictionary<LibraryPathPartKind, string> result = parsedPath.ToDictionary();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(values, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToDictionary_WhenCalled_ShouldReturnACopy()
|
||||
{
|
||||
// Arrange
|
||||
Dictionary<LibraryPathPartKind, string> values = new()
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Pink Floyd"
|
||||
};
|
||||
ParsedLibraryPath parsedPath = _parsedLibraryPathFixture.Create(values);
|
||||
|
||||
// Act
|
||||
IReadOnlyDictionary<LibraryPathPartKind, string> result = parsedPath.ToDictionary();
|
||||
|
||||
// Assert
|
||||
Assert.NotSame(values, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValuesInDifferentOrder_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath firstPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Pink Floyd",
|
||||
[LibraryPathPartKind.TrackName] = "Time"
|
||||
});
|
||||
|
||||
// Act
|
||||
ParsedLibraryPath secondPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.TrackName] = "Time",
|
||||
[LibraryPathPartKind.Artist] = "Pink Floyd"
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstPath, secondPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValues_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath firstPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Pink Floyd"
|
||||
});
|
||||
|
||||
// Act
|
||||
ParsedLibraryPath secondPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Queen"
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstPath, secondPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentKeys_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
ParsedLibraryPath firstPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Artist] = "Pink Floyd"
|
||||
});
|
||||
|
||||
// Act
|
||||
ParsedLibraryPath secondPath = _parsedLibraryPathFixture.Create(new Dictionary<LibraryPathPartKind, string>
|
||||
{
|
||||
[LibraryPathPartKind.Title] = "Pink Floyd"
|
||||
});
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstPath, secondPath);
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.PathTemplate;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.PathTemplate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookLibraryPathPartCatalog"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookLibraryPathPartCatalogTests
|
||||
{
|
||||
private readonly BookLibraryPathPartCatalog _sut = new();
|
||||
|
||||
[Fact]
|
||||
public void SupportedLibraryType_WhenCalled_ShouldReturnBook()
|
||||
{
|
||||
// Act
|
||||
LibraryType result = _sut.SupportedLibraryType;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(LibraryType.Book, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetPartDefinitions_WhenCalled_ShouldReturnTheExpectedDefinitions()
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<LibraryPathPartDefinition> result = _sut.GetPartDefinitions();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(8, result.Count);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[0].Kind);
|
||||
Assert.Equal(LibraryPathValueType.None, result[0].ValueType);
|
||||
Assert.Equal(string.Empty, result[0].DefaultRepresentation);
|
||||
Assert.False(result[0].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[1].Kind);
|
||||
Assert.Equal(LibraryPathValueType.None, result[1].ValueType);
|
||||
Assert.Equal(string.Empty, result[1].DefaultRepresentation);
|
||||
Assert.False(result[1].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Author, result[2].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[2].ValueType);
|
||||
Assert.Equal("{0}", result[2].DefaultRepresentation);
|
||||
Assert.False(result[2].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Title, result[3].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[3].ValueType);
|
||||
Assert.Equal("{0}", result[3].DefaultRepresentation);
|
||||
Assert.False(result[3].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Series, result[4].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[4].ValueType);
|
||||
Assert.Equal("{0}", result[4].DefaultRepresentation);
|
||||
Assert.True(result[4].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.SeriesNumber, result[5].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Integer, result[5].ValueType);
|
||||
Assert.Equal("{0}", result[5].DefaultRepresentation);
|
||||
Assert.True(result[5].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.BookId, result[6].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Integer, result[6].ValueType);
|
||||
Assert.Equal("{0}", result[6].DefaultRepresentation);
|
||||
Assert.False(result[6].IsOptionalByDefault);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Extension, result[7].Kind);
|
||||
Assert.Equal(LibraryPathValueType.Text, result[7].ValueType);
|
||||
Assert.Equal("{0}", result[7].DefaultRepresentation);
|
||||
Assert.False(result[7].IsOptionalByDefault);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetDefaultTemplate_WhenCalled_ShouldReturnTheExpectedParts()
|
||||
{
|
||||
// Act
|
||||
IReadOnlyList<LibraryPathPart> result = _sut.GetDefaultTemplate().Parts;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(12, result.Count);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Author, result[0].Kind);
|
||||
Assert.Equal("{0}", result[0].Representation);
|
||||
Assert.False(result[0].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[1].Kind);
|
||||
Assert.Equal(string.Empty, result[1].Representation);
|
||||
Assert.False(result[1].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Title, result[2].Kind);
|
||||
Assert.Equal("{0}", result[2].Representation);
|
||||
Assert.False(result[2].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[3].Kind);
|
||||
Assert.Equal(" (", result[3].Representation);
|
||||
Assert.False(result[3].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.BookId, result[4].Kind);
|
||||
Assert.Equal("{0}", result[4].Representation);
|
||||
Assert.False(result[4].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[5].Kind);
|
||||
Assert.Equal(")", result[5].Representation);
|
||||
Assert.False(result[5].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Separator, result[6].Kind);
|
||||
Assert.Equal(string.Empty, result[6].Representation);
|
||||
Assert.False(result[6].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Title, result[7].Kind);
|
||||
Assert.Equal("{0}", result[7].Representation);
|
||||
Assert.False(result[7].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[8].Kind);
|
||||
Assert.Equal(" - ", result[8].Representation);
|
||||
Assert.False(result[8].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Author, result[9].Kind);
|
||||
Assert.Equal("{0}", result[9].Representation);
|
||||
Assert.False(result[9].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Literal, result[10].Kind);
|
||||
Assert.Equal(".", result[10].Representation);
|
||||
Assert.False(result[10].IsOptional);
|
||||
|
||||
Assert.Equal(LibraryPathPartKind.Extension, result[11].Kind);
|
||||
Assert.Equal("{0}", result[11].Representation);
|
||||
Assert.False(result[11].IsOptional);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user