Skip to content

Commit

Permalink
Adding tests for various group by scenarios (#18283)
Browse files Browse the repository at this point in the history
- added regression tests for #12289
- added regression tests for #15279
- added regression tests for #15938
- added regression tests for #18267

- resolves #12522
- resolves #12805
- resolves #13231
- resolves #13594
- resolves #13754
- resolves #14851
- resolves #15103
- resolves #15669
- resolves #15853
  • Loading branch information
maumar authored Oct 8, 2019
1 parent e61e7cf commit 5ced404
Show file tree
Hide file tree
Showing 6 changed files with 723 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,11 @@ public override Task Null_semantics_is_correctly_applied_for_function_comparison
{
return base.Null_semantics_is_correctly_applied_for_function_comparisons_that_take_arguments_from_optional_navigation_complex(isAsync);
}

[ConditionalTheory(Skip = "issue #18284")]
public override Task GroupBy_with_boolean_groupin_key_thru_navigation_access(bool isAsync)
{
return GroupBy_with_boolean_groupin_key_thru_navigation_access(isAsync);
}
}
}
151 changes: 151 additions & 0 deletions test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7753,6 +7753,157 @@ public virtual Task Project_entity_and_collection_element(bool isAsync)
});
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_GroupBy_after_set_operator(bool isAsync)
{
return AssertQuery(
isAsync,
ss => (from g in ss.Set<Gear>()
select new
{
g.AssignedCity.Name,
Count = g.Weapons.Count(),
}).Concat(
from g in ss.Set<Gear>()
select new
{
g.CityOfBirth.Name,
Count = g.Weapons.Count(),
})
.GroupBy(x => new { x.Name, x.Count })
.Select(g => new { g.Key.Name, g.Key.Count, Sum = g.Sum(xx => xx.Count) }),
ss => (from g in ss.Set<Gear>()
select new
{
Name = Maybe(g.AssignedCity, () => g.AssignedCity.Name),
Count = g.Weapons.Count(),
}).Concat(
from g in ss.Set<Gear>()
select new
{
g.CityOfBirth.Name,
Count = g.Weapons.Count(),
})
.GroupBy(x => new { x.Name, x.Count })
.Select(g => new { g.Key.Name, g.Key.Count, Sum = g.Sum(xx => xx.Count) }),
elementSorter: e => (e.Name, e.Count, e.Sum));
}

[ConditionalTheory(Skip = "issue #18267")]
[MemberData(nameof(IsAsyncData))]
public virtual Task Complex_GroupBy_after_set_operator_using_result_selector(bool isAsync)
{
return AssertQuery(
isAsync,
ss => (from g in ss.Set<Gear>()
select new
{
g.AssignedCity.Name,
Count = g.Weapons.Count(),
}).Concat(
from g in ss.Set<Gear>()
select new
{
g.CityOfBirth.Name,
Count = g.Weapons.Count(),
})
.GroupBy(
x => new { x.Name, x.Count },
(k, g) => new { k.Name, k.Count, Sum = g.Sum(xx => xx.Count) }),
ss => (from g in ss.Set<Gear>()
select new
{
Name = Maybe(g.AssignedCity, () => g.AssignedCity.Name),
Count = g.Weapons.Count(),
}).Concat(
from g in ss.Set<Gear>()
select new
{
g.CityOfBirth.Name,
Count = g.Weapons.Count(),
})
.GroupBy(
x => new { x.Name, x.Count },
(k, g) => new { k.Name, k.Count, Sum = g.Sum(xx => xx.Count) }),
elementSorter: e => (e.Name, e.Count, e.Sum));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Left_join_with_GroupBy_with_composite_group_key(bool isAsync)
{
return AssertQuery(
isAsync,
ss => from g in ss.Set<Gear>()
join s in ss.Set<Squad>() on g.SquadId equals s.Id
join t in ss.Set<CogTag>() on g.Nickname equals t.GearNickName into grouping
from t in grouping.DefaultIfEmpty()
group g by new { g.CityOrBirthName, g.HasSoulPatch } into groupby
select new { groupby.Key.CityOrBirthName, groupby.Key.HasSoulPatch },
elementSorter: e => (e.CityOrBirthName, e.HasSoulPatch));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_with_boolean_grouping_key(bool isAsync)
{
return AssertQuery(
isAsync,
ss => ss.Set<Gear>()
.Select(g => new { g.Nickname, g.CityOrBirthName, g.HasSoulPatch, IsMarcus = g.Nickname == "Marcus" })
.GroupBy(g => new { g.CityOrBirthName, g.HasSoulPatch, g.IsMarcus })
.Select(x => new { x.Key.CityOrBirthName, x.Key.HasSoulPatch, x.Key.IsMarcus, Count = x.Count() }),
elementSorter: e => (e.CityOrBirthName, e.HasSoulPatch, e.IsMarcus, e.Count));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task GroupBy_with_boolean_groupin_key_thru_navigation_access(bool isAsync)
{
return AssertQuery(
isAsync,
ss => ss.Set<CogTag>()
.GroupBy(t => new { t.Gear.HasSoulPatch, t.Gear.Squad.Name })
.Select(g => new { g.Key.HasSoulPatch, Name = g.Key.Name.ToLower() }),
ss => ss.Set<CogTag>()
.GroupBy(t => new
{
HasSoulPatch = MaybeScalar<bool>(t.Gear, () => t.Gear.HasSoulPatch) ?? false,
Name = Maybe(t.Gear, () => t.Gear.Squad.Name)
})
.Select(g => new { g.Key.HasSoulPatch, Name = Maybe(g.Key.Name, () => g.Key.Name.ToLower()) }),
elementSorter: e => (e.HasSoulPatch, e.Name));
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Group_by_over_projection_with_multiple_properties_accessed_thru_navigation(bool isAsync)
{
return AssertQuery(
isAsync,
ss => ss.Set<Gear>()
.Select(g => new
{
g.Nickname,
AssignedCityName = g.AssignedCity.Name,
CityOfBirthName = g.CityOfBirth.Name,
SquadName = g.Squad.Name
})
.GroupBy(x => x.CityOfBirthName)
.Select(g => g.Key),
ss => ss.Set<Gear>()
.Select(g => new
{
g.Nickname,
AssignedCityName = Maybe(g.AssignedCity, () => g.AssignedCity.Name),
CityOfBirthName = Maybe(g.CityOfBirth, () => g.CityOfBirth.Name),
SquadName = g.Squad.Name
})
.GroupBy(x => x.CityOfBirthName)
.Select(g => g.Key));
}

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

protected virtual void ClearLog()
Expand Down
Loading

0 comments on commit 5ced404

Please sign in to comment.