Skip to content

Commit

Permalink
Add regression tests to several bugs that were fixed previously
Browse files Browse the repository at this point in the history
Resolves #21836
Resolves #22978
Resolves #23205
  • Loading branch information
maumar committed Nov 13, 2020
1 parent b608a57 commit f4628ea
Show file tree
Hide file tree
Showing 10 changed files with 209 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5824,5 +5824,62 @@ 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));
}

[ConditionalTheory(Skip = "issue #23302")]
[MemberData(nameof(IsAsyncData))]
public virtual Task Queryable_in_subquery_works_when_final_projection_is_List(bool async)
{
return AssertQuery(
async,
ss => from l1 in ss.Set<Level1>()
orderby l1.Id
let inner = (from l2 in l1.OneToMany_Optional1
where l2.Name != "Foo"
let innerL1s = from innerL1 in ss.Set<Level1>()
where innerL1.OneToMany_Optional1.Any(innerL2 => innerL2.Id == l2.Id)
select innerL1.Name
select innerL1s).FirstOrDefault()
select inner.ToList(),
assertOrder: true,
elementAsserter: (e, a) => AssertCollection(e, a));
}

[ConditionalTheory(Skip = "issue #23303")]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_query_with_let_collection_projection_FirstOrDefault_with_ToList_on_inner_and_outer(bool async)
{
return AssertQuery(
async,
ss => from l1 in ss.Set<Level1>()
orderby l1.Id
let inner = (from l2 in l1.OneToMany_Optional1
where l2.Name != "Foo"
let innerL1s = from innerL1 in ss.Set<Level1>()
where innerL1.OneToMany_Optional1.Any(innerL2 => innerL2.Id == l2.Id)
select innerL1.Name
select innerL1s.ToList()).FirstOrDefault()
select inner.ToList(),
assertOrder: true,
elementAsserter: (e, a) => AssertCollection(e, a));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_query_with_let_collection_projection_FirstOrDefault(bool async)
{
return AssertQuery(
async,
ss => from l1 in ss.Set<Level1>()
orderby l1.Id
let inner = (from l2 in l1.OneToMany_Optional1
where l2.Name != "Foo"
let innerL1s = from innerL1 in ss.Set<Level1>()
where innerL1.OneToMany_Optional1.Any(innerL2 => innerL2.Id == l2.Id)
select innerL1.Name
select innerL1s.ToList()).FirstOrDefault()
select inner,
assertOrder: true,
elementAsserter: (e, a) => AssertCollection(e, a));
}
}
}
15 changes: 15 additions & 0 deletions test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7933,6 +7933,21 @@ public virtual Task Sum_with_no_data_nullable_double(bool async)
ss => ss.Set<Mission>().Where(m => m.CodeName == "Operation Foobar").Select(m => m.Rating));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task FirstOrDefault_on_empty_collection_of_DateTime_in_subquery(bool async)
{
return AssertQuery(
async,
ss => from g in ss.Set<Gear>()
let invalidTagIssueDate = (from t in ss.Set<CogTag>()
where t.GearNickName == g.FullName
orderby t.Id
select t.IssueDate).FirstOrDefault()
where g.Tag.IssueDate > invalidTagIssueDate
select new { g.Nickname, invalidTagIssueDate });
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2456,5 +2456,15 @@ public virtual Task Two_sets_of_comparison_combine_correctly2(bool async)
c => (c.Region != "WA" && c.Region != "OR" && c.Region != null) || (c.Region != "WA" && c.Region != null)),
entryCount: 28);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Filter_with_property_compared_to_null_wrapped_in_explicit_convert_to_object(bool async)
{
return AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => (object)c.Region == null),
entryCount: 60);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class CogTag
public string GearNickName { get; set; }
public int? GearSquadId { get; set; }
public virtual Gear Gear { get; set; }
public DateTime IssueDate { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ public static IReadOnlyList<Weapon> CreateWeapons()
public static IReadOnlyList<CogTag> CreateTags()
=> new List<CogTag>
{
new CogTag { Id = Guid.Parse("DF36F493-463F-4123-83F9-6B135DEEB7BA"), Note = "Dom's Tag" },
new CogTag { Id = Guid.Parse("A8AD98F9-E023-4E2A-9A70-C2728455BD34"), Note = "Cole's Tag" },
new CogTag { Id = Guid.Parse("A7BE028A-0CF2-448F-AB55-CE8BC5D8CF69"), Note = "Paduk's Tag" },
new CogTag { Id = Guid.Parse("70534E05-782C-4052-8720-C2C54481CE5F"), Note = "Baird's Tag" },
new CogTag { Id = Guid.Parse("34C8D86E-A4AC-4BE5-827F-584DDA348A07"), Note = "Marcus' Tag" },
new CogTag { Id = Guid.Parse("B39A6FBA-9026-4D69-828E-FD7068673E57"), Note = "K.I.A." }
new CogTag { Id = Guid.Parse("DF36F493-463F-4123-83F9-6B135DEEB7BA"), Note = "Dom's Tag", IssueDate = new DateTime(3, 2, 2) },
new CogTag { Id = Guid.Parse("A8AD98F9-E023-4E2A-9A70-C2728455BD34"), Note = "Cole's Tag", IssueDate = new DateTime(2, 10, 11) },
new CogTag { Id = Guid.Parse("A7BE028A-0CF2-448F-AB55-CE8BC5D8CF69"), Note = "Paduk's Tag", IssueDate = new DateTime(15, 3, 7) },
new CogTag { Id = Guid.Parse("70534E05-782C-4052-8720-C2C54481CE5F"), Note = "Baird's Tag", IssueDate = new DateTime(7, 5, 3) },
new CogTag { Id = Guid.Parse("34C8D86E-A4AC-4BE5-827F-584DDA348A07"), Note = "Marcus' Tag", IssueDate = new DateTime(1, 9, 25) },
new CogTag { Id = Guid.Parse("B39A6FBA-9026-4D69-828E-FD7068673E57"), Note = "K.I.A.", IssueDate = new DateTime(21, 7, 7) }
};

public static IReadOnlyList<Gear> CreateGears()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6046,6 +6046,33 @@ FROM [LevelOne] AS [l]
) AS [t]");
}

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

AssertSql(
@"SELECT [t0].[c], [l].[Id], [t0].[Id], [t1].[Name], [t1].[Id]
FROM [LevelOne] AS [l]
LEFT JOIN (
SELECT [t].[c], [t].[Id], [t].[OneToMany_Optional_Inverse2Id]
FROM (
SELECT 1 AS [c], [l0].[Id], [l0].[OneToMany_Optional_Inverse2Id], ROW_NUMBER() OVER(PARTITION BY [l0].[OneToMany_Optional_Inverse2Id] ORDER BY [l0].[Id]) AS [row]
FROM [LevelTwo] AS [l0]
WHERE ([l0].[Name] <> N'Foo') OR [l0].[Name] IS NULL
) AS [t]
WHERE [t].[row] <= 1
) AS [t0] ON [l].[Id] = [t0].[OneToMany_Optional_Inverse2Id]
OUTER APPLY (
SELECT [l1].[Name], [l1].[Id]
FROM [LevelOne] AS [l1]
WHERE EXISTS (
SELECT 1
FROM [LevelTwo] AS [l2]
WHERE ([l1].[Id] = [l2].[OneToMany_Optional_Inverse2Id]) AND ([l2].[Id] = [t0].[Id]))
) AS [t1]
ORDER BY [l].[Id], [t0].[Id], [t1].[Id]");
}

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

0 comments on commit f4628ea

Please sign in to comment.