Returns the unit of work save changes result

This commit is contained in:
BinaryAlley committed 2026-09-26 12:59:17 +03:00
1 parent f3e465255e
commit 64ef3a1e22
141 files changed
+1388 -1151

No files matched your search

@@ -40,6 +40,7 @@ public class AuthorizationServiceTests
public AuthorizationServiceTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockUserRepository = Substitute.For<IUserRepository>();
_mockAuthorizationPolicyFactory = Substitute.For<IAuthorizationPolicyFactory>();
@@ -53,7 +54,7 @@ public class AuthorizationServiceTests
{
// Arrange
Guid userId = Guid.NewGuid();
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(null));
// Act
@@ -61,7 +62,7 @@ public class AuthorizationServiceTests
// Assert
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -70,7 +71,7 @@ public class AuthorizationServiceTests
// Arrange
Guid userId = Guid.NewGuid();
Error error = Error.Failure("Database.Error", "Failed to retrieve user");
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(error);
// Act
@@ -78,7 +79,7 @@ public class AuthorizationServiceTests
// Assert
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -88,7 +89,7 @@ public class AuthorizationServiceTests
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
directPermissions: [AuthorizationPermission.CanViewUsers]);
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -96,7 +97,7 @@ public class AuthorizationServiceTests
// Assert
Assert.True(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -111,7 +112,7 @@ public class AuthorizationServiceTests
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
rolePermissions: rolePermissions);
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -119,7 +120,7 @@ public class AuthorizationServiceTests
// Assert
Assert.True(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -128,7 +129,7 @@ public class AuthorizationServiceTests
// Arrange
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions();
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -136,7 +137,7 @@ public class AuthorizationServiceTests
// Assert
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -146,7 +147,7 @@ public class AuthorizationServiceTests
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
directPermissions: [AuthorizationPermission.CanDeleteUsers]);
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -154,7 +155,7 @@ public class AuthorizationServiceTests
// Assert
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -170,7 +171,7 @@ public class AuthorizationServiceTests
directPermissions: [AuthorizationPermission.CanViewUsers],
rolePermissions: rolePermissions);
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -178,7 +179,7 @@ public class AuthorizationServiceTests
// Assert
Assert.True(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -186,7 +187,7 @@ public class AuthorizationServiceTests
{
// Arrange
Guid userId = Guid.NewGuid();
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(null));
// Act
@@ -194,7 +195,7 @@ public class AuthorizationServiceTests
// Assert
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -203,7 +204,7 @@ public class AuthorizationServiceTests
// Arrange
Guid userId = Guid.NewGuid();
Error error = Error.Failure("Database.Error", "Failed to retrieve user");
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(error);
// Act
@@ -211,7 +212,7 @@ public class AuthorizationServiceTests
// Assert
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -226,7 +227,7 @@ public class AuthorizationServiceTests
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
rolePermissions: rolePermissions);
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -234,7 +235,7 @@ public class AuthorizationServiceTests
// Assert
Assert.True(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -249,7 +250,7 @@ public class AuthorizationServiceTests
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
rolePermissions: rolePermissions);
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -257,7 +258,7 @@ public class AuthorizationServiceTests
// Assert
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -266,7 +267,7 @@ public class AuthorizationServiceTests
// Arrange
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions();
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -274,7 +275,7 @@ public class AuthorizationServiceTests
// Assert
Assert.False(result);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -409,7 +410,7 @@ public class AuthorizationServiceTests
{
// Arrange
Guid userId = Guid.NewGuid();
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(null));
// Act
@@ -418,7 +419,7 @@ public class AuthorizationServiceTests
// Assert
Assert.True(result.IsFailure);
Assert.Equal(Errors.Users.UserDoesNotExist, result.FirstError);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -427,7 +428,7 @@ public class AuthorizationServiceTests
// Arrange
Guid userId = Guid.NewGuid();
Error error = Error.Failure("Database.Error", "Failed to retrieve user");
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(error);
// Act
@@ -436,7 +437,7 @@ public class AuthorizationServiceTests
// Assert
Assert.True(result.IsFailure);
Assert.Equal(error, result.FirstError);
await _mockUserRepository.Received(1).GetByIdAsync(userId, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -444,7 +445,7 @@ public class AuthorizationServiceTests
{
// Arrange
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions();
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -455,7 +456,7 @@ public class AuthorizationServiceTests
Assert.Equal(user.Id, result.Value.UserId);
Assert.Null(result.Value.Role);
Assert.Empty(result.Value.Permissions);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -469,7 +470,7 @@ public class AuthorizationServiceTests
AuthorizationPermission.CanDeleteUsers
]);
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -481,7 +482,7 @@ public class AuthorizationServiceTests
Assert.Null(result.Value.Role);
Assert.Equal([AuthorizationPermission.CanViewUsers, AuthorizationPermission.CanDeleteUsers],
result.Value.Permissions);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -499,7 +500,7 @@ public class AuthorizationServiceTests
UserEntity user = _authorizationServiceFixture.CreateUserWithPermissions(
rolePermissions: rolePermissions);
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -511,7 +512,7 @@ public class AuthorizationServiceTests
Assert.Equal("Admin", result.Value.Role);
Assert.Equal([AuthorizationPermission.CanViewUsers, AuthorizationPermission.CanDeleteUsers],
result.Value.Permissions);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -530,7 +531,7 @@ public class AuthorizationServiceTests
directPermissions: [AuthorizationPermission.CanRegisterUsers],
rolePermissions: rolePermissions);
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -549,6 +550,6 @@ public class AuthorizationServiceTests
},
result.Value.Permissions
);
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, Arg.Any<CancellationToken>());
await _mockUserRepository.Received(1).GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>());
}
}
@@ -40,6 +40,7 @@ public class LibraryOwnershipPolicyTests
public LibraryOwnershipPolicyTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockUserRepository = Substitute.For<IUserRepository>();
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
_mockUnitOfWork.UserRepository.Returns(_mockUserRepository);
@@ -59,8 +60,8 @@ public class LibraryOwnershipPolicyTests
// Assert
Assert.False(result);
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockUserRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -69,7 +70,7 @@ public class LibraryOwnershipPolicyTests
// Arrange
Guid userId = Guid.NewGuid();
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(null));
// Act
@@ -77,7 +78,7 @@ public class LibraryOwnershipPolicyTests
// Assert
Assert.False(result);
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -86,7 +87,7 @@ public class LibraryOwnershipPolicyTests
// Arrange
Guid userId = Guid.NewGuid();
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to retrieve user"));
// Act
@@ -94,7 +95,7 @@ public class LibraryOwnershipPolicyTests
// Assert
Assert.False(result);
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -107,7 +108,7 @@ public class LibraryOwnershipPolicyTests
{ "Admin", [] }
});
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
_mockUserRepository.GetByIdAsync(adminUser.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(adminUser.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(adminUser));
// Act
@@ -115,7 +116,7 @@ public class LibraryOwnershipPolicyTests
// Assert
Assert.True(result);
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>());
await _mockLibraryRepository.DidNotReceive().GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -125,9 +126,9 @@ public class LibraryOwnershipPolicyTests
Guid userId = Guid.NewGuid();
UserEntity regularUser = _authorizationServiceFixture.CreateUserWithPermissions();
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(regularUser));
_mockLibraryRepository.GetByIdAsync(context.LibraryId, Arg.Any<CancellationToken>())
_mockLibraryRepository.GetByIdAsync(context.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result<LibraryEntity?>.Success(null));
// Act
@@ -144,9 +145,9 @@ public class LibraryOwnershipPolicyTests
Guid userId = Guid.NewGuid();
UserEntity regularUser = _authorizationServiceFixture.CreateUserWithPermissions();
LibraryOwnershipPolicyContext context = new(Guid.NewGuid());
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(regularUser));
_mockLibraryRepository.GetByIdAsync(context.LibraryId, Arg.Any<CancellationToken>())
_mockLibraryRepository.GetByIdAsync(context.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to retrieve library"));
// Act
@@ -164,9 +165,9 @@ public class LibraryOwnershipPolicyTests
UserEntity regularUser = _authorizationServiceFixture.CreateUserWithPermissions();
LibraryEntity library = _libraryEntityFixture.Create(userId: userId);
LibraryOwnershipPolicyContext context = new(library.Id);
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(regularUser));
_mockLibraryRepository.GetByIdAsync(context.LibraryId, Arg.Any<CancellationToken>())
_mockLibraryRepository.GetByIdAsync(context.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(library));
// Act
@@ -184,9 +185,9 @@ public class LibraryOwnershipPolicyTests
UserEntity regularUser = _authorizationServiceFixture.CreateUserWithPermissions();
LibraryEntity library = _libraryEntityFixture.Create(userId: Guid.NewGuid());
LibraryOwnershipPolicyContext context = new(library.Id);
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(regularUser));
_mockLibraryRepository.GetByIdAsync(context.LibraryId, Arg.Any<CancellationToken>())
_mockLibraryRepository.GetByIdAsync(context.LibraryId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(library));
// Act
@@ -32,6 +32,7 @@ public class Over18PolicyTests
public Over18PolicyTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockUserRepository = Substitute.For<IUserRepository>();
_mockUnitOfWork.UserRepository.Returns(_mockUserRepository);
@@ -43,7 +44,7 @@ public class Over18PolicyTests
{
// Arrange
UserEntity user = _userEntityFixture.Create();
_mockUserRepository.GetByIdAsync(user.Id, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(user.Id, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(user));
// Act
@@ -58,7 +59,7 @@ public class Over18PolicyTests
{
// Arrange
Guid userId = Guid.NewGuid();
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<UserEntity?>(null));
// Act
@@ -73,7 +74,7 @@ public class Over18PolicyTests
{
// Arrange
Guid userId = Guid.NewGuid();
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to retrieve user"));
// Act
@@ -88,7 +89,7 @@ public class Over18PolicyTests
{
// Arrange
Guid userId = Guid.NewGuid();
_mockUserRepository.GetByIdAsync(userId, Arg.Any<CancellationToken>())
_mockUserRepository.GetByIdAsync(userId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result<UserEntity?>.Success(null));
// Act
@@ -2,7 +2,7 @@
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
using Lumina.Application.Common.DataAccess.UoW;
@@ -139,7 +139,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
"Test Title",
Arg.Any<ArtworkDto>(),
Arg.Any<CancellationToken>());
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkType.Cover, coverArtwork.ArtworkType);
Assert.Equal(0, coverArtwork.Ordinal);
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
@@ -168,7 +168,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
SetupRealServiceProvider(artworkPluginId, artworkProvider, mockBookArtworkService, mockFileHashService);
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
// the book already has a stored cover with the same content hash as the resolved artwork
book.BookArtwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 123ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
book.Artwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 123ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
SetupSingleBookPage(book, artworkPluginId);
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
@@ -179,7 +179,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
// Assert
// the identical artwork is not copied again, so the artwork storage service is not called and the stored file name is kept
await mockBookArtworkService.DidNotReceive().SaveBookArtworkAsync(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<ArtworkDto>(), Arg.Any<CancellationToken>());
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
Assert.Equal("existing\\cover.jpeg", coverArtwork.FileName);
Assert.Equal("Artwork Provider", coverArtwork.Provider);
@@ -212,7 +212,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
// Assert
await mockBookArtworkService.DidNotReceive().SaveBookArtworkAsync(Arg.Any<Guid>(), Arg.Any<Guid>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), Arg.Any<ArtworkDto>(), Arg.Any<CancellationToken>());
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkType.Cover, coverArtwork.ArtworkType);
Assert.Equal(0, coverArtwork.Ordinal);
Assert.Equal(ArtworkStatus.Failed, coverArtwork.Status);
@@ -226,7 +226,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
// Arrange
_mockArtworkConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -330,7 +330,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
_mockServiceScopeFactory.CreateAsyncScope().Returns(asyncServiceScope);
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: false)));
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
@@ -346,7 +346,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -354,7 +354,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
// Assert
// the provider that requires access to the web is skipped when the library does not permit web downloads
await webProvider.DidNotReceive().GetArtworkAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>());
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
Assert.Equal("Local Provider", coverArtwork.Provider);
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
@@ -377,7 +377,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
.Returns(Result.From<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>>([_artworkConfigurationEntityFixture.Create(_libraryId.Value, artworkPluginId, 1)]));
_mockBookRepository.GetBooksNeedingArtworkCountAsync(_libraryId.Value, Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to count the books that need artwork"));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -405,7 +405,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
.Returns(Result.From(1));
_mockBookRepository.GetBooksNeedingArtworkAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to get the books that need artwork"));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -429,7 +429,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: true)));
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
_mockArtworkConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
@@ -440,7 +440,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to get the author display names"));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -465,7 +465,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
SetupRealServiceProvider(artworkPluginId, artworkProvider, mockBookArtworkService, mockFileHashService);
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
book.BookArtwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 123ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
book.Artwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 123ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
SetupSingleBookPage(book, artworkPluginId);
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
@@ -474,7 +474,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
// Assert
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkStatus.Failed, coverArtwork.Status);
Assert.Equal("existing\\cover.jpeg", coverArtwork.FileName);
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
@@ -507,7 +507,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
// Assert
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkStatus.Failed, coverArtwork.Status);
Assert.Null(coverArtwork.FileName);
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
@@ -532,7 +532,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
SetupRealServiceProvider(artworkPluginId, artworkProvider, mockBookArtworkService, mockFileHashService);
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
book.BookArtwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 111ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
book.Artwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 111ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
SetupSingleBookPage(book, artworkPluginId);
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
@@ -541,7 +541,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
// Assert
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkStatus.Failed, coverArtwork.Status);
Assert.Equal("existing\\cover.jpeg", coverArtwork.FileName);
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
@@ -577,7 +577,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
// Assert
// for remote artwork, the content hash is computed on the stored copy, so it is only known after the artwork is stored
await mockBookArtworkService.Received(1).SaveBookArtworkAsync(_libraryId.Value, book.Id, "My Library", "Frank Herbert", Arg.Any<string>(), Arg.Any<ArtworkDto>(), Arg.Any<CancellationToken>());
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
Assert.Equal("\\media\\books\\Library\\Author\\Title\\cover.jpeg", coverArtwork.FileName);
Assert.Equal(999ul, coverArtwork.ContentHash);
@@ -605,7 +605,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
SetupRealServiceProvider(artworkPluginId, artworkProvider, mockBookArtworkService, mockFileHashService);
// the book has no known ISBNs of its own, so the artwork lookup is built without an ISBN
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub", title: "Test Title", includeMetadata: false);
book.BookArtwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 111ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
book.Artwork = [_bookArtworkEntityFixture.Create(bookId: book.Id, artworkType: ArtworkType.Cover, ordinal: 0, fileName: "existing\\cover.jpeg", contentHash: 111ul, status: ArtworkStatus.Pending, provider: "Old Provider", lastUpdateUtc: DateTime.UtcNow.AddDays(-1))];
SetupSingleBookPage(book, artworkPluginId);
// the author of the book is not known, so its artwork directory falls back to an empty author name
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
@@ -623,7 +623,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
"Test Title",
Arg.Any<ArtworkDto>(),
Arg.Any<CancellationToken>());
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
Assert.Equal("\\media\\books\\Library\\Author\\Title\\cover.jpeg", coverArtwork.FileName);
Assert.Equal(222ul, coverArtwork.ContentHash);
@@ -669,7 +669,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: true)));
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
@@ -682,7 +682,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
.Returns(Result.From(1));
_mockBookRepository.GetBooksNeedingArtworkAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
@@ -691,7 +691,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
// Assert
// a failing artwork provider must not prevent the artwork of the other provider from being used
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
Assert.Equal("Second Provider", coverArtwork.Provider);
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
@@ -735,7 +735,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
BookEntity book = _bookEntityFixture.Create(libraryId: _libraryId.Value, path: "/books/test.epub");
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: true)));
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
@@ -748,7 +748,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
.Returns(Result.From(1));
_mockBookRepository.GetBooksNeedingArtworkAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockBookRepository.GetAuthorsDisplayNamesByBookIdsAsync(Arg.Any<IReadOnlyCollection<Guid>>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyDictionary<Guid, string?>>(new Dictionary<Guid, string?> { [book.Id] = "Frank Herbert" }));
@@ -757,7 +757,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
// Assert
// a provider that returns remote artwork must require web access, so its artwork is skipped and the next provider is used
BookArtworkEntity coverArtwork = Assert.Single(book.BookArtwork);
BookArtworkEntity coverArtwork = Assert.Single(book.Artwork);
Assert.Equal(ArtworkStatus.Enriched, coverArtwork.Status);
Assert.Equal("Second Provider", coverArtwork.Provider);
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
@@ -769,7 +769,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
// Arrange
_mockArtworkConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<LibraryArtworkProviderConfigurationEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
IMediaLibraryScanJob mockChildJob = Substitute.For<IMediaLibraryScanJob>();
mockChildJob.ExecuteAsync(Arg.Any<Guid>(), Arg.Any<object>(), Arg.Any<CancellationToken>())
@@ -815,7 +815,7 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
private void SetupSingleBookPage(BookEntity book, Guid artworkPluginId)
{
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(id: _libraryId.Value, title: "My Library", canDownloadMetadataFromWeb: true)));
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
@@ -827,6 +827,6 @@ public class MediaLibraryScanArtworkEnrichmentJobTests
.Returns(Result.From(1));
_mockBookRepository.GetBooksNeedingArtworkAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
}
}
@@ -55,6 +55,7 @@ public class MediaLibraryScanDiffJobTests
_mockServiceScope.ServiceProvider.Returns(_mockServiceProvider);
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockStagingResultsRepository = Substitute.For<ILibraryScanStagingResultsRepository>();
_mockUnitOfWork.LibraryScanStagingResultsRepository.Returns(_mockStagingResultsRepository);
_mockServiceProvider.GetService(typeof(IUnitOfWork)).Returns(_mockUnitOfWork);
@@ -62,6 +62,7 @@ public class MediaLibraryScanHashJobTests
_mockServiceScope.ServiceProvider.Returns(_mockServiceProvider);
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockStagingResultsRepository = Substitute.For<ILibraryScanStagingResultsRepository>();
_mockUnitOfWork.LibraryScanStagingResultsRepository.Returns(_mockStagingResultsRepository);
_mockServiceProvider.GetService(typeof(IUnitOfWork)).Returns(_mockUnitOfWork);
@@ -4,7 +4,7 @@ using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
using Lumina.Application.Common.DataAccess.Repositories.MediaContributors;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
@@ -127,7 +127,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
.Returns(Result.From(0));
_mockBookRepository.GetBooksNeedingMetadataAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<BookEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -144,7 +144,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
// Arrange
_mockConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -339,8 +339,8 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
IMetadataProvider firstProvider = Substitute.For<IMetadataProvider>();
firstProvider.Name.Returns("First Provider");
firstProvider.SupportedLibraryTypes.Returns([LibraryType.Book]);
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", roleName: "Author", roleCategory: MediaContributorRoleCategory.Author);
MediaContributorDto translator = _mediaContributorDtoFixture.Create(displayName: "Jane Translator", roleName: "Translator", roleCategory: MediaContributorRoleCategory.Translator);
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", role: MediaContributorRole.Author);
MediaContributorDto translator = _mediaContributorDtoFixture.Create(displayName: "Jane Translator", role: MediaContributorRole.Translator);
firstProvider.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
.Returns(_bookMetadataDtoFixture.Create(title: "First Title", contributors: [author, translator]));
@@ -362,15 +362,13 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
await _mockMediaContributorRepository.Received(1).FindOrCreateByDisplayNameAsync("Frank Herbert", Arg.Any<string?>(), Arg.Any<CancellationToken>());
await _mockMediaContributorRepository.Received(1).FindOrCreateByDisplayNameAsync("Jane Translator", Arg.Any<string?>(), Arg.Any<CancellationToken>());
// the participation rows are replaced on the entity, carrying the role and the category of each contributor
Assert.Equal(2, book.BookContributors.Count);
BookContributorEntity linkedAuthor = Assert.Single(book.BookContributors, contributor => contributor.MediaContributorId == authorEntity.Id);
Assert.Equal("Author", linkedAuthor.RoleName);
Assert.Equal(MediaContributorRoleCategory.Author, linkedAuthor.RoleCategory);
// the participation rows are replaced on the entity, carrying the canonical role of each contributor
Assert.Equal(2, book.Contributors.Count);
BookContributorEntity linkedAuthor = Assert.Single(book.Contributors, contributor => contributor.MediaContributorId == authorEntity.Id);
Assert.Equal(MediaContributorRole.Author, linkedAuthor.Role);
Assert.Equal(book.Id, linkedAuthor.BookId);
BookContributorEntity linkedTranslator = Assert.Single(book.BookContributors, contributor => contributor.MediaContributorId == translatorEntity.Id);
Assert.Equal("Translator", linkedTranslator.RoleName);
Assert.Equal(MediaContributorRoleCategory.Translator, linkedTranslator.RoleCategory);
BookContributorEntity linkedTranslator = Assert.Single(book.Contributors, contributor => contributor.MediaContributorId == translatorEntity.Id);
Assert.Equal(MediaContributorRole.Translator, linkedTranslator.Role);
Assert.Equal(MetadataStatus.Enriched, book.MetadataStatus);
}
@@ -382,7 +380,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
IMetadataProvider firstProvider = Substitute.For<IMetadataProvider>();
firstProvider.Name.Returns("First Provider");
firstProvider.SupportedLibraryTypes.Returns([LibraryType.Book]);
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", roleName: "Author", roleCategory: MediaContributorRoleCategory.Author);
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", role: MediaContributorRole.Author);
firstProvider.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
.Returns(_bookMetadataDtoFixture.Create(title: "First Title", contributors: [author]));
@@ -396,7 +394,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
.Returns(Result.From(2));
_mockBookRepository.GetBooksNeedingMetadataAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<BookEntity>>([firstBook, secondBook]), Result.From<IReadOnlyList<BookEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
MediaContributorEntity authorEntity = _mediaContributorEntityFixture.Create(displayName: "Frank Herbert");
_mockMediaContributorRepository.FindOrCreateByDisplayNameAsync("Frank Herbert", Arg.Any<string?>(), Arg.Any<CancellationToken>())
@@ -408,10 +406,10 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
// Assert
// the contributor cache of the page guarantees a single contributor per person, so the repository is queried only once
await _mockMediaContributorRepository.Received(1).FindOrCreateByDisplayNameAsync("Frank Herbert", Arg.Any<string?>(), Arg.Any<CancellationToken>());
Assert.Single(firstBook.BookContributors);
Assert.Single(secondBook.BookContributors);
Assert.Equal(authorEntity.Id, firstBook.BookContributors[0].MediaContributorId);
Assert.Equal(authorEntity.Id, secondBook.BookContributors[0].MediaContributorId);
Assert.Single(firstBook.Contributors);
Assert.Single(secondBook.Contributors);
Assert.Equal(authorEntity.Id, firstBook.Contributors[0].MediaContributorId);
Assert.Equal(authorEntity.Id, secondBook.Contributors[0].MediaContributorId);
}
[Fact]
@@ -435,7 +433,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
SetupRealServiceProviderForProviders(localPluginId, localProvider, webPluginId, webProvider, shouldAggregateMetadataWhenMissing: false);
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(title: "My Library", canDownloadMetadataFromWeb: false)));
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
@@ -473,7 +471,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
SetupRealServiceProviderForProviders(localPluginId, localProvider, webPluginId, webProvider, shouldAggregateMetadataWhenMissing: false);
ILibraryRepository mockLibraryRepository = Substitute.For<ILibraryRepository>();
mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(_libraryEntityFixture.Create(title: "My Library", canDownloadMetadataFromWeb: true)));
_mockUnitOfWork.LibraryRepository.Returns(mockLibraryRepository);
@@ -503,7 +501,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([_configurationEntityFixture.Create(_libraryId.Value, firstPluginId, 1)]));
_mockBookRepository.GetBooksNeedingMetadataCountAsync(_libraryId.Value, Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to count the books to enrich"));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -528,7 +526,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
.Returns(Result.From(1));
_mockBookRepository.GetBooksNeedingMetadataAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to get the books to enrich"));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -607,7 +605,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
IMetadataProvider firstProvider = Substitute.For<IMetadataProvider>();
firstProvider.Name.Returns("First Provider");
firstProvider.SupportedLibraryTypes.Returns([LibraryType.Book]);
MediaContributorDto namelessContributor = _mediaContributorDtoFixture.Create(roleName: "Author", roleCategory: MediaContributorRoleCategory.Author) with { Name = null };
MediaContributorDto namelessContributor = _mediaContributorDtoFixture.Create(role: MediaContributorRole.Author) with { Name = null };
firstProvider.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
.Returns(_bookMetadataDtoFixture.Create(title: "First Title", contributors: [namelessContributor]));
@@ -621,7 +619,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
// Assert
// a contributor without a display name cannot be linked to the book, so no contributor is queried or created
await _mockMediaContributorRepository.DidNotReceive().FindOrCreateByDisplayNameAsync(Arg.Any<string>(), Arg.Any<string?>(), Arg.Any<CancellationToken>());
Assert.Empty(book.BookContributors);
Assert.Empty(book.Contributors);
Assert.Equal(MetadataStatus.Enriched, book.MetadataStatus);
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
}
@@ -650,9 +648,9 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
// Assert
BookContributorEntity linkedContributor = Assert.Single(book.BookContributors);
Assert.Equal("Contributor", linkedContributor.RoleName);
Assert.Equal(MediaContributorRoleCategory.Other, linkedContributor.RoleCategory);
// a contributor without a role is linked with the default canonical role
BookContributorEntity linkedContributor = Assert.Single(book.Contributors);
Assert.Equal(MediaContributorRole.Author, linkedContributor.Role);
Assert.Equal(MetadataStatus.Enriched, book.MetadataStatus);
Assert.Equal(LibraryScanJobStatus.Completed, _sut.Status);
}
@@ -665,7 +663,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
IMetadataProvider firstProvider = Substitute.For<IMetadataProvider>();
firstProvider.Name.Returns("First Provider");
firstProvider.SupportedLibraryTypes.Returns([LibraryType.Book]);
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", roleName: "Author", roleCategory: MediaContributorRoleCategory.Author);
MediaContributorDto author = _mediaContributorDtoFixture.Create(displayName: "Frank Herbert", role: MediaContributorRole.Author);
firstProvider.GetMetadataAsync(Arg.Any<MetadataLookupDto>(), Arg.Any<CancellationToken>())
.Returns(_bookMetadataDtoFixture.Create(title: "First Title", contributors: [author]));
@@ -689,7 +687,7 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
// Arrange
_mockConfigurationRepository.GetByLibraryIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<LibraryMetadataProviderConfigurationEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
IMediaLibraryScanJob mockChildJob = Substitute.For<IMediaLibraryScanJob>();
mockChildJob.ExecuteAsync(Arg.Any<Guid>(), Arg.Any<object>(), Arg.Any<CancellationToken>())
@@ -747,6 +745,6 @@ public class MediaLibraryScanMetadataEnrichmentJobTests
.Returns(Result.From(1));
_mockBookRepository.GetBooksNeedingMetadataAsync(_libraryId.Value, Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<BookEntity>>([book]), Result.From<IReadOnlyList<BookEntity>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
}
}
@@ -2,7 +2,7 @@
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DataAccess.Entities.UsersManagement;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
using Lumina.Application.Common.DataAccess.Repositories.Users;
@@ -219,7 +219,7 @@ public class MediaLibraryScanProviderConfigurationInvalidationJobTests
public async Task ExecuteAsync_WhenGettingTheLibraryFails_ShouldMarkJobAsFailedAndPublishFailureEvent()
{
// Arrange
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to get the media library"));
SetupConfigurations();
@@ -254,7 +254,7 @@ public class MediaLibraryScanProviderConfigurationInvalidationJobTests
public async Task ExecuteAsync_WhenLibraryDoesNotExist_ShouldMarkJobAsFailedAndPublishFailureEvent()
{
// Arrange
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(null));
// Act
@@ -413,10 +413,10 @@ public class MediaLibraryScanProviderConfigurationInvalidationJobTests
/// <param name="artworkConfigurations">The artwork provider configurations of the media library.</param>
private void SetupLibraryAndConfigurations(LibraryEntity library, List<LibraryMetadataProviderConfigurationEntity>? metadataConfigurations = null, List<LibraryArtworkProviderConfigurationEntity>? artworkConfigurations = null)
{
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, Arg.Any<CancellationToken>())
_mockLibraryRepository.GetByIdAsync(_libraryId.Value, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<LibraryEntity?>(library));
SetupConfigurations(metadataConfigurations, artworkConfigurations);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
}
/// <summary>
@@ -1,6 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Books;
using Lumina.Application.Common.DataAccess.Repositories.BookLibrary;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Domain.Common.Events;
@@ -106,7 +106,7 @@ public class MediaLibraryScanResultsSaveJobTests
.Returns(Result.From<BookEntity?>(null));
_mockBookRepository.InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.From(Result.Created));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -133,7 +133,7 @@ public class MediaLibraryScanResultsSaveJobTests
.Returns(Result.From(Result.Updated));
_mockSnapshotRepository.GetPathsAsync(_libraryId.Value, Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<string>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -158,7 +158,7 @@ public class MediaLibraryScanResultsSaveJobTests
.Returns(Result.From<IReadOnlyList<string>>(["existing.pdf"]));
_mockBookRepository.GetByPathAsync(_libraryId.Value, "existing.pdf", Arg.Any<CancellationToken>())
.Returns(Result.From<BookEntity?>(_bookEntityFixture.Create(path: "existing.pdf")));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -356,7 +356,7 @@ public class MediaLibraryScanResultsSaveJobTests
.Returns(Result.From(Result.Updated));
_mockSnapshotRepository.GetPathsAsync(_libraryId.Value, Arg.Any<CancellationToken>())
.Returns(Result.From<IReadOnlyList<string>>([]));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
IMediaLibraryScanJob mockChild = Substitute.For<IMediaLibraryScanJob>();
mockChild.ExecuteAsync(Arg.Any<Guid>(), Arg.Any<object>(), Arg.Any<CancellationToken>())
@@ -389,7 +389,7 @@ public class MediaLibraryScanResultsSaveJobTests
.Returns(Result.From<BookEntity?>(null));
_mockBookRepository.InsertAsync(Arg.Any<BookEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.From(Result.Created));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
// Act
await _sut.ExecuteAsync(Guid.NewGuid(), new { }, CancellationToken.None);
@@ -1,4 +1,4 @@
#region ========================================================================= USING =====================================================================================
#region ========================================================================= USING =====================================================================================
using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
using Lumina.Application.Common.DataAccess.UoW;
@@ -45,6 +45,7 @@ public class MediaLibraryProviderConfigurationStoreTests
public MediaLibraryProviderConfigurationStoreTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockMetadataConfigurationRepository = Substitute.For<ILibraryMetadataProviderConfigurationRepository>();
_mockArtworkConfigurationRepository = Substitute.For<IArtworkProviderConfigurationRepository>();
_mockBookReaderConfigurationRepository = Substitute.For<ILibraryBookReaderConfigurationRepository>();
@@ -4,6 +4,8 @@ using Lumina.Application.Common.DataAccess.Entities.Plugins;
using Lumina.Application.Common.DataAccess.Repositories.MediaLibrary;
using Lumina.Application.Common.DataAccess.Repositories.Plugins;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DTO.Filtering;
using Lumina.Application.Common.DTO.Pagination;
using Lumina.Application.Common.Infrastructure.Plugins;
using Lumina.Application.Fixtures.Common.DataAccess.Entities.MediaLibrary.Management;
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Plugins;
@@ -62,6 +64,7 @@ public class PluginDetectionSyncJobTests
_mockServiceScope.ServiceProvider.Returns(_mockServiceProvider);
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockPluginRepository = Substitute.For<IPluginRepository>();
_mockUnitOfWork.PluginRepository.Returns(_mockPluginRepository);
_mockLibraryRepository = Substitute.For<ILibraryRepository>();
@@ -187,8 +190,8 @@ public class PluginDetectionSyncJobTests
.Returns(Result.From(Result.Updated));
PluginEntity loadedPluginRow = _pluginEntityFixture.Create(id: loadedPlugin.Id, name: loadedPlugin.Name, loadStatus: PluginLoadStatus.Loaded);
PluginEntity stalePluginRow = _pluginEntityFixture.Create(name: "Stale Plugin", loadStatus: PluginLoadStatus.Loaded);
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From((IEnumerable<PluginEntity>)[loadedPluginRow, stalePluginRow]));
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = [loadedPluginRow, stalePluginRow], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
_mockPluginRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.Deleted);
PluginDetectionSyncJob sut = CreateSut();
@@ -213,8 +216,8 @@ public class PluginDetectionSyncJobTests
_mockPluginRepository.UpsertAsync(Arg.Any<PluginEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.From(Result.Updated));
LibraryEntity bookLibrary = _libraryEntityFixture.Create(libraryType: LibraryType.Book);
_mockLibraryRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From((IEnumerable<LibraryEntity>)[bookLibrary]));
_mockLibraryRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<LibraryEntity> { Data = [bookLibrary], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
_mockProviderConfigurationStore.EnsureProviderConfigurationsAsync(Arg.Any<Guid>(), Arg.Any<LibraryType>(), Arg.Any<CancellationToken>())
.Returns(Result.Success);
PluginDetectionSyncJob sut = CreateSut();
@@ -240,8 +243,8 @@ public class PluginDetectionSyncJobTests
assemblyName: "MyPlugin",
errorMessage: "Failed to load plugin assembly 'MyPlugin.dll': unexpected error");
PluginEntity staleLoadedRow = _pluginEntityFixture.Create(id: previouslyLoadedPlugin.Id, name: previouslyLoadedPlugin.Name, loadStatus: PluginLoadStatus.Loaded);
_mockPluginRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From((IEnumerable<PluginEntity>)[staleLoadedRow]));
_mockPluginRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<PluginEntity> { Data = [staleLoadedRow], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
_mockPluginRepository.DeleteByIdAsync(previouslyLoadedPlugin.Id, Arg.Any<CancellationToken>())
.Returns(Result.Deleted);
PluginDetectionSyncJob sut = CreateSut([loadError]);
@@ -35,6 +35,7 @@ public class PluginSettingsStoreTests
public PluginSettingsStoreTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockPluginRepository = Substitute.For<IPluginRepository>();
_mockLogger = Substitute.For<ILogger<PluginSettingsStore>>();
_mockUnitOfWork.PluginRepository.Returns(_mockPluginRepository);
@@ -49,7 +50,7 @@ public class PluginSettingsStoreTests
Guid pluginId = Guid.NewGuid();
Dictionary<string, string> expectedSettings = new() { ["ApiKey"] = "test-key", ["Enabled"] = "true" };
PluginEntity pluginEntity = _pluginEntityFixture.Create(id: pluginId, settingsJson: JsonSerializer.Serialize(expectedSettings));
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
_mockPluginRepository.GetByIdAsync(pluginId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<PluginEntity?>(pluginEntity));
// Act
@@ -66,7 +67,7 @@ public class PluginSettingsStoreTests
// Arrange
Guid pluginId = Guid.NewGuid();
PluginEntity pluginEntity = _pluginEntityFixture.Create(id: pluginId, includeSettingsJson: false);
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
_mockPluginRepository.GetByIdAsync(pluginId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<PluginEntity?>(pluginEntity));
// Act
@@ -81,7 +82,7 @@ public class PluginSettingsStoreTests
{
// Arrange
Guid pluginId = Guid.NewGuid();
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
_mockPluginRepository.GetByIdAsync(pluginId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From<PluginEntity?>(null));
// Act
@@ -96,7 +97,7 @@ public class PluginSettingsStoreTests
{
// Arrange
Guid pluginId = Guid.NewGuid();
_mockPluginRepository.GetByIdAsync(pluginId, Arg.Any<CancellationToken>())
_mockPluginRepository.GetByIdAsync(pluginId, cancellationToken: Arg.Any<CancellationToken>())
.Returns(Error.Failure("Database.Error", "Failed to retrieve the plugin"));
// Act
@@ -4,6 +4,8 @@ using Lumina.Application.Common.DataAccess.Entities.Themes;
using Lumina.Application.Common.DataAccess.Repositories.Scheduling;
using Lumina.Application.Common.DataAccess.Repositories.Themes;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DTO.Filtering;
using Lumina.Application.Common.DTO.Pagination;
using Lumina.Application.Common.Infrastructure.Themes;
using Lumina.Application.Common.Infrastructure.Time;
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Scheduling;
@@ -73,7 +75,7 @@ public class ScheduledJobSchedulerJobTests
_mockScheduledJobExecutionRepository = Substitute.For<IScheduledJobExecutionRepository>();
_mockUnitOfWork.ScheduledJobRepository.Returns(_mockScheduledJobRepository);
_mockUnitOfWork.ScheduledJobExecutionRepository.Returns(_mockScheduledJobExecutionRepository);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
_mockScheduledJobExecutionRepository.UpdateAsync(Arg.Any<ScheduledJobExecutionEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
@@ -132,7 +134,7 @@ public class ScheduledJobSchedulerJobTests
{
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
// Act
@@ -152,7 +154,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60));
// Act
@@ -169,7 +171,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60));
using CancellationTokenSource cycleCancellationTokenSource = new();
_runtimeRegistry.TryStartCycle(scheduledJobId, cycleCancellationTokenSource);
@@ -190,7 +192,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob, runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob, runningJob);
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
_mockDomainEventPublisher.When(publisher => publisher.PublishAsync(Arg.Is<ScheduledJobExecutionStartedDomainEvent>(_ => true), Arg.Any<CancellationToken>()))
@@ -213,7 +215,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
@@ -233,7 +235,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: false, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
@@ -252,7 +254,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
// Act
ScheduledJobStatus result = await InvokeAsync<ScheduledJobStatus>("ReconcileInterruptedRunAsync", scheduledJobId, CancellationToken.None);
@@ -269,7 +271,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.OnceAtStartup);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.OnceAtStartup));
// Act
@@ -288,7 +290,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.OnceAtStartup);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetActiveOrRunningAsync(Arg.Any<CancellationToken>()).Returns(new[] { activeJob });
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.OnceAtStartup));
// Act
@@ -340,7 +342,7 @@ public class ScheduledJobSchedulerJobTests
IThemeService mockThemeService = Substitute.For<IThemeService>();
mockThemeService.GetBundledThemeArchivePaths().Returns([]);
IThemeRepository mockThemeRepository = Substitute.For<IThemeRepository>();
mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
_mockUnitOfWork.ThemeRepository.Returns(mockThemeRepository);
_services[typeof(IThemeService)] = mockThemeService;
@@ -349,7 +351,7 @@ public class ScheduledJobSchedulerJobTests
// Assert
mockThemeService.Received(1).GetBundledThemeArchivePaths();
await mockThemeRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
await mockThemeRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
}
[Fact]
@@ -391,7 +393,7 @@ public class ScheduledJobSchedulerJobTests
IThemeService mockThemeService = Substitute.For<IThemeService>();
mockThemeService.GetBundledThemeArchivePaths().Returns([]);
IThemeRepository mockThemeRepository = Substitute.For<IThemeRepository>();
mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
_mockUnitOfWork.ThemeRepository.Returns(mockThemeRepository);
_services[typeof(IThemeService)] = mockThemeService;
using CancellationTokenSource cancellationTokenSource = new();
@@ -412,7 +414,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
Error error = Error.Failure("ScheduledJobs.NotFound", "Failed to read the scheduled job");
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(error);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
// Act
await InvokeAsync("RunCycleWorkerAsync", scheduledJobId, false, CancellationToken.None);
@@ -428,7 +430,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
using CancellationTokenSource cancellationTokenSource = new();
cancellationTokenSource.Cancel();
@@ -445,7 +447,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create();
Error error = Error.Failure("ScheduledJobs.NotFound", "Failed to read the scheduled job");
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(error);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(error);
// Act
await InvokeAsync("ExecuteScheduledJobRunAsync", scheduledJobId, false, CancellationToken.None);
@@ -462,7 +464,7 @@ public class ScheduledJobSchedulerJobTests
// An interval schedule whose interval is not positive cannot be converted to its domain object.
ScheduledJobEntity invalidJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 0);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(invalidJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(invalidJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(invalidJob);
// Act
await InvokeAsync("ExecuteScheduledJobRunAsync", scheduledJobId, false, CancellationToken.None);
@@ -478,7 +480,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
using CancellationTokenSource cancellationTokenSource = new();
_mockDomainEventPublisher.When(publisher => publisher.PublishAsync(Arg.Any<ScheduledJobExecutionStartedDomainEvent>(), Arg.Any<CancellationToken>()))
.Do(_ => cancellationTokenSource.Cancel());
@@ -496,7 +498,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60));
_mockTaskExecutor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>())
.Returns(Error.Failure("Task.Failed", "The task of the scheduled job failed."));
@@ -515,7 +517,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60));
_mockTaskExecutor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>())
.Returns(Task.FromException<Result<Success>>(new InvalidOperationException("The task threw.")));
@@ -533,7 +535,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
_mockTaskExecutor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>())
.Returns(Task.FromException<Result<Success>>(new OperationCanceledException()));
@@ -550,7 +552,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
using CancellationTokenSource cancellationTokenSource = new();
_mockTaskExecutor.When(executor => executor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>()))
.Do(_ => cancellationTokenSource.Cancel());
@@ -570,7 +572,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob);
Assert.True(_runtimeRegistry.TryAcquireRunSlot(scheduledJobId));
// Act
@@ -589,7 +591,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobEntity addedJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Added, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(addedJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(addedJob, runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(addedJob, runningJob);
_mockDomainEventPublisher.When(publisher => publisher.PublishAsync(Arg.Any<ScheduledJobExecutionStartedDomainEvent>(), Arg.Any<CancellationToken>()))
.Do(_ => throw new OperationCanceledException());
@@ -659,7 +661,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
@@ -681,7 +683,7 @@ public class ScheduledJobSchedulerJobTests
{
// Arrange
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create();
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>())
.Returns(Error.Failure("ScheduledJobs.NotFound", "Failed to read the scheduled job"));
// Act
@@ -697,7 +699,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Error.Failure("ScheduledJobExecutions.NotFound", "Failed to read the open execution"));
@@ -736,7 +738,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Result.From<ScheduledJobExecutionEntity?>(null));
@@ -755,7 +757,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
_mockScheduledJobRepository.UpdateAsync(Arg.Any<ScheduledJobEntity>(), Arg.Any<CancellationToken>())
@@ -775,7 +777,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
_mockScheduledJobExecutionRepository.UpdateAsync(Arg.Any<ScheduledJobExecutionEntity>(), Arg.Any<CancellationToken>())
@@ -795,10 +797,10 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.FromException(new InvalidOperationException("Save failed")));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.FromException<Result<Success>>(new InvalidOperationException("Save failed")));
// Act
ScheduledJobStatus result = await InvokeAsync<ScheduledJobStatus>("ReconcileInterruptedRunAsync", scheduledJobId, CancellationToken.None);
@@ -813,10 +815,10 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.FromException(new OperationCanceledException()));
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.FromException<Result<Success>>(new OperationCanceledException()));
// Act
ScheduledJobStatus result = await InvokeAsync<ScheduledJobStatus>("ReconcileInterruptedRunAsync", scheduledJobId, CancellationToken.None);
@@ -846,7 +848,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetActiveOrRunningAsync(Arg.Any<CancellationToken>()).Returns(new[] { runningJob });
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob);
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: false, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
@@ -868,7 +870,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(runningJob.Id);
_mockScheduledJobRepository.GetActiveOrRunningAsync(Arg.Any<CancellationToken>()).Returns(new[] { runningJob });
// The first read reconciles the interrupted run while the job is still running; the reads made by the resumed cycle observe the reconciled active status.
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob, activeJob, activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(runningJob, activeJob, activeJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(_scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.OnceAtStartup));
ScheduledJobExecutionEntity openExecution = _scheduledJobExecutionEntityFixture.Create(scheduledJobId: runningJob.Id, isCycleRun: false, wasCycleActive: true, completedOnUtc: null);
_mockScheduledJobExecutionRepository.GetOpenByScheduledJobIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(openExecution);
@@ -888,7 +890,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetActiveOrRunningAsync(Arg.Any<CancellationToken>()).Returns(new[] { activeJob });
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
// Act
await InvokeAsync("ResumeActiveCyclesAsync", CancellationToken.None);
@@ -907,7 +909,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
RegisterDateTimeProvider();
IScheduledJobCycleTicker mockCycleTicker = Substitute.For<IScheduledJobCycleTicker>();
@@ -931,7 +933,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobEntity dailyJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.DailyAtHourAndMinute, hour: 10, minute: 30);
ScheduledJobEntity runningDailyJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.DailyAtHourAndMinute, hour: 10, minute: 30);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(dailyJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(dailyJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(dailyJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningDailyJob);
RegisterDateTimeProvider();
IScheduledJobCycleTicker mockCycleTicker = Substitute.For<IScheduledJobCycleTicker>();
@@ -955,7 +957,7 @@ public class ScheduledJobSchedulerJobTests
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobEntity runningJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Running, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdWithoutTrackingAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(runningJob);
RegisterDateTimeProvider();
_mockTaskExecutor.ExecutePayloadAsync(Arg.Any<ScheduledJob>(), Arg.Any<CancellationToken>())
@@ -981,7 +983,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
RegisterDateTimeProvider();
using CancellationTokenSource cancellationTokenSource = new();
cancellationTokenSource.Cancel();
@@ -1000,7 +1002,7 @@ public class ScheduledJobSchedulerJobTests
// Arrange
ScheduledJobEntity activeJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 60);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(activeJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(activeJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(activeJob);
RegisterDateTimeProvider();
IScheduledJobCycleTicker mockCycleTicker = Substitute.For<IScheduledJobCycleTicker>();
mockCycleTicker.WaitForNextTickAsync(Arg.Any<CancellationToken>())
@@ -1038,7 +1040,7 @@ public class ScheduledJobSchedulerJobTests
// An interval schedule whose interval is not positive cannot be converted to its domain object.
ScheduledJobEntity invalidJob = _scheduledJobEntityFixture.Create(status: ScheduledJobStatus.Active, scheduleType: ScheduleType.WithIntervalInMinutes, intervalMinutes: 0);
ScheduledJobId scheduledJobId = _scheduledJobIdFixture.Create(invalidJob.Id);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(invalidJob);
_mockScheduledJobRepository.GetByIdAsync(Arg.Any<Guid>(), cancellationToken: Arg.Any<CancellationToken>()).Returns(invalidJob);
// Act
Schedule? result = await InvokeAsync<Schedule?>("GetScheduleAsync", scheduledJobId, CancellationToken.None);
@@ -37,6 +37,7 @@ public class CleanScheduledJobExecutionHistoryTaskExecutorTests
{
_mockDateTimeProvider = Substitute.For<IDateTimeProvider>();
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockScheduledJobExecutionRepository = Substitute.For<IScheduledJobExecutionRepository>();
_mockDateTimeProvider.UtcNow.Returns(_fixedUtcNow);
_mockUnitOfWork.ScheduledJobExecutionRepository.Returns(_mockScheduledJobExecutionRepository);
@@ -44,7 +44,7 @@ public class MediaLibraryScanTaskExecutorTests
_mockLibraryRepository.GetAllEnabledAndUnlockedAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<LibraryEntity>>([]));
_mockUnitOfWork.LibraryRepository.Returns(_mockLibraryRepository);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockDomainEventPublisher = Substitute.For<IDomainEventPublisher>();
_sut = new MediaLibraryScanTaskExecutor(_mockDomainEventPublisher, Substitute.For<ILogger<MediaLibraryScanTaskExecutor>>(), _mockUnitOfWork);
}
@@ -2,6 +2,8 @@
using Lumina.Application.Common.DataAccess.Entities.Themes;
using Lumina.Application.Common.DataAccess.Repositories.Themes;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DTO.Filtering;
using Lumina.Application.Common.DTO.Pagination;
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
using Lumina.Application.Common.Infrastructure.Themes;
using Lumina.Domain.Common.Primitives;
@@ -42,7 +44,7 @@ public class RepairThemesTaskExecutorTests
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockThemeRepository = Substitute.For<IThemeRepository>();
_mockUnitOfWork.ThemeRepository.Returns(_mockThemeRepository);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
ILogger<RepairThemesTaskExecutor> logger = Substitute.For<ILogger<RepairThemesTaskExecutor>>();
_sut = new RepairThemesTaskExecutor(_mockThemeService, logger, _mockUnitOfWork);
}
@@ -53,14 +55,14 @@ public class RepairThemesTaskExecutorTests
// Arrange
ScheduledJob scheduledJob = _scheduledJobFixture.Create(taskType: ScheduledTaskType.RepairThemes);
_mockThemeService.GetBundledThemeArchivePaths().Returns([]);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
// Act
Result<Success> result = await _sut.ExecutePayloadAsync(scheduledJob, CancellationToken.None);
// Assert
Assert.False(result.IsFailure);
await _mockThemeRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
await _mockThemeRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -72,14 +74,14 @@ public class RepairThemesTaskExecutorTests
_mockThemeService.GetBundledThemeArchivePaths().Returns(["missing.zip"]);
_mockThemeService.ReadManifestFromArchiveAsync(Arg.Any<string>(), Arg.Any<CancellationToken>())
.Returns(Error.Failure("Theme.Manifest", "Failed to read the theme manifest"));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
// Act
Result<Success> result = await _sut.ExecutePayloadAsync(scheduledJob, CancellationToken.None);
// Assert
Assert.False(result.IsFailure);
await _mockThemeRepository.Received(1).GetAllAsync(Arg.Any<CancellationToken>());
await _mockThemeRepository.Received(1).GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>());
await _mockUnitOfWork.Received(1).SaveChangesAsync(Arg.Any<CancellationToken>());
}
@@ -88,8 +90,8 @@ public class RepairThemesTaskExecutorTests
{
// Arrange
ScheduledJob scheduledJob = _scheduledJobFixture.Create(taskType: ScheduledTaskType.RepairThemes);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Task.FromException<Result<IEnumerable<ThemeEntity>>>(new InvalidOperationException("The database is unavailable.")));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Task.FromException<Result<PaginatedResultDto<ThemeEntity>>>(new InvalidOperationException("The database is unavailable.")));
// Act
Result<Success> result = await _sut.ExecutePayloadAsync(scheduledJob, CancellationToken.None);
@@ -104,8 +106,8 @@ public class RepairThemesTaskExecutorTests
{
// Arrange
ScheduledJob scheduledJob = _scheduledJobFixture.Create(taskType: ScheduledTaskType.RepairThemes);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Task.FromException<Result<IEnumerable<ThemeEntity>>>(new OperationCanceledException()));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Task.FromException<Result<PaginatedResultDto<ThemeEntity>>>(new OperationCanceledException()));
// Act
async Task Act()
@@ -2,6 +2,8 @@
using Lumina.Application.Common.DataAccess.Entities.Themes;
using Lumina.Application.Common.DataAccess.Repositories.Themes;
using Lumina.Application.Common.DataAccess.UoW;
using Lumina.Application.Common.DTO.Filtering;
using Lumina.Application.Common.DTO.Pagination;
using Lumina.Application.Common.Infrastructure.Models.DTO.Themes;
using Lumina.Application.Common.Infrastructure.Themes;
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Themes;
@@ -46,12 +48,12 @@ public class ThemeSynchronizerTests : IDisposable
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockThemeRepository = Substitute.For<IThemeRepository>();
_mockUnitOfWork.ThemeRepository.Returns(_mockThemeRepository);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Task.CompletedTask);
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockLogger = Substitute.For<ILogger>();
_mockThemeService.GetBundledThemeArchivePaths().Returns([]);
_mockThemeService.HasThemePack(Arg.Any<string>()).Returns(true);
_mockThemeService.DefaultThemeId.Returns("lumina-default");
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(Result.From(Enumerable.Empty<ThemeEntity>()));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [], CurrentPage = 1, PerPage = 0, Count = 0, NumberOfPages = 1 }));
_mockThemeRepository.InsertAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Created);
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>()).Returns(Result.Updated);
_mockThemeRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>()).Returns(Result.Deleted);
@@ -63,7 +65,7 @@ public class ThemeSynchronizerTests : IDisposable
public async Task SynchronizeAsync_WhenTheInstalledThemesCannotBeRead_ShouldLogAndReturn()
{
// Arrange
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Error.Failure("Themes.NotFound", "Failed to read the installed themes"));
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
@@ -97,7 +99,7 @@ public class ThemeSynchronizerTests : IDisposable
// Arrange
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
ThemeEntity installedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { installedTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [installedTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
_mockThemeService.ReadManifestFromArchiveAsync("bundled.zip", Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
@@ -115,7 +117,7 @@ public class ThemeSynchronizerTests : IDisposable
// Arrange
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
ThemeEntity deletedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { deletedTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [deletedTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
_mockThemeService.GetBundledThemeArchivePaths().Returns(["bundled.zip"]);
_mockThemeService.ReadManifestFromArchiveAsync("bundled.zip", Arg.Any<CancellationToken>()).Returns(Result.From(manifest));
@@ -133,7 +135,7 @@ public class ThemeSynchronizerTests : IDisposable
// Arrange
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
ThemeEntity damagedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { damagedTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [damagedTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
string archivePath = CreateArchiveFile();
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
// The first pack check happens before the repair and reports the files as missing; the later checks report the files as present.
@@ -155,7 +157,7 @@ public class ThemeSynchronizerTests : IDisposable
// Arrange
ThemeManifestDto manifest = _themeManifestDtoFixture.Create();
ThemeEntity damagedTheme = _themeEntityFixture.Create(themeId: manifest.Id, installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { damagedTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [damagedTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
string archivePath = CreateArchiveFile();
_mockThemeService.GetBundledThemeArchivePaths().Returns([archivePath]);
_mockThemeService.HasThemePack(damagedTheme.ThemeId).Returns(false, true);
@@ -254,7 +256,7 @@ public class ThemeSynchronizerTests : IDisposable
{
// Arrange
ThemeEntity healthyTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { healthyTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [healthyTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
// Act
await ThemeSynchronizer.SynchronizeAsync(_mockThemeService, _mockUnitOfWork, _mockLogger, CancellationToken.None);
@@ -269,7 +271,7 @@ public class ThemeSynchronizerTests : IDisposable
{
// Arrange
ThemeEntity brokenTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
_mockThemeService.HasThemePack(brokenTheme.ThemeId).Returns(false);
_mockThemeService.RestoreBundledThemeAsync(brokenTheme.ThemeId, Arg.Any<CancellationToken>()).Returns(Result.Success);
@@ -287,7 +289,7 @@ public class ThemeSynchronizerTests : IDisposable
{
// Arrange
ThemeEntity lastBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { lastBundledTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [lastBundledTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
_mockThemeService.HasThemePack(lastBundledTheme.ThemeId).Returns(false);
_mockThemeService.RestoreBundledThemeAsync(lastBundledTheme.ThemeId, Arg.Any<CancellationToken>())
.Returns(Error.Failure("Theme.Restore", "Failed to restore the theme"));
@@ -306,7 +308,7 @@ public class ThemeSynchronizerTests : IDisposable
// Arrange
ThemeEntity brokenBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
ThemeEntity healthyBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenBundledTheme, healthyBundledTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenBundledTheme, healthyBundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
_mockThemeService.HasThemePack(brokenBundledTheme.ThemeId).Returns(false);
_mockThemeService.RestoreBundledThemeAsync(brokenBundledTheme.ThemeId, Arg.Any<CancellationToken>())
.Returns(Error.Failure("Theme.Restore", "Failed to restore the theme"));
@@ -326,7 +328,7 @@ public class ThemeSynchronizerTests : IDisposable
// Arrange
ThemeEntity brokenBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
ThemeEntity healthyBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenBundledTheme, healthyBundledTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenBundledTheme, healthyBundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
_mockThemeService.HasThemePack(brokenBundledTheme.ThemeId).Returns(false);
_mockThemeService.RestoreBundledThemeAsync(brokenBundledTheme.ThemeId, Arg.Any<CancellationToken>())
.Returns(Error.Failure("Theme.Restore", "Failed to restore the theme"));
@@ -346,7 +348,7 @@ public class ThemeSynchronizerTests : IDisposable
{
// Arrange
ThemeEntity brokenUserTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Uploaded, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenUserTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenUserTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
_mockThemeService.HasThemePack(brokenUserTheme.ThemeId).Returns(false);
// Act
@@ -361,7 +363,7 @@ public class ThemeSynchronizerTests : IDisposable
{
// Arrange
ThemeEntity brokenUserTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Uploaded, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenUserTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenUserTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
_mockThemeService.HasThemePack(brokenUserTheme.ThemeId).Returns(false);
_mockThemeRepository.DeleteByIdAsync(Arg.Any<Guid>(), Arg.Any<CancellationToken>())
.Returns(Error.Failure("Themes.DeleteFailed", "Failed to delete the theme"));
@@ -380,7 +382,7 @@ public class ThemeSynchronizerTests : IDisposable
// Arrange
ThemeEntity throwingBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
ThemeEntity healthyBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false, includeIsCurrent: true, isCurrent: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { throwingBundledTheme, healthyBundledTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [throwingBundledTheme, healthyBundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
_mockThemeService.HasThemePack(Arg.Any<string>()).Returns(false);
_mockThemeService.RestoreBundledThemeAsync(throwingBundledTheme.ThemeId, Arg.Any<CancellationToken>())
.Returns(Task.FromException<Result<Success>>(new InvalidOperationException("Unexpected failure")));
@@ -401,7 +403,7 @@ public class ThemeSynchronizerTests : IDisposable
{
// Arrange
ThemeEntity brokenBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>()).Returns(new[] { brokenBundledTheme });
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>()).Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [brokenBundledTheme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
_mockThemeService.HasThemePack(brokenBundledTheme.ThemeId).Returns(false);
_mockThemeService.RestoreBundledThemeAsync(brokenBundledTheme.ThemeId, Arg.Any<CancellationToken>())
.Returns(Task.FromException<Result<Success>>(new OperationCanceledException()));