Skip to content

Additional regression tests for issues that have been fixed previously #22897

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore.Cosmos.Internal;
Expand Down Expand Up @@ -1174,6 +1175,58 @@ public override Task Projecting_Length_of_a_string_property_after_FirstOrDefault
return base.Projecting_Length_of_a_string_property_after_FirstOrDefault_on_correlated_collection(async);
}

public override async Task Projection_take_predicate_projection(bool async)
{
await base.Projection_take_predicate_projection(async);

AssertSql(@"@__p_0='10'

SELECT VALUE {""Aggregate"" : ((c[""CustomerID""] || "" "") || c[""City""])}
FROM root c
WHERE ((c[""Discriminator""] = ""Customer"") AND ((c[""CustomerID""] != null) AND ((""A"" != null) AND STARTSWITH(c[""CustomerID""], ""A""))))
ORDER BY c[""CustomerID""]
OFFSET 0 LIMIT @__p_0");
}

public override async Task Projection_take_projection_doesnt_project_intermittent_column(bool async)
{
await base.Projection_take_projection_doesnt_project_intermittent_column(async);

AssertSql(@"@__p_0='10'

SELECT VALUE {""Aggregate"" : ((c[""CustomerID""] || "" "") || c[""City""])}
FROM root c
WHERE (c[""Discriminator""] = ""Customer"")
ORDER BY c[""CustomerID""]
OFFSET 0 LIMIT @__p_0");
}

public override async Task Projection_skip_projection_doesnt_project_intermittent_column(bool async)
{
var message = (await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Projection_skip_projection_doesnt_project_intermittent_column(async))).Message;

Assert.Equal(CosmosStrings.OffsetRequiresLimit, message);
}

[ConditionalTheory(Skip = "Issue#17246")]
public override Task Projection_Distinct_projection_preserves_columns_used_for_distinct_in_subquery(bool async)
{
return base.Projection_Distinct_projection_preserves_columns_used_for_distinct_in_subquery(async);
}

[ConditionalTheory(Skip = "Cross collection join Issue#17246")]
public override Task Projecting_count_of_navigation_which_is_generic_collection(bool async)
{
return base.Projecting_count_of_navigation_which_is_generic_collection(async);
}

[ConditionalTheory(Skip = "Cross collection join Issue#17246")]
public override Task Projecting_count_of_navigation_which_is_generic_list(bool async)
{
return base.Projecting_count_of_navigation_which_is_generic_list(async);
}

private void AssertSql(params string[] expected)
=> Fixture.TestSqlLoggerFactory.AssertBaseline(expected);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,9 @@ public override Task Client_eval_followed_by_set_operation_throws_meaningful_exc
[ConditionalTheory(Skip = "issue #17537")]
public override Task SelectMany_predicate_with_non_equality_comparison_with_Take_doesnt_convert_to_join(bool async)
=> base.SelectMany_predicate_with_non_equality_comparison_with_Take_doesnt_convert_to_join(async);

[ConditionalTheory(Skip = "issue #19584")]
public override Task Cast_to_derived_followed_by_include_and_FirstOrDefault(bool async)
=> base.Cast_to_derived_followed_by_include_and_FirstOrDefault(async);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using Xunit;

namespace Microsoft.EntityFrameworkCore.Query
{
public abstract class TPTGearsOfWarQueryRelationalTestBase<TFixture> : GearsOfWarQueryRelationalTestBase<TFixture>
Expand All @@ -10,5 +13,11 @@ protected TPTGearsOfWarQueryRelationalTestBase(TFixture fixture)
: base(fixture)
{
}

[ConditionalTheory(Skip = "issue #22691")]
public override async Task Cast_to_derived_followed_by_include_and_FirstOrDefault(bool async)
{
await base.Cast_to_derived_followed_by_include_and_FirstOrDefault(async);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5697,5 +5697,120 @@ public virtual Task Multiple_conditionals_in_projection(bool async)
}
});
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Composite_key_join_on_groupby_aggregate_projecting_only_grouping_key(bool async)
{
return AssertQueryScalar(
async,
ss => ss.Set<Level1>()
.Join(
ss.Set<Level2>().GroupBy(g => g.Id % 3).Select(g => new { g.Key, Sum = g.Sum(x => x.Id) }),
o => new { o.Id, Condition = true },
i => new { Id = i.Key, Condition = i.Sum > 10, },
(o, i) => i.Key));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Multiple_joins_groupby_predicate(bool async)
{
return AssertQuery(
async,
ss => from l1 in ss.Set<Level1>()
join l2 in ss.Set<Level2>() on l1.Id equals l2.Level1_Optional_Id into grouping1
from l2 in grouping1.DefaultIfEmpty()
join x in (from l3 in ss.Set<Level3>()
group l3 by l3.Name into g
select new { Key = g.Key, Count = g.Count() }) on l1.Name equals x.Key into grouping2
from x in grouping2.DefaultIfEmpty()
where l2.Name != null || x.Count > 0
select new { l1.Id, l1.Name, Foo = l2 == null ? "Foo" : "Bar" },
elementSorter: e => (e.Id, e.Name, e.Foo));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Collection_FirstOrDefault_property_accesses_in_projection(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Level1>()
.Include(x => x.OneToMany_Optional1).ThenInclude(x => x.OneToMany_Optional2)
.Where(l1 => l1.Id < 3)
.Select(l1 => new
{
l1.Id,
Pushdown = l1.OneToMany_Optional1.Where(x => x.Name == "L2 02").FirstOrDefault().Name
}));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Collection_FirstOrDefault_entity_reference_accesses_in_projection(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Level1>()
.Include(x => x.OneToMany_Optional1).ThenInclude(x => x.OneToMany_Optional2)
.Where(l1 => l1.Id < 3)
.Select(l1 => new
{
l1.Id,
Pushdown = l1.OneToMany_Optional1
.Where(x => x.Name == "L2 02")
.FirstOrDefault().OneToOne_Optional_FK2
}));
}

[ConditionalTheory(Skip = "issue #22896")]
[MemberData(nameof(IsAsyncData))]
public virtual Task Collection_FirstOrDefault_entity_collection_accesses_in_projection(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Level1>()
.Where(l1 => l1.Id < 2)
.Select(l1 => new
{
l1.Id,
Pushdown = l1.OneToMany_Optional1
.Where(x => x.Name == "L2 02")
.FirstOrDefault().OneToMany_Optional2.ToList()
}));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Multiple_collection_FirstOrDefault_followed_by_member_access_in_projection(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Level1>()
.Where(l1 => l1.Id < 2)
.Select(l1 => new
{
l1.Id,
Pushdown = l1.OneToMany_Optional1
.Where(x => x.Name == "L2 02")
.FirstOrDefault().OneToMany_Optional2
.OrderBy(x => x.Id)
.FirstOrDefault().Name
}));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Projecting_columns_with_same_name_from_different_entities_making_sure_aliasing_works_after_Distinct(bool async)
{
return AssertQuery(
async,
ss => (from l1 in ss.Set<Level1>()
join l2 in ss.Set<Level2>() on l1.Id equals l2.Level1_Optional_Id
join l3 in ss.Set<Level3>() on l2.Id equals l3.Level2_Optional_Id
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),
elementSorter: e => (e.Foo, e.Bar, e.Baz));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,11 @@ public override void Filtered_include_outer_parameter_used_inside_filter()
{
// TODO: this test can be ran with weak entities once #18191 is fixed and we can use query test infra properly
}

[ConditionalTheory(Skip = "Issue#17803")]
public override Task Multiple_collection_FirstOrDefault_followed_by_member_access_in_projection(bool async)
{
return base.Multiple_collection_FirstOrDefault_followed_by_member_access_in_projection(async);
}
}
}
43 changes: 43 additions & 0 deletions test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7898,6 +7898,49 @@ await AssertQuery(
ss => ss.Set<LocustLeader>().Where(ll => ll is LocustCommander && (ll as LocustCommander).HighCommandId != 0));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Cast_to_derived_followed_by_include_and_FirstOrDefault(bool async)
{
return AssertFirstOrDefault(
async,
ss => ss.Set<LocustLeader>().Where(ll => ll.Name.Contains("Queen")).Cast<LocustCommander>().Include(lc => lc.DefeatedBy),
asserter: (e, a) => AssertInclude(e, a, new ExpectedInclude<LocustCommander>(x => x.DefeatedBy)));

}

[ConditionalTheory(Skip = "issue #22692")]
[MemberData(nameof(IsAsyncData))]
public virtual Task Cast_to_derived_followed_by_multiple_includes(bool async)
{
var expectedIncludes = new IExpectedInclude[]
{
new ExpectedInclude<LocustCommander>(x => x.DefeatedBy),
new ExpectedInclude<Gear>(x => x.Weapons, "DefeatedBy"),
};

return AssertQuery(
async,
ss => ss.Set<LocustLeader>().Where(ll => ll.Name.Contains("Queen")).Cast<LocustCommander>().Include(lc => lc.DefeatedBy).ThenInclude(g => g.Weapons),
elementAsserter: (e, a) => AssertInclude(e, a, expectedIncludes));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Correlated_collection_take(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Gear>().Select(g => new { g.Nickname, Weapons = g.Weapons.Take(10).ToList(), g.CityOfBirth }),
elementSorter: e => e.Nickname,
elementAsserter: (e, a) =>
{
AssertEqual(e.Nickname, a.Nickname);
AssertCollection(e.Weapons, a.Weapons, elementSorter: ee => ee.Id);
AssertEqual(e.CityOfBirth, a.CityOfBirth);
});
}

protected GearsOfWarContext CreateContext()
=> Fixture.CreateContext();

Expand Down
Loading