public async Task LazyLoading_NoFilters_Test() { using (var context = new TestDbContext(_dbOptions)) { await FakeDataGenerator.AddFakeDataAsync(context); } using (var lazyContext = new LazyLoadingTestContext(_dbOptions)) { WriteLine("\n======================="); WriteLine("LAZY LOADING NO FILTERS"); WriteLine("=======================\n"); var parent = await lazyContext .Parents .FirstOrDefaultAsync(); Assert.NotNull(parent); Assert.NotEmpty(parent.Children); Assert.Equal(FakeDataGenerator.ChildrenCount, parent.Children.Count()); } }
public async Task LazyLoading_OutsideContext_Exception_Test() { using (var context = new TestDbContext(_dbOptions)) { await FakeDataGenerator.AddFakeDataAsync(context); } ParentEntity parent; using (var lazyContext = new LazyLoadingTestContext(_dbOptions)) { WriteLine("\n======================="); WriteLine("LAZY LOADING NO FILTERS"); WriteLine("=======================\n"); parent = await lazyContext .Parents .FirstOrDefaultAsync(); } Assert.NotNull(parent); Assert.Throws <InvalidOperationException>(() => parent.Children.Count); }
public async Task LazyLoading_WithFilter_Test() { using (var context = new TestDbContext(_dbOptions)) { await FakeDataGenerator.AddFakeDataAsync(context); } using (var lazyContext = new LazyLoadingTestContext(_dbOptions)) { WriteLine("\n========================"); WriteLine("LAZY LOADING WITH FILTER"); WriteLine("========================\n"); var parent = await lazyContext .Parents .FirstOrDefaultAsync(); var filteredChildren = parent.Children.Where(ch => ch.Int64Property > 0).ToArray(); Assert.NotNull(parent); Assert.NotEmpty(filteredChildren); Assert.Equal(FakeDataGenerator.ChildrenCount - 1, filteredChildren.Count()); } }