Skip to content

Commit 89a46a9

Browse files
committed
Additional regression tests for issues that have been fixed previously
Resolves #10295 Resolves #12453 Resolves #13216 Resolves #13550 Resolves #13712 Resolves #13977 Resolves #15302 Resolves #17735
1 parent b715a35 commit 89a46a9

11 files changed

+593
-0
lines changed

test/EFCore.InMemory.FunctionalTests/Query/GearsOfWarQueryInMemoryTest.cs

+4
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,9 @@ public override Task Client_eval_followed_by_set_operation_throws_meaningful_exc
7272
[ConditionalTheory(Skip = "issue #17537")]
7373
public override Task SelectMany_predicate_with_non_equality_comparison_with_Take_doesnt_convert_to_join(bool async)
7474
=> base.SelectMany_predicate_with_non_equality_comparison_with_Take_doesnt_convert_to_join(async);
75+
76+
[ConditionalTheory(Skip = "issue #19584")]
77+
public override Task Cast_to_derived_followed_by_include_and_FirstOrDefault(bool async)
78+
=> base.Cast_to_derived_followed_by_include_and_FirstOrDefault(async);
7579
}
7680
}

test/EFCore.Relational.Specification.Tests/Query/TPTGearsOfWarQueryRelationalTestBase.cs

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System.Threading.Tasks;
5+
using Xunit;
6+
47
namespace Microsoft.EntityFrameworkCore.Query
58
{
69
public abstract class TPTGearsOfWarQueryRelationalTestBase<TFixture> : GearsOfWarQueryRelationalTestBase<TFixture>
@@ -10,5 +13,11 @@ protected TPTGearsOfWarQueryRelationalTestBase(TFixture fixture)
1013
: base(fixture)
1114
{
1215
}
16+
17+
[ConditionalTheory(Skip = "issue #22691")]
18+
public override async Task Cast_to_derived_followed_by_include_and_FirstOrDefault(bool async)
19+
{
20+
await base.Cast_to_derived_followed_by_include_and_FirstOrDefault(async);
21+
}
1322
}
1423
}

test/EFCore.Specification.Tests/Query/ComplexNavigationsQueryTestBase.cs

+115
Original file line numberDiff line numberDiff line change
@@ -5697,5 +5697,120 @@ public virtual Task Multiple_conditionals_in_projection(bool async)
56975697
}
56985698
});
56995699
}
5700+
5701+
[ConditionalTheory]
5702+
[MemberData(nameof(IsAsyncData))]
5703+
public virtual Task Composite_key_join_on_groupby_aggregate_projecting_only_grouping_key(bool async)
5704+
{
5705+
return AssertQueryScalar(
5706+
async,
5707+
ss => ss.Set<Level1>()
5708+
.Join(
5709+
ss.Set<Level2>().GroupBy(g => g.Id % 3).Select(g => new { g.Key, Sum = g.Sum(x => x.Id) }),
5710+
o => new { o.Id, Condition = true },
5711+
i => new { Id = i.Key, Condition = i.Sum > 10, },
5712+
(o, i) => i.Key));
5713+
}
5714+
5715+
[ConditionalTheory]
5716+
[MemberData(nameof(IsAsyncData))]
5717+
public virtual Task Multiple_joins_groupby_predicate(bool async)
5718+
{
5719+
return AssertQuery(
5720+
async,
5721+
ss => from l1 in ss.Set<Level1>()
5722+
join l2 in ss.Set<Level2>() on l1.Id equals l2.Level1_Optional_Id into grouping1
5723+
from l2 in grouping1.DefaultIfEmpty()
5724+
join x in (from l3 in ss.Set<Level3>()
5725+
group l3 by l3.Name into g
5726+
select new { Key = g.Key, Count = g.Count() }) on l1.Name equals x.Key into grouping2
5727+
from x in grouping2.DefaultIfEmpty()
5728+
where l2.Name != null || x.Count > 0
5729+
select new { l1.Id, l1.Name, Foo = l2 == null ? "Foo" : "Bar" },
5730+
elementSorter: e => (e.Id, e.Name, e.Foo));
5731+
}
5732+
5733+
[ConditionalTheory]
5734+
[MemberData(nameof(IsAsyncData))]
5735+
public virtual Task Collection_FirstOrDefault_property_accesses_in_projection(bool async)
5736+
{
5737+
return AssertQuery(
5738+
async,
5739+
ss => ss.Set<Level1>()
5740+
.Include(x => x.OneToMany_Optional1).ThenInclude(x => x.OneToMany_Optional2)
5741+
.Where(l1 => l1.Id < 3)
5742+
.Select(l1 => new
5743+
{
5744+
l1.Id,
5745+
Pushdown = l1.OneToMany_Optional1.Where(x => x.Name == "L2 02").FirstOrDefault().Name
5746+
}));
5747+
}
5748+
5749+
[ConditionalTheory]
5750+
[MemberData(nameof(IsAsyncData))]
5751+
public virtual Task Collection_FirstOrDefault_entity_reference_accesses_in_projection(bool async)
5752+
{
5753+
return AssertQuery(
5754+
async,
5755+
ss => ss.Set<Level1>()
5756+
.Include(x => x.OneToMany_Optional1).ThenInclude(x => x.OneToMany_Optional2)
5757+
.Where(l1 => l1.Id < 3)
5758+
.Select(l1 => new
5759+
{
5760+
l1.Id,
5761+
Pushdown = l1.OneToMany_Optional1
5762+
.Where(x => x.Name == "L2 02")
5763+
.FirstOrDefault().OneToOne_Optional_FK2
5764+
}));
5765+
}
5766+
5767+
[ConditionalTheory(Skip = "issue #22896")]
5768+
[MemberData(nameof(IsAsyncData))]
5769+
public virtual Task Collection_FirstOrDefault_entity_collection_accesses_in_projection(bool async)
5770+
{
5771+
return AssertQuery(
5772+
async,
5773+
ss => ss.Set<Level1>()
5774+
.Where(l1 => l1.Id < 2)
5775+
.Select(l1 => new
5776+
{
5777+
l1.Id,
5778+
Pushdown = l1.OneToMany_Optional1
5779+
.Where(x => x.Name == "L2 02")
5780+
.FirstOrDefault().OneToMany_Optional2.ToList()
5781+
}));
5782+
}
5783+
5784+
[ConditionalTheory]
5785+
[MemberData(nameof(IsAsyncData))]
5786+
public virtual Task Multiple_collection_FirstOrDefault_followed_by_member_access_in_projection(bool async)
5787+
{
5788+
return AssertQuery(
5789+
async,
5790+
ss => ss.Set<Level1>()
5791+
.Where(l1 => l1.Id < 2)
5792+
.Select(l1 => new
5793+
{
5794+
l1.Id,
5795+
Pushdown = l1.OneToMany_Optional1
5796+
.Where(x => x.Name == "L2 02")
5797+
.FirstOrDefault().OneToMany_Optional2
5798+
.OrderBy(x => x.Id)
5799+
.FirstOrDefault().Name
5800+
}));
5801+
}
5802+
5803+
[ConditionalTheory]
5804+
[MemberData(nameof(IsAsyncData))]
5805+
public virtual Task Projecting_columns_with_same_name_from_different_entities_making_sure_aliasing_works_after_Distinct(bool async)
5806+
{
5807+
return AssertQuery(
5808+
async,
5809+
ss => (from l1 in ss.Set<Level1>()
5810+
join l2 in ss.Set<Level2>() on l1.Id equals l2.Level1_Optional_Id
5811+
join l3 in ss.Set<Level3>() on l2.Id equals l3.Level2_Optional_Id
5812+
select new { Id1 = l1.Id, Id2 = l2.Id, Id3 = l3.Id, Name1 = l1.Name, Name2 = l2.Name }).Distinct().Select(x => new { Foo = x.Id1, Bar = x.Id2, Baz = x.Id3 }).Take(10),
5813+
elementSorter: e => (e.Foo, e.Bar, e.Baz));
5814+
}
57005815
}
57015816
}

test/EFCore.Specification.Tests/Query/ComplexNavigationsWeakQueryTestBase.cs

+6
Original file line numberDiff line numberDiff line change
@@ -181,5 +181,11 @@ public override void Filtered_include_outer_parameter_used_inside_filter()
181181
{
182182
// TODO: this test can be ran with weak entities once #18191 is fixed and we can use query test infra properly
183183
}
184+
185+
[ConditionalTheory(Skip = "Issue#17803")]
186+
public override Task Multiple_collection_FirstOrDefault_followed_by_member_access_in_projection(bool async)
187+
{
188+
return base.Multiple_collection_FirstOrDefault_followed_by_member_access_in_projection(async);
189+
}
184190
}
185191
}

test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs

+43
Original file line numberDiff line numberDiff line change
@@ -7898,6 +7898,49 @@ await AssertQuery(
78987898
ss => ss.Set<LocustLeader>().Where(ll => ll is LocustCommander && (ll as LocustCommander).HighCommandId != 0));
78997899
}
79007900

7901+
[ConditionalTheory]
7902+
[MemberData(nameof(IsAsyncData))]
7903+
public virtual Task Cast_to_derived_followed_by_include_and_FirstOrDefault(bool async)
7904+
{
7905+
return AssertFirstOrDefault(
7906+
async,
7907+
ss => ss.Set<LocustLeader>().Where(ll => ll.Name.Contains("Queen")).Cast<LocustCommander>().Include(lc => lc.DefeatedBy),
7908+
asserter: (e, a) => AssertInclude(e, a, new ExpectedInclude<LocustCommander>(x => x.DefeatedBy)));
7909+
7910+
}
7911+
7912+
[ConditionalTheory(Skip = "issue #22692")]
7913+
[MemberData(nameof(IsAsyncData))]
7914+
public virtual Task Cast_to_derived_followed_by_multiple_includes(bool async)
7915+
{
7916+
var expectedIncludes = new IExpectedInclude[]
7917+
{
7918+
new ExpectedInclude<LocustCommander>(x => x.DefeatedBy),
7919+
new ExpectedInclude<Gear>(x => x.Weapons, "DefeatedBy"),
7920+
};
7921+
7922+
return AssertQuery(
7923+
async,
7924+
ss => ss.Set<LocustLeader>().Where(ll => ll.Name.Contains("Queen")).Cast<LocustCommander>().Include(lc => lc.DefeatedBy).ThenInclude(g => g.Weapons),
7925+
elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes));
7926+
}
7927+
7928+
[ConditionalTheory]
7929+
[MemberData(nameof(IsAsyncData))]
7930+
public virtual Task Correlated_collection_take(bool async)
7931+
{
7932+
return AssertQuery(
7933+
async,
7934+
ss => ss.Set<Gear>().Select(g => new { g.Nickname, Weapons = g.Weapons.Take(10).ToList(), g.CityOfBirth }),
7935+
elementSorter: e => e.Nickname,
7936+
elementAsserter: (e, a) =>
7937+
{
7938+
AssertEqual(e.Nickname, a.Nickname);
7939+
AssertCollection(e.Weapons, a.Weapons, elementSorter: ee => ee.Id);
7940+
AssertEqual(e.CityOfBirth, a.CityOfBirth);
7941+
});
7942+
}
7943+
79017944
protected GearsOfWarContext CreateContext()
79027945
=> Fixture.CreateContext();
79037946

test/EFCore.Specification.Tests/Query/NorthwindSelectQueryTestBase.cs

+107
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Linq;
7+
using System.Linq.Expressions;
78
using System.Threading.Tasks;
89
using Microsoft.EntityFrameworkCore.TestModels.Northwind;
910
using Microsoft.EntityFrameworkCore.TestUtilities;
@@ -1860,5 +1861,111 @@ public virtual Task Projecting_Length_of_a_string_property_after_FirstOrDefault_
18601861
.Select(c => c.Orders.OrderBy(o => o.OrderID).Select(o => o.CustomerID).FirstOrDefault().MaybeScalar(x => x.Length)),
18611862
assertOrder: true);
18621863
}
1864+
1865+
[ConditionalTheory]
1866+
[MemberData(nameof(IsAsyncData))]
1867+
public virtual Task Projecting_count_of_navigation_which_is_generic_list(bool async)
1868+
{
1869+
return AssertQueryScalar(
1870+
async,
1871+
ss => ss.Set<Customer>()
1872+
.OrderBy(c => c.CustomerID)
1873+
.Select(c => c.Orders.Count),
1874+
assertOrder: true);
1875+
}
1876+
1877+
[ConditionalTheory]
1878+
[MemberData(nameof(IsAsyncData))]
1879+
public virtual Task Projecting_count_of_navigation_which_is_generic_collection(bool async)
1880+
{
1881+
var collectionCount = typeof(ICollection<Order>).GetProperty("Count");
1882+
1883+
var prm = Expression.Parameter(typeof(Customer), "c");
1884+
var selector = Expression.Lambda<Func<Customer, int>>(
1885+
Expression.Property(
1886+
Expression.Property(prm, "Orders"),
1887+
collectionCount),
1888+
prm);
1889+
1890+
return AssertQueryScalar(
1891+
async,
1892+
ss => ss.Set<Customer>()
1893+
.OrderBy(c => c.CustomerID)
1894+
.Select(selector),
1895+
assertOrder: true);
1896+
}
1897+
1898+
[ConditionalTheory(Skip = "issue #22701")]
1899+
[MemberData(nameof(IsAsyncData))]
1900+
public virtual Task Projecting_count_of_navigation_which_is_generic_collection_using_convert(bool async)
1901+
{
1902+
return AssertQueryScalar(
1903+
async,
1904+
ss => ss.Set<Customer>()
1905+
.OrderBy(c => c.CustomerID)
1906+
.Select(c => ((ICollection<Order>)c.Orders).Count),
1907+
assertOrder: true);
1908+
}
1909+
1910+
[ConditionalTheory]
1911+
[MemberData(nameof(IsAsyncData))]
1912+
public virtual Task Projection_take_projection_doesnt_project_intermittent_column(bool async)
1913+
{
1914+
return AssertQuery(
1915+
async,
1916+
ss => ss
1917+
.Set<Customer>()
1918+
.OrderBy(c => c.CustomerID)
1919+
.Select(c => new { c.CustomerID, c.City, c.CompanyName })
1920+
.Take(10)
1921+
.Select(x => new { Aggregate = x.CustomerID + " " + x.City }),
1922+
assertOrder: true);
1923+
}
1924+
1925+
[ConditionalTheory]
1926+
[MemberData(nameof(IsAsyncData))]
1927+
public virtual Task Projection_skip_projection_doesnt_project_intermittent_column(bool async)
1928+
{
1929+
return AssertQuery(
1930+
async,
1931+
ss => ss
1932+
.Set<Customer>()
1933+
.OrderBy(c => c.CustomerID)
1934+
.Select(c => new { c.CustomerID, c.City, c.CompanyName })
1935+
.Skip(7)
1936+
.Select(x => new { Aggregate = x.CustomerID + " " + x.City }),
1937+
assertOrder: true);
1938+
}
1939+
1940+
[ConditionalTheory]
1941+
[MemberData(nameof(IsAsyncData))]
1942+
public virtual Task Projection_Distinct_projection_contains_intermittent_column(bool async)
1943+
{
1944+
return AssertQuery(
1945+
async,
1946+
ss => ss
1947+
.Set<Customer>()
1948+
.OrderBy(c => c.CustomerID)
1949+
.Select(c => new { c.CustomerID, FirstLetter = c.CustomerID.Substring(0, 1), Foo = "Foo" })
1950+
.Distinct()
1951+
.Select(x => new { Aggregate = x.FirstLetter + " " + x.Foo }),
1952+
elementSorter: e => e.Aggregate);
1953+
}
1954+
1955+
[ConditionalTheory]
1956+
[MemberData(nameof(IsAsyncData))]
1957+
public virtual Task Projection_take_predicate_projection(bool async)
1958+
{
1959+
return AssertQuery(
1960+
async,
1961+
ss => ss
1962+
.Set<Customer>()
1963+
.OrderBy(c => c.CustomerID)
1964+
.Select(c => new { c.CustomerID, c.City, c.CompanyName })
1965+
.Take(10)
1966+
.Where(x => x.CustomerID.StartsWith("A"))
1967+
.Select(x => new { Aggregate = x.CustomerID + " " + x.City }),
1968+
assertOrder: true);
1969+
}
18631970
}
18641971
}

0 commit comments

Comments
 (0)