Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update query logging tests
Browse files Browse the repository at this point in the history
Filed #17498 to add logging
Resolves #17245
smitpatel committed Aug 29, 2019
1 parent 5b0fdfb commit a45bdb5
Showing 1 changed file with 39 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@
// ReSharper disable InconsistentNaming
namespace Microsoft.EntityFrameworkCore.Query
{
// Issue #16963
public class QueryLoggingSqlServerTest : IClassFixture<IncludeSqlServerFixture>
{
private static readonly string _eol = Environment.NewLine;
@@ -65,93 +64,58 @@ var customers
}
}

//[ConditionalFact]
//public virtual void Query_with_ignored_include_should_log_warning()
//{
// using (var context = CreateContext())
// {
// var customers
// = context.Customers
// .Include(c => c.Orders)
// .Select(c => c.CustomerID)
// .ToList();

// Assert.NotNull(customers);
// Assert.Contains(
// CoreResources.LogIgnoredInclude(new TestLogger<SqlServerLoggingDefinitions>()).GenerateMessage("[c].Orders"), Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message));
// }
//}

//[ConditionalFact]
//public virtual void Include_navigation()
//{
// using (var context = CreateContext())
// {
// var customers
// = context.Set<Customer>()
// .Include(c => c.Orders)
// .ToList();

// Assert.NotNull(customers);

// Assert.Equal(
// "Compiling query model: " + _eol +
// "'(from Customer c in DbSet<Customer>" + _eol +
// @"select [c]).Include(""Orders"")'"
// ,
// Fixture.TestSqlLoggerFactory.Log[0].Message);
// Assert.Equal(
// "Including navigation: '[c].Orders'"
// ,
// Fixture.TestSqlLoggerFactory.Log[1].Message);
// Assert.StartsWith(
// "Optimized query model: " + _eol +
// "'from Customer c in DbSet<Customer>" + _eol +
// @"order by EF.Property(?[c]?, ""CustomerID"") asc" + _eol +
// "select Customer _Include("
// ,
// Fixture.TestSqlLoggerFactory.Log[2].Message);
// }
//}

#pragma warning disable CS0612 // Type or member is obsolete
[ConditionalFact(Skip = "Issue #17245")]
public virtual void Concat_Include_collection_ignored()
[ConditionalFact(Skip = "Issue#17498")]
public virtual void Query_with_ignored_include_should_log_warning()
{
using (var context = CreateContext())
{
var orders = context.Orders
.Where(o => o.OrderID < 10250)
.Concat(context.Orders.Where(o => o.CustomerID == "ALFKI"))
.Include(o => o.OrderDetails)
.ToList();
var customers
= context.Customers
.Include(c => c.Orders)
.Select(c => c.CustomerID)
.ToList();

Assert.NotNull(orders);
Assert.NotNull(customers);
Assert.Contains(
CoreResources.LogIgnoredInclude(new TestLogger<SqlServerLoggingDefinitions>()).GenerateMessage("[o].OrderDetails"),
Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message));
#pragma warning disable CS0612 // Type or member is obsolete
CoreResources.LogIgnoredInclude(new TestLogger<SqlServerLoggingDefinitions>()).GenerateMessage("[c].Orders"), Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message));
#pragma warning restore CS0612 // Type or member is obsolete
}
}

[ConditionalFact(Skip = "Issue #17245")]
public virtual void Union_Include_collection_ignored()
[ConditionalFact(Skip = "Issue#17498")]
public virtual void Include_navigation()
{
using (var context = CreateContext())
{
var orders = context.Orders
.Where(o => o.OrderID < 10250)
.Union(context.Orders.Where(o => o.CustomerID == "ALFKI"))
.Include(o => o.OrderDetails)
.ToList();
var customers
= context.Set<Customer>()
.Include(c => c.Orders)
.ToList();

Assert.NotNull(orders);
Assert.Contains(
CoreResources.LogIgnoredInclude(new TestLogger<SqlServerLoggingDefinitions>()).GenerateMessage("[o].OrderDetails"),
Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message));
Assert.NotNull(customers);

Assert.Equal(
"Compiling query model: " + _eol +
"'(from Customer c in DbSet<Customer>" + _eol +
@"select [c]).Include(""Orders"")'"
,
Fixture.TestSqlLoggerFactory.Log[0].Message);
Assert.Equal(
"Including navigation: '[c].Orders'"
,
Fixture.TestSqlLoggerFactory.Log[1].Message);
Assert.StartsWith(
"Optimized query model: " + _eol +
"'from Customer c in DbSet<Customer>" + _eol +
@"order by EF.Property(?[c]?, ""CustomerID"") asc" + _eol +
"select Customer _Include("
,
Fixture.TestSqlLoggerFactory.Log[2].Message);
}
}

[ConditionalFact(Skip = "Issue #17068")]
[ConditionalFact(Skip = "Issue #16752")]
public virtual void GroupBy_Include_collection_ignored()
{
using (var context = CreateContext())
@@ -164,12 +128,13 @@ public virtual void GroupBy_Include_collection_ignored()

Assert.NotNull(orders);
Assert.Contains(
#pragma warning disable CS0612 // Type or member is obsolete
CoreResources.LogIgnoredInclude(new TestLogger<SqlServerLoggingDefinitions>()).GenerateMessage(
#pragma warning restore CS0612 // Type or member is obsolete
"{from Order o in [g] orderby [o].OrderID asc select [o] => FirstOrDefault()}.OrderDetails"),
Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message));
}
}
#pragma warning restore CS0612 // Type or member is obsolete

[ConditionalFact]
public void SelectExpression_does_not_use_an_old_logger()

0 comments on commit a45bdb5

Please sign in to comment.