Get Person Count working correctly

Fix up some unit tests
This commit is contained in:
Amelia 2025-06-22 21:12:14 +02:00
parent 578c8b1e56
commit 8bc792e64a
5 changed files with 147 additions and 82 deletions

View file

@ -61,10 +61,9 @@ public class GenreRepositoryTests : AbstractDbTest
var lib0 = new LibraryBuilder("lib0")
.WithSeries(new SeriesBuilder("lib0-s0")
.WithMetadata(new SeriesMetadata
{
Genres = [SharedSeriesChaptersGenre, SharedSeriesGenre, Lib0SeriesChaptersGenre, Lib0SeriesGenre]
})
.WithMetadata(new SeriesMetadataBuilder()
.WithGenres([SharedSeriesChaptersGenre, SharedSeriesGenre, Lib0SeriesChaptersGenre, Lib0SeriesGenre])
.Build())
.WithVolume(new VolumeBuilder("1")
.WithChapter(new ChapterBuilder("1")
.WithGenres([SharedSeriesChaptersGenre, SharedChaptersGenre, Lib0SeriesChaptersGenre, Lib0ChaptersGenre])
@ -78,10 +77,10 @@ public class GenreRepositoryTests : AbstractDbTest
var lib1 = new LibraryBuilder("lib1")
.WithSeries(new SeriesBuilder("lib1-s0")
.WithMetadata(new SeriesMetadata
{
Genres = [SharedSeriesChaptersGenre, SharedSeriesGenre, Lib1SeriesChaptersGenre, Lib1SeriesGenre]
})
.WithMetadata(new SeriesMetadataBuilder()
.WithGenres([SharedSeriesChaptersGenre, SharedSeriesGenre, Lib1SeriesChaptersGenre, Lib1SeriesGenre])
.WithAgeRating(AgeRating.Mature17Plus)
.Build())
.WithVolume(new VolumeBuilder("1")
.WithChapter(new ChapterBuilder("1")
.WithGenres([SharedSeriesChaptersGenre, SharedChaptersGenre, Lib1SeriesChaptersGenre, Lib1ChaptersGenre])
@ -92,6 +91,19 @@ public class GenreRepositoryTests : AbstractDbTest
.Build())
.Build())
.Build())
.WithSeries(new SeriesBuilder("lib1-s1")
.WithMetadata(new SeriesMetadataBuilder()
.WithGenres([SharedSeriesChaptersGenre, SharedSeriesGenre, Lib1SeriesChaptersGenre, Lib1SeriesGenre])
.Build())
.WithVolume(new VolumeBuilder("1")
.WithChapter(new ChapterBuilder("1")
.WithGenres([SharedSeriesChaptersGenre, SharedChaptersGenre, Lib1SeriesChaptersGenre, Lib1ChaptersGenre])
.Build())
.WithChapter(new ChapterBuilder("2")
.WithGenres([SharedSeriesChaptersGenre, SharedChaptersGenre, Lib1SeriesChaptersGenre, Lib1ChaptersGenre])
.Build())
.Build())
.Build())
.Build();
await Context.SaveChangesAsync();
@ -122,8 +134,9 @@ public class GenreRepositoryTests : AbstractDbTest
Assert.Contains(fullAccessGenres, ContainsGenreCheck(genre));
}
Assert.Equal(2, fullAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).SeriesCount);
Assert.Equal(4, fullAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).ChapterCount);
// 1 lib0 series, 2 lib1 series
Assert.Equal(3, fullAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).SeriesCount);
Assert.Equal(6, fullAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).ChapterCount);
Assert.Equal(1, fullAccessGenres.First(dto => dto.Id == Lib0SeriesGenre.Id).SeriesCount);
@ -139,9 +152,12 @@ public class GenreRepositoryTests : AbstractDbTest
Assert.Contains(restrictedAccessGenres, ContainsGenreCheck(Lib1ChaptersGenre));
Assert.Contains(restrictedAccessGenres, ContainsGenreCheck(Lib1ChapterAgeGenre));
Assert.Equal(1, restrictedAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).SeriesCount);
Assert.Equal(2, restrictedAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).ChapterCount);
Assert.Equal(1, restrictedAccessGenres.First(dto => dto.Id == Lib1SeriesGenre.Id).SeriesCount);
// 2 lib1 series
Assert.Equal(2, restrictedAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).SeriesCount);
Assert.Equal(4, restrictedAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).ChapterCount);
Assert.Equal(2, restrictedAccessGenres.First(dto => dto.Id == Lib1SeriesGenre.Id).SeriesCount);
Assert.Equal(4, restrictedAccessGenres.First(dto => dto.Id == Lib1ChaptersGenre.Id).ChapterCount);
Assert.Equal(1, restrictedAccessGenres.First(dto => dto.Id == Lib1ChapterAgeGenre.Id).ChapterCount);
var restrictedAgeAccessGenres = await UnitOfWork.GenreRepository.GetBrowseableGenre(_restrictedAgeAccess.Id, new UserParams());
@ -157,7 +173,10 @@ public class GenreRepositoryTests : AbstractDbTest
Assert.DoesNotContain(restrictedAgeAccessGenres, ContainsGenreCheck(Lib1ChapterAgeGenre));
Assert.Equal(1, restrictedAgeAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).SeriesCount);
Assert.Equal(1, restrictedAgeAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).ChapterCount);
Assert.Equal(1, restrictedAgeAccessGenres.First(dto => dto.Id == Lib1SeriesGenre.Id).SeriesCount);
// These values are a "bug". And should be 2, however chapters are not filtered out when their series is
Assert.Equal(3, restrictedAgeAccessGenres.First(dto => dto.Id == SharedSeriesChaptersGenre.Id).ChapterCount);
Assert.Equal(3, restrictedAgeAccessGenres.First(dto => dto.Id == Lib1ChaptersGenre.Id).ChapterCount);
}
}