Ejemplo n.º 1
0
        public void ShouldNotEagerLoad_WhenNavigationIsNotAllowedOnTheRootEntity()
        {
            var attribute = new EagerLoadAttribute(notOnRoot: true);

            var navigationHelperMock = new Mock <NavigationHelper>();

            navigationHelperMock.Setup(helper => helper.GetTypeForNavigation(It.IsAny <INavigation>()))
            .Returns(typeof(Book));

            var strategy = new EagerLoadAttributeIncludeStrategy(navigationHelperMock.Object);
            var context  = new EagerLoadContext(Mock.Of <DbContext>(), strategy);

            var firstNavigationMock = SetupGenericNavigationMock();

            EagerLoadAttributeIncludeStrategy.EagerLoadAttributeCache.TryAdd(firstNavigationMock.Object, attribute);

            context.SetCurrentNavigation(firstNavigationMock.Object);
            Assert.False(strategy.ShouldIncludeCurrentNavigation(context));

            var secondNavigationMock = SetupGenericNavigationMock();

            EagerLoadAttributeIncludeStrategy.EagerLoadAttributeCache.TryAdd(secondNavigationMock.Object, new EagerLoadAttribute());

            context.SetCurrentNavigation(secondNavigationMock.Object);

            context.SetCurrentNavigation(firstNavigationMock.Object);
            Assert.True(strategy.ShouldIncludeCurrentNavigation(context));
        }
Ejemplo n.º 2
0
        public void ShouldNotEagerLoad_WhenAttributeDoesNotExistOnNavigation()
        {
            var strategy = new EagerLoadAttributeIncludeStrategy();
            var context  = new EagerLoadContext(Mock.Of <DbContext>(), strategy);

            var navigationMock = SetupGenericNavigationMock();

            context.SetCurrentNavigation(navigationMock.Object);

            Assert.False(strategy.ShouldIncludeCurrentNavigation(context));
        }
Ejemplo n.º 3
0
        public void GlobalSetup()
        {
            _testDbContext = new TestDbContext(new DbContextOptionsBuilder <TestDbContext>()
                                               .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options);

            _strategy = new EagerLoadAttributeIncludeStrategy();

            _context = new EagerLoadContext(_testDbContext, _strategy, new string[0], IncludeExecution.NoCache, typeof(Book));

            _includeFinder = new Engine.IncludeFinder();
        }
Ejemplo n.º 4
0
        public void ShouldNotEagerLoad_WhenNavigationIsNotValid()
        {
            var strategy = new EagerLoadAttributeIncludeStrategy();
            var context  = new EagerLoadContext(Mock.Of <DbContext>(), strategy);

            var navigationMock = new Mock <INavigation>();

            navigationMock.Setup(nav => nav.Name).Returns(nameof(Book));
            context.SetCurrentNavigation(navigationMock.Object);

            Assert.False(strategy.ShouldIncludeCurrentNavigation(context));
        }
Ejemplo n.º 5
0
        public void ShouldNotEagerLoad_WhenAttributeSetToNever()
        {
            var strategy = new EagerLoadAttributeIncludeStrategy();
            var context  = new EagerLoadContext(Mock.Of <DbContext>(), strategy);

            var navigationMock = SetupGenericNavigationMock();
            var navigation     = navigationMock.Object;

            context.SetCurrentNavigation(navigation);
            var attribute = new EagerLoadAttribute(never: true);

            EagerLoadAttributeIncludeStrategy.EagerLoadAttributeCache.TryAdd(navigation, attribute);

            Assert.False(strategy.ShouldIncludeCurrentNavigation(context));
        }
Ejemplo n.º 6
0
        public void ShouldNotEagerLoad_WhenOverTheTypeCount()
        {
            var attribute = new EagerLoadAttribute(maxTypeCount: 1);

            var navigationHelperMock = new Mock <NavigationHelper>();

            var strategy = new EagerLoadAttributeIncludeStrategy(navigationHelperMock.Object);
            var context  = new EagerLoadContext(Mock.Of <DbContext>(), strategy, rootType: typeof(Publisher));

            var firstNavigationMock = SetupGenericNavigationMock();

            EagerLoadAttributeIncludeStrategy.EagerLoadAttributeCache.TryAdd(firstNavigationMock.Object, attribute);
            navigationHelperMock.Setup(helper => helper.GetTypeForNavigation(It.IsAny <INavigation>()))
            .Returns(typeof(Book));

            context.SetCurrentNavigation(firstNavigationMock.Object);
            Assert.True(strategy.ShouldIncludeCurrentNavigation(context));

            var secondNavigationMock = SetupGenericNavigationMock();

            EagerLoadAttributeIncludeStrategy.EagerLoadAttributeCache.TryAdd(secondNavigationMock.Object,
                                                                             new EagerLoadAttribute());
            navigationHelperMock.Setup(helper => helper.GetTypeForNavigation(It.IsAny <INavigation>()))
            .Returns(typeof(Author));

            context.SetCurrentNavigation(secondNavigationMock.Object);
            Assert.True(strategy.ShouldIncludeCurrentNavigation(context));

            var thirdNavigationMock = SetupGenericNavigationMock();

            EagerLoadAttributeIncludeStrategy.EagerLoadAttributeCache.TryAdd(thirdNavigationMock.Object, attribute);
            navigationHelperMock.Setup(helper => helper.GetTypeForNavigation(It.IsAny <INavigation>()))
            .Returns(typeof(Book));

            context.SetCurrentNavigation(thirdNavigationMock.Object);
            Assert.False(strategy.ShouldIncludeCurrentNavigation(context));
        }