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));
            }
        }
        public virtual void Union_Include_collection_ignored()
        {
            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();

                Assert.NotNull(orders);
                Assert.Contains(
                    CoreResources.LogIgnoredInclude(new TestLogger <SqlServerLoggingDefinitions>()).GenerateMessage("[o].OrderDetails"),
                    Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message));
            }
        }
Пример #3
0
        public void Logs_by_default_for_ignored_includes()
        {
            var loggerFactory = new ListLoggerFactory();

            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkInMemoryDatabase()
                                  .AddSingleton <ILoggerFactory>(loggerFactory)
                                  .BuildServiceProvider();

            using (var context = new WarningAsErrorContext(serviceProvider, defaultThrow: false))
            {
                var _ = context.WarningAsErrorEntities.Include(e => e.Nav).OrderBy(e => e.Id).Select(e => e.Id).ToList();

                Assert.Contains(CoreResources.LogIgnoredInclude(new TestLogger <InMemoryLoggingDefinitions>()).GenerateMessage("[e].Nav"), loggerFactory.Log.Select(l => l.Message));
            }
        }
        public virtual void GroupBy_Include_collection_ignored()
        {
            using (var context = CreateContext())
            {
                var orders = context.Orders
                             .GroupBy(o => o.OrderID)
                             .Select(g => g.OrderBy(o => o.OrderID).FirstOrDefault())
                             .Include(o => o.OrderDetails)
                             .ToList();

                Assert.NotNull(orders);
                Assert.Contains(
                    CoreResources.LogIgnoredInclude(new TestLogger <SqlServerLoggingDefinitions>()).GenerateMessage(
                        "{from Order o in [g] orderby [o].OrderID asc select [o] => FirstOrDefault()}.OrderDetails"),
                    Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message));
            }
        }
        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(
#pragma warning disable CS0612 // Type or member is obsolete
                    CoreResources.LogIgnoredInclude(new TestLogger <MySqlLoggingDefinitions>()).GenerateMessage("[c].Orders"), Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message));
#pragma warning restore CS0612 // Type or member is obsolete
            }
        }
        public void Ignored_includes_can_be_configured_to_throw()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkInMemoryDatabase()
                                  .BuildServiceProvider();

            using (var context = new WarningAsErrorContext(serviceProvider, toThrow: CoreEventId.IncludeIgnoredWarning))
            {
                Assert.Equal(
                    CoreStrings.WarningAsErrorTemplate(
                        CoreEventId.IncludeIgnoredWarning.ToString(),
                        CoreResources.LogIgnoredInclude(new TestLogger <InMemoryLoggingDefinitions>()).GenerateMessage("[e].Nav"),
                        "CoreEventId.IncludeIgnoredWarning"),
                    Assert.Throws <InvalidOperationException>(
                        ()
                        => context.WarningAsErrorEntities.Include(e => e.Nav).OrderBy(e => e.Id).Select(e => e.Id).ToList()).Message);
            }
        }
        public virtual void GroupBy_Include_collection_ignored()
        {
            using (var context = CreateContext())
            {
                var orders = context.Orders
                             .GroupBy(o => o.OrderID)
                             .Select(g => g.OrderBy(o => o.OrderID).FirstOrDefault())
                             .Include(o => o.OrderDetails)
                             .ToList();

                Assert.NotNull(orders);
                Assert.Contains(
#pragma warning disable CS0612 // Type or member is obsolete
                    CoreResources.LogIgnoredInclude(new TestLogger <JetLoggingDefinitions>()).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));
            }
        }