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

@@ -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.Authentication;
using Lumina.Application.Common.Infrastructure.Authorization;
using Lumina.Application.Common.Infrastructure.Themes;
@@ -47,6 +49,7 @@ public class DeleteThemeCommandHandlerTests
public DeleteThemeCommandHandlerTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockThemeService = Substitute.For<IThemeService>();
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
@@ -185,7 +188,7 @@ public class DeleteThemeCommandHandlerTests
Error error = Error.Failure("Database.Error", "Failed to get all themes");
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
.Returns(Result.From<ThemeEntity?>(theme));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(error);
// Act
@@ -206,8 +209,8 @@ public class DeleteThemeCommandHandlerTests
ThemeEntity userTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Uploaded, isDeleted: false);
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
.Returns(Result.From<ThemeEntity?>(theme));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, userTheme]));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, userTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
// Act
Result<Success> result = await _sut.HandleAsync(command, CancellationToken.None);
@@ -228,8 +231,8 @@ public class DeleteThemeCommandHandlerTests
ThemeEntity theme = _themeEntityFixture.Create(themeId: command.ThemeId, installSource: ThemeInstallSource.Uploaded, isCurrent: true, includeIsCurrent: true, isDeleted: false);
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
.Returns(Result.From<ThemeEntity?>(theme));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme]));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme], CurrentPage = 1, PerPage = 1, Count = 1, NumberOfPages = 1 }));
// Act
Result<Success> result = await _sut.HandleAsync(command, CancellationToken.None);
@@ -251,8 +254,8 @@ public class DeleteThemeCommandHandlerTests
ThemeEntity otherBundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
.Returns(Result.From<ThemeEntity?>(theme));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, otherBundledTheme]));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, otherBundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Updated);
@@ -278,8 +281,8 @@ public class DeleteThemeCommandHandlerTests
ThemeEntity bundledTheme = _themeEntityFixture.Create(installSource: ThemeInstallSource.Bundled, isDeleted: false);
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
.Returns(Result.From<ThemeEntity?>(theme));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, bundledTheme]));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, bundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
_mockThemeRepository.DeleteByIdAsync(theme.Id, Arg.Any<CancellationToken>())
.Returns(Result.Deleted);
@@ -304,8 +307,8 @@ public class DeleteThemeCommandHandlerTests
Error error = Error.Failure("Database.Error", "Failed to delete theme");
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
.Returns(Result.From<ThemeEntity?>(theme));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, bundledTheme]));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, bundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
_mockThemeRepository.DeleteByIdAsync(theme.Id, Arg.Any<CancellationToken>())
.Returns(error);
@@ -329,8 +332,8 @@ public class DeleteThemeCommandHandlerTests
_mockThemeService.DefaultThemeId.Returns(replacementTheme.ThemeId);
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
.Returns(Result.From<ThemeEntity?>(theme));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, replacementTheme]));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, replacementTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Updated);
@@ -360,8 +363,8 @@ public class DeleteThemeCommandHandlerTests
_mockThemeService.DefaultThemeId.Returns("no-such-default");
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
.Returns(Result.From<ThemeEntity?>(theme));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, betaTheme, alphaTheme]));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, betaTheme, alphaTheme], CurrentPage = 1, PerPage = 3, Count = 3, NumberOfPages = 1 }));
_mockThemeRepository.UpdateAsync(Arg.Any<ThemeEntity>(), Arg.Any<CancellationToken>())
.Returns(Result.Updated);
@@ -388,8 +391,8 @@ public class DeleteThemeCommandHandlerTests
Error error = Error.Failure("Theme.DeleteFailed", "Failed to delete theme files");
_mockThemeRepository.GetByThemeIdAsync(command.ThemeId!, Arg.Any<CancellationToken>())
.Returns(Result.From<ThemeEntity?>(theme));
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<ThemeEntity>>([theme, bundledTheme]));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [theme, bundledTheme], CurrentPage = 1, PerPage = 2, Count = 2, NumberOfPages = 1 }));
_mockThemeRepository.DeleteByIdAsync(theme.Id, Arg.Any<CancellationToken>())
.Returns(Result.Deleted);
_mockThemeService.DeleteAsync(theme.ThemeId, Arg.Any<CancellationToken>())
@@ -51,6 +51,7 @@ public class InstallThemeCommandHandlerTests
public InstallThemeCommandHandlerTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockThemeService = Substitute.For<IThemeService>();
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
@@ -45,6 +45,7 @@ public class RestoreThemeCommandHandlerTests
public RestoreThemeCommandHandlerTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockThemeService = Substitute.For<IThemeService>();
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
@@ -44,6 +44,7 @@ public class SetCurrentThemeCommandHandlerTests
public SetCurrentThemeCommandHandlerTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockCurrentUserService = Substitute.For<ICurrentUserService>();
_mockAuthorizationService = Substitute.For<IAuthorizationService>();
_mockValidator = Substitute.For<IValidator<SetCurrentThemeCommand>>();
@@ -35,6 +35,7 @@ public class GetCurrentThemeQueryHandlerTests
public GetCurrentThemeQueryHandlerTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockThemeRepository = Substitute.For<IThemeRepository>();
_mockUnitOfWork.ThemeRepository.Returns(_mockThemeRepository);
_sut = new GetCurrentThemeQueryHandler(_mockUnitOfWork);
@@ -41,6 +41,7 @@ public class GetThemeArchiveQueryHandlerTests
public GetThemeArchiveQueryHandlerTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockThemeService = Substitute.For<IThemeService>();
_mockValidator = Substitute.For<IValidator<GetThemeArchiveQuery>>();
_mockThemeRepository = Substitute.For<IThemeRepository>();
@@ -42,6 +42,7 @@ public class GetThemeAssetQueryHandlerTests
public GetThemeAssetQueryHandlerTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockThemeService = Substitute.For<IThemeService>();
_mockValidator = Substitute.For<IValidator<GetThemeAssetQuery>>();
_mockThemeRepository = Substitute.For<IThemeRepository>();
@@ -44,6 +44,7 @@ public class GetThemeTemplateQueryHandlerTests
public GetThemeTemplateQueryHandlerTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockThemeService = Substitute.For<IThemeService>();
_mockValidator = Substitute.For<IValidator<GetThemeTemplateQuery>>();
_mockThemeRepository = Substitute.For<IThemeRepository>();
@@ -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.Core.Themes.Management.Queries.GetThemes;
using Lumina.Application.Fixtures.Common.DataAccess.Entities.Themes;
using Lumina.Application.Fixtures.Core.Themes.Management.Queries.GetThemes;
@@ -35,6 +37,7 @@ public class GetThemesQueryHandlerTests
public GetThemesQueryHandlerTests()
{
_mockUnitOfWork = Substitute.For<IUnitOfWork>();
_mockUnitOfWork.SaveChangesAsync(Arg.Any<CancellationToken>()).Returns(Result.Success);
_mockThemeRepository = Substitute.For<IThemeRepository>();
_mockUnitOfWork.ThemeRepository.Returns(_mockThemeRepository);
_sut = new GetThemesQueryHandler(_mockUnitOfWork);
@@ -49,8 +52,8 @@ public class GetThemesQueryHandlerTests
ThemeEntity bundledLowerTheme = _themeEntityFixture.Create(themeId: "bundled-lower", name: "apple", installSource: ThemeInstallSource.Bundled, isDeleted: false);
ThemeEntity bundledUpperTheme = _themeEntityFixture.Create(themeId: "bundled-upper", name: "Banana", installSource: ThemeInstallSource.Bundled, isDeleted: false);
ThemeEntity deletedTheme = _themeEntityFixture.Create(themeId: "deleted-theme", name: "Deleted", installSource: ThemeInstallSource.Uploaded, isDeleted: true);
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<ThemeEntity>>([uploadedTheme, bundledLowerTheme, bundledUpperTheme, deletedTheme]));
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(Result.From(new PaginatedResultDto<ThemeEntity> { Data = [uploadedTheme, bundledLowerTheme, bundledUpperTheme, deletedTheme], CurrentPage = 1, PerPage = 4, Count = 4, NumberOfPages = 1 }));
// Act
Result<IReadOnlyList<ThemeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
@@ -73,8 +76,8 @@ public class GetThemesQueryHandlerTests
{
// Arrange
GetThemesQuery query = _getThemesQueryFixture.Create();
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
.Returns(Result.From<IEnumerable<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<IReadOnlyList<ThemeResponse>> result = await _sut.HandleAsync(query, CancellationToken.None);
@@ -90,7 +93,7 @@ public class GetThemesQueryHandlerTests
// Arrange
GetThemesQuery query = _getThemesQueryFixture.Create();
Error error = Error.Failure("Database.Error", "Failed to get all themes");
_mockThemeRepository.GetAllAsync(Arg.Any<CancellationToken>())
_mockThemeRepository.GetAllAsync<BaseFilterDto>(cancellationToken: Arg.Any<CancellationToken>())
.Returns(error);
// Act