mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 13: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
+169
@@ -0,0 +1,169 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.AudioLibraryBoundedContext.AudioLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.AudioLibraryBoundedContext.AudioLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.AudioLibraryBoundedContext.AudioLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="AudioMetadata"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class AudioMetadataTests
|
||||
{
|
||||
private readonly GenreFixture _genreFixture = new();
|
||||
private readonly TagFixture _tagFixture = new();
|
||||
private readonly ReleaseInfoFixture _releaseInfoFixture = new();
|
||||
private readonly AudioMetadataFixture _audioMetadataFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidValues_ShouldCreateMetadataWithAllPropertiesSet()
|
||||
{
|
||||
// Act
|
||||
Result<AudioMetadata> result = AudioMetadata.Create(
|
||||
"Abbey Road",
|
||||
Optional<string>.None(),
|
||||
durationInSeconds: 2826,
|
||||
sampleRate: 44100,
|
||||
channels: 2,
|
||||
_releaseInfoFixture.Create(),
|
||||
Optional<string>.Some("The last recorded album by the Beatles."),
|
||||
[_genreFixture.Create(name: "Rock")],
|
||||
[_tagFixture.Create(name: "classic")],
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<int>.Some(16),
|
||||
Optional<string>.Some("PCM"),
|
||||
Optional<int>.Some(1411));
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Abbey Road", result.Value.Title);
|
||||
Assert.Equal(2826, result.Value.DurationInSeconds);
|
||||
Assert.Equal(44100, result.Value.SampleRate);
|
||||
Assert.Equal(2, result.Value.Channels);
|
||||
Assert.Equal("The last recorded album by the Beatles.", result.Value.Description.Value);
|
||||
Assert.Equal(16, result.Value.BitDepth.Value);
|
||||
Assert.Equal("PCM", result.Value.AudioCodec.Value);
|
||||
Assert.Equal(1411, result.Value.Bitrate.Value);
|
||||
Assert.Single(result.Value.Genres);
|
||||
Assert.Single(result.Value.Tags);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithOptionalValuesAbsent_ShouldCreateMetadataWithoutThem()
|
||||
{
|
||||
// Act
|
||||
Result<AudioMetadata> result = AudioMetadata.Create(
|
||||
"Abbey Road",
|
||||
Optional<string>.None(),
|
||||
durationInSeconds: 2826,
|
||||
sampleRate: 44100,
|
||||
channels: 2,
|
||||
_releaseInfoFixture.Create(),
|
||||
Optional<string>.None(),
|
||||
[],
|
||||
[],
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<int>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.BitDepth.HasValue);
|
||||
Assert.False(result.Value.AudioCodec.HasValue);
|
||||
Assert.False(result.Value.Bitrate.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfo releaseInfo = _releaseInfoFixture.Create();
|
||||
|
||||
// Act
|
||||
AudioMetadata firstResult = _audioMetadataFixture.Create(
|
||||
title: "Abbey Road",
|
||||
originalTitle: Optional<string>.None(),
|
||||
durationInSeconds: 2826,
|
||||
sampleRate: 44100,
|
||||
channels: 2,
|
||||
releaseInfo: releaseInfo,
|
||||
description: Optional<string>.None(),
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
bitDepth: Optional<int>.None(),
|
||||
audioCodec: Optional<string>.None(),
|
||||
bitrate: Optional<int>.None());
|
||||
AudioMetadata secondResult = _audioMetadataFixture.Create(
|
||||
title: "Abbey Road",
|
||||
originalTitle: Optional<string>.None(),
|
||||
durationInSeconds: 2826,
|
||||
sampleRate: 44100,
|
||||
channels: 2,
|
||||
releaseInfo: releaseInfo,
|
||||
description: Optional<string>.None(),
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
bitDepth: Optional<int>.None(),
|
||||
audioCodec: Optional<string>.None(),
|
||||
bitrate: Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstResult, secondResult);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentSampleRate_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfo releaseInfo = _releaseInfoFixture.Create();
|
||||
|
||||
// Act
|
||||
AudioMetadata firstResult = _audioMetadataFixture.Create(
|
||||
title: "Abbey Road",
|
||||
originalTitle: Optional<string>.None(),
|
||||
durationInSeconds: 2826,
|
||||
sampleRate: 44100,
|
||||
channels: 2,
|
||||
releaseInfo: releaseInfo,
|
||||
description: Optional<string>.None(),
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
bitDepth: Optional<int>.None(),
|
||||
audioCodec: Optional<string>.None(),
|
||||
bitrate: Optional<int>.None());
|
||||
AudioMetadata secondResult = _audioMetadataFixture.Create(
|
||||
title: "Abbey Road",
|
||||
originalTitle: Optional<string>.None(),
|
||||
durationInSeconds: 2826,
|
||||
sampleRate: 48000,
|
||||
channels: 2,
|
||||
releaseInfo: releaseInfo,
|
||||
description: Optional<string>.None(),
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
bitDepth: Optional<int>.None(),
|
||||
audioCodec: Optional<string>.None(),
|
||||
bitrate: Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstResult, secondResult);
|
||||
}
|
||||
}
|
||||
+24
-15
@@ -4,7 +4,8 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -18,6 +19,10 @@ namespace Lumina.Domain.UnitTests.Core.BoundedContexts.FileSystemManagementBound
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class DirectoryTests
|
||||
{
|
||||
private readonly FileSystemPathIdFixture _fileSystemPathIdFixture = new();
|
||||
private readonly DirectoryFixture _directoryFixture = new();
|
||||
private readonly FileFixture _fileFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidParameters_ShouldReturnSuccessfulResult()
|
||||
{
|
||||
@@ -60,9 +65,7 @@ public class DirectoryTests
|
||||
public void Create_WhenCalledWithFileSystemPathId_ShouldReturnSuccessfulResult()
|
||||
{
|
||||
// Arrange
|
||||
Result<FileSystemPathId> pathIdResult = FileSystemPathId.Create("/valid/path");
|
||||
Assert.False(pathIdResult.IsFailure);
|
||||
FileSystemPathId pathId = pathIdResult.Value;
|
||||
FileSystemPathId pathId = _fileSystemPathIdFixture.Create(path: "/valid/path");
|
||||
string name = "TestDirectory";
|
||||
Optional<DateTime> dateCreated = DateTime.Now;
|
||||
Optional<DateTime> dateModified = DateTime.Now;
|
||||
@@ -84,9 +87,11 @@ public class DirectoryTests
|
||||
public void UpdateLastModified_WhenCalled_ShouldUpdateDateModified()
|
||||
{
|
||||
// Arrange
|
||||
Result<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
|
||||
Assert.False(directoryResult.IsFailure);
|
||||
Directory directory = directoryResult.Value;
|
||||
Directory directory = _directoryFixture.Create(
|
||||
path: "/valid/path",
|
||||
name: "TestDirectory",
|
||||
dateCreated: Optional<DateTime>.None(),
|
||||
dateModified: Optional<DateTime>.None());
|
||||
DateTime newDate = DateTime.Now;
|
||||
|
||||
// Act
|
||||
@@ -101,10 +106,12 @@ public class DirectoryTests
|
||||
public void AddItem_WhenCalled_ShouldAddItemToCollection()
|
||||
{
|
||||
// Arrange
|
||||
Result<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
|
||||
Assert.False(directoryResult.IsFailure);
|
||||
Directory directory = directoryResult.Value;
|
||||
FileSystemItem item = new FileSystemItemFixture(FileSystemPathId.Create("/mock/path").Value, "MockItem", FileSystemItemType.File);
|
||||
Directory directory = _directoryFixture.Create(
|
||||
path: "/valid/path",
|
||||
name: "TestDirectory",
|
||||
dateCreated: Optional<DateTime>.None(),
|
||||
dateModified: Optional<DateTime>.None());
|
||||
File item = _fileFixture.Create(path: "/mock/path", name: "MockItem");
|
||||
|
||||
// Act
|
||||
Result<Updated> result = directory.AddItem(item);
|
||||
@@ -118,10 +125,12 @@ public class DirectoryTests
|
||||
public void RemoveItem_WhenCalledWithExistingItem_ShouldRemoveItemFromCollection()
|
||||
{
|
||||
// Arrange
|
||||
Result<Directory> directoryResult = Directory.Create("/valid/path", "TestDirectory", Optional<DateTime>.None(), Optional<DateTime>.None());
|
||||
Assert.False(directoryResult.IsFailure);
|
||||
Directory directory = directoryResult.Value;
|
||||
FileSystemItem item = new FileSystemItemFixture(FileSystemPathId.Create("/mock/path").Value, "MockItem", FileSystemItemType.File);
|
||||
Directory directory = _directoryFixture.Create(
|
||||
path: "/valid/path",
|
||||
name: "TestDirectory",
|
||||
dateCreated: Optional<DateTime>.None(),
|
||||
dateModified: Optional<DateTime>.None());
|
||||
File item = _fileFixture.Create(path: "/mock/path", name: "MockItem");
|
||||
directory.AddItem(item);
|
||||
|
||||
// Act
|
||||
|
||||
+30
-15
@@ -3,6 +3,8 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -16,6 +18,9 @@ namespace Lumina.Domain.UnitTests.Core.BoundedContexts.FileSystemManagementBound
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class FileTests
|
||||
{
|
||||
private readonly FileSystemPathIdFixture _fileSystemPathIdFixture = new();
|
||||
private readonly FileFixture _fileFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidParameters_ShouldReturnSuccessfulResult()
|
||||
{
|
||||
@@ -61,9 +66,7 @@ public class FileTests
|
||||
public void Create_WhenCalledWithFileSystemPathId_ShouldReturnSuccessfulResult()
|
||||
{
|
||||
// Arrange
|
||||
Result<FileSystemPathId> pathIdResult = FileSystemPathId.Create("/valid/path/file.txt");
|
||||
Assert.False(pathIdResult.IsFailure);
|
||||
FileSystemPathId pathId = pathIdResult.Value;
|
||||
FileSystemPathId pathId = _fileSystemPathIdFixture.Create(path: "/valid/path/file.txt");
|
||||
string name = "file.txt";
|
||||
Optional<DateTime> dateCreated = DateTime.Now;
|
||||
Optional<DateTime> dateModified = DateTime.Now;
|
||||
@@ -87,9 +90,12 @@ public class FileTests
|
||||
public void UpdateLastModified_WhenCalled_ShouldUpdateDateModified()
|
||||
{
|
||||
// Arrange
|
||||
Result<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
|
||||
Assert.False(fileResult.IsFailure);
|
||||
File file = fileResult.Value;
|
||||
File file = _fileFixture.Create(
|
||||
path: "/valid/path/file.txt",
|
||||
name: "file.txt",
|
||||
dateCreated: Optional<DateTime>.None(),
|
||||
dateModified: Optional<DateTime>.None(),
|
||||
size: 1024);
|
||||
DateTime newDate = DateTime.Now;
|
||||
|
||||
// Act
|
||||
@@ -104,9 +110,12 @@ public class FileTests
|
||||
public void UpdateSize_WhenCalled_ShouldUpdateFileSize()
|
||||
{
|
||||
// Arrange
|
||||
Result<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
|
||||
Assert.False(fileResult.IsFailure);
|
||||
File file = fileResult.Value;
|
||||
File file = _fileFixture.Create(
|
||||
path: "/valid/path/file.txt",
|
||||
name: "file.txt",
|
||||
dateCreated: Optional<DateTime>.None(),
|
||||
dateModified: Optional<DateTime>.None(),
|
||||
size: 1024);
|
||||
long newSize = 2048;
|
||||
|
||||
// Act
|
||||
@@ -121,9 +130,12 @@ public class FileTests
|
||||
public void Rename_WhenCalledWithValidName_ShouldUpdateFileName()
|
||||
{
|
||||
// Arrange
|
||||
Result<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
|
||||
Assert.False(fileResult.IsFailure);
|
||||
File file = fileResult.Value;
|
||||
File file = _fileFixture.Create(
|
||||
path: "/valid/path/file.txt",
|
||||
name: "file.txt",
|
||||
dateCreated: Optional<DateTime>.None(),
|
||||
dateModified: Optional<DateTime>.None(),
|
||||
size: 1024);
|
||||
string newName = "newfile.txt";
|
||||
|
||||
// Act
|
||||
@@ -138,9 +150,12 @@ public class FileTests
|
||||
public void Rename_WhenCalledWithEmptyName_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Result<File> fileResult = File.Create("/valid/path/file.txt", "file.txt", Optional<DateTime>.None(), Optional<DateTime>.None(), 1024);
|
||||
Assert.False(fileResult.IsFailure);
|
||||
File file = fileResult.Value;
|
||||
File file = _fileFixture.Create(
|
||||
path: "/valid/path/file.txt",
|
||||
name: "file.txt",
|
||||
dateCreated: Optional<DateTime>.None(),
|
||||
dateModified: Optional<DateTime>.None(),
|
||||
size: 1024);
|
||||
string emptyName = "";
|
||||
|
||||
// Act
|
||||
|
||||
+6
-9
@@ -3,6 +3,7 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -16,6 +17,8 @@ namespace Lumina.Domain.UnitTests.Core.BoundedContexts.FileSystemManagementBound
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UnixRootItemTests
|
||||
{
|
||||
private readonly UnixRootItemFixture _unixRootItemFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithDefaultStatus_ShouldReturnSuccessfulResult()
|
||||
{
|
||||
@@ -55,9 +58,7 @@ public class UnixRootItemTests
|
||||
public void Items_WhenAccessed_ShouldReturnEmptyReadOnlyCollection()
|
||||
{
|
||||
// Arrange
|
||||
Result<UnixRootItem> createResult = UnixRootItem.Create();
|
||||
Assert.False(createResult.IsFailure);
|
||||
UnixRootItem unixRootItem = createResult.Value;
|
||||
UnixRootItem unixRootItem = _unixRootItemFixture.Create();
|
||||
|
||||
// Act
|
||||
IReadOnlyCollection<FileSystemItem> items = unixRootItem.Items;
|
||||
@@ -71,9 +72,7 @@ public class UnixRootItemTests
|
||||
public void SetStatus_WhenCalledWithNewStatus_ShouldUpdateStatus()
|
||||
{
|
||||
// Arrange
|
||||
Result<UnixRootItem> createResult = UnixRootItem.Create();
|
||||
Assert.False(createResult.IsFailure);
|
||||
UnixRootItem unixRootItem = createResult.Value;
|
||||
UnixRootItem unixRootItem = _unixRootItemFixture.Create();
|
||||
FileSystemItemStatus newStatus = FileSystemItemStatus.Accessible;
|
||||
|
||||
// Act
|
||||
@@ -88,9 +87,7 @@ public class UnixRootItemTests
|
||||
public void SetParent_WhenCalledWithNullParent_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Result<UnixRootItem> createResult = UnixRootItem.Create();
|
||||
Assert.False(createResult.IsFailure);
|
||||
UnixRootItem unixRootItem = createResult.Value;
|
||||
UnixRootItem unixRootItem = _unixRootItemFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = unixRootItem.SetParent(null!);
|
||||
|
||||
+10
-13
@@ -4,6 +4,8 @@ using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
@@ -17,6 +19,9 @@ namespace Lumina.Domain.UnitTests.Core.BoundedContexts.FileSystemManagementBound
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WindowsRootItemTests
|
||||
{
|
||||
private readonly FileSystemPathIdFixture _fileSystemPathIdFixture = new();
|
||||
private readonly WindowsRootItemFixture _windowsRootItemFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidParameters_ShouldReturnSuccessfulResult()
|
||||
{
|
||||
@@ -76,9 +81,7 @@ public class WindowsRootItemTests
|
||||
public void Create_WhenCalledWithFileSystemPathId_ShouldReturnSuccessfulResult()
|
||||
{
|
||||
// Arrange
|
||||
Result<FileSystemPathId> pathIdResult = FileSystemPathId.Create("E:\\");
|
||||
Assert.False(pathIdResult.IsFailure);
|
||||
FileSystemPathId pathId = pathIdResult.Value;
|
||||
FileSystemPathId pathId = _fileSystemPathIdFixture.Create(path: "E:\\");
|
||||
string name = "E:";
|
||||
|
||||
// Act
|
||||
@@ -97,9 +100,7 @@ public class WindowsRootItemTests
|
||||
public void Items_WhenAccessed_ShouldReturnEmptyReadOnlyCollection()
|
||||
{
|
||||
// Arrange
|
||||
Result<WindowsRootItem> createResult = WindowsRootItem.Create("F:\\", "F:");
|
||||
Assert.False(createResult.IsFailure);
|
||||
WindowsRootItem windowsRootItem = createResult.Value;
|
||||
WindowsRootItem windowsRootItem = _windowsRootItemFixture.Create();
|
||||
|
||||
// Act
|
||||
IReadOnlyCollection<FileSystemItem> items = windowsRootItem.Items;
|
||||
@@ -113,9 +114,7 @@ public class WindowsRootItemTests
|
||||
public void SetStatus_WhenCalledWithNewStatus_ShouldUpdateStatus()
|
||||
{
|
||||
// Arrange
|
||||
Result<WindowsRootItem> createResult = WindowsRootItem.Create("G:\\", "G:");
|
||||
Assert.False(createResult.IsFailure);
|
||||
WindowsRootItem windowsRootItem = createResult.Value;
|
||||
WindowsRootItem windowsRootItem = _windowsRootItemFixture.Create();
|
||||
FileSystemItemStatus newStatus = FileSystemItemStatus.Accessible;
|
||||
|
||||
// Act
|
||||
@@ -130,10 +129,8 @@ public class WindowsRootItemTests
|
||||
public void SetParent_WhenCalledWithNullParent_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
Result<WindowsRootItem> createResult = WindowsRootItem.Create("H:\\", "H:");
|
||||
Assert.False(createResult.IsFailure);
|
||||
WindowsRootItem windowsRootItem = createResult.Value;
|
||||
|
||||
WindowsRootItem windowsRootItem = _windowsRootItemFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = windowsRootItem.SetParent(null!);
|
||||
|
||||
|
||||
+1
-1
@@ -792,7 +792,7 @@ public class DirectoryProviderServiceTests
|
||||
_mockFileSystem.Directory.Exists(destDir).Returns(true);
|
||||
|
||||
// Act
|
||||
_sut.MoveDirectory(FileSystemPathId.Create(sourceDir).Value, FileSystemPathId.Create(destDir).Value, overwrite);
|
||||
_sut.MoveDirectory(_fileSystemPathIdFixture.Create(sourceDir), _fileSystemPathIdFixture.Create(destDir), overwrite);
|
||||
|
||||
// Assert
|
||||
_mockFileSystem.Directory.Received(1).Delete(sourceDir);
|
||||
|
||||
+7
-7
@@ -261,7 +261,7 @@ public class FileProviderServiceTests
|
||||
byte[] expectedContents = [1, 2, 3, 4, 5];
|
||||
File.WriteAllBytes(tempFilePath, expectedContents);
|
||||
|
||||
FileSystemPathId path = FileSystemPathId.Create(tempFilePath).Value;
|
||||
FileSystemPathId path = _fileSystemPathIdFixture.Create(tempFilePath);
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadContents).Returns(true);
|
||||
|
||||
// We need to update the _fileSystem mock to use the real file system for this method
|
||||
@@ -303,7 +303,7 @@ public class FileProviderServiceTests
|
||||
string tempFilePath = Path.GetTempFileName();
|
||||
try
|
||||
{
|
||||
FileSystemPathId path = FileSystemPathId.Create(tempFilePath).Value;
|
||||
FileSystemPathId path = _fileSystemPathIdFixture.Create(tempFilePath);
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadContents).Returns(true);
|
||||
|
||||
// Act
|
||||
@@ -328,7 +328,7 @@ public class FileProviderServiceTests
|
||||
try
|
||||
{
|
||||
File.WriteAllText(tempFilePath, "Test content");
|
||||
FileSystemPathId path = FileSystemPathId.Create(tempFilePath).Value;
|
||||
FileSystemPathId path = _fileSystemPathIdFixture.Create(tempFilePath);
|
||||
DateTime expectedDateTime = File.GetLastWriteTime(tempFilePath);
|
||||
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties).Returns(true);
|
||||
@@ -371,7 +371,7 @@ public class FileProviderServiceTests
|
||||
try
|
||||
{
|
||||
File.WriteAllText(tempFilePath, "Test content");
|
||||
FileSystemPathId path = FileSystemPathId.Create(tempFilePath).Value;
|
||||
FileSystemPathId path = _fileSystemPathIdFixture.Create(tempFilePath);
|
||||
DateTime expectedDateTime = File.GetCreationTime(tempFilePath);
|
||||
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties).Returns(true);
|
||||
@@ -415,7 +415,7 @@ public class FileProviderServiceTests
|
||||
{
|
||||
string content = "Test content";
|
||||
File.WriteAllText(tempFilePath, content);
|
||||
FileSystemPathId path = FileSystemPathId.Create(tempFilePath).Value;
|
||||
FileSystemPathId path = _fileSystemPathIdFixture.Create(tempFilePath);
|
||||
long expectedSize = new FileInfo(tempFilePath).Length;
|
||||
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties).Returns(true);
|
||||
@@ -455,7 +455,7 @@ public class FileProviderServiceTests
|
||||
{
|
||||
// Arrange
|
||||
string nonExistentFilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
|
||||
FileSystemPathId path = FileSystemPathId.Create(nonExistentFilePath).Value;
|
||||
FileSystemPathId path = _fileSystemPathIdFixture.Create(nonExistentFilePath);
|
||||
|
||||
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties).Returns(true);
|
||||
_mockFileSystem.FileInfo.New(path.Path).Returns((IFileInfo)null!);
|
||||
@@ -875,7 +875,7 @@ public class FileProviderServiceTests
|
||||
_mockFileSystem.Path.Combine(parentPath, newName).Returns(newPath);
|
||||
|
||||
// Mock successful creation of parent directory FileSystemPathId
|
||||
Result<FileSystemPathId> parentDirectoryPathId = FileSystemPathId.Create(parentPath);
|
||||
FileSystemPathId parentDirectoryPathId = _fileSystemPathIdFixture.Create(parentPath);
|
||||
_mockFileSystem.Path.GetDirectoryName(path.Path).Returns(parentPath);
|
||||
|
||||
// Mock permissions: executable for the file, but not writable for the parent directory
|
||||
|
||||
+2
-2
@@ -444,7 +444,7 @@ public class PathServiceTests
|
||||
{
|
||||
// Arrange
|
||||
char[] originalInvalidChars = ['<', '>', ':', '"', '|', '?', '*'];
|
||||
_mockPathStrategy.GetInvalidPathCharsForPlatform().Returns(originalInvalidChars);
|
||||
_mockPathStrategy.GetInvalidPathCharsForPlatform().Returns(_ => (char[])originalInvalidChars.Clone());
|
||||
|
||||
// Act
|
||||
char[] result = _sut.GetInvalidPathCharsForPlatform();
|
||||
@@ -452,7 +452,7 @@ public class PathServiceTests
|
||||
|
||||
// Assert
|
||||
char[] secondResult = _sut.GetInvalidPathCharsForPlatform();
|
||||
Assert.Equal(secondResult, originalInvalidChars);
|
||||
Assert.Equal(originalInvalidChars, secondResult);
|
||||
_mockPathStrategy.Received(2).GetInvalidPathCharsForPlatform();
|
||||
}
|
||||
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryDeletedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryDeletedDomainEventTests
|
||||
{
|
||||
private readonly LibraryFixture _libraryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
Library library = _libraryFixture.Create();
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
LibraryDeletedDomainEvent domainEvent = new(id, library, occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(library, domainEvent.Library);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibrarySavedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibrarySavedDomainEventTests
|
||||
{
|
||||
private readonly LibraryFixture _libraryFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
Library library = _libraryFixture.Create();
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
LibrarySavedDomainEvent domainEvent = new(id, library, occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(library, domainEvent.Library);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
}
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="Library"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryTests
|
||||
{
|
||||
private readonly LibraryFixture _libraryFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidData_ShouldCreateLibraryWithAllPropertiesSet()
|
||||
{
|
||||
// Arrange
|
||||
UserId userId = _userIdFixture.Create();
|
||||
string title = "My Books";
|
||||
LibraryType libraryType = LibraryType.Book;
|
||||
List<string> contentLocations = ["C:/Media/Books", "D:/Books"];
|
||||
string coverImageSourcePath = "C:/Cover/cover.jpg";
|
||||
List<ScanId> scanIds = [_scanIdFixture.Create(), _scanIdFixture.Create()];
|
||||
|
||||
// Act
|
||||
Result<Library> result = Library.Create(
|
||||
userId,
|
||||
title,
|
||||
libraryType,
|
||||
contentLocations,
|
||||
coverImageSourcePath,
|
||||
isEnabled: false,
|
||||
isLocked: true,
|
||||
downloadMetadataFromWeb: false,
|
||||
shouldSaveMetadataInMediaDirectories: true,
|
||||
shouldSkipUnchangedDirectoriesDuringScan: true,
|
||||
scanIds);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(userId, result.Value.UserId);
|
||||
Assert.Equal(title, result.Value.Title);
|
||||
Assert.Equal(libraryType, result.Value.LibraryType);
|
||||
Assert.Equal(2, result.Value.ContentLocations.Count);
|
||||
Assert.Equal(coverImageSourcePath, result.Value.CoverImage);
|
||||
Assert.False(result.Value.IsEnabled);
|
||||
Assert.True(result.Value.IsLocked);
|
||||
Assert.False(result.Value.DownloadMetadataFromWeb);
|
||||
Assert.True(result.Value.ShouldSaveMetadataInMediaDirectories);
|
||||
Assert.True(result.Value.ShouldSkipUnchangedDirectoriesDuringScan);
|
||||
Assert.Equal(scanIds, result.Value.ScanIds);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingId_ShouldCreateLibraryWithThatId()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
List<ScanId> scanIds = [_scanIdFixture.Create()];
|
||||
|
||||
// Act
|
||||
Result<Library> result = Library.Create(
|
||||
_libraryIdFixture.Create(id),
|
||||
_userIdFixture.Create(),
|
||||
"My Library",
|
||||
LibraryType.Movie,
|
||||
["C:/Media"],
|
||||
null,
|
||||
isEnabled: true,
|
||||
isLocked: false,
|
||||
downloadMetadataFromWeb: true,
|
||||
shouldSaveMetadataInMediaDirectories: false,
|
||||
shouldSkipUnchangedDirectoriesDuringScan: false,
|
||||
scanIds);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(id, result.Value.Id.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithContentLocations_ShouldCreateFileSystemPathIdForEachLocation()
|
||||
{
|
||||
// Act
|
||||
Result<Library> result = Library.Create(
|
||||
_userIdFixture.Create(),
|
||||
"My Library",
|
||||
LibraryType.Book,
|
||||
["C:/Media/Books", "D:/Books"],
|
||||
null,
|
||||
isEnabled: true,
|
||||
isLocked: false,
|
||||
downloadMetadataFromWeb: true,
|
||||
shouldSaveMetadataInMediaDirectories: false,
|
||||
shouldSkipUnchangedDirectoriesDuringScan: false,
|
||||
[]);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(2, result.Value.ContentLocations.Count);
|
||||
Assert.Contains(result.Value.ContentLocations, location => location.Path == "C:/Media/Books");
|
||||
Assert.Contains(result.Value.ContentLocations, location => location.Path == "D:/Books");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // null content location
|
||||
[InlineData("")] // empty content location
|
||||
[InlineData(" ")] // whitespace content location
|
||||
public void Create_WhenContentLocationIsInvalid_ShouldReturnError(string? contentLocation)
|
||||
{
|
||||
// Act
|
||||
Result<Library> result = Library.Create(
|
||||
_userIdFixture.Create(),
|
||||
"My Library",
|
||||
LibraryType.Book,
|
||||
[contentLocation!],
|
||||
null,
|
||||
isEnabled: true,
|
||||
isLocked: false,
|
||||
downloadMetadataFromWeb: true,
|
||||
shouldSaveMetadataInMediaDirectories: false,
|
||||
shouldSkipUnchangedDirectoriesDuringScan: false,
|
||||
[]);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Lumina.Domain.Common.Errors.Errors.FileSystemManagement.InvalidPath, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Save_WhenCalled_ShouldRaiseLibrarySavedDomainEvent()
|
||||
{
|
||||
// Arrange
|
||||
Library library = _libraryFixture.Create();
|
||||
|
||||
// Act
|
||||
library.Save();
|
||||
|
||||
// Assert
|
||||
List<IDomainEvent> domainEvents = library.GetDomainEvents();
|
||||
LibrarySavedDomainEvent savedEvent = Assert.IsType<LibrarySavedDomainEvent>(Assert.Single(domainEvents));
|
||||
Assert.Equal(library, savedEvent.Library);
|
||||
Assert.NotEqual(default, savedEvent.Id);
|
||||
Assert.NotEqual(default, savedEvent.OccurredOnUtc);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Delete_WhenCalled_ShouldRaiseLibraryDeletedDomainEvent()
|
||||
{
|
||||
// Arrange
|
||||
Library library = _libraryFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = library.Delete();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Deleted, result.Value);
|
||||
List<IDomainEvent> domainEvents = library.GetDomainEvents();
|
||||
LibraryDeletedDomainEvent deletedEvent = Assert.IsType<LibraryDeletedDomainEvent>(Assert.Single(domainEvents));
|
||||
Assert.Equal(library, deletedEvent.Library);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Delete_WhenCalledAfterSave_ShouldClearPreviousEventsAndRaiseOnlyDeletedEvent()
|
||||
{
|
||||
// Arrange
|
||||
Library library = _libraryFixture.Create();
|
||||
library.Save();
|
||||
|
||||
// Act
|
||||
library.Delete();
|
||||
|
||||
// Assert
|
||||
List<IDomainEvent> domainEvents = library.GetDomainEvents();
|
||||
Assert.Single(domainEvents);
|
||||
Assert.IsType<LibraryDeletedDomainEvent>(domainEvents[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Delete_WhenCalledMultipleTimes_ShouldRaiseOnlyOneDeletedEvent()
|
||||
{
|
||||
// Arrange
|
||||
Library library = _libraryFixture.Create();
|
||||
|
||||
// Act
|
||||
library.Delete();
|
||||
library.Delete();
|
||||
|
||||
// Assert
|
||||
List<IDomainEvent> domainEvents = library.GetDomainEvents();
|
||||
Assert.Single(domainEvents);
|
||||
Assert.IsType<LibraryDeletedDomainEvent>(domainEvents[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetInternalLibraryCoverImagePath_WhenCalled_ShouldUpdateCoverImage()
|
||||
{
|
||||
// Arrange
|
||||
Library library = _libraryFixture.Create();
|
||||
string internalPath = "C:/Internal/Covers/cover.jpg";
|
||||
|
||||
// Act
|
||||
library.SetInternalLibraryCoverImagePath(internalPath);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(internalPath, library.CoverImage);
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
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 System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryMediaItemDeletedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryMediaItemDeletedDomainEventTests
|
||||
{
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaLibraryScanCompositeIdFixture _mediaLibraryScanCompositeIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
string path = "C:/Media/Books/old-book.pdf";
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
LibraryMediaItemDeletedDomainEvent domainEvent = new(id, libraryId, compositeId, path, occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(compositeId, domainEvent.MediaLibraryScanCompositeId);
|
||||
Assert.Equal(path, domainEvent.Path);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsAssignableFrom<IDomainEvent>(domainEvent);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
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 System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryScanCancelledDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanCancelledDomainEventTests
|
||||
{
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
LibraryScanCancelledDomainEvent domainEvent = new(id, scanId, libraryId, occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(scanId, domainEvent.ScanId);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsAssignableFrom<IDomainEvent>(domainEvent);
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
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 System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryScanFailedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanFailedDomainEventTests
|
||||
{
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaLibraryScanCompositeIdFixture _mediaLibraryScanCompositeIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithErrorMessage_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
string errorMessage = "Scan failed unexpectedly.";
|
||||
|
||||
// Act
|
||||
LibraryScanFailedDomainEvent domainEvent = new(id, libraryId, compositeId, occurredOnUtc, errorMessage);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(compositeId, domainEvent.MediaLibraryScanCompositeId);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.Equal(errorMessage, domainEvent.ErrorMessage);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithoutErrorMessage_ShouldDefaultErrorMessageToNull()
|
||||
{
|
||||
// Act
|
||||
LibraryScanFailedDomainEvent domainEvent = new(
|
||||
Guid.NewGuid(),
|
||||
_libraryIdFixture.Create(),
|
||||
_mediaLibraryScanCompositeIdFixture.Create(),
|
||||
DateTime.UtcNow);
|
||||
|
||||
// Assert
|
||||
Assert.Null(domainEvent.ErrorMessage);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryScanFinishedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanFinishedDomainEventTests
|
||||
{
|
||||
private readonly MediaLibraryScanCompositeIdFixture _mediaLibraryScanCompositeIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
LibraryScanFinishedDomainEvent domainEvent = new(id, compositeId, occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(compositeId, domainEvent.MediaLibraryScanCompositeId);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
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 System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryScanJobProgressChangedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanJobProgressChangedDomainEventTests
|
||||
{
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaLibraryScanCompositeIdFixture _mediaLibraryScanCompositeIdFixture = new();
|
||||
private readonly MediaLibraryScanJobProgressFixture _mediaLibraryScanJobProgressFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
MediaLibraryScanJobProgress progress = _mediaLibraryScanJobProgressFixture.Create();
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
LibraryScanJobProgressChangedDomainEvent domainEvent = new(id, libraryId, compositeId, progress, occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(compositeId, domainEvent.MediaLibraryScanCompositeId);
|
||||
Assert.Equal(progress, domainEvent.Progress);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
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 System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryScanProgressChangedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanProgressChangedDomainEventTests
|
||||
{
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaLibraryScanCompositeIdFixture _mediaLibraryScanCompositeIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
LibraryScanProgressChangedDomainEvent domainEvent = new(id, libraryId, compositeId, occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(compositeId, domainEvent.MediaLibraryScanCompositeId);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
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 System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryScanQueuedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanQueuedDomainEventTests
|
||||
{
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
LibraryScanQueuedDomainEvent domainEvent = new(id, scanId, libraryId, occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(scanId, domainEvent.ScanId);
|
||||
Assert.Equal(libraryId, domainEvent.LibraryId);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryScanStartedDomainEvent"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanStartedDomainEventTests
|
||||
{
|
||||
private readonly LibraryScanFixture _libraryScanFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
LibraryScan scan = _libraryScanFixture.Create();
|
||||
DateTime occurredOnUtc = DateTime.UtcNow;
|
||||
|
||||
// Act
|
||||
LibraryScanStartedDomainEvent domainEvent = new(id, scan, occurredOnUtc);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, domainEvent.Id);
|
||||
Assert.Equal(scan, domainEvent.LibraryScan);
|
||||
Assert.Equal(occurredOnUtc, domainEvent.OccurredOnUtc);
|
||||
Assert.IsType<IDomainEvent>(domainEvent, exactMatch: false);
|
||||
}
|
||||
}
|
||||
+292
@@ -0,0 +1,292 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="LibraryScan"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class LibraryScanTests
|
||||
{
|
||||
private readonly LibraryScanFixture _libraryScanFixture = new();
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidData_ShouldCreateScanWithPendingStatus()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<LibraryScan> result = LibraryScan.Create(libraryId, userId, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(libraryId, result.Value.LibraryId);
|
||||
Assert.Equal(userId, result.Value.UserId);
|
||||
Assert.Equal(LibraryScanJobStatus.Pending, result.Value.Status);
|
||||
Assert.NotEqual(default, result.Value.Id.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingIdAndStatus_ShouldCreateScanWithThoseValues()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<LibraryScan> result = LibraryScan.Create(_scanIdFixture.Create(id), libraryId, userId, LibraryScanJobStatus.Running, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(id, result.Value.Id.Value);
|
||||
Assert.Equal(libraryId, result.Value.LibraryId);
|
||||
Assert.Equal(userId, result.Value.UserId);
|
||||
Assert.Equal(LibraryScanJobStatus.Running, result.Value.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledTwice_ShouldGenerateDistinctIds()
|
||||
{
|
||||
// Act
|
||||
Result<LibraryScan> firstResult = LibraryScan.Create(_libraryIdFixture.Create(), _userIdFixture.Create(), []);
|
||||
Result<LibraryScan> secondResult = LibraryScan.Create(_libraryIdFixture.Create(), _userIdFixture.Create(), []);
|
||||
|
||||
// Assert
|
||||
Assert.False(firstResult.IsFailure);
|
||||
Assert.False(secondResult.IsFailure);
|
||||
Assert.NotEqual(firstResult.Value.Id.Value, secondResult.Value.Id.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QueueScan_WhenNoActivePastScanExists_ShouldSucceedAndRaiseQueuedEvent()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.QueueScan();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Success, result.Value);
|
||||
Assert.Equal(LibraryScanJobStatus.Pending, scan.Status);
|
||||
LibraryScanQueuedDomainEvent queuedEvent = Assert.IsType<LibraryScanQueuedDomainEvent>(Assert.Single(scan.GetDomainEvents()));
|
||||
Assert.Equal(scan.Id, queuedEvent.ScanId);
|
||||
Assert.Equal(scan.LibraryId, queuedEvent.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QueueScan_WhenPastScanIsRunning_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan pastScan = _libraryScanFixture.Create(status: LibraryScanJobStatus.Running);
|
||||
LibraryScan scan = _libraryScanFixture.Create(pastScans: [pastScan]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.QueueScan();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.LibraryAlreadyBeingScanned, result.FirstError);
|
||||
Assert.Empty(scan.GetDomainEvents());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void QueueScan_WhenPastScanIsPending_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan pastScan = _libraryScanFixture.Create(status: LibraryScanJobStatus.Pending);
|
||||
LibraryScan scan = _libraryScanFixture.Create(pastScans: [pastScan]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.QueueScan();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.LibraryAlreadyBeingScanned, result.FirstError);
|
||||
Assert.Empty(scan.GetDomainEvents());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartScan_WhenPending_ShouldTransitionToRunningAndRaiseStartedEvent()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.StartScan();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Success, result.Value);
|
||||
Assert.Equal(LibraryScanJobStatus.Running, scan.Status);
|
||||
LibraryScanStartedDomainEvent startedEvent = Assert.IsType<LibraryScanStartedDomainEvent>(Assert.Single(scan.GetDomainEvents()));
|
||||
Assert.Equal(scan, startedEvent.LibraryScan);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(LibraryScanJobStatus.Running)] // cannot start an already running scan
|
||||
[InlineData(LibraryScanJobStatus.Completed)] // cannot start a completed scan
|
||||
[InlineData(LibraryScanJobStatus.Canceled)] // cannot start a canceled scan
|
||||
[InlineData(LibraryScanJobStatus.Failed)] // cannot start a failed scan
|
||||
public void StartScan_WhenNotPending_ShouldReturnError(LibraryScanJobStatus status)
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create(status: status);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.StartScan();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.CanOnlyStartPendingScans, result.FirstError);
|
||||
Assert.Equal(status, scan.Status);
|
||||
Assert.Empty(scan.GetDomainEvents());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StartScan_WhenPastScanIsActive_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan pastScan = _libraryScanFixture.Create(status: LibraryScanJobStatus.Running);
|
||||
LibraryScan scan = _libraryScanFixture.Create(pastScans: [pastScan]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.StartScan();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.LibraryAlreadyBeingScanned, result.FirstError);
|
||||
Assert.Empty(scan.GetDomainEvents());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FinishScan_WhenRunning_ShouldTransitionToCompleted()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create(status: LibraryScanJobStatus.Running);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.FinishScan();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Success, result.Value);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, scan.Status);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(LibraryScanJobStatus.Pending)] // cannot complete a pending scan
|
||||
[InlineData(LibraryScanJobStatus.Completed)] // cannot complete an already completed scan
|
||||
[InlineData(LibraryScanJobStatus.Canceled)] // cannot complete a canceled scan
|
||||
[InlineData(LibraryScanJobStatus.Failed)] // cannot complete a failed scan
|
||||
public void FinishScan_WhenNotRunning_ShouldReturnError(LibraryScanJobStatus status)
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create(status: status);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.FinishScan();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.CanOnlyCompleteRunningScans, result.FirstError);
|
||||
Assert.Equal(status, scan.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CancelScan_WhenRunning_ShouldTransitionToCanceledAndRaiseCancelledEvent()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create(status: LibraryScanJobStatus.Running);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.CancelScan();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Success, result.Value);
|
||||
Assert.Equal(LibraryScanJobStatus.Canceled, scan.Status);
|
||||
LibraryScanCancelledDomainEvent cancelledEvent = Assert.IsType<LibraryScanCancelledDomainEvent>(Assert.Single(scan.GetDomainEvents()));
|
||||
Assert.Equal(scan.Id, cancelledEvent.ScanId);
|
||||
Assert.Equal(scan.LibraryId, cancelledEvent.LibraryId);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(LibraryScanJobStatus.Pending)] // cannot cancel a pending scan
|
||||
[InlineData(LibraryScanJobStatus.Completed)] // cannot cancel a completed scan
|
||||
[InlineData(LibraryScanJobStatus.Canceled)] // cannot cancel an already canceled scan
|
||||
[InlineData(LibraryScanJobStatus.Failed)] // cannot cancel a failed scan
|
||||
public void CancelScan_WhenNotRunning_ShouldReturnError(LibraryScanJobStatus status)
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create(status: status);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.CancelScan();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.CanOnlyCancelRunningScans, result.FirstError);
|
||||
Assert.Equal(status, scan.Status);
|
||||
Assert.Empty(scan.GetDomainEvents());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FailScan_WhenRunning_ShouldTransitionToFailed()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create(status: LibraryScanJobStatus.Running);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.FailScan();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Success, result.Value);
|
||||
Assert.Equal(LibraryScanJobStatus.Failed, scan.Status);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(LibraryScanJobStatus.Pending)] // cannot fail a pending scan
|
||||
[InlineData(LibraryScanJobStatus.Completed)] // cannot fail a completed scan
|
||||
[InlineData(LibraryScanJobStatus.Canceled)] // cannot fail a canceled scan
|
||||
[InlineData(LibraryScanJobStatus.Failed)] // cannot fail an already failed scan
|
||||
public void FailScan_WhenNotRunning_ShouldReturnError(LibraryScanJobStatus status)
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create(status: status);
|
||||
|
||||
// Act
|
||||
Result<Success> result = scan.FailScan();
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.CanOnlyFailRunningScans, result.FirstError);
|
||||
Assert.Equal(status, scan.Status);
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanJobFactory"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanJobFactoryTests
|
||||
{
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateJob_WhenJobTypeIsRegistered_ShouldResolveJobAndSetLibraryId()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
IMediaLibraryScanJob expectedJob = Substitute.For<IMediaLibraryScanJob>();
|
||||
ServiceCollection services = new();
|
||||
services.AddSingleton(expectedJob);
|
||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
MediaLibraryScanJobFactory sut = new(serviceProvider);
|
||||
|
||||
// Act
|
||||
IMediaLibraryScanJob job = sut.CreateJob<IMediaLibraryScanJob>(libraryId);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedJob, job);
|
||||
Assert.Equal(libraryId, job.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateJob_WhenJobTypeIsNotRegistered_ShouldThrowInvalidOperationException()
|
||||
{
|
||||
// Arrange
|
||||
ServiceCollection services = new();
|
||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
MediaLibraryScanJobFactory sut = new(serviceProvider);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidOperationException>(() => sut.CreateJob<IMediaLibraryScanJob>(_libraryIdFixture.Create()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateJob_WhenServiceProviderReturnsNull_ShouldThrowInvalidOperationException()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanJobFactory sut = new(new NullServiceProvider());
|
||||
|
||||
// Act & Assert
|
||||
InvalidOperationException exception = Assert.Throws<InvalidOperationException>(() => sut.CreateJob<IMediaLibraryScanJob>(_libraryIdFixture.Create()));
|
||||
Assert.Contains("IMediaLibraryScanJob", exception.Message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test service provider that returns <see langword="null"/> for every requested service.
|
||||
/// </summary>
|
||||
private sealed class NullServiceProvider : IServiceProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the service object of the specified type.
|
||||
/// </summary>
|
||||
/// <param name="serviceType">The type of service to get.</param>
|
||||
/// <returns><see langword="null"/>.</returns>
|
||||
public object? GetService(Type serviceType)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+175
@@ -0,0 +1,175 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanJob"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanJobTests
|
||||
{
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Status_WhenCreated_ShouldBePending()
|
||||
{
|
||||
// Act
|
||||
TestMediaLibraryScanJob job = CreateJob();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(LibraryScanJobStatus.Pending, job.Status);
|
||||
Assert.Empty(job.Children);
|
||||
Assert.Empty(job.Parents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddChild_WhenCalledWithNewJob_ShouldAddChild()
|
||||
{
|
||||
// Arrange
|
||||
TestMediaLibraryScanJob job = CreateJob();
|
||||
TestMediaLibraryScanJob child = CreateJob();
|
||||
|
||||
// Act
|
||||
job.AddChild(child);
|
||||
|
||||
// Assert
|
||||
Assert.Single(job.Children);
|
||||
Assert.Contains(child, job.Children);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddChild_WhenJobIsAlreadyChild_ShouldNotAddDuplicate()
|
||||
{
|
||||
// Arrange
|
||||
TestMediaLibraryScanJob job = CreateJob();
|
||||
TestMediaLibraryScanJob child = CreateJob();
|
||||
|
||||
// Act
|
||||
job.AddChild(child);
|
||||
job.AddChild(child);
|
||||
|
||||
// Assert
|
||||
Assert.Single(job.Children);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddChild_WhenJobIsParent_ShouldNotAddChild()
|
||||
{
|
||||
// Arrange
|
||||
TestMediaLibraryScanJob job = CreateJob();
|
||||
TestMediaLibraryScanJob parent = CreateJob();
|
||||
job.AddParent(parent);
|
||||
|
||||
// Act
|
||||
job.AddChild(parent);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(job.Children);
|
||||
Assert.Single(job.Parents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddParent_WhenCalledWithNewJob_ShouldAddParent()
|
||||
{
|
||||
// Arrange
|
||||
TestMediaLibraryScanJob job = CreateJob();
|
||||
TestMediaLibraryScanJob parent = CreateJob();
|
||||
|
||||
// Act
|
||||
job.AddParent(parent);
|
||||
|
||||
// Assert
|
||||
Assert.Single(job.Parents);
|
||||
Assert.Contains(parent, job.Parents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddParent_WhenJobIsAlreadyParent_ShouldNotAddDuplicate()
|
||||
{
|
||||
// Arrange
|
||||
TestMediaLibraryScanJob job = CreateJob();
|
||||
TestMediaLibraryScanJob parent = CreateJob();
|
||||
|
||||
// Act
|
||||
job.AddParent(parent);
|
||||
job.AddParent(parent);
|
||||
|
||||
// Assert
|
||||
Assert.Single(job.Parents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddParent_WhenJobIsChild_ShouldNotAddParent()
|
||||
{
|
||||
// Arrange
|
||||
TestMediaLibraryScanJob job = CreateJob();
|
||||
TestMediaLibraryScanJob child = CreateJob();
|
||||
job.AddChild(child);
|
||||
|
||||
// Act
|
||||
job.AddParent(child);
|
||||
|
||||
// Assert
|
||||
Assert.Single(job.Children);
|
||||
Assert.Empty(job.Parents);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteAsync_WhenCalled_ShouldCompleteWithoutChangingJobState()
|
||||
{
|
||||
// Arrange
|
||||
TestMediaLibraryScanJob job = CreateJob();
|
||||
|
||||
// Act
|
||||
await job.ExecuteAsync(Guid.NewGuid(), "input", CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(LibraryScanJobStatus.Pending, job.Status);
|
||||
Assert.Empty(job.Children);
|
||||
Assert.Empty(job.Parents);
|
||||
}
|
||||
|
||||
private TestMediaLibraryScanJob CreateJob()
|
||||
{
|
||||
return new TestMediaLibraryScanJob
|
||||
{
|
||||
ScanId = _scanIdFixture.Create(),
|
||||
UserId = _userIdFixture.Create(),
|
||||
LibraryId = _libraryIdFixture.Create()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Concrete test implementation of the abstract <see cref="MediaLibraryScanJob"/> class.
|
||||
/// </summary>
|
||||
private sealed class TestMediaLibraryScanJob : MediaLibraryScanJob
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the payload of the media library scan job.
|
||||
/// </summary>
|
||||
/// <typeparam name="TInput">The type of the input parameter.</typeparam>
|
||||
/// <param name="id">The unique identifier of the media library scan job.</param>
|
||||
/// <param name="input">The input data to be processed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public override Task ExecuteAsync<TInput>(Guid id, TInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Events;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Cancellation;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Progress;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Queue;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Scanners;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanningService"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanningServiceTests
|
||||
{
|
||||
private readonly IMediaLibrariesScanQueue _mockScanQueue;
|
||||
private readonly IMediaLibraryScannerFactory _mockScannerFactory;
|
||||
private readonly IMediaLibrariesScanCancellationTracker _mockCancellationTracker;
|
||||
private readonly IMediaLibrariesScanProgressTracker _mockProgressTracker;
|
||||
private readonly IDomainEventPublisher _mockDomainEventPublisher;
|
||||
private readonly MediaLibraryScanningService _sut;
|
||||
private readonly LibraryScanFixture _libraryScanFixture = new();
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly Channel<IMediaLibraryScanJob> _channel;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MediaLibraryScanningServiceTests"/> class.
|
||||
/// </summary>
|
||||
public MediaLibraryScanningServiceTests()
|
||||
{
|
||||
_channel = Channel.CreateUnbounded<IMediaLibraryScanJob>();
|
||||
_mockScanQueue = Substitute.For<IMediaLibrariesScanQueue>();
|
||||
_mockScanQueue.Writer.Returns(_channel.Writer);
|
||||
_mockScanQueue.Reader.Returns(_channel.Reader);
|
||||
_mockScannerFactory = Substitute.For<IMediaLibraryScannerFactory>();
|
||||
_mockCancellationTracker = Substitute.For<IMediaLibrariesScanCancellationTracker>();
|
||||
_mockCancellationTracker.GetTokenForScan(Arg.Any<MediaLibraryScanCompositeId>()).Returns(CancellationToken.None);
|
||||
_mockProgressTracker = Substitute.For<IMediaLibrariesScanProgressTracker>();
|
||||
_mockProgressTracker.InitializeScanProgress(Arg.Any<LibraryId>(), Arg.Any<MediaLibraryScanCompositeId>(), Arg.Any<int>()).Returns(Result.Created);
|
||||
_mockDomainEventPublisher = Substitute.For<IDomainEventPublisher>();
|
||||
_sut = new MediaLibraryScanningService(_mockScanQueue, _mockScannerFactory, _mockCancellationTracker, _mockProgressTracker, _mockDomainEventPublisher);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartScanAsync_WhenScanStartsSuccessfully_ShouldPublishEventsAndEnqueueJobs()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create();
|
||||
IMediaLibraryScanJob job = CreateJob(children: []);
|
||||
IMediaTypeScanner scanner = CreateScanner([job]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, downloadMetadataFromWeb: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Success, result.Value);
|
||||
Assert.Equal(LibraryScanJobStatus.Running, scan.Status);
|
||||
await _mockDomainEventPublisher.Received(1).PublishAsync(Arg.Any<LibraryScanStartedDomainEvent>(), Arg.Any<CancellationToken>());
|
||||
_mockCancellationTracker.Received(1).RegisterScan(Arg.Is<MediaLibraryScanCompositeId>(compositeId => compositeId.ScanId == scan.Id && compositeId.UserId == scan.UserId));
|
||||
_mockProgressTracker.Received(1).InitializeScanProgress(scan.LibraryId, Arg.Any<MediaLibraryScanCompositeId>(), totalJobs: 1);
|
||||
Assert.Equal(scan.Id, job.ScanId);
|
||||
Assert.Equal(scan.UserId, job.UserId);
|
||||
Assert.True(_channel.Reader.TryRead(out IMediaLibraryScanJob? enqueuedJob));
|
||||
Assert.Same(job, enqueuedJob);
|
||||
Assert.False(_channel.Reader.TryRead(out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartScanAsync_WhenScanCannotStart_ShouldReturnErrorAndNotEnqueueJobs()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create(status: LibraryScanJobStatus.Running);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, downloadMetadataFromWeb: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Lumina.Domain.Common.Errors.Errors.LibraryScanning.CanOnlyStartPendingScans, result.FirstError);
|
||||
await _mockDomainEventPublisher.DidNotReceive().PublishAsync(Arg.Any<IDomainEvent>(), Arg.Any<CancellationToken>());
|
||||
_mockProgressTracker.DidNotReceive().InitializeScanProgress(Arg.Any<LibraryId>(), Arg.Any<MediaLibraryScanCompositeId>(), Arg.Any<int>());
|
||||
Assert.False(_channel.Reader.TryRead(out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartScanAsync_WhenScannerThrowsNotImplementedException_ShouldSucceedWithoutEnqueuingJobs()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create();
|
||||
IMediaTypeScanner scanner = Substitute.For<IMediaTypeScanner>();
|
||||
scanner.CreateScanJobsForLibrary(Arg.Any<LibraryId>(), Arg.Any<bool>()).Returns(_ => throw new NotImplementedException());
|
||||
_mockScannerFactory.CreateLibraryScanner(LibraryType.Book).Returns(scanner);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, downloadMetadataFromWeb: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Success, result.Value);
|
||||
_mockProgressTracker.DidNotReceive().InitializeScanProgress(Arg.Any<LibraryId>(), Arg.Any<MediaLibraryScanCompositeId>(), Arg.Any<int>());
|
||||
Assert.False(_channel.Reader.TryRead(out _));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task StartScanAsync_WhenJobGraphHasSharedChild_ShouldCountOnlyUniqueJobs()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create();
|
||||
IMediaLibraryScanJob sharedChild = CreateJob(children: []);
|
||||
IMediaLibraryScanJob firstRoot = CreateJob(children: [sharedChild]);
|
||||
IMediaLibraryScanJob secondRoot = CreateJob(children: [sharedChild]);
|
||||
IMediaTypeScanner scanner = CreateScanner([firstRoot, secondRoot]);
|
||||
|
||||
// Act
|
||||
Result<Success> result = await _sut.StartScanAsync(scan, LibraryType.Book, downloadMetadataFromWeb: false, CancellationToken.None);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
_mockProgressTracker.Received(1).InitializeScanProgress(scan.LibraryId, Arg.Any<MediaLibraryScanCompositeId>(), totalJobs: 3);
|
||||
Assert.Equal(2, CountEnqueuedJobs());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CancelScan_WhenCalled_ShouldCancelScanInTracker()
|
||||
{
|
||||
// Arrange
|
||||
LibraryScan scan = _libraryScanFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Success> result = _sut.CancelScan(scan);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Success, result.Value);
|
||||
_mockCancellationTracker.Received(1).CancelScan(Arg.Is<MediaLibraryScanCompositeId>(compositeId => compositeId.ScanId == scan.Id && compositeId.UserId == scan.UserId));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetScanPropertiesForJobChain_WhenCalled_ShouldSetScanPropertiesRecursively()
|
||||
{
|
||||
// Arrange
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
IMediaLibraryScanJob leafJob = CreateJob(children: []);
|
||||
IMediaLibraryScanJob middleJob = CreateJob(children: [leafJob]);
|
||||
IMediaLibraryScanJob rootJob = CreateJob(children: [middleJob]);
|
||||
|
||||
// Act
|
||||
MediaLibraryScanningService.SetScanPropertiesForJobChain(rootJob, scanId, userId);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(scanId, rootJob.ScanId);
|
||||
Assert.Equal(userId, rootJob.UserId);
|
||||
Assert.Equal(scanId, middleJob.ScanId);
|
||||
Assert.Equal(userId, middleJob.UserId);
|
||||
Assert.Equal(scanId, leafJob.ScanId);
|
||||
Assert.Equal(userId, leafJob.UserId);
|
||||
}
|
||||
|
||||
private IMediaTypeScanner CreateScanner(List<IMediaLibraryScanJob> jobs)
|
||||
{
|
||||
IMediaTypeScanner scanner = Substitute.For<IMediaTypeScanner>();
|
||||
scanner.CreateScanJobsForLibrary(Arg.Any<LibraryId>(), Arg.Any<bool>()).Returns(jobs);
|
||||
_mockScannerFactory.CreateLibraryScanner(LibraryType.Book).Returns(scanner);
|
||||
return scanner;
|
||||
}
|
||||
|
||||
private static IMediaLibraryScanJob CreateJob(List<IMediaLibraryScanJob> children)
|
||||
{
|
||||
IMediaLibraryScanJob job = Substitute.For<IMediaLibraryScanJob>();
|
||||
job.Children.Returns(children);
|
||||
return job;
|
||||
}
|
||||
|
||||
private int CountEnqueuedJobs()
|
||||
{
|
||||
int count = 0;
|
||||
while (_channel.Reader.TryRead(out _))
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
+197
@@ -0,0 +1,197 @@
|
||||
#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.Progress;
|
||||
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 System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Progress;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibrariesScanProgressTracker"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibrariesScanProgressTrackerTests
|
||||
{
|
||||
private readonly MediaLibrariesScanProgressTracker _sut = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaLibraryScanCompositeIdFixture _mediaLibraryScanCompositeIdFixture = new();
|
||||
private readonly MediaLibraryScanJobProgressFixture _mediaLibraryScanJobProgressFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void InitializeScanProgress_WhenCalled_ShouldCreateProgressWithZeroCompletedJobs()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Created> result = _sut.InitializeScanProgress(libraryId, compositeId, totalJobs: 5);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
Result<MediaLibraryScanProgress> progressResult = _sut.GetScanProgress(compositeId);
|
||||
Assert.False(progressResult.IsFailure);
|
||||
Assert.Equal(0, progressResult.Value.CompletedJobs);
|
||||
Assert.Equal(5, progressResult.Value.TotalJobs);
|
||||
Assert.Equal(LibraryScanJobStatus.Pending, progressResult.Value.Status);
|
||||
Assert.True(progressResult.Value.CurrentJobProgress.HasValue);
|
||||
Assert.Equal("Initializing", progressResult.Value.CurrentJobProgress.Value.CurrentOperation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void InitializeScanProgress_WhenTotalJobsIsNotPositive_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Created> result = _sut.InitializeScanProgress(libraryId, compositeId, totalJobs: 0);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.TotalScanJobsCountMustBePositive, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateScanProgress_WhenScanExists_ShouldIncrementCompletedJobs()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
_sut.InitializeScanProgress(libraryId, compositeId, totalJobs: 2);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = _sut.UpdateScanProgress(libraryId, compositeId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
Result<MediaLibraryScanProgress> progressResult = _sut.GetScanProgress(compositeId);
|
||||
Assert.False(progressResult.IsFailure);
|
||||
Assert.Equal(1, progressResult.Value.CompletedJobs);
|
||||
Assert.Equal(LibraryScanJobStatus.Running, progressResult.Value.Status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateScanProgress_WhenLastJobIsCompleted_ShouldSetStatusCompleted()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
_sut.InitializeScanProgress(libraryId, compositeId, totalJobs: 1);
|
||||
|
||||
// Act
|
||||
Result<Updated> result = _sut.UpdateScanProgress(libraryId, compositeId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Result<MediaLibraryScanProgress> progressResult = _sut.GetScanProgress(compositeId);
|
||||
Assert.False(progressResult.IsFailure);
|
||||
Assert.Equal(1, progressResult.Value.CompletedJobs);
|
||||
Assert.Equal(LibraryScanJobStatus.Completed, progressResult.Value.Status);
|
||||
Assert.Equal(100, progressResult.Value.OverallProgressPercentage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateScanJobProgress_WhenScanExists_ShouldUpdateCurrentJobProgress()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
_sut.InitializeScanProgress(libraryId, compositeId, totalJobs: 2);
|
||||
MediaLibraryScanJobProgress jobProgress = _mediaLibraryScanJobProgressFixture.Create(completedItems: 3, totalItems: 10, currentOperation: "Hashing files");
|
||||
|
||||
// Act
|
||||
Result<Updated> result = _sut.UpdateScanJobProgress(libraryId, compositeId, jobProgress);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Updated, result.Value);
|
||||
Result<MediaLibraryScanProgress> progressResult = _sut.GetScanProgress(compositeId);
|
||||
Assert.False(progressResult.IsFailure);
|
||||
Assert.True(progressResult.Value.CurrentJobProgress.HasValue);
|
||||
Assert.Equal(3, progressResult.Value.CurrentJobProgress.Value.CompletedItems);
|
||||
Assert.Equal("Hashing files", progressResult.Value.CurrentJobProgress.Value.CurrentOperation);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpdateScanJobProgress_WhenScanDoesNotExist_ShouldReturnNotFoundError()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
MediaLibraryScanJobProgress jobProgress = _mediaLibraryScanJobProgressFixture.Create(completedItems: 1, totalItems: 10, currentOperation: "Hashing files");
|
||||
|
||||
// Act
|
||||
Result<Updated> result = _sut.UpdateScanJobProgress(libraryId, compositeId, jobProgress);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.LibraryScanNotFound, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetScanProgress_WhenScanExists_ShouldReturnProgress()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
_sut.InitializeScanProgress(libraryId, compositeId, totalJobs: 3);
|
||||
|
||||
// Act
|
||||
Result<MediaLibraryScanProgress> result = _sut.GetScanProgress(compositeId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(compositeId.ScanId, result.Value.ScanId);
|
||||
Assert.Equal(compositeId.UserId, result.Value.UserId);
|
||||
Assert.Equal(libraryId, result.Value.LibraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetScanProgress_WhenScanDoesNotExist_ShouldReturnNotFoundError()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanProgress> result = _sut.GetScanProgress(_mediaLibraryScanCompositeIdFixture.Create());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.LibraryScanNotFound, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveScanProgress_WhenScanExists_ShouldRemoveAndReturnProgress()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create();
|
||||
_sut.InitializeScanProgress(libraryId, compositeId, totalJobs: 3);
|
||||
|
||||
// Act
|
||||
Result<MediaLibraryScanProgress> result = _sut.RemoveScanProgress(compositeId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(compositeId.ScanId, result.Value.ScanId);
|
||||
Assert.True(_sut.GetScanProgress(compositeId).IsFailure);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveScanProgress_WhenScanDoesNotExist_ShouldReturnNotFoundError()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanProgress> result = _sut.RemoveScanProgress(_mediaLibraryScanCompositeIdFixture.Create());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.LibraryScanNotFound, result.FirstError);
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Scanners;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Scanners;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScannerFactory"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScannerFactoryTests
|
||||
{
|
||||
[Fact]
|
||||
public void CreateLibraryScanner_WhenLibraryTypeIsBook_ShouldReturnBookLibraryTypeScanner()
|
||||
{
|
||||
// Arrange
|
||||
IBookLibraryTypeScanner expectedScanner = Substitute.For<IBookLibraryTypeScanner>();
|
||||
ServiceCollection services = new();
|
||||
services.AddSingleton(expectedScanner);
|
||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
MediaLibraryScannerFactory sut = new(serviceProvider);
|
||||
|
||||
// Act
|
||||
IMediaTypeScanner scanner = sut.CreateLibraryScanner(LibraryType.Book);
|
||||
|
||||
// Assert
|
||||
Assert.Same(expectedScanner, scanner);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(LibraryType.EBook)] // eBook scanner is not implemented
|
||||
[InlineData(LibraryType.Movie)] // movie scanner is not implemented
|
||||
[InlineData(LibraryType.Music)] // music scanner is not implemented
|
||||
[InlineData(LibraryType.Photo)] // photo scanner is not implemented
|
||||
public void CreateLibraryScanner_WhenLibraryTypeIsNotImplemented_ShouldThrowNotImplementedException(LibraryType libraryType)
|
||||
{
|
||||
// Arrange
|
||||
ServiceCollection services = new();
|
||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
MediaLibraryScannerFactory sut = new(serviceProvider);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<NotImplementedException>(() => sut.CreateLibraryScanner(libraryType));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateLibraryScanner_WhenLibraryTypeIsUnknown_ShouldThrowArgumentOutOfRangeException()
|
||||
{
|
||||
// Arrange
|
||||
ServiceCollection services = new();
|
||||
using ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
MediaLibraryScannerFactory sut = new(serviceProvider);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => sut.CreateLibraryScanner((LibraryType)999));
|
||||
}
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanCompositeId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanCompositeIdTests
|
||||
{
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly MediaLibraryScanCompositeIdFixture _mediaLibraryScanCompositeIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithScanIdAndUserId_ShouldCreateCompositeIdWithThoseValues()
|
||||
{
|
||||
// Arrange
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
MediaLibraryScanCompositeId compositeId = MediaLibraryScanCompositeId.Create(scanId, userId);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(scanId, compositeId.ScanId);
|
||||
Assert.Equal(userId, compositeId.UserId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
MediaLibraryScanCompositeId firstId = _mediaLibraryScanCompositeIdFixture.Create(scanId: scanId, userId: userId);
|
||||
MediaLibraryScanCompositeId secondId = _mediaLibraryScanCompositeIdFixture.Create(scanId: scanId, userId: userId);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstId, secondId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentScanId_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
MediaLibraryScanCompositeId firstId = _mediaLibraryScanCompositeIdFixture.Create(userId: userId);
|
||||
MediaLibraryScanCompositeId secondId = _mediaLibraryScanCompositeIdFixture.Create(userId: userId);
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstId, secondId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetHashCode_WithSameValues_ShouldReturnSameHashCode()
|
||||
{
|
||||
// Arrange
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
MediaLibraryScanCompositeId firstId = _mediaLibraryScanCompositeIdFixture.Create(scanId: scanId, userId: userId);
|
||||
MediaLibraryScanCompositeId secondId = _mediaLibraryScanCompositeIdFixture.Create(scanId: scanId, userId: userId);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstId.GetHashCode(), secondId.GetHashCode());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_WhenCalled_ShouldReturnFormattedString()
|
||||
{
|
||||
// Arrange
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
MediaLibraryScanCompositeId compositeId = _mediaLibraryScanCompositeIdFixture.Create(scanId: scanId, userId: userId);
|
||||
|
||||
// Act
|
||||
string result = compositeId.ToString();
|
||||
|
||||
// Assert
|
||||
Assert.Equal($"{scanId}-{userId}", result);
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanJobProgress"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanJobProgressTests
|
||||
{
|
||||
private readonly MediaLibraryScanJobProgressFixture _mediaLibraryScanJobProgressFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidValues_ShouldCreateJobProgressWithExpectedValues()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanJobProgress> result = MediaLibraryScanJobProgress.Create(completedItems: 2, totalItems: 10, "Scanning files");
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(2, result.Value.CompletedItems);
|
||||
Assert.Equal(10, result.Value.TotalItems);
|
||||
Assert.Equal("Scanning files", result.Value.CurrentOperation);
|
||||
Assert.Equal(20, result.Value.ProgressPercentage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenTotalItemsIsZero_ShouldCreateJobProgressWithZeroPercentage()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanJobProgress> result = MediaLibraryScanJobProgress.Create(completedItems: 0, totalItems: 0, "Scanning files");
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(0, result.Value.ProgressPercentage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenTotalItemsIsNegative_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanJobProgress> result = MediaLibraryScanJobProgress.Create(completedItems: 0, totalItems: -1, "Scanning files");
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.TotalScanJobItemsCountMustBePositive, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCompletedItemsIsNegative_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanJobProgress> result = MediaLibraryScanJobProgress.Create(completedItems: -1, totalItems: 10, "Scanning files");
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.CompletedScanJobItemsCountMustBePositive, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCompletedItemsExceedsTotalItems_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanJobProgress> result = MediaLibraryScanJobProgress.Create(completedItems: 11, totalItems: 10, "Scanning files");
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.CompletedScanJobItemsCountCantExceedTotalScanJobItemsCount, result.FirstError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // null current operation
|
||||
[InlineData("")] // empty current operation
|
||||
[InlineData(" ")] // whitespace current operation
|
||||
public void Create_WhenCurrentOperationIsEmpty_ShouldReturnError(string? currentOperation)
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanJobProgress> result = MediaLibraryScanJobProgress.Create(completedItems: 1, totalItems: 10, currentOperation!);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.ScanJobCurrentOperationCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanJobProgress firstProgress = _mediaLibraryScanJobProgressFixture.Create(completedItems: 2, totalItems: 10, currentOperation: "Scanning files");
|
||||
MediaLibraryScanJobProgress secondProgress = _mediaLibraryScanJobProgressFixture.Create(completedItems: 2, totalItems: 10, currentOperation: "Scanning files");
|
||||
|
||||
// Act
|
||||
bool result = firstProgress.Equals(secondProgress);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentCurrentOperation_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanJobProgress firstProgress = _mediaLibraryScanJobProgressFixture.Create(completedItems: 2, totalItems: 10, currentOperation: "Scanning files");
|
||||
MediaLibraryScanJobProgress secondProgress = _mediaLibraryScanJobProgressFixture.Create(completedItems: 2, totalItems: 10, currentOperation: "Hashing files");
|
||||
|
||||
// Act
|
||||
bool result = firstProgress.Equals(secondProgress);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_WhenCalled_ShouldReturnFormattedString()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanJobProgress jobProgress = _mediaLibraryScanJobProgressFixture.Create(completedItems: 2, totalItems: 10, currentOperation: "Scanning files");
|
||||
|
||||
// Act
|
||||
string result = jobProgress.ToString();
|
||||
|
||||
// Assert
|
||||
Assert.Equal("CompletedItems: 2; TotalItems: 10; CurrentOperation: Scanning files", result);
|
||||
}
|
||||
}
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
#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.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryScanProgress"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryScanProgressTests
|
||||
{
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly MediaLibraryScanJobProgressFixture _mediaLibraryScanJobProgressFixture = new();
|
||||
private readonly MediaLibraryScanProgressFixture _mediaLibraryScanProgressFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidValues_ShouldCreateProgressWithExpectedValues()
|
||||
{
|
||||
// Arrange
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
Optional<MediaLibraryScanJobProgress> currentJobProgress = Optional<MediaLibraryScanJobProgress>.Some(_mediaLibraryScanJobProgressFixture.Create());
|
||||
|
||||
// Act
|
||||
Result<MediaLibraryScanProgress> result = MediaLibraryScanProgress.Create(scanId, userId, libraryId, completedJobs: 2, totalJobs: 5, LibraryScanJobStatus.Running, currentJobProgress);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(scanId, result.Value.ScanId);
|
||||
Assert.Equal(userId, result.Value.UserId);
|
||||
Assert.Equal(libraryId, result.Value.LibraryId);
|
||||
Assert.Equal(2, result.Value.CompletedJobs);
|
||||
Assert.Equal(5, result.Value.TotalJobs);
|
||||
Assert.Equal(LibraryScanJobStatus.Running, result.Value.Status);
|
||||
Assert.True(result.Value.CurrentJobProgress.HasValue);
|
||||
Assert.Equal(40, result.Value.OverallProgressPercentage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithDefaults_ShouldUsePendingStatusAndNoCurrentJobProgress()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanProgress> result = MediaLibraryScanProgress.Create(
|
||||
_scanIdFixture.Create(),
|
||||
_userIdFixture.Create(),
|
||||
_libraryIdFixture.Create(),
|
||||
completedJobs: 0,
|
||||
totalJobs: 1,
|
||||
LibraryScanJobStatus.Pending,
|
||||
Optional<MediaLibraryScanJobProgress>.None());
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(LibraryScanJobStatus.Pending, result.Value.Status);
|
||||
Assert.False(result.Value.CurrentJobProgress.HasValue);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0)] // total jobs must be positive
|
||||
[InlineData(-1)] // total jobs must be positive
|
||||
public void Create_WhenTotalJobsIsNotPositive_ShouldReturnError(int totalJobs)
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanProgress> result = MediaLibraryScanProgress.Create(
|
||||
_scanIdFixture.Create(),
|
||||
_userIdFixture.Create(),
|
||||
_libraryIdFixture.Create(),
|
||||
completedJobs: 0,
|
||||
totalJobs: totalJobs,
|
||||
LibraryScanJobStatus.Pending,
|
||||
Optional<MediaLibraryScanJobProgress>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.TotalScanJobsCountMustBePositive, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCompletedJobsIsNegative_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanProgress> result = MediaLibraryScanProgress.Create(
|
||||
_scanIdFixture.Create(),
|
||||
_userIdFixture.Create(),
|
||||
_libraryIdFixture.Create(),
|
||||
completedJobs: -1,
|
||||
totalJobs: 5,
|
||||
LibraryScanJobStatus.Pending,
|
||||
Optional<MediaLibraryScanJobProgress>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.CompletedScanJobsCountMustBePositive, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCompletedJobsExceedsTotalJobs_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<MediaLibraryScanProgress> result = MediaLibraryScanProgress.Create(
|
||||
_scanIdFixture.Create(),
|
||||
_userIdFixture.Create(),
|
||||
_libraryIdFixture.Create(),
|
||||
completedJobs: 6,
|
||||
totalJobs: 5,
|
||||
LibraryScanJobStatus.Pending,
|
||||
Optional<MediaLibraryScanJobProgress>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(Errors.LibraryScanning.CompletedScanJobsCountCantExceedTotalScanJobsCount, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OverallProgressPercentage_WhenNoJobsCompleted_ShouldReturnZero()
|
||||
{
|
||||
// Arrange
|
||||
MediaLibraryScanProgress scanProgress = _mediaLibraryScanProgressFixture.Create(completedJobs: 0, totalJobs: 5);
|
||||
|
||||
// Act
|
||||
decimal result = scanProgress.OverallProgressPercentage;
|
||||
|
||||
// Assert
|
||||
Assert.Equal(0, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
|
||||
// Act
|
||||
MediaLibraryScanProgress firstResult = _mediaLibraryScanProgressFixture.Create(
|
||||
scanId: scanId,
|
||||
userId: userId,
|
||||
libraryId: libraryId,
|
||||
completedJobs: 2,
|
||||
totalJobs: 5,
|
||||
status: LibraryScanJobStatus.Running,
|
||||
currentJobProgress: Optional<MediaLibraryScanJobProgress>.None());
|
||||
MediaLibraryScanProgress secondResult = _mediaLibraryScanProgressFixture.Create(
|
||||
scanId: scanId,
|
||||
userId: userId,
|
||||
libraryId: libraryId,
|
||||
completedJobs: 2,
|
||||
totalJobs: 5,
|
||||
status: LibraryScanJobStatus.Running,
|
||||
currentJobProgress: Optional<MediaLibraryScanJobProgress>.None());
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstResult, secondResult);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentCompletedJobs_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
ScanId scanId = _scanIdFixture.Create();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
|
||||
// Act
|
||||
MediaLibraryScanProgress firstResult = _mediaLibraryScanProgressFixture.Create(
|
||||
scanId: scanId,
|
||||
userId: userId,
|
||||
libraryId: libraryId,
|
||||
completedJobs: 2,
|
||||
totalJobs: 5,
|
||||
status: LibraryScanJobStatus.Running,
|
||||
currentJobProgress: Optional<MediaLibraryScanJobProgress>.None());
|
||||
MediaLibraryScanProgress secondResult = _mediaLibraryScanProgressFixture.Create(
|
||||
scanId: scanId,
|
||||
userId: userId,
|
||||
libraryId: libraryId,
|
||||
completedJobs: 3,
|
||||
totalJobs: 5,
|
||||
status: LibraryScanJobStatus.Running,
|
||||
currentJobProgress: Optional<MediaLibraryScanJobProgress>.None());
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstResult, secondResult);
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="ScanId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class ScanIdTests
|
||||
{
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
ScanId scanId = ScanId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(scanId);
|
||||
Assert.NotEqual(default, scanId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalledTwice_ShouldReturnDistinctIds()
|
||||
{
|
||||
// Act
|
||||
ScanId firstId = ScanId.CreateUnique();
|
||||
ScanId secondId = ScanId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstId.Value, secondId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
ScanId scanId = ScanId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, scanId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
ScanId firstId = _scanIdFixture.Create(value);
|
||||
ScanId secondId = _scanIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
ScanId firstId = _scanIdFixture.Create();
|
||||
ScanId secondId = _scanIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaContributor"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaContributorTests
|
||||
{
|
||||
private readonly MediaContributorIdFixture _mediaContributorIdFixture = new();
|
||||
private readonly MediaContributorNameFixture _mediaContributorNameFixture = new();
|
||||
private readonly MediaContributorRoleFixture _mediaContributorRoleFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingIdAndValues_ShouldCreateContributor()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorId id = _mediaContributorIdFixture.Create();
|
||||
MediaContributorName name = _mediaContributorNameFixture.Create(displayName: "Jane Doe", legalName: Optional<string>.Some("Jane Doe Smith"));
|
||||
MediaContributorRole role = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
Optional<DateOnly> dateOfBirth = Optional<DateOnly>.Some(new DateOnly(1980, 1, 1));
|
||||
Optional<DateOnly> dateOfDeath = Optional<DateOnly>.None();
|
||||
|
||||
// Act
|
||||
Result<MediaContributor> result = MediaContributor.Create(id, name, role, dateOfBirth, dateOfDeath);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(id, result.Value.Id);
|
||||
Assert.Equal(name, result.Value.Name);
|
||||
Assert.Equal(role, result.Value.Role);
|
||||
Assert.True(result.Value.DateOfBirth.HasValue);
|
||||
Assert.Equal(new DateOnly(1980, 1, 1), result.Value.DateOfBirth.Value);
|
||||
Assert.False(result.Value.DateOfDeath.HasValue);
|
||||
Assert.False(result.Value.Biography.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithOptionalValuesAbsent_ShouldCreateContributorWithoutThem()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorName name = _mediaContributorNameFixture.Create(displayName: "Jane Doe", legalName: Optional<string>.None());
|
||||
MediaContributorRole role = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
|
||||
// Act
|
||||
Result<MediaContributor> result = MediaContributor.Create(_mediaContributorIdFixture.Create(), name, role, Optional<DateOnly>.None(), Optional<DateOnly>.None());
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.DateOfBirth.HasValue);
|
||||
Assert.False(result.Value.DateOfDeath.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithoutId_ShouldThrowNotImplementedException()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorName name = _mediaContributorNameFixture.Create(displayName: "Jane Doe", legalName: Optional<string>.None());
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<NotImplementedException>(() => MediaContributor.Create(name));
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaContributorId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaContributorIdTests
|
||||
{
|
||||
private readonly MediaContributorIdFixture _mediaContributorIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
MediaContributorId contributorId = MediaContributorId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(contributorId);
|
||||
Assert.NotEqual(default, contributorId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
MediaContributorId contributorId = MediaContributorId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, contributorId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
MediaContributorId firstId = _mediaContributorIdFixture.Create(value);
|
||||
MediaContributorId secondId = _mediaContributorIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorId firstId = _mediaContributorIdFixture.Create();
|
||||
MediaContributorId secondId = _mediaContributorIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaContributorName"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaContributorNameTests
|
||||
{
|
||||
private readonly MediaContributorNameFixture _mediaContributorNameFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithDisplayNameAndLegalName_ShouldCreateName()
|
||||
{
|
||||
// Act
|
||||
Result<MediaContributorName> result = MediaContributorName.Create("Jane Doe", Optional<string>.Some("Jane Doe Smith"));
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Jane Doe", result.Value.DisplayName);
|
||||
Assert.True(result.Value.LegalName.HasValue);
|
||||
Assert.Equal("Jane Doe Smith", result.Value.LegalName.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithoutLegalName_ShouldCreateNameWithoutLegalName()
|
||||
{
|
||||
// Act
|
||||
Result<MediaContributorName> result = MediaContributorName.Create("Jane Doe", Optional<string>.None());
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Jane Doe", result.Value.DisplayName);
|
||||
Assert.False(result.Value.LegalName.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorName firstName = _mediaContributorNameFixture.Create(displayName: "Jane Doe", legalName: Optional<string>.None());
|
||||
MediaContributorName secondName = _mediaContributorNameFixture.Create(displayName: "Jane Doe", legalName: Optional<string>.None());
|
||||
|
||||
// Act
|
||||
bool result = firstName.Equals(secondName);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentDisplayName_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorName firstName = _mediaContributorNameFixture.Create(displayName: "Jane Doe", legalName: Optional<string>.None());
|
||||
MediaContributorName secondName = _mediaContributorNameFixture.Create(displayName: "John Smith", legalName: Optional<string>.None());
|
||||
|
||||
// Act
|
||||
bool result = firstName.Equals(secondName);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaContributorRole"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaContributorRoleTests
|
||||
{
|
||||
private readonly MediaContributorRoleFixture _mediaContributorRoleFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithNameAndCategory_ShouldCreateRole()
|
||||
{
|
||||
// Act
|
||||
MediaContributorRole role = MediaContributorRole.Create("Actor", "Crew");
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Actor", role.Name);
|
||||
Assert.Equal("Crew", role.Category);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorRole firstRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
MediaContributorRole secondRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
|
||||
// Act
|
||||
bool result = firstRole.Equals(secondRole);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentName_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorRole firstRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
MediaContributorRole secondRole = _mediaContributorRoleFixture.Create(name: "Director", category: "Crew");
|
||||
|
||||
// Act
|
||||
bool result = firstRole.Equals(secondRole);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentCategory_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MediaContributorRole firstRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Crew");
|
||||
MediaContributorRole secondRole = _mediaContributorRoleFixture.Create(name: "Actor", category: "Voice");
|
||||
|
||||
// Act
|
||||
bool result = firstRole.Equals(secondRole);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="User"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserTests
|
||||
{
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly UserFixture _userFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithUsername_ShouldCreateUserWithGeneratedId()
|
||||
{
|
||||
// Act
|
||||
Result<User> result = User.Create("testUser");
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("testUser", result.Value.Username);
|
||||
Assert.NotEqual(default, result.Value.Id.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingId_ShouldCreateUserWithThatId()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
Result<User> result = User.Create(_userIdFixture.Create(id), "testUser");
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(id, result.Value.Id.Value);
|
||||
Assert.Equal("testUser", result.Value.Username);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledTwice_ShouldGenerateDistinctIds()
|
||||
{
|
||||
// Act
|
||||
Result<User> firstResult = User.Create("firstUser");
|
||||
Result<User> secondResult = User.Create("secondUser");
|
||||
|
||||
// Assert
|
||||
Assert.False(firstResult.IsFailure);
|
||||
Assert.False(secondResult.IsFailure);
|
||||
Assert.NotEqual(firstResult.Value.Id.Value, secondResult.Value.Id.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameId_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
User firstUser = _userFixture.Create(id: id);
|
||||
User secondUser = _userFixture.Create(id: id);
|
||||
|
||||
// Act
|
||||
bool result = firstUser.Equals(secondUser);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentId_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
User firstUser = _userFixture.Create(username: "firstUser");
|
||||
User secondUser = _userFixture.Create(username: "secondUser");
|
||||
|
||||
// Act
|
||||
bool result = firstUser.Equals(secondUser);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+16
-11
@@ -3,6 +3,8 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserSettingsAggregate;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
@@ -15,11 +17,14 @@ namespace Lumina.Domain.UnitTests.Core.BoundedContexts.UserManagementBoundedCont
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class UserSettingsTests
|
||||
{
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
private readonly UserSettingsFixture _userSettingsFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithoutValues_ShouldCreateSettingsWithDefaultValues()
|
||||
{
|
||||
// Arrange
|
||||
UserId userId = UserId.CreateUnique();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(userId);
|
||||
@@ -64,7 +69,7 @@ public class UserSettingsTests
|
||||
public void Create_WhenCalledWithValidValues_ShouldCreateSettings()
|
||||
{
|
||||
// Arrange
|
||||
UserId userId = UserId.CreateUnique();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: false, itemsPerPage: 24, ignoreThePrefixForAlphaPicker: true);
|
||||
@@ -81,7 +86,7 @@ public class UserSettingsTests
|
||||
public void Create_WhenCalledWithValidValues_ShouldGenerateDistinctSettingsIdFromUserId()
|
||||
{
|
||||
// Arrange
|
||||
UserId userId = UserId.CreateUnique();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(userId);
|
||||
@@ -97,7 +102,7 @@ public class UserSettingsTests
|
||||
public void Create_WhenItemsPerPageIsNotPositive_ShouldReturnError(int itemsPerPage)
|
||||
{
|
||||
// Arrange
|
||||
UserId userId = UserId.CreateUnique();
|
||||
UserId userId = _userIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<UserSettings> result = UserSettings.Create(userId, isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false);
|
||||
@@ -111,16 +116,16 @@ public class UserSettingsTests
|
||||
public void UpdateSettings_WhenCalledWithValidValues_ShouldUpdateSettings()
|
||||
{
|
||||
// Arrange
|
||||
Result<UserSettings> createResult = UserSettings.Create(UserId.CreateUnique());
|
||||
UserSettings userSettings = _userSettingsFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = createResult.Value.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, ignoreThePrefixForAlphaPicker: true);
|
||||
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: false, itemsPerPage: 12, ignoreThePrefixForAlphaPicker: true);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(createResult.Value.IsPaginationEnabled);
|
||||
Assert.Equal(12, createResult.Value.ItemsPerPage);
|
||||
Assert.True(createResult.Value.IgnoreThePrefixForAlphaPicker);
|
||||
Assert.False(userSettings.IsPaginationEnabled);
|
||||
Assert.Equal(12, userSettings.ItemsPerPage);
|
||||
Assert.True(userSettings.IgnoreThePrefixForAlphaPicker);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -129,10 +134,10 @@ public class UserSettingsTests
|
||||
public void UpdateSettings_WhenItemsPerPageIsNotPositive_ShouldReturnError(int itemsPerPage)
|
||||
{
|
||||
// Arrange
|
||||
Result<UserSettings> createResult = UserSettings.Create(UserId.CreateUnique());
|
||||
UserSettings userSettings = _userSettingsFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Updated> result = createResult.Value.UpdateSettings(isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false);
|
||||
Result<Updated> result = userSettings.UpdateSettings(isPaginationEnabled: true, itemsPerPage: itemsPerPage, ignoreThePrefixForAlphaPicker: false);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.MediaContributorBoundedContext.MediaContributorAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="Movie"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MovieTests
|
||||
{
|
||||
private readonly VideoMetadataFixture _videoMetadataFixture = new();
|
||||
private readonly MovieIdFixture _movieIdFixture = new();
|
||||
private readonly MediaContributorIdFixture _mediaContributorIdFixture = new();
|
||||
private readonly MovieFixture _movieFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidData_ShouldCreateMovieWithGeneratedId()
|
||||
{
|
||||
// Arrange
|
||||
VideoMetadata metadata = _videoMetadataFixture.Create();
|
||||
List<MediaContributorId> contributors = [_mediaContributorIdFixture.Create()];
|
||||
List<Rating> ratings = [];
|
||||
|
||||
// Act
|
||||
Result<Movie> result = Movie.Create(metadata, contributors, ratings);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(metadata, result.Value.Metadata);
|
||||
Assert.Single(result.Value.Contributors);
|
||||
Assert.Empty(result.Value.Ratings);
|
||||
Assert.NotEqual(default, result.Value.Id.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingId_ShouldCreateMovieWithThatId()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
VideoMetadata metadata = _videoMetadataFixture.Create();
|
||||
List<MediaContributorId> contributors = [];
|
||||
List<Rating> ratings = [];
|
||||
|
||||
// Act
|
||||
Result<Movie> result = Movie.Create(_movieIdFixture.Create(id), metadata, contributors, ratings);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(id, result.Value.Id.Value);
|
||||
Assert.Equal(metadata, result.Value.Metadata);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetAllProperties()
|
||||
{
|
||||
// Arrange
|
||||
MovieId id = _movieIdFixture.Create();
|
||||
VideoMetadata metadata = _videoMetadataFixture.Create();
|
||||
List<MediaContributorId> contributors = [_mediaContributorIdFixture.Create(), _mediaContributorIdFixture.Create()];
|
||||
List<Rating> ratings = [CreateRating(4.5m)];
|
||||
|
||||
// Act
|
||||
Movie movie = new(id, metadata, contributors, ratings);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, movie.Id);
|
||||
Assert.Equal(metadata, movie.Metadata);
|
||||
Assert.Equal(2, movie.Contributors.Count);
|
||||
Assert.Single(movie.Ratings);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameId_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
Movie firstMovie = _movieFixture.Create(id: _movieIdFixture.Create(id));
|
||||
Movie secondMovie = _movieFixture.Create(id: _movieIdFixture.Create(id));
|
||||
|
||||
// Act
|
||||
bool result = firstMovie.Equals(secondMovie);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
private static Rating CreateRating(decimal value)
|
||||
{
|
||||
return new TestRating(value, 10);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Concrete test implementation of the abstract <see cref="Rating"/> class.
|
||||
/// </summary>
|
||||
private sealed class TestRating : Rating
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TestRating"/> class.
|
||||
/// </summary>
|
||||
/// <param name="value">The numeric value of the rating.</param>
|
||||
/// <param name="maxValue">The maximum possible rating value.</param>
|
||||
public TestRating(decimal value, decimal maxValue) : base(value, maxValue, Optional<int>.None())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of items that define equality of the object.
|
||||
/// </summary>
|
||||
/// <returns>A list of items defining the equality.</returns>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
yield return Value;
|
||||
yield return MaxValue;
|
||||
yield return VoteCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.Services;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MovieLibraryService"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MovieLibraryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Movies_WhenAccessed_ShouldThrowNotImplementedException()
|
||||
{
|
||||
// Arrange
|
||||
MovieLibraryService sut = new();
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<NotImplementedException>(() => sut.Movies);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MovieId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MovieIdTests
|
||||
{
|
||||
private readonly MovieIdFixture _movieIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
MovieId movieId = MovieId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(movieId);
|
||||
Assert.NotEqual(default, movieId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
MovieId movieId = MovieId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, movieId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
MovieId firstId = _movieIdFixture.Create(value);
|
||||
MovieId secondId = _movieIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
MovieId firstId = _movieIdFixture.Create();
|
||||
MovieId secondId = _movieIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+162
@@ -0,0 +1,162 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="VideoMetadata"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class VideoMetadataTests
|
||||
{
|
||||
private readonly GenreFixture _genreFixture = new();
|
||||
private readonly TagFixture _tagFixture = new();
|
||||
private readonly ReleaseInfoFixture _releaseInfoFixture = new();
|
||||
private readonly LanguageInfoFixture _languageInfoFixture = new();
|
||||
private readonly VideoMetadataFixture _videoMetadataFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidValues_ShouldCreateMetadataWithAllPropertiesSet()
|
||||
{
|
||||
// Act
|
||||
Result<VideoMetadata> result = VideoMetadata.Create(
|
||||
"Inception",
|
||||
Optional<string>.Some("Inception (Original)"),
|
||||
durationInSeconds: 8880,
|
||||
"1920x1080",
|
||||
Optional<string>.Some("A thief who steals corporate secrets."),
|
||||
_releaseInfoFixture.Create(),
|
||||
Optional<LanguageInfo>.Some(_languageInfoFixture.Create()),
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<float>.Some(24),
|
||||
Optional<string>.Some("H.264"),
|
||||
Optional<string>.Some("AAC"),
|
||||
[_genreFixture.Create(name: "Action")],
|
||||
[_tagFixture.Create(name: "heist")]);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Inception", result.Value.Title);
|
||||
Assert.Equal("Inception (Original)", result.Value.OriginalTitle.Value);
|
||||
Assert.Equal(8880, result.Value.DurationInSeconds);
|
||||
Assert.Equal("1920x1080", result.Value.Resolution);
|
||||
Assert.Equal("A thief who steals corporate secrets.", result.Value.Description.Value);
|
||||
Assert.Equal(24, result.Value.FrameRate.Value);
|
||||
Assert.Equal("H.264", result.Value.VideoCodec.Value);
|
||||
Assert.Equal("AAC", result.Value.AudioCodec.Value);
|
||||
Assert.Single(result.Value.Genres);
|
||||
Assert.Single(result.Value.Tags);
|
||||
Assert.True(result.Value.Language.HasValue);
|
||||
Assert.False(result.Value.OriginalLanguage.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenResolutionIsNull_ShouldThrowArgumentNullException()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.Throws<ArgumentNullException>(() => VideoMetadata.Create(
|
||||
"Inception",
|
||||
Optional<string>.None(),
|
||||
durationInSeconds: 8880,
|
||||
null!,
|
||||
Optional<string>.None(),
|
||||
_releaseInfoFixture.Create(),
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<float>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
[],
|
||||
[]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfo releaseInfo = _releaseInfoFixture.Create();
|
||||
VideoMetadata first = _videoMetadataFixture.Create(
|
||||
title: "Inception",
|
||||
originalTitle: Optional<string>.None(),
|
||||
durationInSeconds: 8880,
|
||||
resolution: "1920x1080",
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
frameRate: Optional<float>.None(),
|
||||
videoCodec: Optional<string>.None(),
|
||||
audioCodec: Optional<string>.None(),
|
||||
genres: [],
|
||||
tags: []);
|
||||
VideoMetadata second = _videoMetadataFixture.Create(
|
||||
title: "Inception",
|
||||
originalTitle: Optional<string>.None(),
|
||||
durationInSeconds: 8880,
|
||||
resolution: "1920x1080",
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
frameRate: Optional<float>.None(),
|
||||
videoCodec: Optional<string>.None(),
|
||||
audioCodec: Optional<string>.None(),
|
||||
genres: [],
|
||||
tags: []);
|
||||
|
||||
// Act
|
||||
bool result = first.Equals(second);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentDuration_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfo releaseInfo = _releaseInfoFixture.Create();
|
||||
VideoMetadata first = _videoMetadataFixture.Create(
|
||||
title: "Inception",
|
||||
originalTitle: Optional<string>.None(),
|
||||
durationInSeconds: 8880,
|
||||
resolution: "1920x1080",
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
frameRate: Optional<float>.None(),
|
||||
videoCodec: Optional<string>.None(),
|
||||
audioCodec: Optional<string>.None(),
|
||||
genres: [],
|
||||
tags: []);
|
||||
VideoMetadata second = _videoMetadataFixture.Create(
|
||||
title: "Inception",
|
||||
originalTitle: Optional<string>.None(),
|
||||
durationInSeconds: 8881,
|
||||
resolution: "1920x1080",
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
frameRate: Optional<float>.None(),
|
||||
videoCodec: Optional<string>.None(),
|
||||
audioCodec: Optional<string>.None(),
|
||||
genres: [],
|
||||
tags: []);
|
||||
|
||||
// Act
|
||||
bool result = first.Equals(second);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.MovieLibraryAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Services;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="VideoLibraryService"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class VideoLibraryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetInjectedServices()
|
||||
{
|
||||
// Arrange
|
||||
IMovieLibraryService movieLibraryService = Substitute.For<IMovieLibraryService>();
|
||||
ITvShowLibraryService tvShowLibraryService = Substitute.For<ITvShowLibraryService>();
|
||||
|
||||
// Act
|
||||
VideoLibraryService sut = new(movieLibraryService, tvShowLibraryService);
|
||||
|
||||
// Assert
|
||||
Assert.Same(movieLibraryService, sut.MovieLibraryService);
|
||||
Assert.Same(tvShowLibraryService, sut.TvShowLibraryService);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="Episode"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class EpisodeTests
|
||||
{
|
||||
private readonly EpisodeIdFixture _episodeIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetId()
|
||||
{
|
||||
// Arrange
|
||||
EpisodeId id = _episodeIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Episode episode = new(id);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, episode.Id);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="Season"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SeasonTests
|
||||
{
|
||||
private readonly SeasonIdFixture _seasonIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetId()
|
||||
{
|
||||
// Arrange
|
||||
SeasonId id = _seasonIdFixture.Create();
|
||||
|
||||
// Act
|
||||
Season season = new(id);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, season.Id);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Services;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TvShowLibraryService"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TvShowLibraryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void TvShows_WhenAccessed_ShouldThrowNotImplementedException()
|
||||
{
|
||||
// Arrange
|
||||
TvShowLibraryService sut = new();
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<NotImplementedException>(() => sut.TvShows);
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TvShow"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TvShowTests
|
||||
{
|
||||
private readonly TvShowIdFixture _tvShowIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetId()
|
||||
{
|
||||
// Arrange
|
||||
TvShowId id = _tvShowIdFixture.Create();
|
||||
|
||||
// Act
|
||||
TvShow tvShow = new(id);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(id, tvShow.Id);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="EpisodeId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class EpisodeIdTests
|
||||
{
|
||||
private readonly EpisodeIdFixture _episodeIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
EpisodeId episodeId = EpisodeId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(episodeId);
|
||||
Assert.NotEqual(default, episodeId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
EpisodeId episodeId = EpisodeId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, episodeId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
EpisodeId firstId = _episodeIdFixture.Create(value);
|
||||
EpisodeId secondId = _episodeIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
EpisodeId firstId = _episodeIdFixture.Create();
|
||||
EpisodeId secondId = _episodeIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="SeasonId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class SeasonIdTests
|
||||
{
|
||||
private readonly SeasonIdFixture _seasonIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
SeasonId seasonId = SeasonId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(seasonId);
|
||||
Assert.NotEqual(default, seasonId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
SeasonId seasonId = SeasonId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, seasonId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
SeasonId firstId = _seasonIdFixture.Create(value);
|
||||
SeasonId secondId = _seasonIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
SeasonId firstId = _seasonIdFixture.Create();
|
||||
SeasonId secondId = _seasonIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.VideoLibraryBoundedContext.TvShowLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="TvShowId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class TvShowIdTests
|
||||
{
|
||||
private readonly TvShowIdFixture _tvShowIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
TvShowId tvShowId = TvShowId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(tvShowId);
|
||||
Assert.NotEqual(default, tvShowId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
TvShowId tvShowId = TvShowId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, tvShowId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
TvShowId firstId = _tvShowIdFixture.Create(value);
|
||||
TvShowId secondId = _tvShowIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
TvShowId firstId = _tvShowIdFixture.Create();
|
||||
TvShowId secondId = _tvShowIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookSeries"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookSeriesTests
|
||||
{
|
||||
private readonly BookFixture _bookFixture = new();
|
||||
private readonly BookSeriesIdFixture _bookSeriesIdFixture = new();
|
||||
private readonly WrittenContentMetadataFixture _writtenContentMetadataFixture = new();
|
||||
private readonly BookSeriesFixture _bookSeriesFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidData_ShouldCreateSeries()
|
||||
{
|
||||
// Act
|
||||
Result<BookSeries> result = BookSeries.Create(_writtenContentMetadataFixture.Create(), isComplete: false, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.IsComplete);
|
||||
Assert.Empty(result.Value.Books);
|
||||
Assert.NotEqual(default, result.Value.Id.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithPreExistingId_ShouldCreateSeriesWithThatId()
|
||||
{
|
||||
// Arrange
|
||||
Guid id = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
Result<BookSeries> result = BookSeries.Create(_bookSeriesIdFixture.Create(id), _writtenContentMetadataFixture.Create(), isComplete: true, []);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(id, result.Value.Id.Value);
|
||||
Assert.True(result.Value.IsComplete);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddBook_WhenBookIsNotInSeries_ShouldAddBookAndReturnCreated()
|
||||
{
|
||||
// Arrange
|
||||
BookSeries series = _bookSeriesFixture.Create();
|
||||
Book book = _bookFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Created> result = series.AddBook(book);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Created, result.Value);
|
||||
Assert.Single(series.Books);
|
||||
Assert.Contains(book, series.Books);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddBook_WhenBookIsAlreadyInSeries_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookSeries series = _bookSeriesFixture.Create();
|
||||
Book book = _bookFixture.Create();
|
||||
series.AddBook(book);
|
||||
|
||||
// Act
|
||||
Result<Created> result = series.AddBook(book);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.TheBookIsAlreadyInTheSeries, result.FirstError);
|
||||
Assert.Single(series.Books);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveBook_WhenBookIsInSeries_ShouldRemoveBookAndReturnDeleted()
|
||||
{
|
||||
// Arrange
|
||||
BookSeries series = _bookSeriesFixture.Create();
|
||||
Book book = _bookFixture.Create();
|
||||
series.AddBook(book);
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = series.RemoveBook(book);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(Result.Deleted, result.Value);
|
||||
Assert.Empty(series.Books);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveBook_WhenBookIsNotInSeries_ShouldReturnError()
|
||||
{
|
||||
// Arrange
|
||||
BookSeries series = _bookSeriesFixture.Create();
|
||||
Book book = _bookFixture.Create();
|
||||
|
||||
// Act
|
||||
Result<Deleted> result = series.RemoveBook(book);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.TheBookIsNotInTheSeries, result.FirstError);
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookLibraryService"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookLibraryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Books_WhenAccessed_ShouldThrowNotImplementedException()
|
||||
{
|
||||
// Arrange
|
||||
BookLibraryService sut = new();
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<NotImplementedException>(() => sut.Books);
|
||||
}
|
||||
}
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Jobs;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.LibraryManagementBoundedContext.LibraryScanAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.UserManagementBoundedContext.UserAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.MediaLibrary;
|
||||
using NSubstitute;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services.Scanners;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookLibraryTypeScanner"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookLibraryTypeScannerTests
|
||||
{
|
||||
private readonly IMediaLibraryScanJobFactory _mockJobFactory = Substitute.For<IMediaLibraryScanJobFactory>();
|
||||
private readonly LibraryIdFixture _libraryIdFixture = new();
|
||||
private readonly ScanIdFixture _scanIdFixture = new();
|
||||
private readonly UserIdFixture _userIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void SupportedLibraryType_ShouldBeBook()
|
||||
{
|
||||
// Arrange
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Equal(LibraryType.Book, sut.SupportedLibraryType);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenDownloadMetadataFromWebIsFalse_ShouldCreateJobChainWithoutMetadataEnrichment()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
TestScanJob discoveryJob = CreateJob<IBooksFileSystemDiscoveryJob>();
|
||||
TestScanJob diffJob = CreateJob<IMediaLibraryScanDiffJob>();
|
||||
TestScanJob hashJob = CreateJob<IMediaLibraryScanHashJob>();
|
||||
TestScanJob saveJob = CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
List<IMediaLibraryScanJob> rootJobs = [.. sut.CreateScanJobsForLibrary(libraryId, downloadMetadataFromWeb: false)];
|
||||
|
||||
// Assert
|
||||
IMediaLibraryScanJob rootJob = Assert.Single(rootJobs);
|
||||
Assert.Same(discoveryJob, rootJob);
|
||||
Assert.Contains(diffJob, discoveryJob.Children);
|
||||
Assert.Contains(discoveryJob, diffJob.Parents);
|
||||
Assert.Contains(hashJob, diffJob.Children);
|
||||
Assert.Contains(diffJob, hashJob.Parents);
|
||||
Assert.Contains(saveJob, hashJob.Children);
|
||||
Assert.Contains(hashJob, saveJob.Parents);
|
||||
_mockJobFactory.DidNotReceive().CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(Arg.Any<LibraryId>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenDownloadMetadataFromWebIsTrue_ShouldCreateJobChainWithMetadataEnrichment()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
TestScanJob discoveryJob = CreateJob<IBooksFileSystemDiscoveryJob>();
|
||||
TestScanJob diffJob = CreateJob<IMediaLibraryScanDiffJob>();
|
||||
TestScanJob hashJob = CreateJob<IMediaLibraryScanHashJob>();
|
||||
TestScanJob saveJob = CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
TestScanJob enrichmentJob = CreateJob<IMediaLibraryScanMetadataEnrichmentJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
List<IMediaLibraryScanJob> rootJobs = [.. sut.CreateScanJobsForLibrary(libraryId, downloadMetadataFromWeb: true)];
|
||||
|
||||
// Assert
|
||||
IMediaLibraryScanJob rootJob = Assert.Single(rootJobs);
|
||||
Assert.Same(discoveryJob, rootJob);
|
||||
Assert.Contains(saveJob, hashJob.Children);
|
||||
Assert.Contains(enrichmentJob, saveJob.Children);
|
||||
Assert.Contains(saveJob, enrichmentJob.Parents);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanMetadataEnrichmentJob>(libraryId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CreateScanJobsForLibrary_WhenCalled_ShouldCreateJobsForTheLibrary()
|
||||
{
|
||||
// Arrange
|
||||
LibraryId libraryId = _libraryIdFixture.Create();
|
||||
CreateJob<IBooksFileSystemDiscoveryJob>();
|
||||
CreateJob<IMediaLibraryScanDiffJob>();
|
||||
CreateJob<IMediaLibraryScanHashJob>();
|
||||
CreateJob<IMediaLibraryScanResultsSaveJob>();
|
||||
BookLibraryTypeScanner sut = new(_mockJobFactory);
|
||||
|
||||
// Act
|
||||
_ = sut.CreateScanJobsForLibrary(libraryId, downloadMetadataFromWeb: false).ToList();
|
||||
|
||||
// Assert
|
||||
_mockJobFactory.Received(1).CreateJob<IBooksFileSystemDiscoveryJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanDiffJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanHashJob>(libraryId);
|
||||
_mockJobFactory.Received(1).CreateJob<IMediaLibraryScanResultsSaveJob>(libraryId);
|
||||
}
|
||||
|
||||
private TestScanJob CreateJob<TJob>() where TJob : class, IMediaLibraryScanJob
|
||||
{
|
||||
TestScanJob job = new()
|
||||
{
|
||||
ScanId = _scanIdFixture.Create(),
|
||||
UserId = _userIdFixture.Create(),
|
||||
LibraryId = _libraryIdFixture.Create()
|
||||
};
|
||||
_mockJobFactory.CreateJob<TJob>(Arg.Any<LibraryId>()).Returns((TJob)(object)job);
|
||||
return job;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Concrete test implementation of the abstract <see cref="MediaLibraryScanJob"/> class that satisfies all job interfaces.
|
||||
/// </summary>
|
||||
private sealed class TestScanJob : MediaLibraryScanJob,
|
||||
IBooksFileSystemDiscoveryJob,
|
||||
IMediaLibraryScanDiffJob,
|
||||
IMediaLibraryScanHashJob,
|
||||
IMediaLibraryScanResultsSaveJob,
|
||||
IMediaLibraryScanMetadataEnrichmentJob
|
||||
{
|
||||
/// <summary>
|
||||
/// Executes the payload of the media library scan job.
|
||||
/// </summary>
|
||||
/// <typeparam name="TInput">The type of the input parameter.</typeparam>
|
||||
/// <param name="id">The unique identifier of the media library scan job.</param>
|
||||
/// <param name="input">The input data to be processed.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
public override Task ExecuteAsync<TInput>(Guid id, TInput input, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookIdTests
|
||||
{
|
||||
private readonly BookIdFixture _bookIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
BookId bookId = BookId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(bookId);
|
||||
Assert.NotEqual(default, bookId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
BookId bookId = BookId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, bookId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
BookId firstId = _bookIdFixture.Create(value);
|
||||
BookId secondId = _bookIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
BookId firstId = _bookIdFixture.Create();
|
||||
BookId secondId = _bookIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookLibraryId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookLibraryIdTests
|
||||
{
|
||||
private readonly BookLibraryIdFixture _bookLibraryIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
Result<BookLibraryId> result = BookLibraryId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.NotEqual(default, result.Value.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
Result<BookLibraryId> result = BookLibraryId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(value, result.Value.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
BookLibraryId firstId = _bookLibraryIdFixture.Create(value);
|
||||
BookLibraryId secondId = _bookLibraryIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
BookLibraryId firstId = _bookLibraryIdFixture.Create();
|
||||
BookLibraryId secondId = _bookLibraryIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookRating"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookRatingTests
|
||||
{
|
||||
private readonly BookRatingFixture _bookRatingFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidValues_ShouldCreateRating()
|
||||
{
|
||||
// Act
|
||||
Result<BookRating> result = BookRating.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
Optional<BookRatingSource>.Some(BookRatingSource.Goodreads),
|
||||
Optional<int>.Some(100));
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal(4.5m, result.Value.Value);
|
||||
Assert.Equal(5, result.Value.MaxValue);
|
||||
Assert.True(result.Value.Source.HasValue);
|
||||
Assert.Equal(BookRatingSource.Goodreads, result.Value.Source.Value);
|
||||
Assert.True(result.Value.VoteCount.HasValue);
|
||||
Assert.Equal(100, result.Value.VoteCount.Value);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(-1)] // negative value
|
||||
[InlineData(-0.5)] // negative fractional value
|
||||
public void Create_WhenValueIsNegative_ShouldReturnError(double value)
|
||||
{
|
||||
// Act
|
||||
Result<BookRating> result = BookRating.Create((decimal)value, maxValue: 5, Optional<BookRatingSource>.None(), Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Metadata.RatingValueMustBePositive, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenMaxValueIsNegative_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<BookRating> result = BookRating.Create(value: 4.5m, maxValue: -5, Optional<BookRatingSource>.None(), Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Metadata.RatingValueMustBePositive, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenValueExceedsMaxValue_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<BookRating> result = BookRating.Create(value: 6, maxValue: 5, Optional<BookRatingSource>.None(), Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.Metadata.RatingValueCannotBeGreaterThanMaxValue, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AsPercentage_WhenCalled_ShouldReturnValueAsPercentageOfMaxValue()
|
||||
{
|
||||
// Arrange
|
||||
BookRating rating = _bookRatingFixture.Create(value: 4.5m, maxValue: 5);
|
||||
|
||||
// Act
|
||||
decimal result = rating.AsPercentage();
|
||||
|
||||
// Assert
|
||||
Assert.Equal(90, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_WhenSourceAndVoteCountArePresent_ShouldIncludeThem()
|
||||
{
|
||||
// Arrange
|
||||
BookRating rating = _bookRatingFixture.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
source: Optional<BookRatingSource>.Some(BookRatingSource.Goodreads),
|
||||
voteCount: Optional<int>.Some(100));
|
||||
|
||||
// Act
|
||||
string result = rating.ToString();
|
||||
|
||||
// Assert
|
||||
Assert.Equal("4.5/5 (Goodreads) [100 votes]", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToString_WhenSourceAndVoteCountAreAbsent_ShouldReturnBaseString()
|
||||
{
|
||||
// Arrange
|
||||
BookRating rating = _bookRatingFixture.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
source: Optional<BookRatingSource>.None(),
|
||||
voteCount: Optional<int>.None());
|
||||
|
||||
// Act
|
||||
string result = rating.ToString();
|
||||
|
||||
// Assert
|
||||
Assert.Equal("4.5/5", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
BookRating firstRating = _bookRatingFixture.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
source: Optional<BookRatingSource>.Some(BookRatingSource.Goodreads),
|
||||
voteCount: Optional<int>.Some(100));
|
||||
BookRating secondRating = _bookRatingFixture.Create(
|
||||
value: 4.5m,
|
||||
maxValue: 5,
|
||||
source: Optional<BookRatingSource>.Some(BookRatingSource.Goodreads),
|
||||
voteCount: Optional<int>.Some(100));
|
||||
|
||||
// Act
|
||||
bool result = firstRating.Equals(secondRating);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="BookSeriesId"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class BookSeriesIdTests
|
||||
{
|
||||
private readonly BookSeriesIdFixture _bookSeriesIdFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void CreateUnique_WhenCalled_ShouldReturnIdWithNonEmptyValue()
|
||||
{
|
||||
// Act
|
||||
BookSeriesId seriesId = BookSeriesId.CreateUnique();
|
||||
|
||||
// Assert
|
||||
Assert.NotNull(seriesId);
|
||||
Assert.NotEqual(default, seriesId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValue_ShouldReturnIdWithThatValue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
|
||||
// Act
|
||||
BookSeriesId seriesId = BookSeriesId.Create(value);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(value, seriesId.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValue_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Guid value = Guid.NewGuid();
|
||||
BookSeriesId firstId = _bookSeriesIdFixture.Create(value);
|
||||
BookSeriesId secondId = _bookSeriesIdFixture.Create(value);
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
BookSeriesId firstId = _bookSeriesIdFixture.Create();
|
||||
BookSeriesId secondId = _bookSeriesIdFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstId.Equals(secondId);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+184
@@ -0,0 +1,184 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using DomainErrors = Lumina.Domain.Common.Errors.Errors;
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.SharedKernel.Common.Enums.BookLibrary;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="Isbn"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class IsbnTests
|
||||
{
|
||||
private readonly IsbnFixture _isbnFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidIsbn10_ShouldCreateIsbn10()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("0-306-40615-2", IsbnFormat.Isbn10);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("0-306-40615-2", result.Value.Value);
|
||||
Assert.Equal(IsbnFormat.Isbn10, result.Value.Format);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidIsbn13_ShouldCreateIsbn13()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("978-0-306-40615-7", IsbnFormat.Isbn13);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("978-0-306-40615-7", result.Value.Value);
|
||||
Assert.Equal(IsbnFormat.Isbn13, result.Value.Format);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)] // null ISBN value
|
||||
[InlineData("")] // empty ISBN value
|
||||
[InlineData(" ")] // whitespace ISBN value
|
||||
public void Create_WhenValueIsNullOrWhitespace_ShouldReturnError(string? value)
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create(value, IsbnFormat.Isbn10);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.IsbnValueCannotBeEmpty, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenFormatIsUnknown_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("0-306-40615-2", (IsbnFormat)999);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.UnknownIsbnFormat, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenIsbn10HasInvalidCheckDigit_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("0-306-40615-3", IsbnFormat.Isbn10);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.InvalidIsbn10Format, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenIsbn13HasInvalidCheckDigit_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("978-0-306-40615-8", IsbnFormat.Isbn13);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.InvalidIsbn13Format, result.FirstError);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenIsbn10HasWrongLength_ShouldReturnError()
|
||||
{
|
||||
// Act
|
||||
Result<Isbn> result = Isbn.Create("123456789", IsbnFormat.Isbn10);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.IsFailure);
|
||||
Assert.Equal(DomainErrors.WrittenContent.InvalidIsbn10Format, result.FirstError);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0-306-40615-2")] // valid ISBN-10 with hyphens
|
||||
[InlineData("0306406152")] // valid ISBN-10 without hyphens
|
||||
public void IsValidIsbn10_WhenValueIsValid_ShouldReturnTrue(string isbn)
|
||||
{
|
||||
// Act
|
||||
bool result = Isbn.IsValidIsbn10(isbn);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("0-306-40615-3")] // invalid check digit
|
||||
[InlineData("030640615")] // too short
|
||||
[InlineData("03064061523")] // too long
|
||||
[InlineData("")] // empty value
|
||||
[InlineData("ISBN 0-306-40615-2")] // ISBN prefix is not stripped by the checksum computation
|
||||
public void IsValidIsbn10_WhenValueIsInvalid_ShouldReturnFalse(string isbn)
|
||||
{
|
||||
// Act
|
||||
bool result = Isbn.IsValidIsbn10(isbn);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("978-0-306-40615-7")] // valid ISBN-13 with hyphens
|
||||
[InlineData("9780306406157")] // valid ISBN-13 without hyphens
|
||||
[InlineData("979-0-306-40615-6")] // valid ISBN-13 with 979 prefix
|
||||
public void IsValidIsbn13_WhenValueIsValid_ShouldReturnTrue(string isbn)
|
||||
{
|
||||
// Act
|
||||
bool result = Isbn.IsValidIsbn13(isbn);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("978-0-306-40615-8")] // invalid check digit
|
||||
[InlineData("978030640615")] // too short
|
||||
[InlineData("97803064061578")] // too long
|
||||
[InlineData("")] // empty value
|
||||
[InlineData("ISBN 978-0-306-40615-7")] // ISBN prefix is not stripped by the checksum computation
|
||||
public void IsValidIsbn13_WhenValueIsInvalid_ShouldReturnFalse(string isbn)
|
||||
{
|
||||
// Act
|
||||
bool result = Isbn.IsValidIsbn13(isbn);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValueAndFormat_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
Isbn firstIsbn = _isbnFixture.Create(value: "0-306-40615-2", format: IsbnFormat.Isbn10);
|
||||
Isbn secondIsbn = _isbnFixture.Create(value: "0-306-40615-2", format: IsbnFormat.Isbn10);
|
||||
|
||||
// Act
|
||||
bool result = firstIsbn.Equals(secondIsbn);
|
||||
|
||||
// Assert
|
||||
Assert.True(result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentValue_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
Isbn firstIsbn = _isbnFixture.Create();
|
||||
Isbn secondIsbn = _isbnFixture.Create();
|
||||
|
||||
// Act
|
||||
bool result = firstIsbn.Equals(secondIsbn);
|
||||
|
||||
// Assert
|
||||
Assert.False(result);
|
||||
}
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Common.Primitives;
|
||||
using Lumina.Domain.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using Lumina.Domain.Fixtures.Common.ValueObjects.Metadata;
|
||||
using Lumina.Domain.Fixtures.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.ValueObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="WrittenContentMetadata"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WrittenContentMetadataTests
|
||||
{
|
||||
private readonly GenreFixture _genreFixture = new();
|
||||
private readonly TagFixture _tagFixture = new();
|
||||
private readonly ReleaseInfoFixture _releaseInfoFixture = new();
|
||||
private readonly LanguageInfoFixture _languageInfoFixture = new();
|
||||
private readonly WrittenContentMetadataFixture _writtenContentMetadataFixture = new();
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithValidValues_ShouldCreateMetadataWithAllPropertiesSet()
|
||||
{
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = WrittenContentMetadata.Create(
|
||||
"Dune",
|
||||
Optional<string>.Some("Dune (Original)"),
|
||||
Optional<string>.Some("A classic science fiction novel."),
|
||||
_releaseInfoFixture.Create(),
|
||||
[_genreFixture.Create(name: "Science Fiction")],
|
||||
[_tagFixture.Create(name: "classic")],
|
||||
Optional<LanguageInfo>.Some(_languageInfoFixture.Create()),
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<string>.Some("Chilton Books"),
|
||||
Optional<int>.Some(412));
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.Equal("Dune", result.Value.Title);
|
||||
Assert.Equal("Dune (Original)", result.Value.OriginalTitle.Value);
|
||||
Assert.Equal("A classic science fiction novel.", result.Value.Description.Value);
|
||||
Assert.Single(result.Value.Genres);
|
||||
Assert.Single(result.Value.Tags);
|
||||
Assert.True(result.Value.Language.HasValue);
|
||||
Assert.False(result.Value.OriginalLanguage.HasValue);
|
||||
Assert.True(result.Value.Publisher.HasValue);
|
||||
Assert.Equal("Chilton Books", result.Value.Publisher.Value);
|
||||
Assert.True(result.Value.PageCount.HasValue);
|
||||
Assert.Equal(412, result.Value.PageCount.Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Create_WhenCalledWithOptionalValuesAbsent_ShouldCreateMetadataWithoutThem()
|
||||
{
|
||||
// Act
|
||||
Result<WrittenContentMetadata> result = WrittenContentMetadata.Create(
|
||||
"Dune",
|
||||
Optional<string>.None(),
|
||||
Optional<string>.None(),
|
||||
_releaseInfoFixture.Create(),
|
||||
[],
|
||||
[],
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<LanguageInfo>.None(),
|
||||
Optional<string>.None(),
|
||||
Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.False(result.IsFailure);
|
||||
Assert.False(result.Value.OriginalTitle.HasValue);
|
||||
Assert.False(result.Value.Publisher.HasValue);
|
||||
Assert.False(result.Value.PageCount.HasValue);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithSameValues_ShouldReturnTrue()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfo releaseInfo = _releaseInfoFixture.Create();
|
||||
|
||||
// Act
|
||||
WrittenContentMetadata firstResult = _writtenContentMetadataFixture.Create(
|
||||
title: "Dune",
|
||||
originalTitle: Optional<string>.None(),
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
publisher: Optional<string>.None(),
|
||||
pageCount: Optional<int>.None());
|
||||
WrittenContentMetadata secondResult = _writtenContentMetadataFixture.Create(
|
||||
title: "Dune",
|
||||
originalTitle: Optional<string>.None(),
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
publisher: Optional<string>.None(),
|
||||
pageCount: Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.Equal(firstResult, secondResult);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Equals_WithDifferentPublisher_ShouldReturnFalse()
|
||||
{
|
||||
// Arrange
|
||||
ReleaseInfo releaseInfo = _releaseInfoFixture.Create();
|
||||
|
||||
// Act
|
||||
WrittenContentMetadata firstResult = _writtenContentMetadataFixture.Create(
|
||||
title: "Dune",
|
||||
originalTitle: Optional<string>.None(),
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
publisher: Optional<string>.None(),
|
||||
pageCount: Optional<int>.None());
|
||||
WrittenContentMetadata secondResult = _writtenContentMetadataFixture.Create(
|
||||
title: "Dune",
|
||||
originalTitle: Optional<string>.None(),
|
||||
description: Optional<string>.None(),
|
||||
releaseInfo: releaseInfo,
|
||||
genres: [],
|
||||
tags: [],
|
||||
language: Optional<LanguageInfo>.None(),
|
||||
originalLanguage: Optional<LanguageInfo>.None(),
|
||||
publisher: Optional<string>.Some("Other Publisher"),
|
||||
pageCount: Optional<int>.None());
|
||||
|
||||
// Assert
|
||||
Assert.NotEqual(firstResult, secondResult);
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.BookLibraryAggregate.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.Services;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.BoundedContexts.WrittenContentLibraryBoundedContext.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="WrittenContentLibraryService"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class WrittenContentLibraryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetInjectedService()
|
||||
{
|
||||
// Arrange
|
||||
IBookLibraryService bookLibraryService = Substitute.For<IBookLibraryService>();
|
||||
|
||||
// Act
|
||||
WrittenContentLibraryService sut = new(bookLibraryService);
|
||||
|
||||
// Assert
|
||||
Assert.Same(bookLibraryService, sut.BookLibraryService);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Domain.Core.BoundedContexts.VideoLibraryBoundedContext.Services;
|
||||
using Lumina.Domain.Core.BoundedContexts.WrittenContentLibraryBoundedContext.Services;
|
||||
using Lumina.Domain.Core.Services;
|
||||
using NSubstitute;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Domain.UnitTests.Core.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Contains unit tests for the <see cref="MediaLibraryService"/> class.
|
||||
/// </summary>
|
||||
[ExcludeFromCodeCoverage]
|
||||
public class MediaLibraryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldSetInjectedServices()
|
||||
{
|
||||
// Arrange
|
||||
IVideoLibraryService videoLibraryService = Substitute.For<IVideoLibraryService>();
|
||||
IWrittenContentLibraryService writtenContentLibraryService = Substitute.For<IWrittenContentLibraryService>();
|
||||
|
||||
// Act
|
||||
MediaLibraryService sut = new(videoLibraryService, writtenContentLibraryService);
|
||||
|
||||
// Assert
|
||||
Assert.Same(videoLibraryService, sut.VideoLibraryService);
|
||||
Assert.Same(writtenContentLibraryService, sut.WrittenContentLibraryService);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user