mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 11:11:10 +00:00
Adds media library cover image
This commit is contained in:
1 parent
89debaeaad
commit
666a739b1d
43 files changed
+1170
-94
No files matched your search
+36
-12
@@ -4,7 +4,6 @@ using Lumina.Application.Common.Mapping.MediaLibrary.Management;
|
||||
using Lumina.Application.Core.MediaLibrary.Management.Commands.AddLibrary;
|
||||
using Lumina.Contracts.Requests.MediaLibrary.Management;
|
||||
using Lumina.Domain.Common.Enums.MediaLibrary;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
#endregion
|
||||
|
||||
@@ -20,22 +19,22 @@ public class AddMediaLibraryRequestMappingTests
|
||||
public void ToCommand_WhenMappingValidRequest_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
AddLibraryRequest request = new(
|
||||
"My Library",
|
||||
"Book",
|
||||
["C:/Books", "D:/Media/Books"]
|
||||
["C:/Books", "D:/Media/Books"],
|
||||
"D:/poster.jpg"
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand(userId);
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(userId);
|
||||
result.Title.Should().Be(request.Title);
|
||||
result.LibraryType.Should().Be(request.LibraryType);
|
||||
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
||||
result.CoverImage.Should().BeEquivalentTo(request.CoverImage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -46,22 +45,22 @@ public class AddMediaLibraryRequestMappingTests
|
||||
public void ToCommand_WhenMappingDifferentLibraryTypes_ShouldMapCorrectly(LibraryType libraryType)
|
||||
{
|
||||
// Arrange
|
||||
Guid userId = Guid.NewGuid();
|
||||
AddLibraryRequest request = new(
|
||||
"My Library",
|
||||
libraryType.ToString(),
|
||||
["C:/Media"]
|
||||
["C:/Media"],
|
||||
"D:/poster.jpg"
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand(userId);
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.UserId.Should().Be(userId);
|
||||
result.Title.Should().Be(request.Title);
|
||||
result.LibraryType.Should().Be(libraryType.ToString());
|
||||
result.ContentLocations.Should().BeEquivalentTo(request.ContentLocations);
|
||||
result.CoverImage.Should().BeEquivalentTo(request.CoverImage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -76,18 +75,43 @@ public class AddMediaLibraryRequestMappingTests
|
||||
"F:/Reading Material"
|
||||
];
|
||||
|
||||
Guid userId = Guid.NewGuid();
|
||||
AddLibraryRequest request = new(
|
||||
"My Library",
|
||||
"Book",
|
||||
contentLocations
|
||||
contentLocations,
|
||||
"D:/poster.jpg"
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand(userId);
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.ContentLocations.Should().BeEquivalentTo(contentLocations);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCommand_WhenMappingWithNullCover_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
string[] contentLocations =
|
||||
[
|
||||
"C:/Media/Books",
|
||||
"D:/Books"
|
||||
];
|
||||
|
||||
AddLibraryRequest request = new(
|
||||
"My Library",
|
||||
"Book",
|
||||
contentLocations,
|
||||
null
|
||||
);
|
||||
|
||||
// Act
|
||||
AddLibraryCommand result = request.ToCommand();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.CoverImage.Should().BeNull();
|
||||
}
|
||||
}
|
||||
+32
@@ -32,6 +32,7 @@ public class LibraryEntityMappingTests
|
||||
new() { Path = "C:/Books" },
|
||||
new() { Path = "D:/Media/Books" }
|
||||
],
|
||||
CoverImage = "D:/myPoster.jpg",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = null,
|
||||
@@ -48,6 +49,7 @@ public class LibraryEntityMappingTests
|
||||
result.Title.Should().Be(entity.Title);
|
||||
result.LibraryType.Should().Be(entity.LibraryType);
|
||||
result.ContentLocations.Should().BeEquivalentTo(entity.ContentLocations.Select(l => l.Path));
|
||||
result.CoverImage.Should().Be(entity.CoverImage);
|
||||
result.CreatedOnUtc.Should().Be(entity.CreatedOnUtc);
|
||||
result.UpdatedOnUtc.Should().Be(entity.UpdatedOnUtc);
|
||||
}
|
||||
@@ -67,6 +69,7 @@ public class LibraryEntityMappingTests
|
||||
Title = "My Library",
|
||||
LibraryType = libraryType,
|
||||
ContentLocations = [new() { Path = "C:/Media" }],
|
||||
CoverImage = "D:/myPoster.jpg",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = null,
|
||||
@@ -98,6 +101,7 @@ public class LibraryEntityMappingTests
|
||||
new() { Path = "E:/Digital Library/Books" },
|
||||
new() { Path = "F:/Reading Material" }
|
||||
],
|
||||
CoverImage = "D:/myPoster.jpg",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = null,
|
||||
@@ -124,6 +128,7 @@ public class LibraryEntityMappingTests
|
||||
Title = "My Library",
|
||||
LibraryType = LibraryType.Book,
|
||||
ContentLocations = [new() { Path = "C:/Books" }],
|
||||
CoverImage = "D:/myPoster.jpg",
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = updated,
|
||||
@@ -137,4 +142,31 @@ public class LibraryEntityMappingTests
|
||||
result.Should().NotBeNull();
|
||||
result.UpdatedOnUtc.Should().Be(updated);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToResponse_WhenMappingWithNullCoverImage_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
DateTime updated = DateTime.UtcNow.AddDays(-1);
|
||||
LibraryEntity entity = new()
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserId = Guid.NewGuid(),
|
||||
Title = "My Library",
|
||||
LibraryType = LibraryType.Book,
|
||||
ContentLocations = [new() { Path = "C:/Books" }],
|
||||
CoverImage = null,
|
||||
CreatedOnUtc = DateTime.UtcNow,
|
||||
CreatedBy = Guid.NewGuid(),
|
||||
UpdatedOnUtc = updated,
|
||||
UpdatedBy = Guid.NewGuid()
|
||||
};
|
||||
|
||||
// Act
|
||||
LibraryResponse result = entity.ToResponse();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.CoverImage.Should().BeNull();
|
||||
}
|
||||
}
|
||||
+41
-4
@@ -29,7 +29,8 @@ public class LibraryMappingTests
|
||||
Guid.NewGuid(),
|
||||
"Test Library",
|
||||
LibraryType.Book,
|
||||
["C:/Books", "D:/Media/Books"]
|
||||
["C:/Books", "D:/Media/Books"],
|
||||
"D:/myPoster.jpg"
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
@@ -44,6 +45,7 @@ public class LibraryMappingTests
|
||||
result.LibraryType.Should().Be(library.LibraryType);
|
||||
result.ContentLocations.Select(l => l.Path)
|
||||
.Should().BeEquivalentTo(library.ContentLocations.Select(l => l.Path));
|
||||
result.CoverImage.Should().BeEquivalentTo(library.CoverImage);
|
||||
result.CreatedOnUtc.Should().Be(library.CreatedOnUtc);
|
||||
result.UpdatedOnUtc.Should().Be(library.UpdatedOnUtc.HasValue ? library.UpdatedOnUtc : null);
|
||||
}
|
||||
@@ -56,7 +58,8 @@ public class LibraryMappingTests
|
||||
Guid.NewGuid(),
|
||||
"Empty Library",
|
||||
LibraryType.Book,
|
||||
[]
|
||||
[],
|
||||
"D:/myPoster.jpg"
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
@@ -66,6 +69,7 @@ public class LibraryMappingTests
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.ContentLocations.Should().BeEmpty();
|
||||
result.CoverImage.Should().BeEquivalentTo(library.CoverImage);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -80,7 +84,8 @@ public class LibraryMappingTests
|
||||
Guid.NewGuid(),
|
||||
"Test Library",
|
||||
libraryType,
|
||||
["C:/Media"]
|
||||
["C:/Media"],
|
||||
"D:/myPoster.jpg"
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
@@ -90,6 +95,7 @@ public class LibraryMappingTests
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.LibraryType.Should().Be(libraryType);
|
||||
result.CoverImage.Should().BeEquivalentTo(library.CoverImage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -108,7 +114,8 @@ public class LibraryMappingTests
|
||||
Guid.NewGuid(),
|
||||
"Test Library",
|
||||
LibraryType.Book,
|
||||
contentLocations
|
||||
contentLocations,
|
||||
"D:/myPoster.jpg"
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
@@ -119,5 +126,35 @@ public class LibraryMappingTests
|
||||
result.Should().NotBeNull();
|
||||
result.ContentLocations.Select(l => l.Path)
|
||||
.Should().BeEquivalentTo(library.ContentLocations.Select(l => l.Path));
|
||||
result.CoverImage.Should().BeEquivalentTo(library.CoverImage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToRepositoryEntity_WhenMappingNullCoverimage_ShouldMapCorrectly()
|
||||
{
|
||||
// Arrange
|
||||
List<string> contentLocations =
|
||||
[
|
||||
"C:/Media/Books",
|
||||
"D:/Books"
|
||||
];
|
||||
|
||||
ErrorOr<Library> libraryResult = Library.Create(
|
||||
Guid.NewGuid(),
|
||||
"Test Library",
|
||||
LibraryType.Book,
|
||||
contentLocations,
|
||||
null
|
||||
);
|
||||
Library library = libraryResult.Value;
|
||||
|
||||
// Act
|
||||
LibraryEntity result = library.ToRepositoryEntity();
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result.ContentLocations.Select(l => l.Path)
|
||||
.Should().BeEquivalentTo(library.ContentLocations.Select(l => l.Path));
|
||||
result.CoverImage.Should().BeNull();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user