private IReadOnlyList <ViewLocationCacheItem> GetViewStartPages( string path, HashSet <IChangeToken> expirationTokens) { var viewStartPages = new List <ViewLocationCacheItem>(); foreach (var filePath in RazorFileHierarchy.GetViewStartPaths(path)) { var result = _pageFactory.CreateFactory(filePath); var viewDescriptor = result.ViewDescriptor; if (viewDescriptor?.ExpirationTokens != null) { for (var i = 0; i < viewDescriptor.ExpirationTokens.Count; i++) { expirationTokens.Add(viewDescriptor.ExpirationTokens[i]); } } if (result.Success) { // Populate the viewStartPages list so that _ViewStarts appear in the order the need to be // executed (closest last, furthest first). This is the reverse order in which // ViewHierarchyUtility.GetViewStartLocations returns _ViewStarts. viewStartPages.Insert(0, new ViewLocationCacheItem(result.RazorPageFactory, filePath)); } } return(viewStartPages); }
public void GetViewStartPaths_ForFileAtRoot() { // Arrange var expected = new[] { "/_ViewStart.cshtml", }; var path = "/Home.cshtml"; // Act var actual = RazorFileHierarchy.GetViewStartPaths(path); // Assert Assert.Equal(expected, actual); }
public void GetViewStartPaths_ForForFileInViewsDirectory() { // Arrange var expected = new[] { "/Views/Home/_ViewStart.cshtml", "/Views/_ViewStart.cshtml", "/_ViewStart.cshtml", }; var path = "/Views/Home/Index.cshtml"; // Act var actual = RazorFileHierarchy.GetViewStartPaths(path); // Assert Assert.Equal(expected, actual); }