Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Adding tests for various group by scenarios #18283

Merged
merged 1 commit into from
Oct 8, 2019
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
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