From 13e93d444b7ae4dedd91a7b16498b82ec3ef89c5 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Tue, 4 Jan 2022 09:42:10 +0000 Subject: [PATCH] Inline and un-param expected Includes. --- .../Query/GearsOfWarQueryTestBase.cs | 402 ++++++------------ 1 file changed, 124 insertions(+), 278 deletions(-) diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index 99c816778a0..ee5e9b77812 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -75,12 +75,10 @@ public virtual Task Include_multiple_one_to_one_and_one_to_many(bool async) => AssertQuery( async, ss => ss.Set().Include(t => t.Gear.Weapons), - elementAsserter: (e, a) => AssertInclude(e, a, new IExpectedInclude[] - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(t => t.Gear), new ExpectedInclude(g => g.Weapons, "Gear"), - new ExpectedInclude(o => o.Weapons, "Gear") - })); + new ExpectedInclude(o => o.Weapons, "Gear"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -122,12 +120,10 @@ public virtual Task Include_multiple_one_to_one_optional_and_one_to_one_required => AssertQuery( async, ss => ss.Set().Include(t => t.Gear.Squad), - elementAsserter: (e, a) => AssertInclude(e, a, new IExpectedInclude[] - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(t => t.Gear), new ExpectedInclude(g => g.Squad, "Gear"), - new ExpectedInclude(o => o.Squad, "Gear") - })); + new ExpectedInclude(o => o.Squad, "Gear"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -141,12 +137,10 @@ public virtual Task Include_multiple_circular(bool async) => AssertQuery( async, ss => ss.Set().Include(g => g.CityOfBirth.StationedGears), - elementAsserter: (e, a) => AssertInclude(e, a, new IExpectedInclude[] - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(g => g.CityOfBirth), new ExpectedInclude(o => o.CityOfBirth), - new ExpectedInclude(c => c.StationedGears, "CityOfBirth") - })); + new ExpectedInclude(c => c.StationedGears, "CityOfBirth"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -154,12 +148,10 @@ public virtual Task Include_multiple_circular_with_filter(bool async) => AssertQuery( async, ss => ss.Set().Include(g => g.CityOfBirth.StationedGears).Where(g => g.Nickname == "Marcus"), - elementAsserter: (e, a) => AssertInclude(e, a, new IExpectedInclude[] - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(g => g.CityOfBirth), new ExpectedInclude(o => o.CityOfBirth), - new ExpectedInclude(c => c.StationedGears, "CityOfBirth") - })); + new ExpectedInclude(c => c.StationedGears, "CityOfBirth"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -167,10 +159,9 @@ public virtual Task Include_using_alternate_key(bool async) => AssertQuery( async, ss => ss.Set().Include(g => g.Weapons).Where(g => g.Nickname == "Marcus"), - elementAsserter: (e, a) => AssertInclude(e, a, new IExpectedInclude[] - { - new ExpectedInclude(g => g.Weapons), new ExpectedInclude(o => o.Weapons) - })); + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.Weapons), + new ExpectedInclude(o => o.Weapons))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -191,7 +182,7 @@ public virtual Task Include_navigation_on_derived_type(bool async) => AssertQuery( async, ss => ss.Set().OfType().Include(o => o.Reports), - elementAsserter: (e, a) => AssertInclude(e, a, new IExpectedInclude[] { new ExpectedInclude(o => o.Reports) })); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -199,97 +190,73 @@ public virtual Task String_based_Include_navigation_on_derived_type(bool async) => AssertQuery( async, ss => ss.Set().OfType().Include("Reports"), - elementAsserter: (e, a) => AssertInclude(e, a, new IExpectedInclude[] { new ExpectedInclude(o => o.Reports) })); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_Where_Navigation_Included(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(t => t.Gear) }; - - return AssertQuery( + => AssertQuery( async, ss => from t in ss.Set().Include(o => o.Gear) where t.Gear.Nickname == "Marcus" select t, - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(t => t.Gear))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_reference1(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(g => g.CityOfBirth), new ExpectedInclude(o => o.CityOfBirth) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Join( ss.Set(), g => new { SquadId = (int?)g.SquadId, g.Nickname }, t => new { SquadId = t.GearSquadId, Nickname = t.GearNickName }, (g, t) => g).Include(g => g.CityOfBirth), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.CityOfBirth), + new ExpectedInclude(o => o.CityOfBirth))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_reference2(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(g => g.CityOfBirth), new ExpectedInclude(o => o.CityOfBirth) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Join( ss.Set(), t => new { SquadId = t.GearSquadId, Nickname = t.GearNickName }, g => new { SquadId = (int?)g.SquadId, g.Nickname }, (t, g) => g).Include(g => g.CityOfBirth), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.CityOfBirth), + new ExpectedInclude(o => o.CityOfBirth))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_collection1(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(g => g.Weapons), new ExpectedInclude(o => o.Weapons) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Join( ss.Set(), g => new { SquadId = (int?)g.SquadId, g.Nickname }, t => new { SquadId = t.GearSquadId, Nickname = t.GearNickName }, (g, t) => g).Include(g => g.Weapons), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.Weapons), + new ExpectedInclude(o => o.Weapons))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_collection2(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(g => g.Weapons), new ExpectedInclude(o => o.Weapons) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Join( ss.Set(), t => new { SquadId = t.GearSquadId, Nickname = t.GearNickName }, g => new { SquadId = (int?)g.SquadId, g.Nickname }, (t, g) => g).Include(g => g.Weapons), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.Weapons), + new ExpectedInclude(o => o.Weapons))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -359,47 +326,34 @@ public virtual async Task Navigation_accessed_twice_outside_and_inside_subquery( [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_multi_level(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(g => g.CityOfBirth), - new ExpectedInclude(o => o.CityOfBirth), - new ExpectedInclude(c => c.StationedGears, "CityOfBirth") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Join( ss.Set(), g => new { SquadId = (int?)g.SquadId, g.Nickname }, t => new { SquadId = t.GearSquadId, Nickname = t.GearNickName }, (g, t) => g).Include(g => g.CityOfBirth.StationedGears), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.CityOfBirth), + new ExpectedInclude(o => o.CityOfBirth), + new ExpectedInclude(c => c.StationedGears, "CityOfBirth"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_and_inheritance1(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.CityOfBirth) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Join( ss.Set().OfType(), t => new { SquadId = t.GearSquadId, Nickname = t.GearNickName }, o => new { SquadId = (int?)o.SquadId, o.Nickname }, (t, o) => o).Include(o => o.CityOfBirth), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.CityOfBirth))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_and_inheritance_with_orderby_before_and_after_include(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.Reports) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Join( ss.Set().OfType().OrderBy(ee => ee.SquadId), @@ -407,57 +361,44 @@ public virtual Task Include_with_join_and_inheritance_with_orderby_before_and_af o => new { SquadId = (int?)o.SquadId, o.Nickname }, (t, o) => o).OrderBy(ee => ee.FullName).Include(o => o.Reports).OrderBy(oo => oo.HasSoulPatch) .ThenByDescending(oo => oo.Nickname), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_and_inheritance2(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.Weapons) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().OfType().Join( ss.Set(), o => new { SquadId = (int?)o.SquadId, o.Nickname }, t => new { SquadId = t.GearSquadId, Nickname = t.GearNickName }, (o, t) => o).Include(g => g.Weapons), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Weapons))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_and_inheritance3(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.Reports) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Join( ss.Set().OfType(), t => new { SquadId = t.GearSquadId, Nickname = t.GearNickName }, g => new { SquadId = (int?)g.SquadId, g.Nickname }, (t, o) => o).Include(o => o.Reports), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_nested_navigation_in_order_by(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(w => w.Owner) }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set() .Include(w => w.Owner) .Where(w => w.Owner.Nickname != "Paduk") .OrderBy(e => e.Owner.CityOfBirth.Name).ThenBy(e => e.Id), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(w => w.Owner)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -1702,21 +1643,16 @@ orderby g1.Nickname [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_coalesce_result3(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(g => g.Weapons), new ExpectedInclude(g => g.Weapons) - }; - - return AssertQuery( + => AssertQuery( async, ss => from g1 in ss.Set().Include(g => g.Weapons) join g2 in ss.Set().Include(g => g.Weapons) on g1.LeaderNickname equals g2.Nickname into grouping from g2 in grouping.DefaultIfEmpty() select g2 ?? g1, - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.Weapons), + new ExpectedInclude(g => g.Weapons))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -1751,32 +1687,21 @@ from g2 in grouping.DefaultIfEmpty() [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_inheritance_and_coalesce_result(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(g => g.Weapons), new ExpectedInclude(g => g.Weapons) - }; - - return AssertQuery( + => AssertQuery( async, ss => from g1 in ss.Set().Include(g => g.Weapons) join g2 in ss.Set().OfType().Include(g => g.Weapons) on g1.LeaderNickname equals g2.Nickname into grouping from g2 in grouping.DefaultIfEmpty() select g2 ?? g1, - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.Weapons), + new ExpectedInclude(g => g.Weapons))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_conditional_result(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(g => g.Weapons), new ExpectedInclude(g => g.Weapons) - }; - - return AssertQuery( + => AssertQuery( async, ss => from g1 in ss.Set().Include(g => g.Weapons) join g2 in ss.Set().Include(g => g.Weapons) @@ -1785,8 +1710,9 @@ from g2 in grouping.DefaultIfEmpty() #pragma warning disable IDE0029 // Use coalesce expression select g2 != null ? g2 : g1, #pragma warning restore IDE0029 // Use coalesce expression - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.Weapons), + new ExpectedInclude(g => g.Weapons))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -2821,37 +2747,28 @@ orderby l.Name [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_derived_entity_using_OfType(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.Commander), new ExpectedInclude(e => e.Leaders) - }; - - return AssertQuery( + => AssertQuery( async, ss => from lh in ss.Set().OfType().Include(h => h.Commander).Include(h => h.Leaders) orderby lh.Name select lh, - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.Commander), + new ExpectedInclude(e2 => e2.Leaders)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_derived_entity_with_cast(bool async) - { - var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Capital) }; - // TODO: should we disable this scenario? see #14671 - return AssertQuery( + => AssertQuery( async, ss => (from f in ss.Set() where f is LocustHorde orderby f.Id select f).Include(f => f.Capital), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e1 => e1.Capital)), assertOrder: true); - } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -3002,34 +2919,23 @@ public virtual Task Include_reference_on_derived_type_using_string(bool async) [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_on_derived_type_using_string_nested1(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(lc => lc.DefeatedBy), new ExpectedInclude(g => g.Squad, "DefeatedBy") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include("DefeatedBy.Squad"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(lc => lc.DefeatedBy), + new ExpectedInclude(g => g.Squad, "DefeatedBy"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_on_derived_type_using_string_nested2(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(lc => lc.DefeatedBy), - new ExpectedInclude(o => o.Reports, "DefeatedBy"), - new ExpectedInclude(g => g.CityOfBirth, "DefeatedBy.Reports") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include("DefeatedBy.Reports.CityOfBirth"), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(lc => lc.DefeatedBy), + new ExpectedInclude(o => o.Reports, "DefeatedBy"), + new ExpectedInclude(g => g.CityOfBirth, "DefeatedBy.Reports"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -3083,113 +2989,75 @@ public virtual Task Include_collection_on_derived_type_using_lambda_with_soft_ca [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_base_navigation_on_derived_entity(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.Tag), new ExpectedInclude(e => e.Weapons) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(g => ((Officer)g).Tag).Include(g => ((Officer)g).Weapons), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.Tag), + new ExpectedInclude(e2 => e2.Weapons))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task ThenInclude_collection_on_derived_after_base_reference(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.Gear), new ExpectedInclude(e => e.Weapons, "Gear") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(t => t.Gear).ThenInclude(g => (g as Officer).Weapons), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.Gear), + new ExpectedInclude(e2 => e2.Weapons, "Gear"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task ThenInclude_collection_on_derived_after_derived_reference(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.Commander), - new ExpectedInclude(e => e.DefeatedBy, "Commander"), - new ExpectedInclude(e => e.Reports, "Commander.DefeatedBy") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(f => (f as LocustHorde).Commander).ThenInclude(c => (c.DefeatedBy as Officer).Reports), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.Commander), + new ExpectedInclude(e2 => e2.DefeatedBy, "Commander"), + new ExpectedInclude(e3 => e3.Reports, "Commander.DefeatedBy"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task ThenInclude_collection_on_derived_after_derived_collection(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.Reports), new ExpectedInclude(e => e.Reports, "Reports") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(g => ((Officer)g).Reports).ThenInclude(g => ((Officer)g).Reports), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.Reports), + new ExpectedInclude(e2 => e2.Reports, "Reports"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task ThenInclude_reference_on_derived_after_derived_collection(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.Leaders), new ExpectedInclude(e => e.DefeatedBy, "Leaders") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(f => ((LocustHorde)f).Leaders).ThenInclude(l => ((LocustCommander)l).DefeatedBy), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.Leaders), + new ExpectedInclude(e2 => e2.DefeatedBy, "Leaders"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_derived_included_on_one_method(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.Commander), - new ExpectedInclude(e => e.DefeatedBy, "Commander"), - new ExpectedInclude(e => e.Reports, "Commander.DefeatedBy") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(f => (((LocustHorde)f).Commander.DefeatedBy as Officer).Reports), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.Commander), + new ExpectedInclude(e2 => e2.DefeatedBy, "Commander"), + new ExpectedInclude(e3 => e3.Reports, "Commander.DefeatedBy"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_derived_multi_level(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.Reports), - new ExpectedInclude(e => e.Squad, "Reports"), - new ExpectedInclude(e => e.Missions, "Reports.Squad") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(g => ((Officer)g).Reports).ThenInclude(g => g.Squad.Missions), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.Reports), + new ExpectedInclude(e2 => e2.Squad, "Reports"), + new ExpectedInclude(e3 => e3.Missions, "Reports.Squad"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -4248,19 +4116,14 @@ from h in grouping.DefaultIfEmpty() [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_derived_type_with_order_by_and_paging(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.DefeatedBy), new ExpectedInclude(e => e.Weapons, "DefeatedBy") - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(ll => ((LocustCommander)ll).DefeatedBy).ThenInclude(g => g.Weapons) .OrderBy(ll => ((LocustCommander)ll).DefeatedBy.Tag.Note).Take(10), ss => ss.Set().Take(10), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.DefeatedBy), + new ExpectedInclude(e2 => e2.Weapons, "DefeatedBy"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -4341,22 +4204,15 @@ from g in grouping.DefaultIfEmpty() [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual async Task Include_with_concat(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(g => g.Squad), new ExpectedInclude(o => o.Squad) - }; - - var message = (await Assert.ThrowsAsync( - () => AssertQuery( - async, - ss => ss.Set().Include(g => g.Squad).Concat(ss.Set()), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)))).Message; - - Assert.Equal( + => Assert.Equal( CoreStrings.SetOperationWithDifferentIncludesInOperands, - message); - } + (await Assert.ThrowsAsync( + () => AssertQuery( + async, + ss => ss.Set().Include(g => g.Squad).Concat(ss.Set()), + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(g => g.Squad), + new ExpectedInclude(o => o.Squad))))).Message); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -5145,17 +5001,12 @@ public virtual Task Group_by_with_include_with_entity_in_result_selector(bool as [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_group_by_and_FirstOrDefault_gets_properly_applied(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(e => e.CityOfBirth), new ExpectedInclude(e => e.CityOfBirth) - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Include(g => g.CityOfBirth).GroupBy(g => g.Rank).Select(g => g.FirstOrDefault(gg => gg.HasSoulPatch)), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(e1 => e1.CityOfBirth), + new ExpectedInclude(e2 => e2.CityOfBirth))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))] @@ -6943,18 +6794,13 @@ public virtual Task Cast_to_derived_followed_by_include_and_FirstOrDefault(bool [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Cast_to_derived_followed_by_multiple_includes(bool async) - { - var expectedIncludes = new IExpectedInclude[] - { - new ExpectedInclude(x => x.DefeatedBy), new ExpectedInclude(x => x.Weapons, "DefeatedBy"), - }; - - return AssertQuery( + => AssertQuery( async, ss => ss.Set().Where(ll => ll.Name.Contains("Queen")).Cast().Include(lc => lc.DefeatedBy) .ThenInclude(g => g.Weapons), - elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); - } + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(x => x.DefeatedBy), + new ExpectedInclude(x => x.Weapons, "DefeatedBy"))); [ConditionalTheory] [MemberData(nameof(IsAsyncData))]