diff --git a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs index 05f9bdc4dc2..0e541489641 100644 --- a/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs @@ -162,16 +162,16 @@ public virtual Task Key_equality_two_conditions_on_same_navigation2(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Multi_level_include_one_to_many_optional_and_one_to_many_optional_produces_valid_sql(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToMany_Optional1), new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToMany_Optional1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(e => e.OneToMany_Optional1).ThenInclude(e => e.OneToMany_Optional2), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -179,7 +179,7 @@ public virtual Task Multi_level_include_one_to_many_optional_and_one_to_many_opt public virtual Task Multi_level_include_correct_PK_is_chosen_as_the_join_predicate_for_queries_that_join_same_table_multiple_times( bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToMany_Optional1), new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToMany_Optional1"), @@ -187,11 +187,11 @@ public virtual Task Multi_level_include_correct_PK_is_chosen_as_the_join_predica new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToMany_Optional1.OneToMany_Optional2.OneToMany_Required_Inverse3") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(e => e.OneToMany_Optional1).ThenInclude(e => e.OneToMany_Optional2) .ThenInclude(e => e.OneToMany_Required_Inverse3.OneToMany_Optional2), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalFact] @@ -653,7 +653,7 @@ join e4 in ss.Set() on e1.Name equals e4.OneToOne_Required_FK_Inverse4.O [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_complex_includes(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), @@ -661,21 +661,21 @@ public virtual Task Multiple_complex_includes(bool async) new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToMany_Optional1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_FK1) .ThenInclude(e => e.OneToMany_Optional2) .Include(e => e.OneToMany_Optional1) .ThenInclude(e => e.OneToOne_Optional_FK2), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_complex_includes_self_ref(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_Self1), new ExpectedInclude(l2 => l2.OneToMany_Optional_Self1, "OneToOne_Optional_Self1"), @@ -683,21 +683,21 @@ public virtual Task Multiple_complex_includes_self_ref(bool async) new ExpectedInclude(l2 => l2.OneToOne_Optional_Self1, "OneToMany_Optional_Self1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_Self1) .ThenInclude(e => e.OneToMany_Optional_Self1) .Include(e => e.OneToMany_Optional_Self1) .ThenInclude(e => e.OneToOne_Optional_Self1), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_complex_include_select(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), @@ -705,7 +705,7 @@ public virtual Task Multiple_complex_include_select(bool async) new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToMany_Optional1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(e => e) @@ -714,7 +714,7 @@ public virtual Task Multiple_complex_include_select(bool async) .Select(e => e) .Include(e => e.OneToMany_Optional1) .ThenInclude(e => e.OneToOne_Optional_FK2), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -1249,33 +1249,33 @@ from l2 in groupJoin.DefaultIfEmpty() [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_optional_navigation(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => from l1 in ss.Set().Include(e => e.OneToOne_Optional_FK1) where l1.OneToOne_Optional_FK1.Name != "L2 05" select l1, - new List { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_nested_with_optional_navigation(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l1 => l1.OneToMany_Required2, "OneToOne_Optional_FK1"), new ExpectedInclude(l1 => l1.OneToOne_Required_FK3, "OneToOne_Optional_FK1.OneToMany_Required2") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => from l1 in ss.Set() .Include(e => e.OneToOne_Optional_FK1.OneToMany_Required2) .ThenInclude(e => e.OneToOne_Required_FK3) where l1.OneToOne_Optional_FK1.Name != "L2 09" select l1, - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -1431,28 +1431,28 @@ public virtual Task Where_navigation_property_to_collection_of_original_entity_t [MemberData(nameof(IsAsyncData))] public virtual Task Complex_multi_include_with_order_by_and_paging(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Required_FK1), new ExpectedInclude(l1 => l1.OneToMany_Optional2, "OneToOne_Required_FK1"), new ExpectedInclude(l1 => l1.OneToMany_Required2, "OneToOne_Required_FK1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Required_FK1).ThenInclude(e => e.OneToMany_Optional2) .Include(e => e.OneToOne_Required_FK1).ThenInclude(e => e.OneToMany_Required2) .OrderBy(t => t.Name) .Skip(0).Take(10), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_multi_include_with_order_by_and_paging_joins_on_correct_key(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Optional_FK1"), @@ -1460,41 +1460,41 @@ public virtual Task Complex_multi_include_with_order_by_and_paging_joins_on_corr new ExpectedInclude(l2 => l2.OneToMany_Required2, "OneToOne_Required_FK1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_FK1).ThenInclude(e => e.OneToMany_Optional2) .Include(e => e.OneToOne_Required_FK1).ThenInclude(e => e.OneToMany_Required2) .OrderBy(t => t.Name) .Skip(0).Take(10), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Complex_multi_include_with_order_by_and_paging_joins_on_correct_key2(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l2 => l2.OneToOne_Required_FK2, "OneToOne_Optional_FK1"), new ExpectedInclude(l3 => l3.OneToMany_Optional3, "OneToOne_Optional_FK1.OneToOne_Required_FK2") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Optional_FK1.OneToOne_Required_FK2).ThenInclude(e => e.OneToMany_Optional3) .OrderBy(t => t.Name) .Skip(0).Take(10), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_include_with_multiple_optional_navigations(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Required_FK1), new ExpectedInclude(l2 => l2.OneToMany_Optional2, "OneToOne_Required_FK1"), @@ -1503,7 +1503,7 @@ public virtual Task Multiple_include_with_multiple_optional_navigations(bool asy new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_FK1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(e => e.OneToOne_Required_FK1).ThenInclude(e => e.OneToMany_Optional2) @@ -1511,7 +1511,7 @@ public virtual Task Multiple_include_with_multiple_optional_navigations(bool asy .Include(e => e.OneToOne_Optional_FK1).ThenInclude(e => e.OneToOne_Optional_FK2) .Where(e => e.OneToOne_Required_FK1.OneToOne_Optional_PK2.Name != "Foo") .OrderBy(e => e.Id), - expectedIncludes, + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), assertOrder: true); } @@ -1724,310 +1724,268 @@ public virtual Task Where_predicate_on_optional_reference_navigation(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_Include1(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include(l2 => l2.OneToMany_Optional2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToMany_Optional2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Orderby_SelectMany_with_Include1(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().OrderBy(l1 => l1.Id) .SelectMany(l1 => l1.OneToMany_Optional1) .Include(l2 => l2.OneToMany_Optional2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToMany_Optional2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_Include2(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include(l2 => l2.OneToOne_Required_FK2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToOne_Required_FK2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Required_FK2))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_Include_ThenInclude(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Required_FK2), new ExpectedInclude(l3 => l3.OneToMany_Optional3, "OneToOne_Required_FK2") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include(l2 => l2.OneToOne_Required_FK2) .ThenInclude(l3 => l3.OneToMany_Optional3), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_SelectMany_with_Include(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l3 => l3.OneToOne_Required_FK3), new ExpectedInclude(l3 => l3.OneToMany_Optional3) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .SelectMany(l2 => l2.OneToMany_Optional2) .Include(l3 => l3.OneToOne_Required_FK3) .Include(l3 => l3.OneToMany_Optional3), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_string_based_Include1(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include("OneToOne_Required_FK2"), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToOne_Required_FK2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Required_FK2))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_string_based_Include2(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Required_FK2), new ExpectedInclude(l3 => l3.OneToOne_Required_FK3, "OneToOne_Required_FK2") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include("OneToOne_Required_FK2.OneToOne_Required_FK3"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_SelectMany_with_string_based_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .SelectMany(l1 => l1.OneToMany_Optional2) .Include("OneToOne_Required_FK3"), - expectedIncludes: new List - { - new ExpectedInclude(l3 => l3.OneToOne_Required_FK3) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l3 => l3.OneToOne_Required_FK3))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Required_navigation_with_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l3 => l3.OneToOne_Required_FK_Inverse3) .Include(l2 => l2.OneToMany_Required_Inverse2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToMany_Required_Inverse2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Required_Inverse2))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Required_navigation_with_Include_ThenInclude(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l3 => l3.OneToMany_Required_Inverse3), new ExpectedInclude(l2 => l2.OneToMany_Optional_Inverse2, "OneToMany_Required_Inverse3") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l4 => l4.OneToOne_Required_FK_Inverse4) .Include(l3 => l3.OneToMany_Required_Inverse3) .ThenInclude(l2 => l2.OneToMany_Optional_Inverse2), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_required_navigations_with_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3) .Include(l2 => l2.OneToOne_Optional_FK2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_required_navigation_using_multiple_selects_with_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l4 => l4.OneToOne_Required_FK_Inverse4) .Select(l3 => l3.OneToOne_Required_FK_Inverse3) .Include(l2 => l2.OneToOne_Optional_FK2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_required_navigation_with_string_based_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3) .Include("OneToOne_Optional_FK2"), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_required_navigation_using_multiple_selects_with_string_based_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l4 => l4.OneToOne_Required_FK_Inverse4) .Select(l3 => l3.OneToOne_Required_FK_Inverse3) .Include("OneToOne_Optional_FK2"), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_with_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l1 => l1.OneToOne_Optional_FK1) .Include(l2 => l2.OneToOne_Optional_FK2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_with_Include_ThenInclude(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToMany_Optional2), new ExpectedInclude(l3 => l3.OneToOne_Optional_FK3, "OneToMany_Optional2") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l1 => l1.OneToOne_Optional_FK1) .Include(l2 => l2.OneToMany_Optional2) .ThenInclude(l3 => l3.OneToOne_Optional_FK3), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_optional_navigation_with_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2) .Include(l3 => l3.OneToMany_Optional3), - expectedIncludes: new List - { - new ExpectedInclude(l3 => l3.OneToMany_Optional3) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l3 => l3.OneToMany_Optional3))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_optional_navigation_with_string_based_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l1 => l1.OneToOne_Optional_FK1) .Select(l2 => l2.OneToOne_Optional_PK2) .Include("OneToMany_Optional3"), - expectedIncludes: new List - { - new ExpectedInclude(l3 => l3.OneToMany_Optional3) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l3 => l3.OneToMany_Optional3))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_with_order_by_and_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l1 => l1.OneToOne_Optional_FK1) .OrderBy(l2 => l2.Name) .Include(l2 => l2.OneToMany_Optional2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToMany_Optional2) - }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2)), assertOrder: true); } @@ -2035,16 +1993,13 @@ public virtual Task Optional_navigation_with_order_by_and_Include(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Optional_navigation_with_Include_and_order(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Select(l1 => l1.OneToOne_Optional_FK1) .Include(l2 => l2.OneToMany_Optional2) .OrderBy(l2 => l2.Name), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToMany_Optional2) - }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2)), assertOrder: true); } @@ -2052,16 +2007,13 @@ public virtual Task Optional_navigation_with_Include_and_order(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_order_by_and_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .OrderBy(l2 => l2.Name) .Include(l2 => l2.OneToMany_Optional2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToMany_Optional2) - }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2)), assertOrder: true); } @@ -2069,16 +2021,13 @@ public virtual Task SelectMany_with_order_by_and_Include(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_Include_and_order_by(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .SelectMany(l1 => l1.OneToMany_Optional1) .Include(l2 => l2.OneToMany_Optional2) .OrderBy(l2 => l2.Name), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToMany_Optional2) - }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToMany_Optional2)), assertOrder: true); } @@ -2099,16 +2048,13 @@ from l2 in l1.OneToMany_Optional1.DefaultIfEmpty() [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_with_navigation_and_Distinct(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => from l1 in ss.Set().Include(l => l.OneToMany_Optional1) from l2 in l1.OneToMany_Optional1.Distinct() where l2 != null select l1, - expectedIncludes: new List - { - new ExpectedInclude(l1 => l1.OneToMany_Optional1) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToMany_Optional1))); } [ConditionalTheory] @@ -3213,7 +3159,7 @@ where l2.OneToOne_Required_FK2.OneToMany_Optional3.MaybeScalar( [MemberData(nameof(IsAsyncData))] public virtual Task Level4_Include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Select(l1 => l1.OneToOne_Required_PK1) .Where(t => t != null) @@ -3223,10 +3169,7 @@ public virtual Task Level4_Include(bool async) .Where(t => t != null) .Select(l4 => l4.OneToOne_Required_FK_Inverse4.OneToOne_Required_FK_Inverse3) .Include(l2 => l2.OneToOne_Optional_FK2), - expectedIncludes: new List - { - new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2) - }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)), elementSorter: e => e.Id); } @@ -3449,7 +3392,7 @@ public virtual Task Project_navigation_and_collection(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_inside_subquery(bool async) { - // can't use AssertIncludeQuery here, see #18191 + // can't use AssertQuery here, see #18191 return AssertQuery( async, ss => ss.Set() @@ -3475,13 +3418,13 @@ from l2 in l1.OneToMany_Optional1.Where(l => l.Id > 5).OrderByDescending(l => l. [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_member(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) .OrderBy(l2 => l2.Name) .ThenBy(l2 => l2.Level1_Required_Id), - new List { new ExpectedInclude(e => e.OneToMany_Optional2) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); } @@ -3489,13 +3432,13 @@ public virtual Task Include_collection_with_multiple_orderbys_member(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_property(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) .OrderBy(l2 => EF.Property(l2, "Level1_Required_Id")) .ThenBy(l2 => l2.Name), - new List { new ExpectedInclude(e => e.OneToMany_Optional2) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); } @@ -3503,13 +3446,13 @@ public virtual Task Include_collection_with_multiple_orderbys_property(bool asyn [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_methodcall(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) .OrderBy(l2 => Math.Abs(l2.Level1_Required_Id)) .ThenBy(l2 => l2.Name), - new List { new ExpectedInclude(e => e.OneToMany_Optional2) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); } @@ -3517,13 +3460,13 @@ public virtual Task Include_collection_with_multiple_orderbys_methodcall(bool as [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_complex(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) .OrderBy(l2 => Math.Abs(l2.Level1_Required_Id) + 7) .ThenBy(l2 => l2.Name), - new List { new ExpectedInclude(e => e.OneToMany_Optional2) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); } @@ -3531,13 +3474,13 @@ public virtual Task Include_collection_with_multiple_orderbys_complex(bool async [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_multiple_orderbys_complex_repeated(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) .OrderBy(l2 => -l2.Level1_Required_Id) .ThenBy(l2 => -l2.Level1_Required_Id).ThenBy(l2 => l2.Name), - new List { new ExpectedInclude(e => e.OneToMany_Optional2) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); } @@ -3547,13 +3490,13 @@ public virtual Task Include_collection_with_multiple_orderbys_complex_repeated_c { checked { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToMany_Optional2) .OrderBy(l2 => -l2.Level1_Required_Id) .ThenBy(l2 => -l2.Level1_Required_Id).ThenBy(l2 => l2.Name), - new List { new ExpectedInclude(e => e.OneToMany_Optional2) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional2)), assertOrder: true); } } @@ -3578,117 +3521,105 @@ public virtual void Entries_for_detached_entities_are_removed() [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_with_groupby_in_subquery(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1) .GroupBy(g => g.Name) .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), - expectedIncludes: new List - { - new ExpectedInclude(e => e.OneToOne_Optional_FK1) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToOne_Optional_FK1))); } [ConditionalTheory(Skip = "Issue#12088")] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_groupby_in_subquery(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) .GroupBy(g => g.Name) .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), - expectedIncludes: new List - { - new ExpectedInclude(e => e.OneToMany_Optional1) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional1))); } [ConditionalTheory(Skip = "Issue#12088")] [MemberData(nameof(IsAsyncData))] public virtual Task Multi_include_with_groupby_in_subquery(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.OneToOne_Optional_FK1), new ExpectedInclude(e => e.OneToMany_Optional2, "OneToOne_Optional_FK1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2) .GroupBy(g => g.Name) .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory(Skip = "Issue#12088")] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_groupby_in_subquery_and_filter_before_groupby(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) .Where(l1 => l1.Id > 3) .GroupBy(g => g.Name) .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), - expectedIncludes: new List - { - new ExpectedInclude(e => e.OneToMany_Optional1) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional1))); } [ConditionalTheory(Skip = "Issue#12088")] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_groupby_in_subquery_and_filter_after_groupby(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) .GroupBy(g => g.Name) .Where(g => g.Key != "Foo") .Select(g => g.OrderBy(e => e.Id).FirstOrDefault()), - expectedIncludes: new List - { - new ExpectedInclude(e => e.OneToMany_Optional1) - }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional1))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_navigation_with_same_name_and_same_type(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.ReferenceSameType), new ExpectedInclude(e => e.ReferenceSameType) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("ReferenceSameType"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_navigation_with_same_name_and_different_type(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.ReferenceDifferentType), new ExpectedInclude(e => e.ReferenceDifferentType) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("ReferenceDifferentType"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -3697,49 +3628,49 @@ public virtual Task String_include_multiple_derived_navigation_with_same_name_and_different_type_nested_also_includes_partially_matching_navigation_chains( bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.ReferenceDifferentType), new ExpectedInclude(e => e.ReferenceDifferentType), new ExpectedInclude(e => e.BaseCollection, "ReferenceDifferentType") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("ReferenceDifferentType.BaseCollection"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_collection_navigation_with_same_name_and_same_type(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.CollectionSameType), new ExpectedInclude(e => e.CollectionSameType) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("CollectionSameType"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_collection_navigation_with_same_name_and_different_type(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.CollectionDifferentType), new ExpectedInclude(e => e.CollectionDifferentType) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("CollectionDifferentType"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -3748,24 +3679,24 @@ public virtual Task String_include_multiple_derived_collection_navigation_with_same_name_and_different_type_nested_also_includes_partially_matching_navigation_chains( bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.CollectionDifferentType), new ExpectedInclude(e => e.CollectionDifferentType), new ExpectedInclude(e => e.BaseCollection, "CollectionDifferentType") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("CollectionDifferentType.BaseCollection"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_include_multiple_derived_navigations_complex(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Reference), new ExpectedInclude(e => e.CollectionDifferentType, "Reference"), @@ -3775,26 +3706,24 @@ public virtual Task String_include_multiple_derived_navigations_complex(bool asy new ExpectedInclude(e => e.ReferenceSameType, "Collection") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("Reference.CollectionDifferentType").Include("Collection.ReferenceSameType"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_collection_order_by_reference_navigation(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2) .OrderBy(l1 => (int?)l1.OneToOne_Optional_FK1.Id), - expectedIncludes: new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToOne_Optional_FK1), - new ExpectedInclude(e => e.OneToMany_Optional2, "OneToOne_Optional_FK1") - }, + new ExpectedInclude(e => e.OneToMany_Optional2, "OneToOne_Optional_FK1")), assertOrder: true); } @@ -3823,40 +3752,40 @@ public virtual Task Accessing_optional_property_inside_result_operator_subquery( [MemberData(nameof(IsAsyncData))] public virtual Task Include_after_SelectMany_and_reference_navigation(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Required1).Select(l2 => l2.OneToOne_Optional_FK2) .Include(l3 => l3.OneToMany_Optional3), - new List { new ExpectedInclude(l3 => l3.OneToMany_Optional3) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l3 => l3.OneToMany_Optional3))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Include_after_multiple_SelectMany_and_reference_navigation(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Required1).SelectMany(l2 => l2.OneToMany_Optional2) .Select(l3 => l3.OneToOne_Required_FK3).Include(l4 => l4.OneToMany_Required_Self4), - new List { new ExpectedInclude(l4 => l4.OneToMany_Required_Self4) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l4 => l4.OneToMany_Required_Self4))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Include_after_SelectMany_and_multiple_reference_navigations(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().SelectMany(l1 => l1.OneToMany_Required1).Select(l2 => l2.OneToOne_Optional_FK2) .Select(l3 => l3.OneToOne_Required_FK3).Include(l4 => l4.OneToMany_Optional_Self4), - new List { new ExpectedInclude(l4 => l4.OneToMany_Optional_Self4) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l4 => l4.OneToMany_Optional_Self4))); } [ConditionalTheory(Skip = "Issue#16752")] [MemberData(nameof(IsAsyncData))] public virtual Task Include_after_SelectMany_and_reference_navigation_with_another_SelectMany_with_Distinct(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => from lOuter in ss.Set().SelectMany(l1 => l1.OneToMany_Required1).Select(l2 => l2.OneToOne_Optional_FK2) .Include(l3 => l3.OneToMany_Optional3) @@ -3868,7 +3797,7 @@ from lInner in lOuter.OneToMany_Optional3.Distinct() from lInner in lOuter.OneToMany_Optional3.Distinct() where lInner != null select lOuter, - new List { new ExpectedInclude(l3 => l3.OneToMany_Optional3) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l3 => l3.OneToMany_Optional3))); } [ConditionalTheory] @@ -3971,7 +3900,7 @@ public virtual Task Multiple_SelectMany_navigation_property_followed_by_select_c [MemberData(nameof(IsAsyncData))] public virtual Task SelectMany_navigation_property_with_include_and_followed_by_select_collection_navigation(bool async) { - // can't use AssertIncludeQuery here, see #18191 + // can't use AssertQuery here, see #18191 return AssertQuery( async, ss => ss.Set() @@ -3991,140 +3920,139 @@ public virtual Task SelectMany_navigation_property_with_include_and_followed_by_ [MemberData(nameof(IsAsyncData))] public virtual Task Include1(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1), - new List { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include2(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1).Include(l1 => l1.OneToOne_Optional_FK1), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include3(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l1 => l1.OneToOne_Optional_PK1) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1).Include(l1 => l1.OneToOne_Optional_PK1), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include4(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1).ThenInclude(l1 => l1.OneToOne_Optional_PK2), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include5(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include6(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2).Select(l1 => l1.OneToOne_Optional_FK1), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include7(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, - ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2).Select(l1 => l1.OneToOne_Optional_PK1), - new List()); + ss => ss.Set().Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2).Select(l1 => l1.OneToOne_Optional_PK1)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include8(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Optional_FK_Inverse2) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Where(l2 => l2.OneToOne_Optional_FK_Inverse2.Name != "Fubar") .Include(l2 => l2.OneToOne_Optional_FK_Inverse2), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include9(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Optional_FK_Inverse2) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l2 => l2.OneToOne_Optional_FK_Inverse2) .Where(l2 => l2.OneToOne_Optional_FK_Inverse2.Name != "Fubar"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include10(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_FK1"), @@ -4133,19 +4061,19 @@ public virtual Task Include10(bool async) new ExpectedInclude(l3 => l3.OneToOne_Optional_PK3, "OneToOne_Optional_FK1.OneToOne_Optional_FK2") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_PK2) .Include(l1 => l1.OneToOne_Optional_PK1.OneToOne_Optional_FK2.OneToOne_Optional_PK3), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include11(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_FK1"), @@ -4159,7 +4087,7 @@ public virtual Task Include11(bool async) new ExpectedInclude(l2 => l2.OneToOne_Optional_PK2, "OneToOne_Optional_PK1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2) @@ -4167,42 +4095,45 @@ public virtual Task Include11(bool async) .Include(l1 => l1.OneToOne_Optional_PK1.OneToOne_Optional_FK2.OneToOne_Optional_FK3) .Include(l1 => l1.OneToOne_Optional_PK1.OneToOne_Optional_FK2.OneToOne_Optional_PK3) .Include(l1 => l1.OneToOne_Optional_PK1.OneToOne_Optional_PK2), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include12(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToOne_Optional_FK2) .Select(l1 => l1.OneToOne_Optional_FK1), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include13(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1) .Select(l1 => new { one = l1, two = l1 }), - expectedIncludes, - clientProjections: new List> { x => x.one, x => x.two }, + elementAsserter: (e, a) => + { + AssertInclude(e.one, a.one, expectedIncludes); + AssertInclude(e.two, a.two, expectedIncludes); + }, elementSorter: e => e.one.Id); } @@ -4210,13 +4141,13 @@ public virtual Task Include13(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include14(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1), new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2, "OneToOne_Optional_FK1") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1).ThenInclude(l2 => l2.OneToOne_Optional_FK2) @@ -4227,12 +4158,11 @@ public virtual Task Include14(bool async) two = l1.OneToOne_Optional_FK1, three = l1.OneToOne_Optional_PK1 }), - expectedIncludes, - clientProjections: new List> + elementAsserter: (e, a) => { - x => x.one - // issue #15368 - //x => x.two, + AssertInclude(e.one, a.one, expectedIncludes); + AssertInclude(e.two, a.two, new ExpectedInclude(l2 => l2.OneToOne_Optional_FK2)); + AssertEqual(e.three, a.three); }, elementSorter: e => e.one.Id); } @@ -4271,45 +4201,45 @@ public virtual void Include17() [MemberData(nameof(IsAsyncData))] public virtual Task Include18_1(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(x => x.OneToOne_Optional_FK1).Distinct(), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include18_1_1(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().OrderBy(x => x.OneToOne_Required_FK1.Name).Include(x => x.OneToOne_Optional_FK1).Take(10), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include18_2(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK1) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Where(x => x.OneToOne_Required_FK1.Name != "Foo").Include(x => x.OneToOne_Optional_FK1).Distinct(), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalFact] @@ -4355,18 +4285,18 @@ public virtual void Include18_3_2() [MemberData(nameof(IsAsyncData))] public virtual Task Include18_3_3(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(l1 => l1.OneToOne_Optional_FK2) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(x => x.OneToOne_Optional_FK1.OneToOne_Optional_FK2) .Select(l1 => l1.OneToOne_Optional_FK1) .Distinct(), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalFact] @@ -4511,21 +4441,21 @@ public virtual void IncludeCollection7() [MemberData(nameof(IsAsyncData))] public virtual Task IncludeCollection8(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.OneToMany_Optional1), new ExpectedInclude(e => e.OneToOne_Optional_PK2, "OneToMany_Optional1"), new ExpectedInclude(e => e.OneToOne_Optional_FK3, "OneToMany_Optional1.OneToOne_Optional_PK2") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) .ThenInclude(l2 => l2.OneToOne_Optional_PK2) .ThenInclude(l3 => l3.OneToOne_Optional_FK3) .Where(l1 => l1.OneToMany_Optional1.Where(l2 => l2.OneToOne_Optional_PK2.Name != "Foo").Count() > 0), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -4645,14 +4575,12 @@ public virtual Task Member_pushdown_with_multiple_collections(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_multiple_collections_on_same_level(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1).Include(l1 => l1.OneToMany_Required1), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(l1 => l1.OneToMany_Optional1), - new ExpectedInclude(l1 => l1.OneToMany_Required1) - }, + new ExpectedInclude(l1 => l1.OneToMany_Required1)), assertOrder: true); } @@ -4985,113 +4913,99 @@ public virtual Task Contains_over_optional_navigation_with_null_entity_reference [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_basic_Where(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.Where(l2 => l2.Id > 5)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, - includeFilter: x => x.Where(l2 => l2.Id > 5)) - }); + includeFilter: x => x.Where(l2 => l2.Id > 5)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_OrderBy(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, - includeFilter: x => x.OrderBy(x => x.Name)) - }); + includeFilter: x => x.OrderBy(x => x.Name)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_ThenInclude_OrderBy(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToMany_Optional2.OrderBy(x => x.Name)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional1), new ExpectedFilteredInclude( e => e.OneToMany_Optional2, "OneToMany_Optional1", - includeFilter: x => x.OrderBy(x => x.Name)) - }); + includeFilter: x => x.OrderBy(x => x.Name)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_ThenInclude_OrderBy(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name)) .ThenInclude(l2 => l2.OneToMany_Optional2.OrderByDescending(x => x.Name)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, includeFilter: x => x.OrderBy(x => x.Name)), new ExpectedFilteredInclude( e => e.OneToMany_Optional2, "OneToMany_Optional1", - includeFilter: x => x.OrderByDescending(x => x.Name)) - }); + includeFilter: x => x.OrderByDescending(x => x.Name)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_basic_OrderBy_Take(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name).Take(3)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, - includeFilter: x => x.OrderBy(x => x.Name).Take(3)) - }); + includeFilter: x => x.OrderBy(x => x.Name).Take(3)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_basic_OrderBy_Skip(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name).Skip(1)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, - includeFilter: x => x.OrderBy(x => x.Name).Skip(1)) - }); + includeFilter: x => x.OrderBy(x => x.Name).Skip(1)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_basic_OrderBy_Skip_Take(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(l1 => l1.OneToMany_Optional1.OrderBy(x => x.Name).Skip(1).Take(3)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, - includeFilter: x => x.OrderBy(x => x.Name).Skip(1).Take(3)) - }); + includeFilter: x => x.OrderBy(x => x.Name).Skip(1).Take(3)))); } [ConditionalFact] @@ -5114,78 +5028,70 @@ public virtual void Filtered_include_Take_without_OrderBy() [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_on_ThenInclude(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1) .ThenInclude(l2 => l2.OneToMany_Optional2.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Skip(1).Take(3)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToOne_Optional_FK1), new ExpectedFilteredInclude( e => e.OneToMany_Optional2, "OneToOne_Optional_FK1", - x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Skip(1).Take(3)) - }); + x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Skip(1).Take(3)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_after_reference_navigation(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToOne_Optional_FK1.OneToMany_Optional2.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Skip(1).Take(3)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToOne_Optional_FK1), new ExpectedFilteredInclude( e => e.OneToMany_Optional2, "OneToOne_Optional_FK1", - x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Skip(1).Take(3)) - }); + x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Skip(1).Take(3)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_after_different_filtered_include_same_level(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Take(3)) .Include(l1 => l1.OneToMany_Required1.Where(x => x.Name != "Bar").OrderByDescending(x => x.Name).Skip(1)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Take(3)), new ExpectedFilteredInclude( e => e.OneToMany_Required1, - includeFilter: x => x.Where(x => x.Name != "Bar").OrderByDescending(x => x.Name).Skip(1)) - }); + includeFilter: x => x.Where(x => x.Name != "Bar").OrderByDescending(x => x.Name).Skip(1)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_after_different_filtered_include_different_level(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Take(3)) .ThenInclude(l2 => l2.OneToMany_Required2.Where(x => x.Name != "Bar").OrderByDescending(x => x.Name).Skip(1)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Name).Take(3)), new ExpectedFilteredInclude( e => e.OneToMany_Required2, "OneToMany_Optional1", - includeFilter: x => x.Where(x => x.Name != "Bar").OrderByDescending(x => x.Name).Skip(1)) - }); + includeFilter: x => x.Where(x => x.Name != "Bar").OrderByDescending(x => x.Name).Skip(1)))); } [ConditionalTheory] @@ -5216,102 +5122,91 @@ public virtual async Task Filtered_include_different_filter_set_on_same_navigati [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_same_filter_set_on_same_navigation_twice(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderByDescending(x => x.Id).Take(2)) .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderByDescending(x => x.Id).Take(2)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, - includeFilter: x => x.Where(x => x.Name != "Foo").OrderByDescending(x => x.Id).Take(2)), - }); + includeFilter: x => x.Where(x => x.Name != "Foo").OrderByDescending(x => x.Id).Take(2)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_same_filter_set_on_same_navigation_twice_followed_by_ThenIncludes(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(2)).ThenInclude(l2 => l2.OneToMany_Optional2) .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(2)).ThenInclude(l2 => l2.OneToOne_Required_FK2), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(2)), new ExpectedInclude(e => e.OneToMany_Optional2), - new ExpectedInclude(e => e.OneToOne_Required_FK2), - }); + new ExpectedInclude(e => e.OneToOne_Required_FK2))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_multiple_multi_level_includes_with_first_level_using_filter_include_on_one_of_the_chains_only(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(2)).ThenInclude(l2 => l2.OneToMany_Optional2) .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Required_FK2), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(2)), new ExpectedInclude(e => e.OneToMany_Optional2, "OneToMany_Optional1"), - new ExpectedInclude(e => e.OneToOne_Required_FK2, "OneToMany_Optional1"), - }); + new ExpectedInclude(e => e.OneToOne_Required_FK2, "OneToMany_Optional1"))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_and_non_filtered_include_on_same_navigation1(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1) .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, - includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3)) - }); + includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_and_non_filtered_include_on_same_navigation2(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3)) .Include(l1 => l1.OneToMany_Optional1), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, - includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3)) - }); + includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(3)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_and_non_filtered_include_followed_by_then_include_on_same_navigation(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(1)) .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToOne_Optional_PK2.OneToMany_Optional3.Where(x => x.Id > 1)), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedFilteredInclude( e => e.OneToMany_Optional1, includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(1)), @@ -5319,50 +5214,45 @@ public virtual Task Filtered_include_and_non_filtered_include_followed_by_then_i new ExpectedFilteredInclude( e => e.OneToMany_Optional3, "OneToMany_Optional1.OneToOne_Optional_PK2", - includeFilter: x => x.Where(x => x.Id > 1)), - }); + includeFilter: x => x.Where(x => x.Id > 1)))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_complex_three_level_with_middle_having_filter1(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToMany_Optional2.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(1)).ThenInclude(l3 => l3.OneToMany_Optional3) .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToMany_Optional2.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(1)).ThenInclude(l3 => l3.OneToMany_Required3), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional1), new ExpectedFilteredInclude( e => e.OneToMany_Optional2, "OneToMany_Optional1", includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(1)), new ExpectedInclude(e => e.OneToMany_Optional3, "OneToMany_Optional1.OneToMany_Optional2"), - new ExpectedInclude(e => e.OneToMany_Required3, "OneToMany_Optional1.OneToMany_Optional2"), - }); + new ExpectedInclude(e => e.OneToMany_Required3, "OneToMany_Optional1.OneToMany_Optional2"))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Filtered_include_complex_three_level_with_middle_having_filter2(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToMany_Optional2.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(1)).ThenInclude(l3 => l3.OneToMany_Optional3) .Include(l1 => l1.OneToMany_Optional1).ThenInclude(l2 => l2.OneToMany_Optional2).ThenInclude(l3 => l3.OneToMany_Required3), - new List - { + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.OneToMany_Optional1), new ExpectedFilteredInclude( e => e.OneToMany_Optional2, "OneToMany_Optional1", includeFilter: x => x.Where(x => x.Name != "Foo").OrderBy(x => x.Id).Take(1)), new ExpectedInclude(e => e.OneToMany_Optional3, "OneToMany_Optional1.OneToMany_Optional2"), - new ExpectedInclude(e => e.OneToMany_Required3, "OneToMany_Optional1.OneToMany_Optional2"), - }); + new ExpectedInclude(e => e.OneToMany_Required3, "OneToMany_Optional1.OneToMany_Optional2"))); } [ConditionalFact] diff --git a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs index b838e459906..a17068d20e7 100644 --- a/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs @@ -48,17 +48,17 @@ public virtual Task Entity_equality_empty(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_multiple_one_to_one_and_one_to_many(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(t => t.Gear), new ExpectedInclude(g => g.Weapons, "Gear"), new ExpectedInclude(o => o.Weapons, "Gear") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(t => t.Gear.Weapons), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -89,17 +89,17 @@ public virtual Task Include_multiple_one_to_one_and_one_to_many_self_reference(b [MemberData(nameof(IsAsyncData))] public virtual Task Include_multiple_one_to_one_optional_and_one_to_one_required(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(t => t.Gear), new ExpectedInclude(g => g.Squad, "Gear"), new ExpectedInclude(o => o.Squad, "Gear") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(t => t.Gear.Squad), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -114,49 +114,49 @@ public virtual Task Include_multiple_one_to_one_and_one_to_one_and_one_to_many(b [MemberData(nameof(IsAsyncData))] public virtual Task Include_multiple_circular(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.CityOfBirth), new ExpectedInclude(o => o.CityOfBirth), new ExpectedInclude(c => c.StationedGears, "CityOfBirth") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(g => g.CityOfBirth.StationedGears), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_multiple_circular_with_filter(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.CityOfBirth), new ExpectedInclude(o => o.CityOfBirth), new ExpectedInclude(c => c.StationedGears, "CityOfBirth") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(g => g.CityOfBirth.StationedGears).Where(g => g.Nickname == "Marcus"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_using_alternate_key(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.Weapons), new ExpectedInclude(o => o.Weapons) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(g => g.Weapons).Where(g => g.Nickname == "Marcus"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -178,116 +178,116 @@ public virtual Task Include_multiple_include_then_include(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_navigation_on_derived_type(bool async) { - var expectedIncludes = new List { new ExpectedInclude(o => o.Reports) }; + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.Reports) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().OfType().Include(o => o.Reports), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task String_based_Include_navigation_on_derived_type(bool async) { - var expectedIncludes = new List { new ExpectedInclude(o => o.Reports) }; + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.Reports) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().OfType().Include("Reports"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Select_Where_Navigation_Included(bool async) { - var expectedIncludes = new List { new ExpectedInclude(t => t.Gear) }; + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(t => t.Gear) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => from t in ss.Set().Include(o => o.Gear) where t.Gear.Nickname == "Marcus" select t, - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_reference1(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.CityOfBirth), new ExpectedInclude(o => o.CityOfBirth) }; - return AssertIncludeQuery( + return 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), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_reference2(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.CityOfBirth), new ExpectedInclude(o => o.CityOfBirth) }; - return AssertIncludeQuery( + return 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), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_collection1(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.Weapons), new ExpectedInclude(o => o.Weapons) }; - return AssertIncludeQuery( + return 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), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_collection2(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.Weapons), new ExpectedInclude(o => o.Weapons) }; - return AssertIncludeQuery( + return 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), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -359,46 +359,46 @@ public virtual async Task Navigation_accessed_twice_outside_and_inside_subquery( [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_multi_level(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.CityOfBirth), new ExpectedInclude(o => o.CityOfBirth), new ExpectedInclude(c => c.StationedGears, "CityOfBirth") }; - return AssertIncludeQuery( + return 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), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_and_inheritance1(bool async) { - var expectedIncludes = new List { new ExpectedInclude(o => o.CityOfBirth) }; + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.CityOfBirth) }; - return AssertIncludeQuery( + return 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), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_and_inheritance_with_orderby_before_and_after_include(bool async) { - var expectedIncludes = new List { new ExpectedInclude(o => o.Reports) }; + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.Reports) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Join( ss.Set().OfType().OrderBy(ee => ee.SquadId), @@ -406,7 +406,7 @@ 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), - expectedIncludes, + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), assertOrder: true); } @@ -414,47 +414,47 @@ public virtual Task Include_with_join_and_inheritance_with_orderby_before_and_af [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_and_inheritance2(bool async) { - var expectedIncludes = new List { new ExpectedInclude(o => o.Weapons) }; + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.Weapons) }; - return AssertIncludeQuery( + return 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), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_join_and_inheritance3(bool async) { - var expectedIncludes = new List { new ExpectedInclude(o => o.Reports) }; + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(o => o.Reports) }; - return AssertIncludeQuery( + return 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), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_nested_navigation_in_order_by(bool async) { - var expectedIncludes = new List { new ExpectedInclude(w => w.Owner) }; + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(w => w.Owner) }; - return AssertIncludeQuery( + return 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), - expectedIncludes, + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), assertOrder: true); } @@ -1711,26 +1711,26 @@ join w in ss.Set().OrderBy(ww => ww.Name) on g.FullName equals w.OwnerFu [MemberData(nameof(IsAsyncData))] public virtual Task Collection_with_inheritance_and_join_include_joined(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => (from t in ss.Set() join g in ss.Set().OfType() on new { id1 = t.GearSquadId, id2 = t.GearNickName } equals new { id1 = (int?)g.SquadId, id2 = g.Nickname } select g).Include(g => g.Tag), - new List { new ExpectedInclude(o => o.Tag) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Tag))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Collection_with_inheritance_and_join_include_source(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => (from g in ss.Set().OfType() join t in ss.Set() on new { id1 = (int?)g.SquadId, id2 = g.Nickname } equals new { id1 = t.GearSquadId, id2 = t.GearNickName } select g).Include(g => g.Tag), - new List { new ExpectedInclude(o => o.Tag) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Tag))); } [ConditionalTheory] @@ -1866,31 +1866,31 @@ from g2 in grouping.DefaultIfEmpty() [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_coalesce_result3(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.Weapons), new ExpectedInclude(g => g.Weapons) }; - return AssertIncludeQuery( + return 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, - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory(Skip = "Issue#16899")] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_coalesce_result4(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.Weapons), new ExpectedInclude(g => g.Weapons) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => from g1 in ss.Set().Include(g => g.Weapons) join g2 in ss.Set().Include(g => g.Weapons) @@ -1902,45 +1902,44 @@ from g2 in grouping.DefaultIfEmpty() g2, coalesce = g2 ?? g1 }, - expectedIncludes, - elementSorter: e => e.g1.Nickname, - clientProjections: new List> + elementAsserter: (e, a) => { - r => r.g1, - r => r.g2, - r => r.coalesce - }); + AssertInclude(e.g1, a.g1, expectedIncludes); + AssertInclude(e.g2, a.g2, expectedIncludes); + AssertInclude(e.coalesce, a.coalesce, expectedIncludes); + }, + elementSorter: e => e.g1.Nickname); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_inheritance_and_coalesce_result(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.Weapons), new ExpectedInclude(g => g.Weapons) }; - return AssertIncludeQuery( + return 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, - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory(Skip = "Issue#15783")] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_conditional_result(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.Weapons), new ExpectedInclude(g => g.Weapons) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => from g1 in ss.Set().Include(g => g.Weapons) join g2 in ss.Set().Include(g => g.Weapons) @@ -1949,19 +1948,19 @@ from g2 in grouping.DefaultIfEmpty() #pragma warning disable IDE0029 // Use coalesce expression select g2 != null ? g2 : g1, #pragma warning restore IDE0029 // Use coalesce expression - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory(Skip = "issue #16899")] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_GroupJoin_SelectMany_DefaultIfEmpty_with_complex_projection_result(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.Weapons), new ExpectedInclude(g => g.Weapons) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => from g1 in ss.Set().Include(g => g.Weapons) join g2 in ss.Set().Include(g => g.Weapons) @@ -1976,15 +1975,14 @@ from g2 in grouping.DefaultIfEmpty() conditional = g2 != null ? g2 : g1 }, #pragma warning restore IDE0029 // Use coalesce expression - expectedIncludes, - elementSorter: e => e.g1.Nickname + " " + e.g2?.Nickname, - clientProjections: new List> + elementAsserter: (e, a) => { - e => e.g1, - e => e.g2, - e => e.coalesce, - e => e.conditional - }); + AssertInclude(e.g1, a.g1, expectedIncludes); + AssertInclude(e.g2, a.g2, expectedIncludes); + AssertInclude(e.coalesce, a.coalesce, expectedIncludes); + AssertInclude(e.conditional, a.conditional, expectedIncludes); + }, + elementSorter: e => e.g1.Nickname + " " + e.g2?.Nickname); } [ConditionalTheory] @@ -2736,7 +2734,7 @@ public virtual Task Order_by_is_properly_lifted_from_subquery_with_same_order_by [MemberData(nameof(IsAsyncData))] public virtual Task Where_is_properly_lifted_from_subquery_created_by_include(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Where(g => g.FullName != "Augustus Cole") @@ -2744,7 +2742,7 @@ public virtual Task Where_is_properly_lifted_from_subquery_created_by_include(bo .OrderBy(g => g.FullName) .Where(g => !g.HasSoulPatch) .Select(g => g), - expectedIncludes: new List { new ExpectedInclude(e => e.Tag) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.Tag)), assertOrder: true); } @@ -2833,13 +2831,13 @@ join tag in ss.Set() on gear.Nickname equals tag.GearNickName [MemberData(nameof(IsAsyncData))] public virtual Task Subquery_created_by_include_gets_lifted_nested(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => from gear in ss.Set().OrderBy(g => g.Rank).Where(g => g.Weapons.Any()).Include(g => g.CityOfBirth) where !gear.HasSoulPatch orderby gear.Nickname select gear, - expectedIncludes: new List { new ExpectedInclude(e => e.CityOfBirth) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.CityOfBirth)), assertOrder: true); } @@ -3161,18 +3159,18 @@ orderby l.Name [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_derived_entity_using_OfType(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Commander), new ExpectedInclude(e => e.Leaders) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => from lh in ss.Set().OfType().Include(h => h.Commander).Include(h => h.Leaders) orderby lh.Name select lh, - expectedIncludes, + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), assertOrder: true); } @@ -3180,15 +3178,15 @@ orderby lh.Name [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_derived_entity_with_cast(bool async) { - var expectedIncludes = new List { new ExpectedInclude(e => e.Capital) }; + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Capital) }; // TODO: should we disable this scenario? see #14671 - return AssertIncludeQuery( + return AssertQuery( async, ss => (from f in ss.Set() where f is LocustHorde select f).Include(f => f.Capital), - expectedIncludes, + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), assertOrder: true); } @@ -3360,217 +3358,217 @@ public virtual Task Project_collection_navigation_with_inheritance3(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_on_derived_type_using_string(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("DefeatedBy"), - new List { new ExpectedInclude(lc => lc.DefeatedBy) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(lc => lc.DefeatedBy))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_on_derived_type_using_string_nested1(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(lc => lc.DefeatedBy), new ExpectedInclude(g => g.Squad, "DefeatedBy") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("DefeatedBy.Squad"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_on_derived_type_using_string_nested2(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(lc => lc.DefeatedBy), new ExpectedInclude(o => o.Reports, "DefeatedBy"), new ExpectedInclude(g => g.CityOfBirth, "DefeatedBy.Reports") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("DefeatedBy.Reports.CityOfBirth"), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_on_derived_type_using_lambda(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(ll => ((LocustCommander)ll).DefeatedBy), - new List { new ExpectedInclude(lc => lc.DefeatedBy) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(lc => lc.DefeatedBy))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_on_derived_type_using_lambda_with_soft_cast(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(ll => (ll as LocustCommander).DefeatedBy), - new List { new ExpectedInclude(lc => lc.DefeatedBy) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(lc => lc.DefeatedBy))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_reference_on_derived_type_using_lambda_with_tracking(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().AsTracking().Include(ll => ((LocustCommander)ll).DefeatedBy), - new List { new ExpectedInclude(lc => lc.DefeatedBy) }, - entryCount: 7); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(lc => lc.DefeatedBy)), + entryCount: 7); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_on_derived_type_using_string(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include("Reports"), - new List { new ExpectedInclude(o => o.Reports) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_on_derived_type_using_lambda(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(g => ((Officer)g).Reports), - new List { new ExpectedInclude(o => o.Reports) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_on_derived_type_using_lambda_with_soft_cast(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(g => (g as Officer).Reports), - new List { new ExpectedInclude(o => o.Reports) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports))); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_base_navigation_on_derived_entity(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Tag), new ExpectedInclude(e => e.Weapons) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(g => ((Officer)g).Tag).Include(g => ((Officer)g).Weapons), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task ThenInclude_collection_on_derived_after_base_reference(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Gear), new ExpectedInclude(e => e.Weapons, "Gear") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(t => t.Gear).ThenInclude(g => (g as Officer).Weapons), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task ThenInclude_collection_on_derived_after_derived_reference(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Commander), new ExpectedInclude(e => e.DefeatedBy, "Commander"), new ExpectedInclude(e => e.Reports, "Commander.DefeatedBy") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(f => (f as LocustHorde).Commander).ThenInclude(c => (c.DefeatedBy as Officer).Reports), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task ThenInclude_collection_on_derived_after_derived_collection(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Reports), new ExpectedInclude(e => e.Reports, "Reports") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(g => ((Officer)g).Reports).ThenInclude(g => ((Officer)g).Reports), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task ThenInclude_reference_on_derived_after_derived_collection(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Leaders), new ExpectedInclude(e => e.DefeatedBy, "Leaders") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(f => ((LocustHorde)f).Leaders).ThenInclude(l => ((LocustCommander)l).DefeatedBy), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Multiple_derived_included_on_one_method(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Commander), new ExpectedInclude(e => e.DefeatedBy, "Commander"), new ExpectedInclude(e => e.Reports, "Commander.DefeatedBy") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(f => (((LocustHorde)f).Commander.DefeatedBy as Officer).Reports), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_derived_multi_level(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.Reports), new ExpectedInclude(e => e.Squad, "Reports"), new ExpectedInclude(e => e.Missions, "Reports.Squad") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(g => ((Officer)g).Reports).ThenInclude(g => g.Squad.Missions), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory(Skip = "Issue#15312")] @@ -4733,18 +4731,18 @@ from h in grouping.DefaultIfEmpty() [MemberData(nameof(IsAsyncData))] public virtual Task Include_on_derived_type_with_order_by_and_paging(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.DefeatedBy), new ExpectedInclude(e => e.Weapons, "DefeatedBy") }; - return AssertIncludeQuery( + return 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), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] @@ -4839,16 +4837,16 @@ from g in grouping.DefaultIfEmpty() [MemberData(nameof(IsAsyncData))] public virtual async Task Include_with_concat(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(g => g.Squad), new ExpectedInclude(o => o.Squad) }; var message = (await Assert.ThrowsAsync( - () => AssertIncludeQuery( + () => AssertQuery( async, ss => ss.Set().Include(g => g.Squad).Concat(ss.Set()), - expectedIncludes))).Message; + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)))).Message; Assert.Equal( "When performing a set operation, both operands must have the same Include operations.", @@ -5169,11 +5167,11 @@ public virtual Task Select_subquery_projecting_multiple_constants_inside_anonymo [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_order_by_constant(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(s => s.Members).OrderBy(s => 42).Select(s => s), expectedQuery: ss => ss.Set(), - new List { new ExpectedInclude(s => s.Members) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(s => s.Members))); } [ConditionalTheory] @@ -5225,31 +5223,6 @@ public virtual Task Select_subquery_projecting_single_constant_of_non_mapped_typ }); } - [ConditionalTheory(Skip = "issue #11567")] - [MemberData(nameof(IsAsyncData))] - public virtual Task Include_with_order_by_constant_null_of_non_mapped_type(bool async) - { - return AssertIncludeQuery( - async, - ss => ss.Set().Include(s => s.Members).OrderBy(s => (MyDTO)null), - expectedQuery: ss => ss.Set(), - new List { new ExpectedInclude(s => s.Members) }); - } - - [ConditionalFact(Skip = "issue #11567")] - public virtual void Include_groupby_constant_null_of_non_mapped_type() - { - using var ctx = CreateContext(); - var query = ctx.Squads.Include(s => s.Members).GroupBy(s => (MyDTO)null); - var result = query.ToList(); - - Assert.Single(result); - var bucket = result[0].ToList(); - Assert.Equal(2, bucket.Count); - Assert.NotNull(bucket[0].Members); - Assert.NotNull(bucket[1].Members); - } - [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Correlated_collection_order_by_constant_null_of_non_mapped_type(bool async) @@ -5271,12 +5244,12 @@ public virtual Task Correlated_collection_order_by_constant_null_of_non_mapped_t [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_OrderBy_aggregate(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().OfType() .Include(o => o.Reports) .OrderBy(o => o.Weapons.Count).ThenBy(o => o.Nickname), - new List { new ExpectedInclude(o => o.Reports) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports)), assertOrder: true); } @@ -5284,12 +5257,12 @@ public virtual Task Include_collection_OrderBy_aggregate(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_complex_OrderBy2(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().OfType() .Include(o => o.Reports) .OrderBy(o => o.Weapons.OrderBy(w => w.Id).FirstOrDefault().IsAutomatic).ThenBy(o => o.Nickname), - new List { new ExpectedInclude(o => o.Reports) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports)), assertOrder: true); } @@ -5297,12 +5270,12 @@ public virtual Task Include_collection_with_complex_OrderBy2(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_complex_OrderBy3(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().OfType() .Include(o => o.Reports) .OrderBy(o => o.Weapons.OrderBy(w => w.Id).Select(w => w.IsAutomatic).FirstOrDefault()).ThenBy(o => o.Nickname), - new List { new ExpectedInclude(o => o.Reports) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Reports)), assertOrder: true); } @@ -5790,7 +5763,7 @@ public virtual Task GroupBy_Property_Include_Aggregate_with_anonymous_selector(b [MemberData(nameof(IsAsyncData))] public virtual Task Group_by_entity_key_with_include_on_that_entity_with_key_in_result_selector(bool async) { - // TODO: convert to AssertIncludeQuery + // TODO: convert to AssertQuery return AssertQuery( async, ss => ss.Set() @@ -5811,7 +5784,7 @@ public virtual Task Group_by_entity_key_with_include_on_that_entity_with_key_in_ [MemberData(nameof(IsAsyncData))] public virtual Task Group_by_entity_key_with_include_on_that_entity_with_key_in_result_selector_using_EF_Property(bool async) { - // TODO: convert to AssertIncludeQuery + // TODO: convert to AssertQuery return AssertQuery( async, ss => ss.Set() @@ -5861,26 +5834,26 @@ public virtual Task Group_by_with_include_with_entity_in_result_selector(bool as [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_group_by_and_FirstOrDefault_gets_properly_applied(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(e => e.CityOfBirth), new ExpectedInclude(e => e.CityOfBirth) }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().Include(g => g.CityOfBirth).GroupBy(g => g.Rank).Select(g => g.FirstOrDefault(gg => gg.HasSoulPatch)), - expectedIncludes); + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes)); } [ConditionalTheory] [MemberData(nameof(IsAsyncData))] public virtual Task Include_collection_with_Cast_to_base(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().OfType().Include(o => o.Weapons).Cast(), - new List { new ExpectedInclude(e => e.Weapons) }); + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.Weapons))); } [ConditionalTheory] @@ -6200,13 +6173,13 @@ public virtual Task Project_derivied_entity_with_convert_to_parent(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_complex_order_by(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(g => g.Weapons) .OrderBy(g => g.Weapons.FirstOrDefault(w => w.Name.Contains("Gnasher")).Name) .ThenBy(g => g.Nickname), - expectedIncludes: new List { new ExpectedInclude(e => e.Weapons) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(e => e.Weapons)), assertOrder: true); } @@ -6503,13 +6476,11 @@ public virtual Task Acessing_reference_navigation_collection_composition_generat [MemberData(nameof(IsAsyncData))] public virtual Task Reference_include_chain_loads_correctly_when_middle_is_null(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set().AsTracking().OrderBy(t => t.Note).Include(t => t.Gear).ThenInclude(g => g.Squad), - new List - { - new ExpectedInclude(t => t.Gear), new ExpectedInclude(t => t.Squad, "Gear") - }, + elementAsserter: (e, a) => AssertInclude(e, a, + new ExpectedInclude(t => t.Gear), new ExpectedInclude(t => t.Squad, "Gear")), entryCount: 13); } diff --git a/test/EFCore.Specification.Tests/Query/NorthwindNavigationsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindNavigationsQueryTestBase.cs index 4ff9e169cf6..7a6ff277108 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindNavigationsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindNavigationsQueryTestBase.cs @@ -306,12 +306,12 @@ where o2.CustomerID.StartsWith("A") [MemberData(nameof(IsAsyncData))] public virtual Task Select_Where_Navigation_Included(bool async) { - return AssertIncludeQuery( + return AssertQuery( async, ss => from o in ss.Set().Include(o => o.Customer) where o.Customer.City == "Seattle" select o, - new List { new ExpectedInclude(o => o.Customer) }, + elementAsserter: (e, a) => AssertInclude(e, a, new ExpectedInclude(o => o.Customer)), entryCount: 15); } @@ -319,18 +319,18 @@ public virtual Task Select_Where_Navigation_Included(bool async) [MemberData(nameof(IsAsyncData))] public virtual Task Include_with_multiple_optional_navigations(bool async) { - var expectedIncludes = new List + var expectedIncludes = new IExpectedInclude[] { new ExpectedInclude(od => od.Order), new ExpectedInclude(o => o.Customer, "Order") }; - return AssertIncludeQuery( + return AssertQuery( async, ss => ss.Set() .Include(od => od.Order.Customer) .Where(od => od.Order.Customer.City == "London"), - expectedIncludes, + elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes), entryCount: 164); } @@ -985,7 +985,7 @@ public virtual void Navigation_in_subquery_referencing_outer_query() { using var context = CreateContext(); var query = from o in context.Orders - // ReSharper disable once UseMethodAny.0 + // ReSharper disable once UseMethodAny.0 where (from od in context.OrderDetails where o.Customer.Country == od.Order.Customer.Country select od).Count() diff --git a/test/EFCore.Specification.Tests/Query/QueryTestBase.cs b/test/EFCore.Specification.Tests/Query/QueryTestBase.cs index 21573effc31..8f526b8f179 100644 --- a/test/EFCore.Specification.Tests/Query/QueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/QueryTestBase.cs @@ -80,47 +80,6 @@ public Task AssertQueryScalar( where TResult : struct => Fixture.QueryAsserter.AssertQueryScalar(actualQuery, expectedQuery, assertOrder, async, testMethodName); - public Task> AssertIncludeQuery( - bool async, - Func> query, - List expectedIncludes, - Func elementSorter = null, - List> clientProjections = null, - bool assertOrder = false, - int entryCount = 0, - [CallerMemberName] string testMethodName = null) - => AssertIncludeQuery( - async, - query, - query, - expectedIncludes, - elementSorter, - clientProjections, - assertOrder, - entryCount, - testMethodName); - - public Task> AssertIncludeQuery( - bool async, - Func> actualQuery, - Func> expectedQuery, - List expectedIncludes, - Func elementSorter = null, - List> clientProjections = null, - bool assertOrder = false, - int entryCount = 0, - [CallerMemberName] string testMethodName = null) - => Fixture.QueryAsserter.AssertIncludeQuery( - actualQuery, - expectedQuery, - expectedIncludes, - elementSorter, - clientProjections, - assertOrder, - entryCount, - async, - testMethodName); - protected Task AssertSingleResult( bool async, Expression> syncQuery, @@ -1117,6 +1076,12 @@ protected void AssertCollection( Action elementAsserter = null) => Fixture.QueryAsserter.AssertCollection(expected, actual, ordered, elementSorter, elementAsserter); + protected void AssertInclude( + TEntity expected, + TEntity actual, + params IExpectedInclude[] expectedIncludes) + => Fixture.QueryAsserter.AssertInclude(expected, actual, expectedIncludes); + protected void AssertGrouping( IGrouping expected, IGrouping actual, diff --git a/test/EFCore.Specification.Tests/TestUtilities/QueryAsserter.cs b/test/EFCore.Specification.Tests/TestUtilities/QueryAsserter.cs index de258892953..78eff087cbb 100644 --- a/test/EFCore.Specification.Tests/TestUtilities/QueryAsserter.cs +++ b/test/EFCore.Specification.Tests/TestUtilities/QueryAsserter.cs @@ -212,69 +212,6 @@ public override async Task AssertQueryScalar( assertOrder); } - public override async Task> AssertIncludeQuery( - Func> actualQuery, - Func> expectedQuery, - List expectedIncludes, - Func elementSorter, - List> clientProjections, - bool assertOrder, - int entryCount, - bool async, - string testMethodName) - { - using var context = _contextCreator(); - var query = actualQuery(SetSourceCreator(context)); - if (ProceduralQueryGeneration && !async) - { - new ProcedurallyGeneratedQueryExecutor().Execute(query, context, testMethodName); - - return default; - } - - OrderingSettingsVerifier(assertOrder, query.Expression.Type, elementSorter); - - var actual = async - ? await query.ToListAsync() - : query.ToList(); - - AssertRogueExecution(actual.Count, query); - - var expected = GetExpectedResults(expectedQuery).ToList(); - - if (!assertOrder - && elementSorter == null) - { - _entitySorters.TryGetValue(typeof(TResult), out var sorter); - elementSorter = (Func)sorter; - } - - if (elementSorter != null) - { - actual = actual.OrderBy(elementSorter).ToList(); - expected = expected.OrderBy(elementSorter).ToList(); - } - - if (clientProjections != null) - { - foreach (var clientProjection in clientProjections) - { - var projectedActual = actual.Select(clientProjection).ToList(); - var projectedExpected = expected.Select(clientProjection).ToList(); - - _includeResultAsserter.AssertResult(projectedExpected, projectedActual, expectedIncludes); - } - } - else - { - _includeResultAsserter.AssertResult(expected, actual, expectedIncludes); - } - - Assert.Equal(entryCount, context.ChangeTracker.Entries().Count()); - - return actual; - } - #region Assert termination operation methods public override async Task AssertAny( @@ -1551,6 +1488,9 @@ public override void AssertCollection( } } + public override void AssertInclude(TEntity expected, TEntity actual, IExpectedInclude[] expectedIncludes) + => _includeResultAsserter.AssertResult(expected, actual, expectedIncludes); + #endregion private class DefaultSetSource : ISetSource diff --git a/test/EFCore.Specification.Tests/TestUtilities/QueryAsserterBase.cs b/test/EFCore.Specification.Tests/TestUtilities/QueryAsserterBase.cs index 493f46d804f..c094bae47d0 100644 --- a/test/EFCore.Specification.Tests/TestUtilities/QueryAsserterBase.cs +++ b/test/EFCore.Specification.Tests/TestUtilities/QueryAsserterBase.cs @@ -51,17 +51,6 @@ public abstract Task AssertQueryScalar( string testMethodName) where TResult : struct; - public abstract Task> AssertIncludeQuery( - Func> actualQuery, - Func> expectedQuery, - List expectedIncludes, - Func elementSorter, - List> clientProjections, - bool assertOrder, - int entryCount, - bool async, - string testMethodName); - #region Assert termination operation methods public abstract Task AssertAny( @@ -537,6 +526,11 @@ public abstract void AssertCollection( Func elementSorter = null, Action elementAsserter = null); + public abstract void AssertInclude( + TEntity expected, + TEntity actual, + IExpectedInclude[] expectedIncludes); + #endregion } } diff --git a/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs b/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs index 3fa5d525f59..dac4d1dc44e 100644 --- a/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs +++ b/test/EFCore.Specification.Tests/TestUtilities/TestHelpers.cs @@ -208,22 +208,17 @@ public static int AssertResults( Assert.Equal(expected.Count, actual.Count); if (elementSorter == null - && !verifyOrdered) + && !verifyOrdered + && expected.FirstOrDefault(e => e != null) is T nonNullElement + && nonNullElement.GetType().GetInterface(nameof(IComparable)) == null) { - if (expected.Count > 1) + if (elementAsserter != null) { - if (expected.FirstOrDefault(e => e != null) is T nonNullElement - && nonNullElement.GetType().GetInterface(nameof(IComparable)) == null) - { - if (elementAsserter != null) - { - throw new InvalidOperationException( - "Element asserter will not be used because results are not properly ordered - either remove asserter from the AssertQuery, add element sorter or set assertOrder to 'true'."); - } - - return AssertResults(expected, actual); - } + throw new InvalidOperationException( + "Element asserter will not be used because results are not properly ordered - either remove asserter from the AssertQuery, add element sorter or set assertOrder to 'true'."); } + + return AssertResults(expected, actual); } elementSorter ??= (e => e); diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index b3b5e14b72c..b3368267768 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -4839,22 +4839,6 @@ FROM [Gears] AS [g] ) AS [t0] ON [s].[Id] = [t0].[SquadId]"); } - public override async Task Include_with_order_by_constant_null_of_non_mapped_type(bool async) - { - await base.Include_with_order_by_constant_null_of_non_mapped_type(async); - - AssertSql( - ""); - } - - public override void Include_groupby_constant_null_of_non_mapped_type() - { - base.Include_groupby_constant_null_of_non_mapped_type(); - - AssertSql( - ""); - } - public override async Task Include_collection_OrderBy_aggregate(bool async) { await base.Include_collection_OrderBy_aggregate(async);