Skip to content

Commit

Permalink
Make warning as error exception more helpful
Browse files Browse the repository at this point in the history
Issue #9178
  • Loading branch information
ajcvickers committed Feb 28, 2018
1 parent 44ecf7a commit 42deab2
Show file tree
Hide file tree
Showing 26 changed files with 375 additions and 56 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -40,7 +40,8 @@ public virtual ModelBuilder Default_for_key_string_column_throws()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.ModelValidationKeyDefaultValueWarning,
RelationalStrings.LogKeyHasDefaultValue.GenerateMessage(nameof(Login1.UserName), nameof(Login1))),
RelationalStrings.LogKeyHasDefaultValue.GenerateMessage(nameof(Login1.UserName), nameof(Login1)),
"RelationalEventId.ModelValidationKeyDefaultValueWarning"),
Assert.Throws<InvalidOperationException>(() => Validate(modelBuilder)).Message);

return modelBuilder;
Expand Down
2 changes: 2 additions & 0 deletions src/EFCore.InMemory/Properties/InMemoryStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -28,7 +28,8 @@ public virtual void Throws_when_where()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.Where(c => c.IsLondon).ToList())
.Message);
Expand All @@ -43,7 +44,8 @@ public virtual void Throws_when_orderby()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("orderby [c].IsLondon asc")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("orderby [c].IsLondon asc"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.OrderBy(c => c.IsLondon).ToList()).Message);
}
Expand All @@ -57,7 +59,8 @@ public virtual void Throws_when_orderby_multiple()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("orderby [c].IsLondon asc, ClientMethod([c]) asc")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("orderby [c].IsLondon asc, ClientMethod([c]) asc"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers
.OrderBy(c => c.IsLondon)
Expand All @@ -77,7 +80,8 @@ public virtual void Throws_when_where_subquery_correlated()
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage(
"where {from Customer c2 in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.TestModels.Northwind.Customer]) where (([c1].CustomerID == [c2].CustomerID) AndAlso [c2].IsLondon) select [c2] => Any()}")),
"where {from Customer c2 in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[Microsoft.EntityFrameworkCore.TestModels.Northwind.Customer]) where (([c1].CustomerID == [c2].CustomerID) AndAlso [c2].IsLondon) select [c2] => Any()}"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers
.Where(
Expand All @@ -95,7 +99,8 @@ public virtual void Throws_when_all()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("All([c].IsLondon)")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("All([c].IsLondon)"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.All(c => c.IsLondon)).Message);
}
Expand All @@ -109,7 +114,8 @@ public virtual void Throws_when_from_sql_composed()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers
.FromSql(@"select * from ""Customers""")
Expand Down Expand Up @@ -140,7 +146,8 @@ public virtual void Throws_when_subquery_main_from_clause()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() =>
(from c1 in context.Customers
Expand All @@ -160,7 +167,8 @@ public virtual void Throws_when_select_many()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("from Int32 i in value(System.Int32[])")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("from Int32 i in value(System.Int32[])"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() =>
(from c1 in context.Customers
Expand All @@ -184,7 +192,8 @@ public virtual void Throws_when_join()
#else
"join UInt32 i in __p_0 on [e1].EmployeeID equals [i]"
#endif
)),
),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() =>
(from e1 in context.Employees
Expand Down Expand Up @@ -212,7 +221,8 @@ public virtual void Throws_when_group_join()
#else
"join UInt32 i in __p_0 on [e1].EmployeeID equals [i]"
#endif
)),
),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() =>
(from e1 in context.Employees
Expand All @@ -234,7 +244,8 @@ public virtual void Throws_when_group_by()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("GroupBy([c].CustomerID, [c])")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("GroupBy([c].CustomerID, [c])"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers
.GroupBy(c => c.CustomerID)
Expand All @@ -250,7 +261,8 @@ public virtual void Throws_when_first()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.First(c => c.IsLondon)).Message);
}
Expand All @@ -264,7 +276,8 @@ public virtual void Throws_when_single()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.Single(c => c.IsLondon)).Message);
}
Expand All @@ -278,7 +291,8 @@ public virtual void Throws_when_first_or_default()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.FirstOrDefault(c => c.IsLondon)).Message);
}
Expand All @@ -292,7 +306,8 @@ public virtual void Throws_when_single_or_default()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.SingleOrDefault(c => c.IsLondon)).Message);
}
Expand Down
Expand Up @@ -28,7 +28,8 @@ public virtual void Throws_when_warning_as_error()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("where [c].IsLondon"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.Where(c => c.IsLondon).ToList()).Message);
}
Expand Down Expand Up @@ -130,7 +131,8 @@ public virtual void Last_without_order_by_issues_client_eval_warning()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("Last()")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("Last()"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.Last()).Message);
}
Expand All @@ -144,7 +146,8 @@ public virtual void Last_with_order_by_issues_client_eval_warning_in_subquery()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("Last()")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("Last()"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers
.Where(c => c.CustomerID == "ALFKI"
Expand All @@ -160,7 +163,8 @@ public virtual void LastOrDefault_without_order_by_issues_client_eval_warning()
Assert.Equal(
CoreStrings.WarningAsErrorTemplate(
RelationalEventId.QueryClientEvaluationWarning,
RelationalStrings.LogClientEvalWarning.GenerateMessage("LastOrDefault()")),
RelationalStrings.LogClientEvalWarning.GenerateMessage("LastOrDefault()"),
"RelationalEventId.QueryClientEvaluationWarning"),
Assert.Throws<InvalidOperationException>(
() => context.Customers.LastOrDefault()).Message);
}
Expand Down

0 comments on commit 42deab2

Please sign in to comment.