예제 #1
0
        public void Lazy_loading_is_logged_only_when_actually_loading()
        {
            var loggerFactory = new ListLoggerFactory();

            using (var context = new WarningAsErrorContext(loggerFactory))
            {
                context.Add(
                    new WarningAsErrorEntity
                {
                    Nav = new IncludedEntity()
                });
                context.SaveChanges();
            }

            using (var context = new WarningAsErrorContext(loggerFactory))
            {
                var entity = context.WarningAsErrorEntities.OrderBy(e => e.Id).First();

                loggerFactory.Clear();
                Assert.NotNull(entity.Nav);

                Assert.Contains(
                    CoreStrings.LogNavigationLazyLoading.GenerateMessage("Nav", "WarningAsErrorEntity"),
                    loggerFactory.Log.Select(l => l.Message));

                loggerFactory.Clear();
                Assert.NotNull(entity.Nav);
                Assert.DoesNotContain(
                    CoreStrings.LogNavigationLazyLoading.GenerateMessage("Nav", "WarningAsErrorEntity"),
                    loggerFactory.Log.Select(l => l.Message));
            }
        }
예제 #2
0
        public void LogsWarningWhenRouteIsOverwritten()
        {
            _router.Map <string>("some_endpoint");
            _loggerFactory.Clear();

            _router.Map <string>("another_endpoint");

            var logLines = _loggerFactory
                           .Where(l => l.Level == LogLevel.Warn)
                           .ToList();

            Assert.That(logLines.Count, Is.EqualTo(1));
        }
예제 #3
0
        public void Lazy_loading_is_logged_only_when_actually_loading()
        {
            var loggerFactory = new ListLoggerFactory();

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

            using (var context = new WarningAsErrorContext(serviceProvider, defaultThrow: false))
            {
                context.Add(
                    new WarningAsErrorEntity {
                    Nav = new IncludedEntity()
                });
                context.SaveChanges();
            }

            using (var context = new WarningAsErrorContext(serviceProvider, defaultThrow: false))
            {
                var entity = context.WarningAsErrorEntities.OrderBy(e => e.Id).First();

                loggerFactory.Clear();
                Assert.NotNull(entity.Nav);

                Assert.Contains(
                    CoreResources.LogNavigationLazyLoading(new TestLogger <InMemoryLoggingDefinitions>())
                    .GenerateMessage("WarningAsErrorEntity", "Nav"),
                    loggerFactory.Log.Select(l => l.Message));

                loggerFactory.Clear();
                Assert.NotNull(entity.Nav);
                Assert.DoesNotContain(
                    CoreResources.LogNavigationLazyLoading(new TestLogger <InMemoryLoggingDefinitions>())
                    .GenerateMessage("WarningAsErrorEntity", "Nav"),
                    loggerFactory.Log.Select(l => l.Message));
            }
        }
예제 #4
0
            public DbContextOptions CreateOptions(
                Action <ModelBuilder> onModelCreating = null, object additionalModelCacheKey = null, bool seed = true)
            {
                OnModelCreatingAction   = onModelCreating;
                AdditionalModelCacheKey = additionalModelCacheKey;
                var options = CreateOptions(TestStore);

                TestStore.Initialize(ServiceProvider, () => new EmbeddedTransportationContext(options), c =>
                {
                    if (seed)
                    {
                        ((TransportationContext)c).Seed();
                    }
                });

                ListLoggerFactory.Clear();
                return(options);
            }
예제 #5
0
 public DbContextOptions CreateOptions()
 {
     TestStore.Initialize(null, (Func <DbContext>)null);
     ListLoggerFactory.Clear();
     return(CreateOptions(TestStore));
 }
예제 #6
0
 protected virtual void ClearLog() => ListLoggerFactory.Clear();
예제 #7
0
 protected override void SetUp()
 {
     _listLoggerFactory.Clear();
     _network.Reset();
 }
예제 #8
0
 protected override void SetUp() => _listLoggerFactory.Clear();