public void IncludeNotIgnoredWhenProjectionAfterQueryExecution()
        {
            var options = Builder
                          .ConfigureWarnings(w => w.Throw(CoreEventId.IncludeIgnoredWarning))
                          .Options;

            using (var context = new SchoolContext(options))
                using (var provider = new SelectPlusOneLoggerProvider(context))
                {
                    var result = context
                                 .Person
                                 .Include(p => p.StudentGrade)
                                 .ThenInclude(pc => pc.Course)
                                 .ToList() // force execution, loading additional data, projecting later on
                                 .Select(p => new
                    {
                        p.FirstName,
                        p.LastName,
                        Courses = p.StudentGrade.Select(sg => sg.Course.Title)
                    }).ToList();

                    Assert.NotEmpty(result);
                    Assert.Contains(result, p => p.Courses.Any());

                    provider.Verify();
                }
        }
        public void ManyToMany()
        {
            using (var context = new SchoolContext(Options))
                using (var provider = new SelectPlusOneLoggerProvider(context, treshold: 2))
                {
                    // Arrange
                    var result = context
                                 .Person
                                 .Select(p => new
                    {
                        p.FirstName,
                        p.LastName,
                        Courses = p.StudentGrade.Select(sg => sg.Course.Title)
                    }).ToList();

                    // Act
                    Assert.NotEmpty(result);
                    foreach (var p in result)
                    {
                        foreach (var c in p.Courses)
                        {
                        }
                    }

                    // Assert
                    var ex = Assert.Throws <AggregateException>(() => provider.Verify());
                    Assert.IsType <PossibleSlectPlusOneQueryException>(ex.InnerException);
                }
        }
        public void OneToManyNavigationPropertyPartOfSelect()
        {
            using (var context = new SchoolContext(Options))
                using (var provider = new SelectPlusOneLoggerProvider(context, treshold: 2))
                {
                    var result = context
                                 .Person
                                 .Select(p => new
                    {
                        p.FirstName,
                        p.LastName,
                        Grades = p.StudentGrade
                    }).ToList();

                    Assert.NotEmpty(result);
                    foreach (var p in result)
                    {
                        foreach (var g in p.Grades)
                        {
                        }
                    }

                    var ex = Assert.Throws <AggregateException>(() => provider.Verify());
                    Assert.IsType <PossibleSlectPlusOneQueryException>(ex.InnerException);
                }
        }
        private static SelectPlusOneLoggerProvider InitializeLoggerProviderForTesting(int count = 20, int treshold = 20)
        {
            var provider = new SelectPlusOneLoggerProvider(treshold);
            var logger   = provider.CreateLogger(null);

            for (int i = 0; i < count; i++)
            {
                logger.Log <object>(LogLevel.Critical, new EventId(i), null, null, null);
            }

            return(provider);
        }
        private static SelectPlusOneLoggerProvider InitializeLoggerProviderForTesting(int count = 20, int treshold = 20)
        {
            var provider = new SelectPlusOneLoggerProvider(treshold);
            var logger   = provider.CreateLogger(null);

            for (int i = 0; i < count; i++)
            {
                logger.Log(LogLevel.Critical, new EventId(i), new DbCommandLogData("hoi", System.Data.CommandType.Text, 0, new List <DbParameterLogData>().AsReadOnly(), null), null, null);
            }

            return(provider);
        }
        public void OneToOne()
        {
            using (var context = new SchoolContext(Options))
                using (var provider = new SelectPlusOneLoggerProvider(context, treshold: 2))
                {
                    var result = context
                                 .Person
                                 .Select(p => new
                    {
                        p.FirstName,
                        p.LastName,
                        p.OfficeAssignment.Location
                    }).ToList();

                    Assert.NotEmpty(result);
                    Assert.Contains(result, p => p.Location != null);

                    provider.Verify();
                }
        }