Skip to content

Commit

Permalink
Fix to #8962 - External: Dynamic fails on netcoreapp2.0
Browse files Browse the repository at this point in the history
Adjusting affected tests so that they no longer use dynamic Funcs. This change can be revered once/if https://github.com/dotnet/corefx/issues/21689 is fixed
  • Loading branch information
maumar committed Jul 3, 2017
1 parent 8f120e0 commit c781e01
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1253,36 +1253,49 @@ from e in l3s
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Failing after netcoreapp2.0 upgrade")]
public virtual void Optional_navigation_projected_into_DTO()
{
AssertQuery<Level1>(
l1s =>
l1s.Select(e => new MyOuterDto
{
Id = e.Id,
Name = e.Name,
Inner = e.OneToOne_Optional_FK != null ? new MyInnerDto
{
Id = (int?)e.OneToOne_Optional_FK.Id,
Name = e.OneToOne_Optional_FK.Name
} : null
}),
e => e.Id + " " + e.Name + " " + e.Inner,
(e, a) =>
{
Assert.Equal(e.Id, a.Id);
Assert.Equal(e.Name, a.Name);
if (e.Inner == null)
{
Assert.Null(a.Inner);
}
else
{
Assert.Equal(e.Inner.Id, a.Inner.Id);
Assert.Equal(e.Inner.Name, a.Inner.Name);
}
});
using (var context = CreateContext())
{
var actual = context.Set<Level1>().Select(e => new MyOuterDto
{
Id = e.Id,
Name = e.Name,
Inner = e.OneToOne_Optional_FK != null ? new MyInnerDto
{
Id = (int?)e.OneToOne_Optional_FK.Id,
Name = e.OneToOne_Optional_FK.Name
} : null
}).ToList().OrderBy(e => e.Id + " " + e.Name + " " + e.Inner).ToList();

var expected = ExpectedSet<Level1>().Select(e => new MyOuterDto
{
Id = e.Id,
Name = e.Name,
Inner = e.OneToOne_Optional_FK != null ? new MyInnerDto
{
Id = (int?)e.OneToOne_Optional_FK.Id,
Name = e.OneToOne_Optional_FK.Name
} : null
}).ToList().OrderBy(e => e.Id + " " + e.Name + " " + e.Inner).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i].Id, actual[i].Id);
Assert.Equal(expected[i].Name, actual[i].Name);

if (expected[i].Inner == null)
{
Assert.Null(actual[i].Inner);
}
else
{
Assert.Equal(expected[i].Inner.Id, actual[i].Inner.Id);
Assert.Equal(expected[i].Inner.Name, actual[i].Inner.Name);
}
}
}
}

public class MyOuterDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,33 +52,58 @@ public virtual void Select_GroupBy_All()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Failing after netcoreapp2.0 upgrade")]
public virtual void Select_GroupBy()
{
AssertQuery<Order>(
os => os.Select(o => new ProjectedType
using (var context = CreateContext())
{
var actual = context.Set<Order>().Select(o => new ProjectedType
{
Order = o.OrderID,
Customer = o.CustomerID
}).GroupBy(p => p.Customer).ToList().OrderBy(g => g.Key + " " + g.Count()).ToList();

var expected = NorthwindData.Set<Order>().Select(o => new ProjectedType
{
Order = o.OrderID,
Customer = o.CustomerID
}).GroupBy(p => p.Customer),
elementSorter: GroupingSorter<string, ProjectedType>(),
elementAsserter: GroupingAsserter<string, ProjectedType>(t => t.Order));
}).GroupBy(p => p.Customer).ToList().OrderBy(g => g.Key + " " + g.Count()).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i].Key, actual[i].Key);
Assert.Equal(expected[i].Count(), actual[i].Count());
}
}
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Failing after netcoreapp2.0 upgrade")]
public virtual void Select_GroupBy_SelectMany()
{
AssertQuery<Order>(
os => os
.Select(o => new ProjectedType
using (var context = CreateContext())
{
var actual = context.Set<Order>().Select(o => new ProjectedType
{
Order = o.OrderID,
Customer = o.CustomerID
})
.GroupBy(o => o.Order)
.SelectMany(g => g).ToList().OrderBy(e => e.Order).ToList();

var expected = NorthwindData.Set<Order>().Select(o => new ProjectedType
{
Order = o.OrderID,
Customer = o.CustomerID
})
.GroupBy(o => o.Order)
.SelectMany(g => g),
e => e.Order);
.SelectMany(g => g).ToList().OrderBy(e => e.Order).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i], actual[i]);
}
}
}

private class ProjectedType
Expand Down
23 changes: 18 additions & 5 deletions src/EFCore.Specification.Tests/Query/QueryTestBase.Select.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,26 @@ public virtual void Select_nested_collection_count_using_anonymous_type()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Failing after netcoreapp2.0 upgrade")]
public virtual void Select_nested_collection_count_using_DTO()
{
AssertQuery<Customer>(
cs => cs.Where(c => c.CustomerID.StartsWith("A"))
.Select(c => new OrderCountDTO { Id = c.CustomerID, Count = c.Orders.Count }),
e => e.Id);
using (var context = CreateContext())
{
var actual = context.Set<Customer>()
.Where(c => c.CustomerID.StartsWith("A"))
.Select(c => new OrderCountDTO { Id = c.CustomerID, Count = c.Orders.Count })
.ToList().OrderBy(e => e.Id).ToList();

var expected = NorthwindData.Set<Customer>()
.Where(c => c.CustomerID.StartsWith("A"))
.Select(c => new OrderCountDTO { Id = c.CustomerID, Count = c.Orders.Count })
.ToList().OrderBy(e => e.Id).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i], actual[i]);
}
}
}

[ConditionalFact]
Expand Down
97 changes: 73 additions & 24 deletions src/EFCore.Specification.Tests/Query/QueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,38 +926,75 @@ public virtual void Where_subquery_expression_same_parametername()
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Failing after netcoreapp2.0 upgrade")]
public virtual void Select_DTO_distinct_translated_to_server()
{
AssertQuery<Order>(
os => os
using (var context = CreateContext())
{
var actual = context.Set<Order>()
.Where(o => o.OrderID < 10300)
.Select(o => new OrderCountDTO())
.Distinct().ToList().OrderBy(e => e.Id).ToList();

var expected = NorthwindData.Set<Order>()
.Where(o => o.OrderID < 10300)
.Select(o => new OrderCountDTO())
.Distinct());
.Distinct().ToList().OrderBy(e => e.Id).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i].Id, actual[i].Id);
Assert.Equal(expected[i].Count, actual[i].Count);
}
}
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Failing after netcoreapp2.0 upgrade")]
public virtual void Select_DTO_constructor_distinct_translated_to_server()
{
AssertQuery<Order>(
os => os
using (var context = CreateContext())
{
var actual = context.Set<Order>()
.Where(o => o.OrderID < 10300)
.Select(o => new OrderCountDTO(o.CustomerID))
.Distinct().ToList().OrderBy(e => e.Id).ToList();

var expected = NorthwindData.Set<Order>()
.Where(o => o.OrderID < 10300)
.Select(o => new OrderCountDTO(o.CustomerID))
.Distinct(),
e => e.Id);
.Distinct().ToList().OrderBy(e => e.Id).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i].Id, actual[i].Id);
Assert.Equal(expected[i].Count, actual[i].Count);
}
}
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Failing after netcoreapp2.0 upgrade")]
public virtual void Select_DTO_with_member_init_distinct_translated_to_server()
{
AssertQuery<Order>(
os => os
using (var context = CreateContext())
{
var actual = context.Set<Order>()
.Where(o => o.OrderID < 10300)
.Select(o => new OrderCountDTO { Id = o.CustomerID, Count = o.OrderID })
.Distinct().ToList().OrderBy(e => e.Count).ToList();

var expected = NorthwindData.Set<Order>()
.Where(o => o.OrderID < 10300)
.Select(o => new OrderCountDTO { Id = o.CustomerID, Count = o.OrderID })
.Distinct(),
e => e.Count);
.Distinct().ToList().OrderBy(e => e.Count).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i].Id, actual[i].Id);
Assert.Equal(expected[i].Count, actual[i].Count);
}
}
}

[ConditionalFact]
Expand All @@ -974,18 +1011,30 @@ from c in cs.Where(c => c.CustomerID == o.Id)
}

[ConditionalFact]
[FrameworkSkipCondition(RuntimeFrameworks.CoreCLR, SkipReason = "Failing after netcoreapp2.0 upgrade")]
public virtual void Select_DTO_with_member_init_distinct_in_subquery_used_in_projection_translated_to_server()
{
AssertQuery<Customer, Order>(
(cs, os) =>
from c in cs.Where(c => c.CustomerID.StartsWith("A"))
from o in os.Where(o => o.OrderID < 10300)
.Select(o => new OrderCountDTO { Id = o.CustomerID, Count = o.OrderID })
.Distinct()
select new { c, o },
e => e.c.CustomerID + " " + e.o.Count,
entryCount: 4);
using (var context = CreateContext())
{
var actual = (from c in context.Set<Customer>().Where(c => c.CustomerID.StartsWith("A"))
from o in context.Set<Order>().Where(o => o.OrderID < 10300)
.Select(o => new OrderCountDTO { Id = o.CustomerID, Count = o.OrderID })
.Distinct()
select new { c, o }).ToList().OrderBy(e => e.c.CustomerID + " " + e.o.Count).ToList();

var expected = (from c in NorthwindData.Set<Customer>().Where(c => c.CustomerID.StartsWith("A"))
from o in NorthwindData.Set<Order>().Where(o => o.OrderID < 10300)
.Select(o => new OrderCountDTO { Id = o.CustomerID, Count = o.OrderID })
.Distinct()
select new { c, o }).ToList().OrderBy(e => e.c.CustomerID + " " + e.o.Count).ToList();

Assert.Equal(expected.Count, actual.Count);
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i].c.CustomerID, actual[i].c.CustomerID);
Assert.Equal(expected[i].o.Id, actual[i].o.Id);
Assert.Equal(expected[i].o.Count, actual[i].o.Count);
}
}
}

private class OrderCountDTO
Expand Down

0 comments on commit c781e01

Please sign in to comment.