예제 #1
0
        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());
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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());
            }
        }