Skip to content

Commit

Permalink
Query: Enable throwing behavior for Single/SingleOrDefault on top level
Browse files Browse the repository at this point in the history
In future we need to detect cases when it is used inside subquery to not throw but currently all such tests are disabled because it was doing client eval in previous pipeline

Part of #15559
Resolves #15866
  • Loading branch information
smitpatel committed Jun 4, 2019
1 parent f9e8c4a commit 7081516
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ protected override ShapedQueryExpression TranslateSingleOrDefault(ShapedQueryExp
}

var selectExpression = (SelectExpression)source.QueryExpression;
selectExpression.ApplyLimit(TranslateExpression(Expression.Constant(1)));
selectExpression.ApplyLimit(TranslateExpression(Expression.Constant(2)));

if (source.ShaperExpression.Type != returnType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@ public void AppendOrdering(OrderingExpression orderingExpression)

public void ApplyLimit(SqlExpression sqlExpression)
{
if (Limit != null)
{
PushdownIntoSubQuery();
}

Limit = sqlExpression;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public virtual Task Min_with_arg(bool isAsync)
selector: o => o.OrderID);
}

[ConditionalFact(Skip = "TaskList#24")]
[ConditionalFact]
public virtual void Min_no_data()
{
using (var context = CreateContext())
Expand All @@ -436,7 +436,7 @@ public virtual void Min_no_data_subquery()
}
}

[ConditionalFact(Skip = "TaskList#24")]
[ConditionalFact]
public virtual void Max_no_data()
{
using (var context = CreateContext())
Expand All @@ -456,7 +456,7 @@ public virtual void Max_no_data_subquery()
}
}

[ConditionalFact(Skip = "TaskList#24")]
[ConditionalFact]
public virtual void Average_no_data()
{
using (var context = CreateContext())
Expand Down Expand Up @@ -821,10 +821,13 @@ public virtual Task Select_Select_Distinct_Count(bool isAsync)
cs => cs.Select(c => c.City).Select(c => c).Distinct());
}

[ConditionalTheory(Skip = "TaskList#24")]
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Single_Throws(bool isAsync)
{
// TODO: See issue#15535
isAsync = false;

return Assert.ThrowsAsync<InvalidOperationException>(
async () => await AssertSingle<Customer>(isAsync, cs => cs));
}
Expand All @@ -846,16 +849,20 @@ public virtual Task Where_Single(bool isAsync)
{
// TODO: See issue#15535
isAsync = false;

return AssertSingle<Customer>(
isAsync,
cs => cs.Where(c => c.CustomerID == "ALFKI"),
entryCount: 1);
}

[ConditionalTheory(Skip = "TaskList#24")]
[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task SingleOrDefault_Throws(bool isAsync)
{
// TODO: See issue#15535
isAsync = false;

return Assert.ThrowsAsync<InvalidOperationException>(
async () =>
await AssertSingleOrDefault<Customer>(isAsync, cs => cs));
Expand Down
13 changes: 7 additions & 6 deletions test/EFCore.Specification.Tests/Query/SimpleQueryTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected virtual void ClearLog()
{
}

[ConditionalFact(Skip = "TaskList#24")]
[ConditionalFact]
public virtual void Multiple_context_instances()
{
using (var context1 = CreateContext())
Expand All @@ -74,7 +74,7 @@ from o in context2.Orders
}
}

[ConditionalFact(Skip = "TaskList#24")]
[ConditionalFact]
public virtual void Multiple_context_instances_2()
{
using (var context1 = CreateContext())
Expand All @@ -92,7 +92,7 @@ from o in context2.Set<Order>()
}
}

[ConditionalFact(Skip = "TaskList#24")]
[ConditionalFact]
public virtual void Multiple_context_instances_set()
{
using (var context1 = CreateContext())
Expand All @@ -111,7 +111,7 @@ from o in set
}
}

[ConditionalFact(Skip = "TaskList#24")]
[ConditionalFact]
public virtual void Multiple_context_instances_parameter()
{
using (var context1 = CreateContext())
Expand Down Expand Up @@ -1208,6 +1208,7 @@ public virtual Task Take_with_single(bool isAsync)
{
// TODO: Issue#15535
isAsync = false;

return AssertSingle<Customer>(
isAsync,
cs => cs.OrderBy(c => c.CustomerID).Take(1),
Expand Down Expand Up @@ -4044,7 +4045,7 @@ await AssertQuery<Order>(
entryCount: 830);
}

[ConditionalFact(Skip = "TaskList#24")]
[ConditionalFact]
public virtual void Parameter_extraction_can_throw_exception_from_user_code()
{
using (var context = CreateContext())
Expand All @@ -4056,7 +4057,7 @@ public virtual void Parameter_extraction_can_throw_exception_from_user_code()
}
}

[ConditionalFact(Skip = "TaskList#24")]
[ConditionalFact]
public virtual void Parameter_extraction_can_throw_exception_from_user_code_2()
{
using (var context = CreateContext())
Expand Down

0 comments on commit 7081516

Please sign in to comment.