public void ShouldDisplayCorrect_CurrentIncludePath_WhenRemovingNavigation() { var context = new EagerLoadContext(Mock.Of <DbContext>(), Mock.Of <IIncludeStrategy>()); var bookNavigationMock = new Mock <INavigation>(); bookNavigationMock.Setup(nav => nav.Name).Returns(nameof(Book)); var authorNavigationMock = new Mock <INavigation>(); authorNavigationMock.Setup(nav => nav.Name).Returns(nameof(Author)); var publisherNavigationMock = new Mock <INavigation>(); publisherNavigationMock.Setup(nav => nav.Name).Returns(nameof(Publisher)); context.SetCurrentNavigation(bookNavigationMock.Object); context.SetCurrentNavigation(authorNavigationMock.Object); context.SetCurrentNavigation(publisherNavigationMock.Object); Assert.Equal($"{nameof(Book)}.{nameof(Author)}.{nameof(Publisher)}", context.CurrentIncludePath); context.RemoveCurrentNavigation(); Assert.Equal($"{nameof(Book)}.{nameof(Author)}", context.CurrentIncludePath); context.RemoveCurrentNavigation(); Assert.Equal($"{nameof(Book)}", context.CurrentIncludePath); context.RemoveCurrentNavigation(); Assert.Equal(string.Empty, context.CurrentIncludePath); context.RemoveCurrentNavigation(); Assert.Equal(string.Empty, context.CurrentIncludePath); }
private void BuildIncludesForEagerLoadContext(EagerLoadContext context) { BuildIncludesForEagerLoadContext(); void BuildIncludesForEagerLoadContext() { var navigationsToConsider = _navigationFinder.GetNavigationsForType(context, context.CurrentType ?? context.RootType); foreach (var navigation in navigationsToConsider) { context.SetCurrentNavigation(navigation); if (context.IncludeStrategy.ShouldIncludeCurrentNavigation(context)) { context.IncludePathsToInclude.Add(context.CurrentIncludePath); BuildIncludesForEagerLoadContext(); } context.RemoveCurrentNavigation(); } } }