From 3b5189c83fd4223ed600196a68c01a1649e1393a Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Sun, 8 Dec 2024 15:28:57 -0600 Subject: [PATCH] Fixed up a broken unit test. For People restriction, IncludeUnknowns doesn't really do much. --- API.Tests/Extensions/QueryableExtensionsTests.cs | 8 ++++---- API/Extensions/QueryExtensions/RestrictByAgeExtensions.cs | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/API.Tests/Extensions/QueryableExtensionsTests.cs b/API.Tests/Extensions/QueryableExtensionsTests.cs index d902ae3532..4ea9a5a4bb 100644 --- a/API.Tests/Extensions/QueryableExtensionsTests.cs +++ b/API.Tests/Extensions/QueryableExtensionsTests.cs @@ -123,14 +123,14 @@ public void RestrictAgainstAgeRestriction_Tag_ShouldRestrictEverythingAboveTeen( [Theory] [InlineData(true, 2)] - [InlineData(false, 1)] - public void RestrictAgainstAgeRestriction_Person_ShouldRestrictEverythingAboveTeen(bool includeUnknowns, int expectedCount) + [InlineData(false, 2)] + public void RestrictAgainstAgeRestriction_Person_ShouldRestrictEverythingAboveTeen(bool includeUnknowns, int expectedPeopleCount) { // Arrange var items = new List { CreatePersonWithSeriesMetadata("Test1", AgeRating.Teen), - CreatePersonWithSeriesMetadata("Test2", AgeRating.Unknown, AgeRating.Teen), + CreatePersonWithSeriesMetadata("Test2", AgeRating.Unknown, AgeRating.Teen), // 2 series on this person, restrict will still allow access CreatePersonWithSeriesMetadata("Test3", AgeRating.X18Plus) }; @@ -144,7 +144,7 @@ public void RestrictAgainstAgeRestriction_Person_ShouldRestrictEverythingAboveTe var filtered = items.AsQueryable().RestrictAgainstAgeRestriction(ageRestriction); // Assert - Assert.Equal(expectedCount, filtered.Count()); + Assert.Equal(expectedPeopleCount, filtered.Count()); } private static Person CreatePersonWithSeriesMetadata(string name, params AgeRating[] ageRatings) diff --git a/API/Extensions/QueryExtensions/RestrictByAgeExtensions.cs b/API/Extensions/QueryExtensions/RestrictByAgeExtensions.cs index 000fea68f2..ebc2330562 100644 --- a/API/Extensions/QueryExtensions/RestrictByAgeExtensions.cs +++ b/API/Extensions/QueryExtensions/RestrictByAgeExtensions.cs @@ -101,12 +101,13 @@ public static IQueryable RestrictAgainstAgeRestriction(this IQueryable

c.SeriesMetadataPeople.All(sm => - sm.SeriesMetadata.AgeRating <= restriction.AgeRating)); + return queryable.Where(c => + c.SeriesMetadataPeople.Any(sm => sm.SeriesMetadata.AgeRating <= restriction.AgeRating) || + c.ChapterPeople.Any(cp => cp.Chapter.AgeRating <= restriction.AgeRating)); } return queryable.Where(c => - c.SeriesMetadataPeople.Any(sm => sm.SeriesMetadata.AgeRating <= restriction.AgeRating && sm.SeriesMetadata.AgeRating != AgeRating.Unknown) && + c.SeriesMetadataPeople.Any(sm => sm.SeriesMetadata.AgeRating <= restriction.AgeRating && sm.SeriesMetadata.AgeRating != AgeRating.Unknown) || c.ChapterPeople.Any(cp => cp.Chapter.AgeRating <= restriction.AgeRating && cp.Chapter.AgeRating != AgeRating.Unknown) ); }