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)); } }
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)); }
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)); } }
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); }
public DbContextOptions CreateOptions() { TestStore.Initialize(null, (Func <DbContext>)null); ListLoggerFactory.Clear(); return(CreateOptions(TestStore)); }
protected virtual void ClearLog() => ListLoggerFactory.Clear();
protected override void SetUp() { _listLoggerFactory.Clear(); _network.Reset(); }
protected override void SetUp() => _listLoggerFactory.Clear();