From 3be6167aa093033a71ab6822fbc9199b4731a030 Mon Sep 17 00:00:00 2001 From: Doug Bunting Date: Mon, 16 Nov 2015 16:35:45 -0800 Subject: [PATCH] Switch concepts from misnamed `isPartial` to `isMainPage` - `true` has the opposite meaning now but most changes are due to new parameters names in `IViewEngine` - use name names in `Microsoft.AspNet.Mvc.ViewFound` and not found events - remove `IRazorPage.IsPartial` and `RazorView.IsPartial` - remove `IsPartial` properties from `Microsoft.AspNet.Mvc.Razor.BeginInstrumentationContext` and end events - add parameter checks to `RazorView` constructor; instances are not retrieved from DI nits: - remove unused `cacheKey` parameter from `RazorViewEngine.CreateCacheResult()` - correct duplicate test names in `RazorPageTest` - also `...OnPageExecutionListenerContext` -> `...OnPageExecutionContext` --- src/Microsoft.AspNet.Mvc.Razor/IRazorPage.cs | 6 - .../IRazorViewEngine.cs | 8 +- src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs | 5 - src/Microsoft.AspNet.Mvc.Razor/RazorView.cs | 59 +- .../RazorViewEngine.cs | 62 +- .../ViewLocationCacheKey.cs | 20 +- .../ViewLocationExpanderContext.cs | 10 +- .../ViewExecutorDiagnosticSourceExtensions.cs | 8 +- .../ViewComponents/ViewViewComponentResult.cs | 4 +- .../ViewEngines/CompositeViewEngine.cs | 8 +- .../ViewEngines/IViewEngine.cs | 8 +- .../ViewFeatures/HtmlHelper.cs | 4 +- .../ViewFeatures/PartialViewResultExecutor.cs | 18 +- .../ViewFeatures/TemplateRenderer.cs | 4 +- .../ViewFeatures/ViewResultExecutor.cs | 8 +- .../ViewEngineTests.cs | 16 +- .../RazorPageTest.cs | 31 +- .../RazorViewEngineTest.cs | 539 ++++++++--------- .../RazorViewTest.cs | 268 +++----- .../TestDiagnosticListener.cs | 20 +- .../PartialViewResultTest.cs | 16 +- .../Rendering/DefaultTemplatesUtilities.cs | 4 +- .../HtmlHelperPartialExtensionsTest.cs | 24 +- .../ViewViewComponentResultTest.cs | 44 +- .../ViewEngines/CompositeViewEngineTest.cs | 572 +++++++++--------- .../DefaultDisplayTemplatesTest.cs | 30 +- .../DefaultEditorTemplatesTest.cs | 66 +- .../PartialViewResultExecutorTest.cs | 30 +- .../ViewFeatures/ViewResultExecutorTest.cs | 26 +- .../ViewResultTest.cs | 16 +- .../TestViewEngine.cs | 6 +- ....cs => NonMainPageViewLocationExpander.cs} | 16 +- test/WebSites/RazorWebSite/Startup.cs | 3 +- 33 files changed, 914 insertions(+), 1045 deletions(-) rename test/WebSites/RazorWebSite/Services/{CustomPartialDirectoryViewLocationExpander.cs => NonMainPageViewLocationExpander.cs} (57%) diff --git a/src/Microsoft.AspNet.Mvc.Razor/IRazorPage.cs b/src/Microsoft.AspNet.Mvc.Razor/IRazorPage.cs index 5530185be3..156bedb227 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/IRazorPage.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/IRazorPage.cs @@ -45,12 +45,6 @@ namespace Microsoft.AspNet.Mvc.Razor /// string Layout { get; set; } - /// - /// Gets or sets a value that determines if the current instance of is being executed - /// from a partial view. - /// - bool IsPartial { get; set; } - /// /// Gets or sets a instance used to instrument the page execution. /// diff --git a/src/Microsoft.AspNet.Mvc.Razor/IRazorViewEngine.cs b/src/Microsoft.AspNet.Mvc.Razor/IRazorViewEngine.cs index 0c200f95f8..2459a641b7 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/IRazorViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/IRazorViewEngine.cs @@ -16,10 +16,10 @@ namespace Microsoft.AspNet.Mvc.Razor /// /// The . /// The name of the page. - /// Determines if the page being found is a partial. + /// Determines if the page being found is the main page for an action. /// The of locating the page. /// . - RazorPageResult FindPage(ActionContext context, string pageName, bool isPartial); + RazorPageResult FindPage(ActionContext context, string pageName, bool isMainPage); /// /// Gets the page with the given , relative to @@ -27,10 +27,10 @@ namespace Microsoft.AspNet.Mvc.Razor /// /// The absolute path to the currently-executing page, if any. /// The path to the page. - /// Determines if the page being found is a partial. + /// Determines if the page being found is the main page for an action. /// The of locating the page. /// . - RazorPageResult GetPage(string executingFilePath, string pagePath, bool isPartial); + RazorPageResult GetPage(string executingFilePath, string pagePath, bool isMainPage); /// /// Converts the given to be absolute, relative to diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs index b03ff33284..5e224193df 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorPage.cs @@ -72,9 +72,6 @@ namespace Microsoft.AspNet.Mvc.Razor /// public string Layout { get; set; } - /// - public bool IsPartial { get; set; } - /// /// Gets the to be used for encoding HTML. /// @@ -1080,7 +1077,6 @@ namespace Microsoft.AspNet.Mvc.Razor { httpContext = Context, path = Path, - isPartial = IsPartial, position = position, length = length, isLiteral = isLiteral, @@ -1101,7 +1097,6 @@ namespace Microsoft.AspNet.Mvc.Razor { httpContext = Context, path = Path, - isPartial = IsPartial, }); } } diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs index c1f461e8a1..1eadc9f201 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorView.cs @@ -34,21 +34,43 @@ namespace Microsoft.AspNet.Mvc.Razor /// /// The instance to execute. /// The HTML encoder. - /// Determines if the view is to be executed as a partial. public RazorView( IRazorViewEngine viewEngine, IRazorPageActivator pageActivator, IReadOnlyList viewStartPages, IRazorPage razorPage, - HtmlEncoder htmlEncoder, - bool isPartial) + HtmlEncoder htmlEncoder) { + if (viewEngine == null) + { + throw new ArgumentNullException(nameof(viewEngine)); + } + + if (pageActivator == null) + { + throw new ArgumentNullException(nameof(pageActivator)); + } + + if (viewStartPages == null) + { + throw new ArgumentNullException(nameof(viewStartPages)); + } + + if (razorPage == null) + { + throw new ArgumentNullException(nameof(razorPage)); + } + + if (htmlEncoder == null) + { + throw new ArgumentNullException(nameof(htmlEncoder)); + } + _viewEngine = viewEngine; _pageActivator = pageActivator; ViewStartPages = viewStartPages; RazorPage = razorPage; _htmlEncoder = htmlEncoder; - IsPartial = isPartial; } /// @@ -63,13 +85,7 @@ namespace Microsoft.AspNet.Mvc.Razor public IRazorPage RazorPage { get; } /// - /// Gets a value that determines if the view is executed as a partial. - /// - public bool IsPartial { get; } - - /// - /// Gets the sequence of _ViewStart instances - /// that are executed by this view if is false. + /// Gets the sequence of _ViewStart instances that are executed by this view. /// public IReadOnlyList ViewStartPages { get; } @@ -88,16 +104,14 @@ namespace Microsoft.AspNet.Mvc.Razor _pageExecutionFeature = context.HttpContext.Features.Get(); - // Partials don't execute _ViewStart pages, but may execute Layout pages if the Layout property - // is explicitly specified in the page. - var bodyWriter = await RenderPageAsync(RazorPage, context, executeViewStart: !IsPartial); + var bodyWriter = await RenderPageAsync(RazorPage, context, ViewStartPages); await RenderLayoutAsync(context, bodyWriter); } private async Task RenderPageAsync( IRazorPage page, ViewContext context, - bool executeViewStart) + IReadOnlyList viewStartPages) { var razorTextWriter = new RazorTextWriter(context.Writer, context.Writer.Encoding, _htmlEncoder); var writer = (TextWriter)razorTextWriter; @@ -126,10 +140,10 @@ namespace Microsoft.AspNet.Mvc.Razor try { - if (executeViewStart) + if (viewStartPages != null) { // Execute view starts using the same context + writer as the page to render. - await RenderViewStartAsync(context); + await RenderViewStartsAsync(context, viewStartPages); } await RenderPageCoreAsync(page, context); @@ -145,7 +159,6 @@ namespace Microsoft.AspNet.Mvc.Razor private Task RenderPageCoreAsync(IRazorPage page, ViewContext context) { - page.IsPartial = IsPartial; page.ViewContext = context; if (EnableInstrumentation) { @@ -156,13 +169,13 @@ namespace Microsoft.AspNet.Mvc.Razor return page.ExecuteAsync(); } - private async Task RenderViewStartAsync(ViewContext context) + private async Task RenderViewStartsAsync(ViewContext context, IReadOnlyList viewStartPages) { string layout = null; var oldFilePath = context.ExecutingFilePath; try { - for (var i = 0; i < ViewStartPages.Count; i++) + for (var i = 0; i < viewStartPages.Count; i++) { var viewStart = ViewStartPages[i]; context.ExecutingFilePath = viewStart.Path; @@ -223,7 +236,7 @@ namespace Microsoft.AspNet.Mvc.Razor previousPage.IsLayoutBeingRendered = true; layoutPage.PreviousSectionWriters = previousPage.SectionWriters; layoutPage.RenderBodyDelegateAsync = bodyWriter.CopyToAsync; - bodyWriter = await RenderPageAsync(layoutPage, context, executeViewStart: false); + bodyWriter = await RenderPageAsync(layoutPage, context, viewStartPages: null); renderedLayouts.Add(layoutPage); previousPage = layoutPage; @@ -244,11 +257,11 @@ namespace Microsoft.AspNet.Mvc.Razor private IRazorPage GetLayoutPage(ViewContext context, string executingFilePath, string layoutPath) { - var layoutPageResult = _viewEngine.GetPage(executingFilePath, layoutPath, isPartial: true); + var layoutPageResult = _viewEngine.GetPage(executingFilePath, layoutPath, isMainPage: false); var originalLocations = layoutPageResult.SearchedLocations; if (layoutPageResult.Page == null) { - layoutPageResult = _viewEngine.FindPage(context, layoutPath, isPartial: true); + layoutPageResult = _viewEngine.FindPage(context, layoutPath, isMainPage: false); } if (layoutPageResult.Page == null) diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs index c3613ee667..e0cf899c76 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs @@ -175,7 +175,7 @@ namespace Microsoft.AspNet.Mvc.Razor } /// - public RazorPageResult FindPage(ActionContext context, string pageName, bool isPartial) + public RazorPageResult FindPage(ActionContext context, string pageName, bool isMainPage) { if (context == null) { @@ -193,11 +193,10 @@ namespace Microsoft.AspNet.Mvc.Razor return new RazorPageResult(pageName, Enumerable.Empty()); } - var cacheResult = LocatePageFromViewLocations(context, pageName, isPartial); + var cacheResult = LocatePageFromViewLocations(context, pageName, isMainPage); if (cacheResult.Success) { var razorPage = cacheResult.ViewEntry.PageFactory(); - razorPage.IsPartial = isPartial; return new RazorPageResult(pageName, razorPage); } else @@ -207,7 +206,7 @@ namespace Microsoft.AspNet.Mvc.Razor } /// - public RazorPageResult GetPage(string executingFilePath, string pagePath, bool isPartial) + public RazorPageResult GetPage(string executingFilePath, string pagePath, bool isMainPage) { if (string.IsNullOrEmpty(pagePath)) { @@ -220,11 +219,10 @@ namespace Microsoft.AspNet.Mvc.Razor return new RazorPageResult(pagePath, Enumerable.Empty()); } - var cacheResult = LocatePageFromPath(executingFilePath, pagePath, isPartial); + var cacheResult = LocatePageFromPath(executingFilePath, pagePath, isMainPage); if (cacheResult.Success) { var razorPage = cacheResult.ViewEntry.PageFactory(); - razorPage.IsPartial = isPartial; return new RazorPageResult(pagePath, razorPage); } else @@ -234,7 +232,7 @@ namespace Microsoft.AspNet.Mvc.Razor } /// - public ViewEngineResult FindView(ActionContext context, string viewName, bool isPartial) + public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage) { if (context == null) { @@ -252,12 +250,12 @@ namespace Microsoft.AspNet.Mvc.Razor return ViewEngineResult.NotFound(viewName, Enumerable.Empty()); } - var cacheResult = LocatePageFromViewLocations(context, viewName, isPartial); - return CreateViewEngineResult(cacheResult, viewName, isPartial); + var cacheResult = LocatePageFromViewLocations(context, viewName, isMainPage); + return CreateViewEngineResult(cacheResult, viewName); } /// - public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isPartial) + public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage) { if (string.IsNullOrEmpty(viewPath)) { @@ -270,19 +268,19 @@ namespace Microsoft.AspNet.Mvc.Razor return ViewEngineResult.NotFound(viewPath, Enumerable.Empty()); } - var cacheResult = LocatePageFromPath(executingFilePath, viewPath, isPartial); - return CreateViewEngineResult(cacheResult, viewPath, isPartial); + var cacheResult = LocatePageFromPath(executingFilePath, viewPath, isMainPage); + return CreateViewEngineResult(cacheResult, viewPath); } - private ViewLocationCacheResult LocatePageFromPath(string executingFilePath, string pagePath, bool isPartial) + private ViewLocationCacheResult LocatePageFromPath(string executingFilePath, string pagePath, bool isMainPage) { var applicationRelativePath = GetAbsolutePath(executingFilePath, pagePath); - var cacheKey = new ViewLocationCacheKey(applicationRelativePath, isPartial); + var cacheKey = new ViewLocationCacheKey(applicationRelativePath, isMainPage); ViewLocationCacheResult cacheResult; if (!ViewLookupCache.TryGetValue(cacheKey, out cacheResult)) { var expirationTokens = new HashSet(); - cacheResult = CreateCacheResult(cacheKey, expirationTokens, applicationRelativePath, isPartial); + cacheResult = CreateCacheResult(expirationTokens, applicationRelativePath, isMainPage); var cacheEntryOptions = new MemoryCacheEntryOptions(); cacheEntryOptions.SetSlidingExpiration(_cacheExpirationDuration); @@ -309,7 +307,7 @@ namespace Microsoft.AspNet.Mvc.Razor private ViewLocationCacheResult LocatePageFromViewLocations( ActionContext actionContext, string pageName, - bool isPartial) + bool isMainPage) { var controllerName = GetNormalizedRouteValue(actionContext, ControllerKey); var areaName = GetNormalizedRouteValue(actionContext, AreaKey); @@ -318,7 +316,7 @@ namespace Microsoft.AspNet.Mvc.Razor pageName, controllerName, areaName, - isPartial); + isMainPage); Dictionary expanderValues = null; if (_viewLocationExpanders.Count > 0) @@ -337,7 +335,7 @@ namespace Microsoft.AspNet.Mvc.Razor expanderContext.ViewName, expanderContext.ControllerName, expanderContext.ViewName, - expanderContext.IsPartial, + expanderContext.IsMainPage, expanderValues); ViewLocationCacheResult cacheResult; @@ -411,7 +409,7 @@ namespace Microsoft.AspNet.Mvc.Razor expanderContext.ControllerName, expanderContext.AreaName); - cacheResult = CreateCacheResult(cacheKey, expirationTokens, path, expanderContext.IsPartial); + cacheResult = CreateCacheResult(expirationTokens, path, expanderContext.IsMainPage); if (cacheResult != null) { break; @@ -437,10 +435,9 @@ namespace Microsoft.AspNet.Mvc.Razor } private ViewLocationCacheResult CreateCacheResult( - ViewLocationCacheKey cacheKey, HashSet expirationTokens, string relativePath, - bool isPartial) + bool isMainPage) { var factoryResult = _pageFactory.CreateFactory(relativePath); if (factoryResult.ExpirationTokens != null) @@ -453,10 +450,10 @@ namespace Microsoft.AspNet.Mvc.Razor if (factoryResult.Success) { - // Don't need to lookup _ViewStarts for partials. - var viewStartPages = isPartial ? - EmptyViewStartLocationCacheItems : - GetViewStartPages(relativePath, expirationTokens); + // Only need to lookup _ViewStarts for the main page. + var viewStartPages = isMainPage ? + GetViewStartPages(relativePath, expirationTokens) : + EmptyViewStartLocationCacheItems; return new ViewLocationCacheResult( new ViewLocationCacheItem(factoryResult.RazorPageFactory, relativePath), @@ -494,10 +491,7 @@ namespace Microsoft.AspNet.Mvc.Razor return viewStartPages; } - private ViewEngineResult CreateViewEngineResult( - ViewLocationCacheResult result, - string viewName, - bool isPartial) + private ViewEngineResult CreateViewEngineResult(ViewLocationCacheResult result, string viewName) { if (!result.Success) { @@ -505,23 +499,15 @@ namespace Microsoft.AspNet.Mvc.Razor } var page = result.ViewEntry.PageFactory(); - page.IsPartial = isPartial; var viewStarts = new IRazorPage[result.ViewStartEntries.Count]; for (var i = 0; i < viewStarts.Length; i++) { var viewStartItem = result.ViewStartEntries[i]; viewStarts[i] = viewStartItem.PageFactory(); - viewStarts[i].IsPartial = true; } - var view = new RazorView( - this, - _pageActivator, - viewStarts, - page, - _htmlEncoder, - isPartial); + var view = new RazorView(this, _pageActivator, viewStarts, page, _htmlEncoder); return ViewEngineResult.Found(viewName, view); } diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewLocationCacheKey.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewLocationCacheKey.cs index f73900402d..dc4c31754c 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewLocationCacheKey.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewLocationCacheKey.cs @@ -16,15 +16,15 @@ namespace Microsoft.AspNet.Mvc.Razor /// Initializes a new instance of . /// /// The view name or path. - /// Determines if the view is a partial. + /// Determines if the page being found is the main page for an action. public ViewLocationCacheKey( string viewName, - bool isPartial) + bool isMainPage) : this( viewName, controllerName: null, areaName: null, - isPartial: isPartial, + isMainPage: isMainPage, values: null) { } @@ -35,19 +35,19 @@ namespace Microsoft.AspNet.Mvc.Razor /// The view name. /// The controller name. /// The area name. - /// Determines if the view is a partial. + /// Determines if the page being found is the main page for an action. /// Values from instances. public ViewLocationCacheKey( string viewName, string controllerName, string areaName, - bool isPartial, + bool isMainPage, IReadOnlyDictionary values) { ViewName = viewName; ControllerName = controllerName; AreaName = areaName; - IsPartial = isPartial; + IsMainPage = isMainPage; ViewLocationExpanderValues = values; } @@ -67,9 +67,9 @@ namespace Microsoft.AspNet.Mvc.Razor public string AreaName { get; } /// - /// Determines if the view is a partial. + /// Determines if the page being found is the main page for an action. /// - public bool IsPartial { get; } + public bool IsMainPage { get; } /// /// Gets the values populated by instances. @@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.Razor /// public bool Equals(ViewLocationCacheKey y) { - if (IsPartial != y.IsPartial || + if (IsMainPage != y.IsMainPage || !string.Equals(ViewName, y.ViewName, StringComparison.Ordinal) || !string.Equals(ControllerName, y.ControllerName, StringComparison.Ordinal) || !string.Equals(AreaName, y.AreaName, StringComparison.Ordinal)) @@ -127,7 +127,7 @@ namespace Microsoft.AspNet.Mvc.Razor public override int GetHashCode() { var hashCodeCombiner = HashCodeCombiner.Start(); - hashCodeCombiner.Add(IsPartial ? 1 : 0); + hashCodeCombiner.Add(IsMainPage ? 1 : 0); hashCodeCombiner.Add(ViewName, StringComparer.Ordinal); hashCodeCombiner.Add(ControllerName, StringComparer.Ordinal); hashCodeCombiner.Add(AreaName, StringComparer.Ordinal); diff --git a/src/Microsoft.AspNet.Mvc.Razor/ViewLocationExpanderContext.cs b/src/Microsoft.AspNet.Mvc.Razor/ViewLocationExpanderContext.cs index f120ccb7ee..60bc7b6a64 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/ViewLocationExpanderContext.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/ViewLocationExpanderContext.cs @@ -18,13 +18,13 @@ namespace Microsoft.AspNet.Mvc.Razor /// The view name. /// The controller name. /// The area name. - /// Determines if the view being discovered is a partial. + /// Determines if the page being found is the main page for an action. public ViewLocationExpanderContext( ActionContext actionContext, string viewName, string controllerName, string areaName, - bool isPartial) + bool isMainPage) { if (actionContext == null) { @@ -40,7 +40,7 @@ namespace Microsoft.AspNet.Mvc.Razor ViewName = viewName; ControllerName = controllerName; AreaName = areaName; - IsPartial = isPartial; + IsMainPage = isMainPage; } /// @@ -64,9 +64,9 @@ namespace Microsoft.AspNet.Mvc.Razor public string AreaName { get; } /// - /// Gets a value that determines if a partial view is being discovered. + /// Determines if the page being found is the main page for an action. /// - public bool IsPartial { get; } + public bool IsMainPage { get; } /// /// Gets or sets the that is populated with values as part of diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/DiagnosticSource/ViewExecutorDiagnosticSourceExtensions.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/DiagnosticSource/ViewExecutorDiagnosticSourceExtensions.cs index eade9c269c..28a4ee470d 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/DiagnosticSource/ViewExecutorDiagnosticSourceExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/DiagnosticSource/ViewExecutorDiagnosticSourceExtensions.cs @@ -39,7 +39,7 @@ namespace Microsoft.AspNet.Mvc.Diagnostics public static void ViewFound( this DiagnosticSource diagnosticSource, ActionContext actionContext, - bool isPartial, + bool isMainPage, PartialViewResult viewResult, string viewName, IView view) @@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.Diagnostics new { actionContext = actionContext, - isPartial = isPartial, + isMainPage = isMainPage, result = viewResult, viewName = viewName, view = view, @@ -62,7 +62,7 @@ namespace Microsoft.AspNet.Mvc.Diagnostics public static void ViewNotFound( this DiagnosticSource diagnosticSource, ActionContext actionContext, - bool isPartial, + bool isMainPage, PartialViewResult viewResult, string viewName, IEnumerable searchedLocations) @@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.Diagnostics new { actionContext = actionContext, - isPartial = isPartial, + isMainPage = isMainPage, result = viewResult, viewName = viewName, searchedLocations = searchedLocations, diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewViewComponentResult.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewViewComponentResult.cs index 7c9291e5ab..a536e2653f 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewViewComponentResult.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewComponents/ViewViewComponentResult.cs @@ -87,7 +87,7 @@ namespace Microsoft.AspNet.Mvc.ViewComponents if (!isNullOrEmptyViewName) { // If view name was passed in is already a path, the view engine will handle this. - result = viewEngine.GetView(viewContext.ExecutingFilePath, ViewName, isPartial: true); + result = viewEngine.GetView(viewContext.ExecutingFilePath, ViewName, isMainPage: false); originalLocations = result.SearchedLocations; } @@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Mvc.ViewComponents context.ViewComponentDescriptor.ShortName, viewName); - result = viewEngine.FindView(viewContext, qualifiedViewName, isPartial: true); + result = viewEngine.FindView(viewContext, qualifiedViewName, isMainPage: false); } var view = result.EnsureSuccessful(originalLocations).View; diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/CompositeViewEngine.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/CompositeViewEngine.cs index 2e1b0ed122..079f1af416 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/CompositeViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/CompositeViewEngine.cs @@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.ViewEngines public IReadOnlyList ViewEngines { get; } /// - public ViewEngineResult FindView(ActionContext context, string viewName, bool isPartial) + public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage) { if (context == null) { @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.ViewEngines List searchedList = null; for (var index = 0; index < ViewEngines.Count; index++) { - var result = ViewEngines[index].FindView(context, viewName, isPartial); + var result = ViewEngines[index].FindView(context, viewName, isMainPage); if (result.Success) { return result; @@ -70,7 +70,7 @@ namespace Microsoft.AspNet.Mvc.ViewEngines } /// - public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isPartial) + public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage) { if (string.IsNullOrEmpty(viewPath)) { @@ -82,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.ViewEngines List searchedList = null; for (var index = 0; index < ViewEngines.Count; index++) { - var result = ViewEngines[index].GetView(executingFilePath, viewPath, isPartial); + var result = ViewEngines[index].GetView(executingFilePath, viewPath, isMainPage); if (result.Success) { return result; diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/IViewEngine.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/IViewEngine.cs index 72811b6312..d1a5c9b599 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/IViewEngine.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewEngines/IViewEngine.cs @@ -14,9 +14,9 @@ namespace Microsoft.AspNet.Mvc.ViewEngines /// /// The . /// The name of the view. - /// Determines if the view being found is a partial. + /// Determines if the page being found is the main page for an action. /// The of locating the view. - ViewEngineResult FindView(ActionContext context, string viewName, bool isPartial); + ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage); /// /// Gets the view with the given , relative to @@ -24,8 +24,8 @@ namespace Microsoft.AspNet.Mvc.ViewEngines /// /// The absolute path to the currently-executing view, if any. /// The path to the view. - /// Determines if the view being found is a partial. + /// Determines if the page being found is the main page for an action. /// The of locating the view. - ViewEngineResult GetView(string executingFilePath, string viewPath, bool isPartial); + ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage); } } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs index 88c40932ea..ad3fc8a91c 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/HtmlHelper.cs @@ -543,11 +543,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewEngineResult = _viewEngine.GetView( ViewContext.ExecutingFilePath, partialViewName, - isPartial: true); + isMainPage: false); var originalLocations = viewEngineResult.SearchedLocations; if (!viewEngineResult.Success) { - viewEngineResult = _viewEngine.FindView(ViewContext, partialViewName, isPartial: true); + viewEngineResult = _viewEngine.FindView(ViewContext, partialViewName, isMainPage: false); } if (!viewEngineResult.Success) diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs index 4358f20a1a..80f70c7982 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/PartialViewResultExecutor.cs @@ -71,11 +71,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewEngine = viewResult.ViewEngine ?? ViewEngine; var viewName = viewResult.ViewName ?? actionContext.ActionDescriptor.Name; - var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isPartial: true); + var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: false); var originalResult = result; if (!result.Success) { - result = viewEngine.FindView(actionContext, viewName, isPartial: true); + result = viewEngine.FindView(actionContext, viewName, isMainPage: false); } if (!result.Success) @@ -99,13 +99,23 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures if (result.Success) { - DiagnosticSource.ViewFound(actionContext, true, viewResult, viewName, result.View); + DiagnosticSource.ViewFound( + actionContext, + isMainPage: false, + viewResult: viewResult, + viewName: viewName, + view: result.View); Logger.PartialViewFound(viewName); } else { - DiagnosticSource.ViewNotFound(actionContext, true, viewResult, viewName, result.SearchedLocations); + DiagnosticSource.ViewNotFound( + actionContext, + isMainPage: false, + viewResult: viewResult, + viewName: viewName, + searchedLocations: result.SearchedLocations); Logger.PartialViewNotFound(viewName, result.SearchedLocations); } diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/TemplateRenderer.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/TemplateRenderer.cs index 8846fa28c5..96458f9f55 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/TemplateRenderer.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/TemplateRenderer.cs @@ -109,12 +109,12 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures.Internal foreach (string viewName in GetViewNames()) { - var viewEngineResult = _viewEngine.GetView(_viewContext.ExecutingFilePath, viewName, isPartial: true); + var viewEngineResult = _viewEngine.GetView(_viewContext.ExecutingFilePath, viewName, isMainPage: false); if (!viewEngineResult.Success) { // Success here is more common than with GetView() but GetView() is less expensive. var fullViewName = modeViewPath + "/" + viewName; - viewEngineResult = _viewEngine.FindView(_viewContext, fullViewName, isPartial: true); + viewEngineResult = _viewEngine.FindView(_viewContext, fullViewName, isMainPage: false); } if (viewEngineResult.Success) diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs index f40b3d02fb..3cbb44c70c 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/ViewFeatures/ViewResultExecutor.cs @@ -69,11 +69,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewEngine = viewResult.ViewEngine ?? ViewEngine; var viewName = viewResult.ViewName ?? actionContext.ActionDescriptor.Name; - var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isPartial: false); + var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true); var originalResult = result; if (!result.Success) { - result = viewEngine.FindView(actionContext, viewName, isPartial: false); + result = viewEngine.FindView(actionContext, viewName, isMainPage: true); } if (!result.Success) @@ -104,7 +104,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures new { actionContext = actionContext, - isPartial = false, + isMainPage = true, result = viewResult, viewName = viewName, view = result.View, @@ -122,7 +122,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures new { actionContext = actionContext, - isPartial = false, + isMainPage = true, result = viewResult, viewName = viewName, searchedLocations = result.SearchedLocations diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs index c0a10209fe..8587db74d9 100644 --- a/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs +++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/ViewEngineTests.cs @@ -158,21 +158,27 @@ expander-partial"; Assert.Equal(expected, body.Trim(), ignoreLineEndingDifferences: true); } - public static TheoryData ViewLocationExpanders_PassesInIsPartialToViewLocationExpanderContextData + public static TheoryData ViewLocationExpanders_GetIsMainPageFromContextData { get { return new TheoryData { - { "Index", "/Shared-Views/ExpanderViews/_ExpanderPartial.cshtml" }, - { "Partial", "/Shared-Views/ExpanderViews/_ExpanderPartial.cshtml" } + { + "Index", + "/Shared-Views/ExpanderViews/_ExpanderPartial.cshtml" + }, + { + "Partial", + "/Shared-Views/ExpanderViews/_ExpanderPartial.cshtml" + }, }; } } [Theory] - [MemberData(nameof(ViewLocationExpanders_PassesInIsPartialToViewLocationExpanderContextData))] - public async Task ViewLocationExpanders_PassesInIsPartialToViewLocationExpanderContext(string action, string expected) + [MemberData(nameof(ViewLocationExpanders_GetIsMainPageFromContextData))] + public async Task ViewLocationExpanders_GetIsMainPageFromContext(string action, string expected) { // Arrange & Act var body = await Client.GetStringAsync($"http://localhost/ExpanderViews/{action}"); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs index c30e2e0978..2197bffd21 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorPageTest.cs @@ -660,7 +660,7 @@ namespace Microsoft.AspNet.Mvc.Razor } [Fact] - public async Task WriteAttribute_CallsBeginAndEndContext_OnPageExecutionListenerContext() + public async Task WriteAttribute_CallsBeginAndEndContext_OnPageExecutionContext() { // Arrange var page = CreatePage(p => @@ -695,7 +695,7 @@ namespace Microsoft.AspNet.Mvc.Razor } [Fact] - public async Task WriteAttribute_WithBoolValue_CallsBeginAndEndContext_OnPageExecutionListenerContext() + public async Task WriteAttribute_WithBoolValue_CallsBeginAndEndContext_OnPageExecutionContext() { // Arrange var page = CreatePage(p => @@ -746,10 +746,8 @@ namespace Microsoft.AspNet.Mvc.Razor context.Verify(); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public async Task WriteAttribute_CallsBeginAndEndContext_OnPageExecutionListenerContext(bool isPartial) + [Fact] + public async Task WriteAttribute_WritesBeginAndEndEvents_ToDiagnosticSource() { // Arrange var path = "path-to-page"; @@ -762,7 +760,6 @@ namespace Microsoft.AspNet.Mvc.Razor p.EndWriteAttribute(); }); page.Path = path; - page.IsPartial = isPartial; var adapter = new TestDiagnosticListener(); var diagnosticListener = new DiagnosticListener("Microsoft.AspNet.Mvc.Razor"); diagnosticListener.SubscribeWithAdapter(adapter); @@ -777,7 +774,6 @@ namespace Microsoft.AspNet.Mvc.Razor var beginEvent = Assert.IsType(data); Assert.NotNull(beginEvent.HttpContext); Assert.Equal(path, beginEvent.Path); - Assert.Equal(isPartial, beginEvent.IsPartial); return beginEvent; }; @@ -787,7 +783,6 @@ namespace Microsoft.AspNet.Mvc.Razor var endEvent = Assert.IsType(data); Assert.NotNull(endEvent.HttpContext); Assert.Equal(path, endEvent.Path); - Assert.Equal(isPartial, endEvent.IsPartial); }; Assert.Collection(adapter.PageInstrumentationData, @@ -841,10 +836,8 @@ namespace Microsoft.AspNet.Mvc.Razor assertEndEvent); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public async Task WriteAttribute_WithBoolValue_CallsBeginAndEndContext_OnPageExecutionListenerContext(bool isPartial) + [Fact] + public async Task WriteAttribute_WithBoolValue_WritesBeginAndEndEvents_ToDiagnosticSource() { // Arrange var path = "some-path"; @@ -856,7 +849,6 @@ namespace Microsoft.AspNet.Mvc.Razor p.EndWriteAttribute(); }); page.Path = path; - page.IsPartial = isPartial; var adapter = new TestDiagnosticListener(); var diagnosticListener = new DiagnosticListener("Microsoft.AspNet.Mvc.Razor"); diagnosticListener.SubscribeWithAdapter(adapter); @@ -871,7 +863,6 @@ namespace Microsoft.AspNet.Mvc.Razor var beginEvent = Assert.IsType(data); Assert.NotNull(beginEvent.HttpContext); Assert.Equal(path, beginEvent.Path); - Assert.Equal(isPartial, beginEvent.IsPartial); return beginEvent; }; @@ -881,7 +872,6 @@ namespace Microsoft.AspNet.Mvc.Razor var endEvent = Assert.IsType(data); Assert.NotNull(endEvent.HttpContext); Assert.Equal(path, endEvent.Path); - Assert.Equal(isPartial, endEvent.IsPartial); }; Assert.Collection(adapter.PageInstrumentationData, @@ -911,10 +901,8 @@ namespace Microsoft.AspNet.Mvc.Razor assertEndEvent); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public async Task WriteAttribute_CallsBeginAndEndContext_OnPrefixAndSuffixValues(bool isPartial) + [Fact] + public async Task WriteAttribute_WritesBeginAndEndEvents_ToDiagnosticSource_OnPrefixAndSuffixValues() { // Arrange var path = "some-path"; @@ -924,7 +912,6 @@ namespace Microsoft.AspNet.Mvc.Razor p.EndWriteAttribute(); }); page.Path = path; - page.IsPartial = isPartial; var adapter = new TestDiagnosticListener(); var diagnosticListener = new DiagnosticListener("Microsoft.AspNet.Mvc.Razor"); diagnosticListener.SubscribeWithAdapter(adapter); @@ -939,7 +926,6 @@ namespace Microsoft.AspNet.Mvc.Razor var beginEvent = Assert.IsType(data); Assert.NotNull(beginEvent.HttpContext); Assert.Equal(path, beginEvent.Path); - Assert.Equal(isPartial, beginEvent.IsPartial); return beginEvent; }; @@ -949,7 +935,6 @@ namespace Microsoft.AspNet.Mvc.Razor var endEvent = Assert.IsType(data); Assert.NotNull(endEvent.HttpContext); Assert.Equal(path, endEvent.Path); - Assert.Equal(isPartial, endEvent.IsPartial); }; Assert.Collection(adapter.PageInstrumentationData, diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineTest.cs index a33fbdca79..e316a91433 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineTest.cs @@ -73,7 +73,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData(null)] [InlineData("")] - public void FindView_ThrowsIfViewNameIsNullOrEmpty(string viewName) + public void FindView_IsMainPage_ThrowsIfViewNameIsNullOrEmpty(string viewName) { // Arrange var viewEngine = CreateViewEngine(); @@ -81,20 +81,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Test // Act & Assert ExceptionAssert.ThrowsArgumentNullOrEmpty( - () => viewEngine.FindView(context, viewName, isPartial: false), + () => viewEngine.FindView(context, viewName, isMainPage: true), "viewName"); } [Theory] [MemberData(nameof(AbsoluteViewPathData))] - public void FindView_WithFullPath_ReturnsNotFound(string viewName) + public void FindView_IsMainPage_WithFullPath_ReturnsNotFound(string viewName) { // Arrange var viewEngine = CreateSuccessfulViewEngine(); var context = GetActionContext(_controllerTestContext); // Act - var result = viewEngine.FindView(context, viewName, isPartial: false); + var result = viewEngine.FindView(context, viewName, isMainPage: true); // Assert Assert.False(result.Success); @@ -102,7 +102,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [MemberData(nameof(AbsoluteViewPathData))] - public void FindView_WithFullPathAndCshtmlEnding_ReturnsNotFound(string viewName) + public void FindView_IsMainPage_WithFullPathAndCshtmlEnding_ReturnsNotFound(string viewName) { // Arrange var viewEngine = CreateSuccessfulViewEngine(); @@ -110,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test viewName += ".cshtml"; // Act - var result = viewEngine.FindView(context, viewName, isPartial: false); + var result = viewEngine.FindView(context, viewName, isMainPage: true); // Assert Assert.False(result.Success); @@ -119,14 +119,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData(false)] [InlineData(true)] - public void FindView_WithRelativePath_ReturnsNotFound(bool isPartial) + public void FindView_WithRelativePath_ReturnsNotFound(bool isMainPage) { // Arrange var viewEngine = CreateSuccessfulViewEngine(); var context = GetActionContext(_controllerTestContext); // Act - var result = viewEngine.FindView(context, "View.cshtml", isPartial); + var result = viewEngine.FindView(context, "View.cshtml", isMainPage); // Assert Assert.False(result.Success); @@ -135,216 +135,18 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData(false)] [InlineData(true)] - public void GetView_WithViewName_ReturnsNotFound(bool isPartial) + public void GetView_WithViewName_ReturnsNotFound(bool isMainPage) { // Arrange var viewEngine = CreateSuccessfulViewEngine(); // Act - var result = viewEngine.GetView("~/Home/View1.cshtml", "View2", isPartial); + var result = viewEngine.GetView("~/Home/View1.cshtml", "View2", isMainPage); // Assert Assert.False(result.Success); } - [Fact] - public void FindView_IsPartial_ReturnsRazorView_IfLookupWasSuccessful() - { - // Arrange - var pageFactory = new Mock(); - var page = Mock.Of(); - var viewStart1 = Mock.Of(); - var viewStart2 = Mock.Of(); - - pageFactory - .Setup(p => p.CreateFactory("/Views/bar/test-view.cshtml")) - .Returns(new RazorPageFactoryResult(() => page, new IChangeToken[0])); - - pageFactory - .Setup(p => p.CreateFactory("/Views/_ViewStart.cshtml")) - .Returns(new RazorPageFactoryResult(() => viewStart2, new IChangeToken[0])); - - pageFactory - .Setup(p => p.CreateFactory("/_ViewStart.cshtml")) - .Returns(new RazorPageFactoryResult(() => viewStart1, new IChangeToken[0])); - - var viewEngine = CreateViewEngine(pageFactory.Object); - var context = GetActionContext(_controllerTestContext); - - // Act - var result = viewEngine.FindView(context, "test-view", isPartial: true); - - // Assert - Assert.True(result.Success); - var view = Assert.IsType(result.View); - Assert.Same(page, view.RazorPage); - Assert.Equal("test-view", result.ViewName); - Assert.Empty(view.ViewStartPages); - } - - [Fact] - public void FindView_IsPartial_DoesNotExpireCachedResults_IfViewStartsExpire() - { - // Arrange - var pageFactory = new Mock(); - var page = Mock.Of(); - var viewStart = Mock.Of(); - var cancellationTokenSource = new CancellationTokenSource(); - var changeToken = new CancellationChangeToken(cancellationTokenSource.Token); - - pageFactory - .Setup(p => p.CreateFactory("/Views/bar/test-view.cshtml")) - .Returns(new RazorPageFactoryResult(() => page, new IChangeToken[0])); - - pageFactory - .Setup(p => p.CreateFactory("/Views/_ViewStart.cshtml")) - .Returns(new RazorPageFactoryResult(() => viewStart, new[] { changeToken })); - - var viewEngine = CreateViewEngine(pageFactory.Object); - var context = GetActionContext(_controllerTestContext); - - // Act - 1 - var result1 = viewEngine.FindView(context, "test-view", isPartial: true); - - // Assert - 1 - Assert.True(result1.Success); - var view1 = Assert.IsType(result1.View); - Assert.Same(page, view1.RazorPage); - Assert.Equal("test-view", result1.ViewName); - Assert.Empty(view1.ViewStartPages); - - // Act - 2 - cancellationTokenSource.Cancel(); - var result2 = viewEngine.FindView(context, "test-view", isPartial: true); - - // Assert - 2 - Assert.True(result2.Success); - var view2 = Assert.IsType(result2.View); - Assert.Same(page, view2.RazorPage); - pageFactory.Verify(p => p.CreateFactory("/Views/bar/test-view.cshtml"), Times.Once()); - } - - [Theory] - [InlineData(null)] - [InlineData("")] - public void FindView_IsPartial_ThrowsIfViewNameIsNullOrEmpty(string partialViewName) - { - // Arrange - var viewEngine = CreateViewEngine(); - var context = GetActionContext(_controllerTestContext); - - // Act & Assert - ExceptionAssert.ThrowsArgumentNullOrEmpty( - () => viewEngine.FindView(context, partialViewName, isPartial: true), - "viewName"); - } - - [Theory] - [MemberData(nameof(AbsoluteViewPathData))] - public void FindView_IsPartialWithFullPath_ReturnsNotFound(string partialViewName) - { - // Arrange - var viewEngine = CreateSuccessfulViewEngine(); - var context = GetActionContext(_controllerTestContext); - - // Act - var result = viewEngine.FindView(context, partialViewName, isPartial: true); - - // Assert - Assert.False(result.Success); - } - - [Theory] - [MemberData(nameof(AbsoluteViewPathData))] - public void FindView_IsPartialWithFullPathAndCshtmlEnding_ReturnsNotFound(string partialViewName) - { - // Arrange - var viewEngine = CreateSuccessfulViewEngine(); - var context = GetActionContext(_controllerTestContext); - partialViewName += ".cshtml"; - - // Act - var result = viewEngine.FindView(context, partialViewName, isPartial: true); - - // Assert - Assert.False(result.Success); - } - - [Fact] - public void FindView_IsPartial_FailsButSearchesCorrectLocations_WithAreas() - { - // Arrange - var viewEngine = CreateViewEngine(); - var context = GetActionContext(_areaTestContext); - - // Act - var result = viewEngine.FindView(context, "partial", isPartial: true); - - // Assert - Assert.False(result.Success); - Assert.Equal(new[] - { - "/Areas/foo/Views/bar/partial.cshtml", - "/Areas/foo/Views/Shared/partial.cshtml", - "/Views/Shared/partial.cshtml", - }, result.SearchedLocations); - } - - [Fact] - public void FindView_IsPartial_FailsButSearchesCorrectLocations_WithoutAreas() - { - // Arrange - var viewEngine = CreateViewEngine(); - var context = GetActionContext(_controllerTestContext); - - // Act - var result = viewEngine.FindView(context, "partialNoArea", isPartial: true); - - // Assert - Assert.False(result.Success); - Assert.Equal(new[] { - "/Views/bar/partialNoArea.cshtml", - "/Views/Shared/partialNoArea.cshtml", - }, result.SearchedLocations); - } - - [Fact] - public void FindView_FailsButSearchesCorrectLocationsWithAreas() - { - // Arrange - var viewEngine = CreateViewEngine(); - var context = GetActionContext(_areaTestContext); - - // Act - var result = viewEngine.FindView(context, "full", isPartial: false); - - // Assert - Assert.False(result.Success); - Assert.Equal(new[] { - "/Areas/foo/Views/bar/full.cshtml", - "/Areas/foo/Views/Shared/full.cshtml", - "/Views/Shared/full.cshtml", - }, result.SearchedLocations); - } - - [Fact] - public void FindView_FailsButSearchesCorrectLocationsWithoutAreas() - { - // Arrange - var viewEngine = CreateViewEngine(); - var context = GetActionContext(_controllerTestContext); - - // Act - var result = viewEngine.FindView(context, "fullNoArea", isPartial: false); - - // Assert - Assert.False(result.Success); - Assert.Equal(new[] { - "/Views/bar/fullNoArea.cshtml", - "/Views/Shared/fullNoArea.cshtml", - }, result.SearchedLocations); - } - [Fact] public void FindView_ReturnsRazorView_IfLookupWasSuccessful() { @@ -370,19 +172,216 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(_controllerTestContext); // Act - var result = viewEngine.FindView(context, "test-view", isPartial: false); + var result = viewEngine.FindView(context, "test-view", isMainPage: false); + + // Assert + Assert.True(result.Success); + var view = Assert.IsType(result.View); + Assert.Same(page, view.RazorPage); + Assert.Equal("test-view", result.ViewName); + Assert.Empty(view.ViewStartPages); + } + + [Fact] + public void FindView_DoesNotExpireCachedResults_IfViewStartsExpire() + { + // Arrange + var pageFactory = new Mock(); + var page = Mock.Of(); + var viewStart = Mock.Of(); + var cancellationTokenSource = new CancellationTokenSource(); + var changeToken = new CancellationChangeToken(cancellationTokenSource.Token); + + pageFactory + .Setup(p => p.CreateFactory("/Views/bar/test-view.cshtml")) + .Returns(new RazorPageFactoryResult(() => page, new IChangeToken[0])); + + pageFactory + .Setup(p => p.CreateFactory("/Views/_ViewStart.cshtml")) + .Returns(new RazorPageFactoryResult(() => viewStart, new[] { changeToken })); + + var viewEngine = CreateViewEngine(pageFactory.Object); + var context = GetActionContext(_controllerTestContext); + + // Act - 1 + var result1 = viewEngine.FindView(context, "test-view", isMainPage: false); + + // Assert - 1 + Assert.True(result1.Success); + var view1 = Assert.IsType(result1.View); + Assert.Same(page, view1.RazorPage); + Assert.Equal("test-view", result1.ViewName); + Assert.Empty(view1.ViewStartPages); + + // Act - 2 + cancellationTokenSource.Cancel(); + var result2 = viewEngine.FindView(context, "test-view", isMainPage: false); + + // Assert - 2 + Assert.True(result2.Success); + var view2 = Assert.IsType(result2.View); + Assert.Same(page, view2.RazorPage); + pageFactory.Verify(p => p.CreateFactory("/Views/bar/test-view.cshtml"), Times.Once()); + } + + [Theory] + [InlineData(null)] + [InlineData("")] + public void FindView_ThrowsIfViewNameIsNullOrEmpty(string partialViewName) + { + // Arrange + var viewEngine = CreateViewEngine(); + var context = GetActionContext(_controllerTestContext); + + // Act & Assert + ExceptionAssert.ThrowsArgumentNullOrEmpty( + () => viewEngine.FindView(context, partialViewName, isMainPage: false), + "viewName"); + } + + [Theory] + [MemberData(nameof(AbsoluteViewPathData))] + public void FindViewWithFullPath_ReturnsNotFound(string partialViewName) + { + // Arrange + var viewEngine = CreateSuccessfulViewEngine(); + var context = GetActionContext(_controllerTestContext); + + // Act + var result = viewEngine.FindView(context, partialViewName, isMainPage: false); + + // Assert + Assert.False(result.Success); + } + + [Theory] + [MemberData(nameof(AbsoluteViewPathData))] + public void FindViewWithFullPathAndCshtmlEnding_ReturnsNotFound(string partialViewName) + { + // Arrange + var viewEngine = CreateSuccessfulViewEngine(); + var context = GetActionContext(_controllerTestContext); + partialViewName += ".cshtml"; + + // Act + var result = viewEngine.FindView(context, partialViewName, isMainPage: false); + + // Assert + Assert.False(result.Success); + } + + [Fact] + public void FindView_FailsButSearchesCorrectLocations_WithAreas() + { + // Arrange + var viewEngine = CreateViewEngine(); + var context = GetActionContext(_areaTestContext); + + // Act + var result = viewEngine.FindView(context, "partial", isMainPage: false); + + // Assert + Assert.False(result.Success); + Assert.Equal(new[] + { + "/Areas/foo/Views/bar/partial.cshtml", + "/Areas/foo/Views/Shared/partial.cshtml", + "/Views/Shared/partial.cshtml", + }, result.SearchedLocations); + } + + [Fact] + public void FindView_FailsButSearchesCorrectLocations_WithoutAreas() + { + // Arrange + var viewEngine = CreateViewEngine(); + var context = GetActionContext(_controllerTestContext); + + // Act + var result = viewEngine.FindView(context, "partialNoArea", isMainPage: false); + + // Assert + Assert.False(result.Success); + Assert.Equal(new[] { + "/Views/bar/partialNoArea.cshtml", + "/Views/Shared/partialNoArea.cshtml", + }, result.SearchedLocations); + } + + [Fact] + public void FindView_IsMainPage_FailsButSearchesCorrectLocationsWithAreas() + { + // Arrange + var viewEngine = CreateViewEngine(); + var context = GetActionContext(_areaTestContext); + + // Act + var result = viewEngine.FindView(context, "full", isMainPage: true); + + // Assert + Assert.False(result.Success); + Assert.Equal(new[] { + "/Areas/foo/Views/bar/full.cshtml", + "/Areas/foo/Views/Shared/full.cshtml", + "/Views/Shared/full.cshtml", + }, result.SearchedLocations); + } + + [Fact] + public void FindView_IsMainPage_FailsButSearchesCorrectLocationsWithoutAreas() + { + // Arrange + var viewEngine = CreateViewEngine(); + var context = GetActionContext(_controllerTestContext); + + // Act + var result = viewEngine.FindView(context, "fullNoArea", isMainPage: true); + + // Assert + Assert.False(result.Success); + Assert.Equal(new[] { + "/Views/bar/fullNoArea.cshtml", + "/Views/Shared/fullNoArea.cshtml", + }, result.SearchedLocations); + } + + [Fact] + public void FindView_IsMainPage_ReturnsRazorView_IfLookupWasSuccessful() + { + // Arrange + var pageFactory = new Mock(); + var page = Mock.Of(); + var viewStart1 = Mock.Of(); + var viewStart2 = Mock.Of(); + + pageFactory + .Setup(p => p.CreateFactory("/Views/bar/test-view.cshtml")) + .Returns(new RazorPageFactoryResult(() => page, new IChangeToken[0])); + + pageFactory + .Setup(p => p.CreateFactory("/Views/_ViewStart.cshtml")) + .Returns(new RazorPageFactoryResult(() => viewStart2, new IChangeToken[0])); + + pageFactory + .Setup(p => p.CreateFactory("/_ViewStart.cshtml")) + .Returns(new RazorPageFactoryResult(() => viewStart1, new IChangeToken[0])); + + var viewEngine = CreateViewEngine(pageFactory.Object); + var context = GetActionContext(_controllerTestContext); + + // Act + var result = viewEngine.FindView(context, "test-view", isMainPage: true); // Assert Assert.True(result.Success); var view = Assert.IsType(result.View); Assert.Equal("test-view", result.ViewName); Assert.Same(page, view.RazorPage); - Assert.False(view.IsPartial); Assert.Equal(new[] { viewStart1, viewStart2 }, view.ViewStartPages); } [Fact] - public void FindView_UsesViewLocationFormat_IfRouteDoesNotContainArea() + public void FindView_IsMainPage_UsesViewLocationFormat_IfRouteDoesNotContainArea() { // Arrange var pageFactory = new Mock(); @@ -401,7 +400,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(_controllerTestContext); // Act - var result = viewEngine.FindView(context, "test-view", isPartial: false); + var result = viewEngine.FindView(context, "test-view", isMainPage: true); // Assert pageFactory.Verify(); @@ -410,7 +409,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test } [Fact] - public void FindView_UsesAreaViewLocationFormat_IfRouteContainsArea() + public void FindView_IsMainPage_UsesAreaViewLocationFormat_IfRouteContainsArea() { // Arrange var viewName = "test-view2"; @@ -430,7 +429,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(_areaTestContext); // Act - var result = viewEngine.FindView(context, viewName, isPartial: false); + var result = viewEngine.FindView(context, viewName, isMainPage: true); // Assert Assert.True(result.Success); @@ -441,7 +440,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData("Test-View.cshtml")] [InlineData("/Home/Test-View.cshtml")] - public void GetView_DoesNotUseViewLocationFormat_WithRelativePath_IfRouteDoesNotContainArea(string viewName) + public void GetView_IsMainPage_DoesNotUseViewLocationFormat_WithRelativePath_IfRouteDoesNotContainArea(string viewName) { // Arrange var expectedViewName = "/Home/Test-View.cshtml"; @@ -456,7 +455,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test GetOptionsAccessor()); // Act - var result = viewEngine.GetView("/Home/Page.cshtml", viewName, isPartial: false); + var result = viewEngine.GetView("/Home/Page.cshtml", viewName, isMainPage: true); // Assert Assert.True(result.Success); @@ -467,7 +466,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData("Test-View.cshtml")] [InlineData("/Home/Test-View.cshtml")] - public void GetView_DoesNotUseViewLocationFormat_WithRelativePath_IfRouteContainArea(string viewName) + public void GetView_IsMainPage_DoesNotUseViewLocationFormat_WithRelativePath_IfRouteContainArea(string viewName) { // Arrange var expectedViewName = "/Home/Test-View.cshtml"; @@ -482,7 +481,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test GetOptionsAccessor()); // Act - var result = viewEngine.GetView("/Home/Page.cshtml", viewName, isPartial: false); + var result = viewEngine.GetView("/Home/Page.cshtml", viewName, isMainPage: true); // Assert Assert.True(result.Success); @@ -496,7 +495,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [InlineData("/Home/Test-View.CSHTML")] [InlineData("~/Home/Test-View.cshtml")] [InlineData("~/SHARED/TEST-VIEW.CSHTML")] - public void GetView_UsesGivenPath_WithAppRelativePath(string viewName) + public void GetView_IsMainPage_UsesGivenPath_WithAppRelativePath(string viewName) { // Arrange var pageFactory = new Mock(); @@ -510,7 +509,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test GetOptionsAccessor()); // Act - var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isPartial: false); + var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true); // Assert Assert.True(result.Success); @@ -523,7 +522,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [InlineData("Test-View.CSHTML")] [InlineData("PATH/TEST-VIEW.CSHTML")] [InlineData("Path1/Path2/Test-View.cshtml")] - public void GetView_ResolvesRelativeToCurrentPage_WithRelativePath(string viewName) + public void GetView_IsMainPage_ResolvesRelativeToCurrentPage_WithRelativePath(string viewName) { // Arrange var expectedViewName = $"/Home/{ viewName }"; @@ -538,7 +537,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test GetOptionsAccessor()); // Act - var result = viewEngine.GetView("/Home/Page.cshtml", viewName, isPartial: false); + var result = viewEngine.GetView("/Home/Page.cshtml", viewName, isMainPage: true); // Assert Assert.True(result.Success); @@ -551,7 +550,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [InlineData("Test-View.CSHTML")] [InlineData("PATH/TEST-VIEW.CSHTML")] [InlineData("Path1/Path2/Test-View.cshtml")] - public void GetView_ResolvesRelativeToAppRoot_WithRelativePath_IfNoPageExecuting(string viewName) + public void GetView_IsMainPage_ResolvesRelativeToAppRoot_WithRelativePath_IfNoPageExecuting(string viewName) { // Arrange var expectedViewName = $"/{ viewName }"; @@ -566,7 +565,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test GetOptionsAccessor()); // Act - var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isPartial: false); + var result = viewEngine.GetView(executingFilePath: null, viewPath: viewName, isMainPage: true); // Assert Assert.True(result.Success); @@ -578,7 +577,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [MemberData(nameof(ViewLocationExpanderTestData))] - public void FindView_UsesViewLocationExpandersToLocateViews( + public void FindView_IsMainPage_UsesViewLocationExpandersToLocateViews( IDictionary routeValues, IEnumerable expectedSeeds) { @@ -629,7 +628,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(routeValues); // Act - var result = viewEngine.FindView(context, "test-view", isPartial: false); + var result = viewEngine.FindView(context, "test-view", isMainPage: true); // Assert Assert.True(result.Success); @@ -640,7 +639,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test } [Fact] - public void FindView_CachesValuesIfViewWasFound() + public void FindView_IsMainPage_CachesValuesIfViewWasFound() { // Arrange var page = Mock.Of(); @@ -658,7 +657,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(_controllerTestContext); // Act 1 - var result1 = viewEngine.FindView(context, "baz", isPartial: false); + var result1 = viewEngine.FindView(context, "baz", isMainPage: true); // Assert 1 Assert.True(result1.Success); @@ -671,7 +670,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test .Setup(p => p.CreateFactory(It.IsAny())) .Throws(new Exception("Shouldn't be called")); - var result2 = viewEngine.FindView(context, "baz", isPartial: false); + var result2 = viewEngine.FindView(context, "baz", isMainPage: true); // Assert 2 Assert.True(result2.Success); @@ -681,7 +680,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test } [Fact] - public void FindView_InvokesPageFactoryIfChangeTokenExpired() + public void FindView_IsMainPage_InvokesPageFactoryIfChangeTokenExpired() { // Arrange var page1 = Mock.Of(); @@ -709,7 +708,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(_controllerTestContext); // Act 1 - var result1 = viewEngine.FindView(context, "baz", isPartial: false); + var result1 = viewEngine.FindView(context, "baz", isMainPage: true); // Assert 1 Assert.True(result1.Success); @@ -718,7 +717,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test // Act 2 cancellationTokenSource.Cancel(); - var result2 = viewEngine.FindView(context, "baz", isPartial: false); + var result2 = viewEngine.FindView(context, "baz", isMainPage: true); // Assert 2 Assert.True(result2.Success); @@ -728,7 +727,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test } [Fact] - public void FindView_InvokesPageFactoryIfViewStartExpirationTokensHaveExpired() + public void FindView_IsMainPage_InvokesPageFactoryIfViewStartExpirationTokensHaveExpired() { // Arrange var page1 = Mock.Of(); @@ -761,7 +760,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(_controllerTestContext); // Act 1 - var result1 = viewEngine.FindView(context, "baz", isPartial: false); + var result1 = viewEngine.FindView(context, "baz", isMainPage: true); // Assert 1 Assert.True(result1.Success); @@ -771,7 +770,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test // Act 2 cancellationTokenSource.Cancel(); - var result2 = viewEngine.FindView(context, "baz", isPartial: false); + var result2 = viewEngine.FindView(context, "baz", isMainPage: true); // Assert 2 Assert.True(result2.Success); @@ -785,7 +784,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test // This test validates an important perf scenario of RazorViewEngine not constructing // multiple strings for views that do not exist in the file system on a per-request basis. [Fact] - public void FindView_DoesNotInvokeViewLocationExpanders_IfChangeTokenHasNotExpired() + public void FindView_IsMainPage_DoesNotInvokeViewLocationExpanders_IfChangeTokenHasNotExpired() { // Arrange var pageFactory = Mock.Of(); @@ -816,7 +815,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(_controllerTestContext); // Act - 1 - var result = viewEngine.FindView(context, "myview", isPartial: false); + var result = viewEngine.FindView(context, "myview", isMainPage: true); // Assert - 1 Assert.False(result.Success); @@ -824,7 +823,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test expander.Verify(); // Act - 2 - result = viewEngine.FindView(context, "myview", isPartial: false); + result = viewEngine.FindView(context, "myview", isMainPage: true); // Assert - 2 Assert.False(result.Success); @@ -838,7 +837,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test } [Fact] - public void FindView_InvokesViewLocationExpanders_IfChangeTokenExpires() + public void FindView_IsMainPage_InvokesViewLocationExpanders_IfChangeTokenExpires() { // Arrange var cancellationTokenSource = new CancellationTokenSource(); @@ -875,7 +874,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(_controllerTestContext); // Act - 1 - var result = viewEngine.FindView(context, "MyView", isPartial: false); + var result = viewEngine.FindView(context, "MyView", isMainPage: true); // Assert - 1 Assert.False(result.Success); @@ -887,7 +886,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test .Setup(p => p.CreateFactory("viewlocation3")) .Returns(new RazorPageFactoryResult(() => page, new IChangeToken[0])); cancellationTokenSource.Cancel(); - result = viewEngine.FindView(context, "MyView", isPartial: false); + result = viewEngine.FindView(context, "MyView", isMainPage: true); // Assert - 2 Assert.True(result.Success); @@ -903,14 +902,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [MemberData(nameof(AbsoluteViewPathData))] - public void FindPage_WithFullPath_ReturnsNotFound(string viewName) + public void FindPage_IsMainPage_WithFullPath_ReturnsNotFound(string viewName) { // Arrange var viewEngine = CreateSuccessfulViewEngine(); var context = GetActionContext(_controllerTestContext); // Act - var result = viewEngine.FindPage(context, viewName, isPartial: false); + var result = viewEngine.FindPage(context, viewName, isMainPage: true); // Assert Assert.Null(result.Page); @@ -918,7 +917,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [MemberData(nameof(AbsoluteViewPathData))] - public void FindPage_WithFullPathAndCshtmlEnding_ReturnsNotFound(string viewName) + public void FindPage_IsMainPage_WithFullPathAndCshtmlEnding_ReturnsNotFound(string viewName) { // Arrange var viewEngine = CreateSuccessfulViewEngine(); @@ -926,7 +925,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test viewName += ".cshtml"; // Act - var result = viewEngine.FindPage(context, viewName, isPartial: false); + var result = viewEngine.FindPage(context, viewName, isMainPage: true); // Assert Assert.Null(result.Page); @@ -935,14 +934,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData(false)] [InlineData(true)] - public void FindPage_WithRelativePath_ReturnsNotFound(bool isPartial) + public void FindPage_WithRelativePath_ReturnsNotFound(bool isMainPage) { // Arrange var viewEngine = CreateSuccessfulViewEngine(); var context = GetActionContext(_controllerTestContext); // Act - var result = viewEngine.FindPage(context, "View.cshtml", isPartial); + var result = viewEngine.FindPage(context, "View.cshtml", isMainPage); // Assert Assert.Null(result.Page); @@ -951,13 +950,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData(false)] [InlineData(true)] - public void GetPage_WithViewName_ReturnsNotFound(bool isPartial) + public void GetPage_WithViewName_ReturnsNotFound(bool isMainPage) { // Arrange var viewEngine = CreateSuccessfulViewEngine(); // Act - var result = viewEngine.GetPage("~/Home/View1.cshtml", "View2", isPartial); + var result = viewEngine.GetPage("~/Home/View1.cshtml", "View2", isMainPage); // Assert Assert.Null(result.Page); @@ -966,7 +965,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData(null)] [InlineData("")] - public void FindPage_IsPartial_ThrowsIfNameIsNullOrEmpty(string pageName) + public void FindPage_ThrowsIfNameIsNullOrEmpty(string pageName) { // Arrange var viewEngine = CreateViewEngine(); @@ -974,13 +973,13 @@ namespace Microsoft.AspNet.Mvc.Razor.Test // Act & Assert ExceptionAssert.ThrowsArgumentNullOrEmpty( - () => viewEngine.FindPage(context, pageName, isPartial: true), + () => viewEngine.FindPage(context, pageName, isMainPage: false), "pageName"); } [Theory] [MemberData(nameof(ViewLocationExpanderTestData))] - public void FindPage_IsPartial_UsesViewLocationExpander_ToExpandPaths( + public void FindPage_UsesViewLocationExpander_ToExpandPaths( IDictionary routeValues, IEnumerable expectedSeeds) { @@ -1022,7 +1021,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(routeValues); // Act - var result = viewEngine.FindPage(context, "layout", isPartial: true); + var result = viewEngine.FindPage(context, "layout", isMainPage: false); // Assert Assert.Equal("layout", result.Name); @@ -1035,7 +1034,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData(false)] [InlineData(true)] - public void FindPage_ReturnsSearchedLocationsIfPageCannotBeFound(bool isPartial) + public void FindPage_ReturnsSearchedLocationsIfPageCannotBeFound(bool isMainPage) { // Arrange var expected = new[] @@ -1048,7 +1047,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test var context = GetActionContext(_controllerTestContext); // Act - var result = viewEngine.FindPage(context, "layout", isPartial); + var result = viewEngine.FindPage(context, "layout", isMainPage); // Assert Assert.Equal("layout", result.Name); @@ -1061,7 +1060,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [InlineData(true)] // Looks in RouteConstraints [InlineData(false)] - public void FindPage_IsPartial_SelectsActionCaseInsensitively(bool isAttributeRouted) + public void FindPage_SelectsActionCaseInsensitively(bool isAttributeRouted) { // The ActionDescriptor contains "Foo" and the RouteData contains "foo" // which matches the case of the constructor thus searching in the appropriate location. @@ -1071,8 +1070,6 @@ namespace Microsoft.AspNet.Mvc.Razor.Test { "controller", "foo" } }; var page = new Mock(MockBehavior.Strict); - page.SetupSet(p => p.IsPartial = true); - var pageFactory = new Mock(); pageFactory .Setup(p => p.CreateFactory("/Views/Foo/details.cshtml")) @@ -1091,7 +1088,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test isAttributeRouted); // Act - var result = viewEngine.FindPage(context, "details", isPartial: true); + var result = viewEngine.FindPage(context, "details", isMainPage: false); // Assert Assert.Equal("details", result.Name); @@ -1105,7 +1102,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [InlineData(true)] // Looks in RouteConstraints [InlineData(false)] - public void FindPage_IsPartial_LooksForPages_UsingActionDescriptor_Controller(bool isAttributeRouted) + public void FindPage_LooksForPages_UsingActionDescriptor_Controller(bool isAttributeRouted) { // Arrange var expected = new[] @@ -1130,7 +1127,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test isAttributeRouted); // Act - var result = viewEngine.FindPage(context, "foo", isPartial: true); + var result = viewEngine.FindPage(context, "foo", isMainPage: false); // Assert Assert.Equal("foo", result.Name); @@ -1143,7 +1140,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [InlineData(true)] // Looks in RouteConstraints [InlineData(false)] - public void FindPage_IsPartial_LooksForPages_UsingActionDescriptor_Areas(bool isAttributeRouted) + public void FindPage_LooksForPages_UsingActionDescriptor_Areas(bool isAttributeRouted) { // Arrange var expected = new[] @@ -1171,7 +1168,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test isAttributeRouted); // Act - var result = viewEngine.FindPage(context, "foo", isPartial: true); + var result = viewEngine.FindPage(context, "foo", isMainPage: false); // Assert Assert.Equal("foo", result.Name); @@ -1182,7 +1179,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [Theory] [InlineData(true)] [InlineData(false)] - public void FindPage_IsPartial_LooksForPages_UsesRouteValuesAsFallback(bool isAttributeRouted) + public void FindPage_LooksForPages_UsesRouteValuesAsFallback(bool isAttributeRouted) { // Arrange var expected = new[] @@ -1203,7 +1200,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test isAttributeRouted); // Act - var result = viewEngine.FindPage(context, "bar", isPartial: true); + var result = viewEngine.FindPage(context, "bar", isMainPage: false); // Assert Assert.Equal("bar", result.Name); @@ -1217,7 +1214,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [InlineData("/Home/Test-View.CSHTML")] [InlineData("~/Home/Test-View.cshtml")] [InlineData("~/SHARED/TEST-VIEW.CSHTML")] - public void GetPage_UsesGivenPath_WithAppRelativePath(string pageName) + public void GetPage_IsMainPage_UsesGivenPath_WithAppRelativePath(string pageName) { // Arrange var pageFactory = new Mock(); @@ -1231,7 +1228,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test GetOptionsAccessor()); // Act - var result = viewEngine.GetPage("~/Another/Place.cshtml", pagePath: pageName, isPartial: false); + var result = viewEngine.GetPage("~/Another/Place.cshtml", pagePath: pageName, isMainPage: true); // Assert Assert.Same(page, result.Page); @@ -1244,7 +1241,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [InlineData("Test-View.CSHTML")] [InlineData("PATH/TEST-VIEW.CSHTML")] [InlineData("Path1/Path2/Test-View.cshtml")] - public void GetPage_ResolvesRelativeToCurrentPage_WithRelativePath(string pageName) + public void GetPage_IsMainPage_ResolvesRelativeToCurrentPage_WithRelativePath(string pageName) { // Arrange var expectedPageName = $"/Home/{ pageName }"; @@ -1259,7 +1256,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test GetOptionsAccessor()); // Act - var result = viewEngine.GetPage("/Home/Page.cshtml", pageName, isPartial: false); + var result = viewEngine.GetPage("/Home/Page.cshtml", pageName, isMainPage: true); // Assert Assert.Same(page, result.Page); @@ -1272,7 +1269,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test [InlineData("Test-View.CSHTML")] [InlineData("PATH/TEST-VIEW.CSHTML")] [InlineData("Path1/Path2/Test-View.cshtml")] - public void GetPage_ResolvesRelativeToAppRoot_WithRelativePath_IfNoPageExecuting(string pageName) + public void GetPage_IsMainPage_ResolvesRelativeToAppRoot_WithRelativePath_IfNoPageExecuting(string pageName) { // Arrange var expectedPageName = $"/{ pageName }"; @@ -1287,7 +1284,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test GetOptionsAccessor()); // Act - var result = viewEngine.GetPage(executingFilePath: null, pagePath: pageName, isPartial: false); + var result = viewEngine.GetPage(executingFilePath: null, pagePath: pageName, isMainPage: true); // Assert Assert.Same(page, result.Page); diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewTest.cs index e301d71e8e..b97101fd90 100644 --- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewTest.cs +++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewTest.cs @@ -45,8 +45,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: true); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); var expected = viewContext.Writer; @@ -75,8 +74,7 @@ namespace Microsoft.AspNet.Mvc.Razor activator.Object, new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: true); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); var expectedWriter = viewContext.Writer; @@ -138,15 +136,14 @@ namespace Microsoft.AspNet.Mvc.Razor .Setup(p => p.GetAbsolutePath("_ViewStart", LayoutPath)) .Returns(LayoutPath); viewEngine - .Setup(v => v.GetPage(pagePath, LayoutPath, /*isPartial*/ true)) + .Setup(v => v.GetPage(pagePath, LayoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(LayoutPath, layout)); var view = new RazorView( viewEngine.Object, activator, new[] { viewStart }, page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); var expectedWriter = viewContext.Writer; @@ -172,8 +169,7 @@ namespace Microsoft.AspNet.Mvc.Razor activator.Object, new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: true); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -212,7 +208,7 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetPage(/*executingFilePath*/ null, LayoutPath, /*isPartial*/ true)) + .Setup(v => v.GetPage(/*executingFilePath*/ null, LayoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(LayoutPath, layout)); var view = new RazorView( @@ -220,8 +216,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: true); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -245,8 +240,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); var original = viewContext.Writer; @@ -271,8 +265,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); var original = viewContext.Writer; @@ -300,8 +293,7 @@ namespace Microsoft.AspNet.Mvc.Razor activator.Object, new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -356,8 +348,7 @@ namespace Microsoft.AspNet.Mvc.Razor activator.Object, new[] { viewStart1, viewStart2 }, page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -390,15 +381,14 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); viewEngine - .Setup(v => v.GetPage(/*executingFilePath*/ null, layoutPath, /*isPartial*/ true)) + .Setup(v => v.GetPage(/*executingFilePath*/ null, layoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(layoutPath, new[] { "path1", "path2" })) .Verifiable(); viewEngine - .Setup(v => v.FindPage(viewContext, layoutPath, /*isPartial*/ true)) + .Setup(v => v.FindPage(viewContext, layoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(layoutPath, Enumerable.Empty())) .Verifiable(); @@ -433,15 +423,14 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); viewEngine - .Setup(v => v.GetPage(/*executingFilePath*/ null, layoutPath, /*isPartial*/ true)) + .Setup(v => v.GetPage(/*executingFilePath*/ null, layoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(layoutPath, Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindPage(viewContext, layoutPath, /*isPartial*/ true)) + .Setup(v => v.FindPage(viewContext, layoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(layoutPath, new[] { "path1", "path2" })) .Verifiable(); @@ -478,15 +467,14 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); viewEngine - .Setup(v => v.GetPage(/*executingFilePath*/ null, layoutPath, /*isPartial*/ true)) + .Setup(v => v.GetPage(/*executingFilePath*/ null, layoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(layoutPath, new[] { "path1", "path2" })) .Verifiable(); viewEngine - .Setup(v => v.FindPage(viewContext, layoutPath, /*isPartial*/ true)) + .Setup(v => v.FindPage(viewContext, layoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(layoutPath, new[] { "path3", "path4" })) .Verifiable(); @@ -545,7 +533,7 @@ namespace Microsoft.AspNet.Mvc.Razor .Verifiable(); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetPage(/*executingFilePath*/ null, LayoutPath, /*isPartial*/ true)) + .Setup(v => v.GetPage(/*executingFilePath*/ null, LayoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(LayoutPath, layout)) .Verifiable(); @@ -554,8 +542,7 @@ namespace Microsoft.AspNet.Mvc.Razor activator.Object, new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -587,7 +574,7 @@ namespace Microsoft.AspNet.Mvc.Razor }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetPage(/*executingFilePath*/ null, LayoutPath, /*isPartial*/ true)) + .Setup(v => v.GetPage(/*executingFilePath*/ null, LayoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(LayoutPath, layout)); var view = new RazorView( @@ -595,8 +582,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act and Assert @@ -650,10 +636,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetPage(/*executingFilePath*/ null, "~/Shared/Layout1.cshtml", /*isPartial*/ true)) + .Setup(v => v.GetPage(/*executingFilePath*/ null, "~/Shared/Layout1.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout1.cshtml", nestedLayout)); viewEngine - .Setup(v => v.GetPage("/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isPartial*/ true)) + .Setup(v => v.GetPage("/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout2.cshtml", baseLayout)); var view = new RazorView( @@ -661,8 +647,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -713,16 +698,16 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetPage(/*executingFilePath*/ null, "NestedLayout", /*isPartial*/ true)) + .Setup(v => v.GetPage(/*executingFilePath*/ null, "NestedLayout", /*isMainPage*/ false)) .Returns(new RazorPageResult("NestedLayout", Enumerable.Empty())); viewEngine - .Setup(p => p.FindPage(It.IsAny(), "NestedLayout", /*isPartial*/ true)) + .Setup(p => p.FindPage(It.IsAny(), "NestedLayout", /*isMainPage*/ false)) .Returns(new RazorPageResult("NestedLayout", nestedLayout)); viewEngine - .Setup(v => v.GetPage("NestedLayout", "Layout", /*isPartial*/ true)) + .Setup(v => v.GetPage("NestedLayout", "Layout", /*isMainPage*/ false)) .Returns(new RazorPageResult("Layout", Enumerable.Empty())); viewEngine - .Setup(p => p.FindPage(It.IsAny(), "Layout", /*isPartial*/ true)) + .Setup(p => p.FindPage(It.IsAny(), "Layout", /*isMainPage*/ false)) .Returns(new RazorPageResult("Layout", baseLayout)); var view = new RazorView( @@ -730,8 +715,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -782,10 +766,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetPage(/*executingFilePath*/ null, "~/Shared/Layout1.cshtml", /*isPartial*/ true)) + .Setup(v => v.GetPage(/*executingFilePath*/ null, "~/Shared/Layout1.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout1.cshtml", nestedLayout)); viewEngine - .Setup(v => v.GetPage("/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isPartial*/ true)) + .Setup(v => v.GetPage("/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout2.cshtml", baseLayout)); var view = new RazorView( @@ -793,8 +777,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act and Assert @@ -850,10 +833,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage("Page", "~/Shared/Layout1.cshtml", /*isPartial*/ true)) + .Setup(p => p.GetPage("Page", "~/Shared/Layout1.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout1.cshtml", nestedLayout)); viewEngine - .Setup(p => p.GetPage("/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isPartial*/ true)) + .Setup(p => p.GetPage("/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout2.cshtml", baseLayout)); var view = new RazorView( @@ -861,8 +844,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act and Assert @@ -887,7 +869,7 @@ namespace Microsoft.AspNet.Mvc.Razor }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage(/*executingFilePath*/ null, LayoutPath, /*isPartial*/ true)) + .Setup(p => p.GetPage(/*executingFilePath*/ null, LayoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(LayoutPath, layout)); var view = new RazorView( @@ -895,8 +877,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act and Assert @@ -951,10 +932,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage(/*executingFilePath*/ null, "~/Shared/Layout1.cshtml", /*isPartial*/ true)) + .Setup(p => p.GetPage(/*executingFilePath*/ null, "~/Shared/Layout1.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout1.cshtml", layout1)); viewEngine - .Setup(p => p.GetPage("~/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isPartial*/ true)) + .Setup(p => p.GetPage("~/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout2.cshtml", layout2)); var view = new RazorView( @@ -962,8 +943,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -1025,10 +1005,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage("~/Shared/Page.cshtml", "Layout1.cshtml", /*isPartial*/ true)) + .Setup(p => p.GetPage("~/Shared/Page.cshtml", "Layout1.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout1.cshtml", layout1)); viewEngine - .Setup(p => p.GetPage("~/Shared/Layout1.cshtml", "Layout2.cshtml", /*isPartial*/ true)) + .Setup(p => p.GetPage("~/Shared/Layout1.cshtml", "Layout2.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout2.cshtml", layout2)); var view = new RazorView( @@ -1036,8 +1016,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -1066,10 +1045,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage(It.IsAny(), "_Layout", /*isPartial*/ true)) + .Setup(p => p.GetPage(It.IsAny(), "_Layout", /*isMainPage*/ false)) .Returns(new RazorPageResult("_Layout", Enumerable.Empty())); viewEngine - .Setup(p => p.FindPage(It.IsAny(), "_Layout", /*isPartial*/ true)) + .Setup(p => p.FindPage(It.IsAny(), "_Layout", /*isMainPage*/ false)) .Returns(new RazorPageResult("_Layout", layout)); var view = new RazorView( @@ -1077,8 +1056,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act and Assert @@ -1114,16 +1092,16 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage(It.IsAny(), "_Layout", /*isPartial*/ true)) + .Setup(p => p.GetPage(It.IsAny(), "_Layout", /*isMainPage*/ false)) .Returns(new RazorPageResult("_Layout1", Enumerable.Empty())); viewEngine - .Setup(p => p.FindPage(It.IsAny(), "_Layout", /*isPartial*/ true)) + .Setup(p => p.FindPage(It.IsAny(), "_Layout", /*isMainPage*/ false)) .Returns(new RazorPageResult("_Layout", layout1)); viewEngine - .Setup(p => p.GetPage("Shared/_Layout.cshtml", "_Layout2", /*isPartial*/ true)) + .Setup(p => p.GetPage("Shared/_Layout.cshtml", "_Layout2", /*isMainPage*/ false)) .Returns(new RazorPageResult("_Layout2", Enumerable.Empty())); viewEngine - .Setup(p => p.FindPage(It.IsAny(), "_Layout2", /*isPartial*/ true)) + .Setup(p => p.FindPage(It.IsAny(), "_Layout2", /*isMainPage*/ false)) .Returns(new RazorPageResult("_Layout2", layout2)); var view = new RazorView( @@ -1131,8 +1109,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act and Assert @@ -1190,10 +1167,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage(/*executingFilePath*/ null, "~/Shared/Layout1.cshtml", /*isPartial*/ true)) + .Setup(p => p.GetPage(/*executingFilePath*/ null, "~/Shared/Layout1.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout1.cshtml", nestedLayout)); viewEngine - .Setup(p => p.GetPage("~/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isPartial*/ true)) + .Setup(p => p.GetPage("~/Shared/Layout1.cshtml", "~/Shared/Layout2.cshtml", /*isMainPage*/ false)) .Returns(new RazorPageResult("~/Shared/Layout2.cshtml", baseLayout)); var view = new RazorView( @@ -1201,8 +1178,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -1248,10 +1224,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage(/*executingFilePath*/ null, "layout-1", /*isPartial*/ true)) + .Setup(p => p.GetPage(/*executingFilePath*/ null, "layout-1", /*isMainPage*/ false)) .Returns(new RazorPageResult("layout-1", Enumerable.Empty())); viewEngine - .Setup(p => p.FindPage(It.IsAny(), "layout-1", /*isPartial*/ true)) + .Setup(p => p.FindPage(It.IsAny(), "layout-1", /*isMainPage*/ false)) .Returns(new RazorPageResult("layout-1", layout1)); var view = new RazorView( @@ -1259,8 +1235,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -1303,10 +1278,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage(/*executingFilePath*/ null, "layout-1", /*isPartial*/ true)) + .Setup(p => p.GetPage(/*executingFilePath*/ null, "layout-1", /*isMainPage*/ false)) .Returns(new RazorPageResult("layout-1", Enumerable.Empty())); viewEngine - .Setup(p => p.FindPage(It.IsAny(), "layout-1", /*isPartial*/ true)) + .Setup(p => p.FindPage(It.IsAny(), "layout-1", /*isMainPage*/ false)) .Returns(new RazorPageResult("layout-1", layout1)); var view = new RazorView( @@ -1314,8 +1289,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -1345,8 +1319,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act and Assert @@ -1384,7 +1357,7 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); var layoutPath = "~/Shared/Layout1.cshtml"; viewEngine - .Setup(p => p.GetPage("/Views/TestPath/Test.cshtml", layoutPath, /*isPartial*/ true)) + .Setup(p => p.GetPage("/Views/TestPath/Test.cshtml", layoutPath, /*isMainPage*/ false)) .Returns(new RazorPageResult(layoutPath, layoutPage)); var view = new RazorView( @@ -1392,8 +1365,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act and Assert @@ -1462,10 +1434,10 @@ namespace Microsoft.AspNet.Mvc.Razor var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(p => p.GetPage("/MyPage.cshtml", "Layout", /*isPartial*/ true)) + .Setup(p => p.GetPage("/MyPage.cshtml", "Layout", /*isMainPage*/ false)) .Returns(new RazorPageResult("Layout", Enumerable.Empty())); viewEngine - .Setup(p => p.FindPage(It.IsAny(), "Layout", /*isPartial*/ true)) + .Setup(p => p.FindPage(It.IsAny(), "Layout", /*isMainPage*/ false)) .Returns(new RazorPageResult("/Layout.cshtml", layout)); var view = new RazorView( @@ -1473,8 +1445,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); viewContext.HttpContext.Features.Set(feature.Object); @@ -1519,8 +1490,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial: true); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); viewContext.Writer = writer; viewContext.HttpContext.Features.Set(feature.Object); @@ -1534,10 +1504,8 @@ namespace Microsoft.AspNet.Mvc.Razor Assert.Equal("HtmlEncode[[Hello world]]", viewContext.Writer.ToString()); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public async Task RenderAsync_DoesNotSetExecutionContextWhenListenerIsNotRegistered(bool isPartial) + [Fact] + public async Task RenderAsync_DoesNotSetExecutionContextWhenListenerIsNotRegistered() { // Arrange var executed = false; @@ -1547,13 +1515,12 @@ namespace Microsoft.AspNet.Mvc.Razor executed = true; }); - var view = new RazorView - (Mock.Of(), + var view = new RazorView( + Mock.Of(), Mock.Of(), new IRazorPage[0], page, - new HtmlTestEncoder(), - isPartial); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -1599,8 +1566,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new[] { viewStart1, viewStart2 }, page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -1657,8 +1623,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new[] { viewStart1, viewStart2 }, page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -1702,8 +1667,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new[] { viewStart1, viewStart2 }, page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act @@ -1713,79 +1677,6 @@ namespace Microsoft.AspNet.Mvc.Razor Assert.Equal(expected, actual); } - [Fact] - public async Task IsPartial_IsSetToFalse_ForViewStartPageAndLayoutOfAView() - { - // Arrange - bool? isPartialPage = null; - bool? isPartialLayout = null; - bool? isPartialViewStart = null; - - var page = new TestableRazorPage(v => - { - isPartialPage = v.IsPartial; - }); - var viewStart = new TestableRazorPage(v => - { - v.Layout = "/Layout.cshtml"; - isPartialViewStart = v.IsPartial; - }); - var layout = new TestableRazorPage(v => - { - isPartialLayout = v.IsPartial; - v.RenderBodyPublic(); - }); - var viewEngine = new Mock(MockBehavior.Strict); - viewEngine - .Setup(p => p.GetAbsolutePath(/*executingFilePath*/ null, "/Layout.cshtml")) - .Returns("/Layout.cshtml"); - viewEngine - .Setup(p => p.GetPage(/*executingFilePath*/ null, "/Layout.cshtml", /*isPartial*/ true)) - .Returns(new RazorPageResult("/Layout.cshtml", layout)); - - var view = new RazorView( - viewEngine.Object, - Mock.Of(), - new[] { viewStart }, - page, - new HtmlTestEncoder(), - isPartial: false); - var viewContext = CreateViewContext(view); - - // Act - await view.RenderAsync(viewContext); - - // Assert - Assert.False(isPartialPage.Value); - Assert.False(isPartialLayout.Value); - Assert.False(isPartialViewStart.Value); - } - - [Fact] - public async Task IsPartial_IsSetToTrue_ForPartialView() - { - // Arrange - bool? isPartialPage = null; - var page = new TestableRazorPage(v => - { - isPartialPage = v.IsPartial; - }); - var view = new RazorView( - Mock.Of(), - Mock.Of(), - new IRazorPage[0], - page, - new HtmlTestEncoder(), - isPartial: true); - var viewContext = CreateViewContext(view); - - // Act - await view.RenderAsync(viewContext); - - // Assert - Assert.True(isPartialPage.Value); - } - [Fact] public async Task RenderAsync_RendersViewStartsInOrderInWhichTheyAreSpecified() { @@ -1817,8 +1708,7 @@ namespace Microsoft.AspNet.Mvc.Razor Mock.Of(), new[] { viewStart1, viewStart2 }, page, - new HtmlTestEncoder(), - isPartial: false); + new HtmlTestEncoder()); var viewContext = CreateViewContext(view); // Act diff --git a/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/TestDiagnosticListener.cs b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/TestDiagnosticListener.cs index ee2f61af2c..aaaf0b91aa 100644 --- a/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/TestDiagnosticListener.cs +++ b/test/Microsoft.AspNet.Mvc.TestDiagnosticListener.Sources/TestDiagnosticListener.cs @@ -130,7 +130,7 @@ namespace Microsoft.AspNet.Mvc public class OnViewFoundEventData { public IProxyActionContext ActionContext { get; set; } - public bool IsPartial { get; set; } + public bool IsMainPage { get; set; } public IProxyActionResult Result { get; set; } public string ViewName { get; set; } public IProxyView View { get; set; } @@ -141,7 +141,7 @@ namespace Microsoft.AspNet.Mvc [DiagnosticName("Microsoft.AspNet.Mvc.ViewFound")] public virtual void OnViewFound( IProxyActionContext actionContext, - bool isPartial, + bool isMainPage, IProxyActionResult result, string viewName, IProxyView view) @@ -149,7 +149,7 @@ namespace Microsoft.AspNet.Mvc ViewFound = new OnViewFoundEventData() { ActionContext = actionContext, - IsPartial = isPartial, + IsMainPage = isMainPage, Result = result, ViewName = viewName, View = view, @@ -159,7 +159,7 @@ namespace Microsoft.AspNet.Mvc public class OnViewNotFoundEventData { public IProxyActionContext ActionContext { get; set; } - public bool IsPartial { get; set; } + public bool IsMainPage { get; set; } public IProxyActionResult Result { get; set; } public string ViewName { get; set; } public IEnumerable SearchedLocations { get; set; } @@ -170,7 +170,7 @@ namespace Microsoft.AspNet.Mvc [DiagnosticName("Microsoft.AspNet.Mvc.ViewNotFound")] public virtual void OnViewNotFound( IProxyActionContext actionContext, - bool isPartial, + bool isMainPage, IProxyActionResult result, string viewName, IEnumerable searchedLocations) @@ -178,7 +178,7 @@ namespace Microsoft.AspNet.Mvc ViewNotFound = new OnViewNotFoundEventData() { ActionContext = actionContext, - IsPartial = isPartial, + IsMainPage = isMainPage, Result = result, ViewName = viewName, SearchedLocations = searchedLocations, @@ -331,8 +331,6 @@ namespace Microsoft.AspNet.Mvc public string Path { get; set; } - public bool IsPartial { get; set; } - public int Position { get; set; } public int Length { get; set; } @@ -345,8 +343,6 @@ namespace Microsoft.AspNet.Mvc public IProxyHttpContext HttpContext { get; set; } public string Path { get; set; } - - public bool IsPartial { get; set; } } public List PageInstrumentationData { get; set; } = new List(); @@ -355,7 +351,6 @@ namespace Microsoft.AspNet.Mvc public virtual void OnBeginPageInstrumentationContext( IProxyHttpContext httpContext, string path, - bool isPartial, int position, int length, bool isLiteral) @@ -364,7 +359,6 @@ namespace Microsoft.AspNet.Mvc { HttpContext = httpContext, Path = path, - IsPartial = isPartial, Position = position, Length = length, IsLiteral = isLiteral, @@ -375,7 +369,6 @@ namespace Microsoft.AspNet.Mvc public virtual void OnEndPageInstrumentationContext( IProxyHttpContext httpContext, string path, - bool isPartial, int position, int length, bool isLiteral) @@ -384,7 +377,6 @@ namespace Microsoft.AspNet.Mvc { HttpContext = httpContext, Path = path, - IsPartial = isPartial, }); } } diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/PartialViewResultTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/PartialViewResultTest.cs index 745813e4cf..523fab47e4 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/PartialViewResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/PartialViewResultTest.cs @@ -39,11 +39,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "MyView", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "MyView", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "MyView", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "MyView", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("MyView", Enumerable.Empty())) .Verifiable(); @@ -76,11 +76,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "MyView", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "MyView", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("MyView", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "MyView", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "MyView", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" })) .Verifiable(); @@ -115,11 +115,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "MyView", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "MyView", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "MyView", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "MyView", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("MyView", new[] { "Location3", "Location4" })) .Verifiable(); @@ -163,11 +163,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("myview", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "myview", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("myview", view.Object)) .Verifiable(); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultTemplatesUtilities.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultTemplatesUtilities.cs index f79d2c9426..57a8da43d5 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultTemplatesUtilities.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/DefaultTemplatesUtilities.cs @@ -318,11 +318,11 @@ namespace Microsoft.AspNet.Mvc.Rendering var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("MyView", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("MyView", view.Object)) .Verifiable(); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPartialExtensionsTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPartialExtensionsTest.cs index a008de9be8..31577cd84a 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPartialExtensionsTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperPartialExtensionsTest.cs @@ -337,11 +337,11 @@ namespace Microsoft.AspNet.Mvc.Rendering var model = new TestModel(); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", Enumerable.Empty())) .Verifiable(); @@ -366,11 +366,11 @@ namespace Microsoft.AspNet.Mvc.Rendering var model = new TestModel(); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" })) .Verifiable(); @@ -397,11 +397,11 @@ namespace Microsoft.AspNet.Mvc.Rendering var model = new TestModel(); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", new[] { "location3", "location4" })) .Verifiable(); @@ -426,11 +426,11 @@ namespace Microsoft.AspNet.Mvc.Rendering var model = new TestModel(); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", Enumerable.Empty())) .Verifiable(); @@ -455,11 +455,11 @@ namespace Microsoft.AspNet.Mvc.Rendering var model = new TestModel(); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" })) .Verifiable(); @@ -486,11 +486,11 @@ namespace Microsoft.AspNet.Mvc.Rendering var model = new TestModel(); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("test-view", new[] { "location3", "location4" })) .Verifiable(); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewComponents/ViewViewComponentResultTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewComponents/ViewViewComponentResultTest.cs index 74e7821a63..8856cbb5a1 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewComponents/ViewViewComponentResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewComponents/ViewViewComponentResultTest.cs @@ -37,11 +37,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("some-view", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("Components/Invoke/some-view", view.Object)) .Verifiable(); @@ -76,7 +76,7 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/Default", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/Default", /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("Components/Invoke/Default", view.Object)) .Verifiable(); @@ -110,7 +110,7 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/Default", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/Default", /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("Components/Invoke/Default", view.Object)) .Verifiable(); @@ -155,11 +155,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("some-view", new[] { "location1", "location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("Components/Invoke/some-view", Enumerable.Empty())) .Verifiable(); @@ -193,11 +193,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("some-view", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("Components/Invoke/some-view", new[] { "location1", "location2" })) .Verifiable(); @@ -233,11 +233,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("some-view", new[] { "location1", "location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("Components/Invoke/some-view", new[] { "location3", "location4" })) .Verifiable(); @@ -271,11 +271,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("some-view", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("Components/Invoke/some-view", view.Object)) .Verifiable(); @@ -307,11 +307,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("some-view", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("Components/Invoke/some-view", view)) .Verifiable(); @@ -342,11 +342,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("some-view", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("Components/Invoke/some-view", view)) .Verifiable(); @@ -391,11 +391,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, "some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("some-view", new[] { "view-location1", "view-location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "Components/Invoke/some-view", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound( "Components/Invoke/some-view", new[] { "view-location3", "view-location4" })) @@ -451,7 +451,7 @@ namespace Microsoft.AspNet.Mvc [Theory] [InlineData(null)] [InlineData("")] - public void Execute_CallsFindView_WithIsPartialAndExpectedPath_WhenViewNameIsNullOrEmpty(string viewName) + public void Execute_CallsFindView_WithExpectedPath_WhenViewNameIsNullOrEmpty(string viewName) { // Arrange var shortName = "SomeShortName"; @@ -461,7 +461,7 @@ namespace Microsoft.AspNet.Mvc var expectedViewName = $"Components/{shortName}/Default"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.FindView(It.IsAny(), expectedViewName, /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), expectedViewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.Found(expectedViewName, new Mock().Object)) .Verifiable(); @@ -480,12 +480,12 @@ namespace Microsoft.AspNet.Mvc [InlineData("~/Home/Index/MyViewComponent1.cshtml")] [InlineData("~MyViewComponent2.cshtml")] [InlineData("/MyViewComponent3.cshtml")] - public void Execute_CallsFindView_WithIsPartialAndExpectedPath_WhenViewNameIsSpecified(string viewName) + public void Execute_CallsFindView_WithExpectedPath_WhenViewNameIsSpecified(string viewName) { // Arrange var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, viewName, /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.Found(viewName, new Mock().Object)) .Verifiable(); var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewEngines/CompositeViewEngineTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewEngines/CompositeViewEngineTest.cs index 5ce060a69b..5c62577f14 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewEngines/CompositeViewEngineTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewEngines/CompositeViewEngineTest.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.ViewEngines } [Fact] - public void FindView_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered() + public void FindView_IsMainPage_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered() { // Arrange var viewName = "test-view"; @@ -42,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.ViewEngines var compositeViewEngine = new CompositeViewEngine(optionsAccessor); // Act - var result = compositeViewEngine.FindView(actionContext, viewName, isPartial: false); + var result = compositeViewEngine.FindView(actionContext, viewName, isMainPage: true); // Assert Assert.False(result.Success); @@ -51,26 +51,294 @@ namespace Microsoft.AspNet.Mvc.ViewEngines [Fact] - public void FindView_ReturnsNotFoundResult_WhenExactlyOneViewEngineIsRegisteredWhichReturnsNotFoundResult() + public void FindView_IsMainPage_ReturnsNotFoundResult_WhenExactlyOneViewEngineIsRegisteredWhichReturnsNotFoundResult() { // Arrange var viewName = "test-view"; var engine = new Mock(MockBehavior.Strict); engine - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ false)) + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound(viewName, new[] { "controller/test-view" })); var optionsAccessor = new TestOptionsManager(); optionsAccessor.Value.ViewEngines.Add(engine.Object); var compositeViewEngine = new CompositeViewEngine(optionsAccessor); // Act - var result = compositeViewEngine.FindView(GetActionContext(), viewName, isPartial: false); + var result = compositeViewEngine.FindView(GetActionContext(), viewName, isMainPage: true); // Assert Assert.False(result.Success); Assert.Equal(new[] { "controller/test-view" }, result.SearchedLocations); } + [Fact] + public void FindView_IsMainPage_ReturnsView_WhenExactlyOneViewEngineIsRegisteredWhichReturnsAFoundResult() + { + // Arrange + var viewName = "test-view"; + var engine = new Mock(MockBehavior.Strict); + var view = Mock.Of(); + engine + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ true)) + .Returns(ViewEngineResult.Found(viewName, view)); + var optionsAccessor = new TestOptionsManager(); + optionsAccessor.Value.ViewEngines.Add(engine.Object); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.FindView(GetActionContext(), viewName, isMainPage: true); + + // Assert + Assert.True(result.Success); + Assert.Same(view, result.View); + } + + [Fact] + public void FindView_IsMainPage_ReturnsViewFromFirstViewEngineWithFoundResult() + { + // Arrange + var viewName = "foo"; + var engine1 = new Mock(MockBehavior.Strict); + var engine2 = new Mock(MockBehavior.Strict); + var engine3 = new Mock(MockBehavior.Strict); + var view2 = Mock.Of(); + var view3 = Mock.Of(); + engine1 + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ true)) + .Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty())); + engine2 + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ true)) + .Returns(ViewEngineResult.Found(viewName, view2)); + engine3 + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ true)) + .Returns(ViewEngineResult.Found(viewName, view3)); + + var optionsAccessor = new TestOptionsManager(); + optionsAccessor.Value.ViewEngines.Add(engine1.Object); + optionsAccessor.Value.ViewEngines.Add(engine2.Object); + optionsAccessor.Value.ViewEngines.Add(engine3.Object); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.FindView(GetActionContext(), viewName, isMainPage: true); + + // Assert + Assert.True(result.Success); + Assert.Same(view2, result.View); + Assert.Equal(viewName, result.ViewName); + } + + [Fact] + public void FindView_IsMainPage_ReturnsNotFound_IfAllViewEnginesReturnNotFound() + { + // Arrange + var viewName = "foo"; + var engine1 = new Mock(MockBehavior.Strict); + var engine2 = new Mock(MockBehavior.Strict); + var engine3 = new Mock(MockBehavior.Strict); + engine1 + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ true)) + .Returns(ViewEngineResult.NotFound(viewName, new[] { "1", "2" })); + engine2 + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ true)) + .Returns(ViewEngineResult.NotFound(viewName, new[] { "3" })); + engine3 + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ true)) + .Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" })); + + var optionsAccessor = new TestOptionsManager(); + optionsAccessor.Value.ViewEngines.Add(engine1.Object); + optionsAccessor.Value.ViewEngines.Add(engine2.Object); + optionsAccessor.Value.ViewEngines.Add(engine3.Object); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.FindView(GetActionContext(), viewName, isMainPage: true); + + // Assert + Assert.False(result.Success); + Assert.Equal(new[] { "1", "2", "3", "4", "5" }, result.SearchedLocations); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void GetView_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered(bool isMainPage) + { + // Arrange + var viewName = "test-view.cshtml"; + var optionsAccessor = new TestOptionsManager(); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage); + + // Assert + Assert.False(result.Success); + Assert.Empty(result.SearchedLocations); + } + + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void GetView_ReturnsNotFoundResult_WhenExactlyOneViewEngineIsRegisteredWhichReturnsNotFoundResult( + bool isMainPage) + { + // Arrange + var viewName = "test-view.cshtml"; + var expectedViewName = "~/" + viewName; + var engine = new Mock(MockBehavior.Strict); + engine + .Setup(e => e.GetView("~/Index.html", viewName, isMainPage)) + .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { expectedViewName })); + var optionsAccessor = new TestOptionsManager(); + optionsAccessor.Value.ViewEngines.Add(engine.Object); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage); + + // Assert + Assert.False(result.Success); + Assert.Equal(new[] { expectedViewName }, result.SearchedLocations); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void GetView_ReturnsView_WhenExactlyOneViewEngineIsRegisteredWhichReturnsAFoundResult(bool isMainPage) + { + // Arrange + var viewName = "test-view.cshtml"; + var expectedViewName = "~/" + viewName; + var engine = new Mock(MockBehavior.Strict); + var view = Mock.Of(); + engine + .Setup(e => e.GetView("~/Index.html", viewName, isMainPage)) + .Returns(ViewEngineResult.Found(expectedViewName, view)); + var optionsAccessor = new TestOptionsManager(); + optionsAccessor.Value.ViewEngines.Add(engine.Object); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage); + + // Assert + Assert.True(result.Success); + Assert.Same(view, result.View); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void GetView_ReturnsViewFromFirstViewEngineWithFoundResult(bool isMainPage) + { + // Arrange + var viewName = "foo.cshtml"; + var expectedViewName = "~/" + viewName; + var engine1 = new Mock(MockBehavior.Strict); + var engine2 = new Mock(MockBehavior.Strict); + var engine3 = new Mock(MockBehavior.Strict); + var view2 = Mock.Of(); + var view3 = Mock.Of(); + engine1 + .Setup(e => e.GetView("~/Index.html", viewName, isMainPage)) + .Returns(ViewEngineResult.NotFound(expectedViewName, Enumerable.Empty())); + engine2 + .Setup(e => e.GetView("~/Index.html", viewName, isMainPage)) + .Returns(ViewEngineResult.Found(expectedViewName, view2)); + engine3 + .Setup(e => e.GetView("~/Index.html", viewName, isMainPage)) + .Returns(ViewEngineResult.Found(expectedViewName, view3)); + + var optionsAccessor = new TestOptionsManager(); + optionsAccessor.Value.ViewEngines.Add(engine1.Object); + optionsAccessor.Value.ViewEngines.Add(engine2.Object); + optionsAccessor.Value.ViewEngines.Add(engine3.Object); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage); + + // Assert + Assert.True(result.Success); + Assert.Same(view2, result.View); + Assert.Equal(expectedViewName, result.ViewName); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public void GetView_ReturnsNotFound_IfAllViewEnginesReturnNotFound(bool isMainPage) + { + // Arrange + var viewName = "foo.cshtml"; + var expectedViewName = "~/" + viewName; + var engine1 = new Mock(MockBehavior.Strict); + var engine2 = new Mock(MockBehavior.Strict); + var engine3 = new Mock(MockBehavior.Strict); + engine1 + .Setup(e => e.GetView("~/Index.html", viewName, isMainPage)) + .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "1", "2" })); + engine2 + .Setup(e => e.GetView("~/Index.html", viewName, isMainPage)) + .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "3" })); + engine3 + .Setup(e => e.GetView("~/Index.html", viewName, isMainPage)) + .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "4", "5" })); + + var optionsAccessor = new TestOptionsManager(); + optionsAccessor.Value.ViewEngines.Add(engine1.Object); + optionsAccessor.Value.ViewEngines.Add(engine2.Object); + optionsAccessor.Value.ViewEngines.Add(engine3.Object); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.GetView("~/Index.html", viewName, isMainPage); + + // Assert + Assert.False(result.Success); + Assert.Equal(new[] { "1", "2", "3", "4", "5" }, result.SearchedLocations); + } + + [Fact] + public void FindView_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered() + { + // Arrange + var viewName = "my-partial-view"; + var optionsAccessor = new TestOptionsManager(); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.FindView(GetActionContext(), viewName, isMainPage: false); + + // Assert + Assert.False(result.Success); + Assert.Empty(result.SearchedLocations); + } + + [Fact] + public void FindView_ReturnsNotFoundResult_WhenExactlyOneViewEngineIsRegisteredWhichReturnsNotFoundResult() + { + // Arrange + var viewName = "partial-view"; + var engine = new Mock(MockBehavior.Strict); + engine + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ false)) + .Returns(ViewEngineResult.NotFound(viewName, new[] { "Shared/partial-view" })); + var optionsAccessor = new TestOptionsManager(); + optionsAccessor.Value.ViewEngines.Add(engine.Object); + var compositeViewEngine = new CompositeViewEngine(optionsAccessor); + + // Act + var result = compositeViewEngine.FindView(GetActionContext(), viewName, isMainPage: false); + + // Assert + Assert.False(result.Success); + Assert.Equal(new[] { "Shared/partial-view" }, result.SearchedLocations); + } + [Fact] public void FindView_ReturnsView_WhenExactlyOneViewEngineIsRegisteredWhichReturnsAFoundResult() { @@ -79,14 +347,14 @@ namespace Microsoft.AspNet.Mvc.ViewEngines var engine = new Mock(MockBehavior.Strict); var view = Mock.Of(); engine - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ false)) + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.Found(viewName, view)); var optionsAccessor = new TestOptionsManager(); optionsAccessor.Value.ViewEngines.Add(engine.Object); var compositeViewEngine = new CompositeViewEngine(optionsAccessor); // Act - var result = compositeViewEngine.FindView(GetActionContext(), viewName, isPartial: false); + var result = compositeViewEngine.FindView(GetActionContext(), viewName, isMainPage: false); // Assert Assert.True(result.Success); @@ -97,20 +365,20 @@ namespace Microsoft.AspNet.Mvc.ViewEngines public void FindView_ReturnsViewFromFirstViewEngineWithFoundResult() { // Arrange - var viewName = "foo"; + var viewName = "bar"; var engine1 = new Mock(MockBehavior.Strict); var engine2 = new Mock(MockBehavior.Strict); var engine3 = new Mock(MockBehavior.Strict); var view2 = Mock.Of(); var view3 = Mock.Of(); engine1 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ false)) + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty())); engine2 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ false)) + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.Found(viewName, view2)); engine3 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ false)) + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.Found(viewName, view3)); var optionsAccessor = new TestOptionsManager(); @@ -120,7 +388,7 @@ namespace Microsoft.AspNet.Mvc.ViewEngines var compositeViewEngine = new CompositeViewEngine(optionsAccessor); // Act - var result = compositeViewEngine.FindView(GetActionContext(), viewName, isPartial: false); + var result = compositeViewEngine.FindView(GetActionContext(), viewName, isMainPage: false); // Assert Assert.True(result.Success); @@ -137,13 +405,13 @@ namespace Microsoft.AspNet.Mvc.ViewEngines var engine2 = new Mock(MockBehavior.Strict); var engine3 = new Mock(MockBehavior.Strict); engine1 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ false)) + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(viewName, new[] { "1", "2" })); engine2 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ false)) + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(viewName, new[] { "3" })); engine3 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ false)) + .Setup(e => e.FindView(It.IsAny(), viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" })); var optionsAccessor = new TestOptionsManager(); @@ -153,275 +421,7 @@ namespace Microsoft.AspNet.Mvc.ViewEngines var compositeViewEngine = new CompositeViewEngine(optionsAccessor); // Act - var result = compositeViewEngine.FindView(GetActionContext(), viewName, isPartial: false); - - // Assert - Assert.False(result.Success); - Assert.Equal(new[] { "1", "2", "3", "4", "5" }, result.SearchedLocations); - } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public void GetView_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered(bool isPartial) - { - // Arrange - var viewName = "test-view.cshtml"; - var optionsAccessor = new TestOptionsManager(); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.GetView("~/Index.html", viewName, isPartial); - - // Assert - Assert.False(result.Success); - Assert.Empty(result.SearchedLocations); - } - - - [Theory] - [InlineData(false)] - [InlineData(true)] - public void GetView_ReturnsNotFoundResult_WhenExactlyOneViewEngineIsRegisteredWhichReturnsNotFoundResult( - bool isPartial) - { - // Arrange - var viewName = "test-view.cshtml"; - var expectedViewName = "~/" + viewName; - var engine = new Mock(MockBehavior.Strict); - engine - .Setup(e => e.GetView("~/Index.html", viewName, isPartial)) - .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { expectedViewName })); - var optionsAccessor = new TestOptionsManager(); - optionsAccessor.Value.ViewEngines.Add(engine.Object); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.GetView("~/Index.html", viewName, isPartial); - - // Assert - Assert.False(result.Success); - Assert.Equal(new[] { expectedViewName }, result.SearchedLocations); - } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public void GetView_ReturnsView_WhenExactlyOneViewEngineIsRegisteredWhichReturnsAFoundResult(bool isPartial) - { - // Arrange - var viewName = "test-view.cshtml"; - var expectedViewName = "~/" + viewName; - var engine = new Mock(MockBehavior.Strict); - var view = Mock.Of(); - engine - .Setup(e => e.GetView("~/Index.html", viewName, isPartial)) - .Returns(ViewEngineResult.Found(expectedViewName, view)); - var optionsAccessor = new TestOptionsManager(); - optionsAccessor.Value.ViewEngines.Add(engine.Object); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.GetView("~/Index.html", viewName, isPartial); - - // Assert - Assert.True(result.Success); - Assert.Same(view, result.View); - } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public void GetView_ReturnsViewFromFirstViewEngineWithFoundResult(bool isPartial) - { - // Arrange - var viewName = "foo.cshtml"; - var expectedViewName = "~/" + viewName; - var engine1 = new Mock(MockBehavior.Strict); - var engine2 = new Mock(MockBehavior.Strict); - var engine3 = new Mock(MockBehavior.Strict); - var view2 = Mock.Of(); - var view3 = Mock.Of(); - engine1 - .Setup(e => e.GetView("~/Index.html", viewName, isPartial)) - .Returns(ViewEngineResult.NotFound(expectedViewName, Enumerable.Empty())); - engine2 - .Setup(e => e.GetView("~/Index.html", viewName, isPartial)) - .Returns(ViewEngineResult.Found(expectedViewName, view2)); - engine3 - .Setup(e => e.GetView("~/Index.html", viewName, isPartial)) - .Returns(ViewEngineResult.Found(expectedViewName, view3)); - - var optionsAccessor = new TestOptionsManager(); - optionsAccessor.Value.ViewEngines.Add(engine1.Object); - optionsAccessor.Value.ViewEngines.Add(engine2.Object); - optionsAccessor.Value.ViewEngines.Add(engine3.Object); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.GetView("~/Index.html", viewName, isPartial); - - // Assert - Assert.True(result.Success); - Assert.Same(view2, result.View); - Assert.Equal(expectedViewName, result.ViewName); - } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public void GetView_ReturnsNotFound_IfAllViewEnginesReturnNotFound(bool isPartial) - { - // Arrange - var viewName = "foo.cshtml"; - var expectedViewName = "~/" + viewName; - var engine1 = new Mock(MockBehavior.Strict); - var engine2 = new Mock(MockBehavior.Strict); - var engine3 = new Mock(MockBehavior.Strict); - engine1 - .Setup(e => e.GetView("~/Index.html", viewName, isPartial)) - .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "1", "2" })); - engine2 - .Setup(e => e.GetView("~/Index.html", viewName, isPartial)) - .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "3" })); - engine3 - .Setup(e => e.GetView("~/Index.html", viewName, isPartial)) - .Returns(ViewEngineResult.NotFound(expectedViewName, new[] { "4", "5" })); - - var optionsAccessor = new TestOptionsManager(); - optionsAccessor.Value.ViewEngines.Add(engine1.Object); - optionsAccessor.Value.ViewEngines.Add(engine2.Object); - optionsAccessor.Value.ViewEngines.Add(engine3.Object); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.GetView("~/Index.html", viewName, isPartial); - - // Assert - Assert.False(result.Success); - Assert.Equal(new[] { "1", "2", "3", "4", "5" }, result.SearchedLocations); - } - - [Fact] - public void FindView_IsPartial_ReturnsNotFoundResult_WhenNoViewEnginesAreRegistered() - { - // Arrange - var viewName = "my-partial-view"; - var optionsAccessor = new TestOptionsManager(); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.FindView(GetActionContext(), viewName, isPartial: true); - - // Assert - Assert.False(result.Success); - Assert.Empty(result.SearchedLocations); - } - - [Fact] - public void FindView_IsPartial_ReturnsNotFoundResult_WhenExactlyOneViewEngineIsRegisteredWhichReturnsNotFoundResult() - { - // Arrange - var viewName = "partial-view"; - var engine = new Mock(MockBehavior.Strict); - engine - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ true)) - .Returns(ViewEngineResult.NotFound(viewName, new[] { "Shared/partial-view" })); - var optionsAccessor = new TestOptionsManager(); - optionsAccessor.Value.ViewEngines.Add(engine.Object); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.FindView(GetActionContext(), viewName, isPartial: true); - - // Assert - Assert.False(result.Success); - Assert.Equal(new[] { "Shared/partial-view" }, result.SearchedLocations); - } - - [Fact] - public void FindView_IsPartial_ReturnsView_WhenExactlyOneViewEngineIsRegisteredWhichReturnsAFoundResult() - { - // Arrange - var viewName = "test-view"; - var engine = new Mock(MockBehavior.Strict); - var view = Mock.Of(); - engine - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ true)) - .Returns(ViewEngineResult.Found(viewName, view)); - var optionsAccessor = new TestOptionsManager(); - optionsAccessor.Value.ViewEngines.Add(engine.Object); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.FindView(GetActionContext(), viewName, isPartial: true); - - // Assert - Assert.True(result.Success); - Assert.Same(view, result.View); - } - - [Fact] - public void FindView_IsPartial_ReturnsViewFromFirstViewEngineWithFoundResult() - { - // Arrange - var viewName = "bar"; - var engine1 = new Mock(MockBehavior.Strict); - var engine2 = new Mock(MockBehavior.Strict); - var engine3 = new Mock(MockBehavior.Strict); - var view2 = Mock.Of(); - var view3 = Mock.Of(); - engine1 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ true)) - .Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty())); - engine2 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ true)) - .Returns(ViewEngineResult.Found(viewName, view2)); - engine3 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ true)) - .Returns(ViewEngineResult.Found(viewName, view3)); - - var optionsAccessor = new TestOptionsManager(); - optionsAccessor.Value.ViewEngines.Add(engine1.Object); - optionsAccessor.Value.ViewEngines.Add(engine2.Object); - optionsAccessor.Value.ViewEngines.Add(engine3.Object); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.FindView(GetActionContext(), viewName, isPartial: true); - - // Assert - Assert.True(result.Success); - Assert.Same(view2, result.View); - Assert.Equal(viewName, result.ViewName); - } - - [Fact] - public void FindView_IsPartial_ReturnsNotFound_IfAllViewEnginesReturnNotFound() - { - // Arrange - var viewName = "foo"; - var engine1 = new Mock(MockBehavior.Strict); - var engine2 = new Mock(MockBehavior.Strict); - var engine3 = new Mock(MockBehavior.Strict); - engine1 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ true)) - .Returns(ViewEngineResult.NotFound(viewName, new[] { "1", "2" })); - engine2 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ true)) - .Returns(ViewEngineResult.NotFound(viewName, new[] { "3" })); - engine3 - .Setup(e => e.FindView(It.IsAny(), viewName, /*isPartial*/ true)) - .Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" })); - - var optionsAccessor = new TestOptionsManager(); - optionsAccessor.Value.ViewEngines.Add(engine1.Object); - optionsAccessor.Value.ViewEngines.Add(engine2.Object); - optionsAccessor.Value.ViewEngines.Add(engine3.Object); - var compositeViewEngine = new CompositeViewEngine(optionsAccessor); - - // Act - var result = compositeViewEngine.FindView(GetActionContext(), viewName, isPartial: true); + var result = compositeViewEngine.FindView(GetActionContext(), viewName, isMainPage: false); // Assert Assert.False(result.Success); @@ -443,12 +443,12 @@ namespace Microsoft.AspNet.Mvc.ViewEngines public ITestService Service { get; private set; } - public ViewEngineResult FindView(ActionContext context, string viewName, bool isPartial) + public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage) { throw new NotImplementedException(); } - public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isPartial) + public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage) { throw new NotImplementedException(); } diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/DefaultDisplayTemplatesTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/DefaultDisplayTemplatesTest.cs index 9d4352d269..6bddfe9518 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/DefaultDisplayTemplatesTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/DefaultDisplayTemplatesTest.cs @@ -130,10 +130,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var model = new DefaultTemplatesUtilities.ObjectWithScaffoldColumn(); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); @@ -265,10 +265,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "Model string" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); helper.ViewData["Property1"] = "ViewData string"; @@ -287,10 +287,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "Model string" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); helper.ViewData["Property1"] = "ViewData string"; @@ -309,10 +309,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "Model string" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); @@ -332,10 +332,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = propertyValue, }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); helper.ViewData["Property1"] = "ViewData string"; @@ -361,10 +361,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures })); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("test-view", view.Object)); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); helper.ViewData["Property1"] = "ViewData string"; @@ -375,15 +375,15 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures } [Fact] - public void Display_CallsFindView_WithIsPartialAndExpectedPath() + public void Display_CallsFindView_WithExpectedPath() { // Arrange var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), "DisplayTemplates/String", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "DisplayTemplates/String", /*isMainPage*/ false)) .Returns(ViewEngineResult.Found(string.Empty, new Mock().Object)) .Verifiable(); var html = DefaultTemplatesUtilities.GetHtmlHelper(new object(), viewEngine: viewEngine.Object); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/DefaultEditorTemplatesTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/DefaultEditorTemplatesTest.cs index 575d766ccd..c3e3e263b0 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/DefaultEditorTemplatesTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/DefaultEditorTemplatesTest.cs @@ -191,10 +191,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectWithScaffoldColumn(); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("", Enumerable.Empty())); var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); @@ -360,10 +360,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper( model, @@ -393,10 +393,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper( model, @@ -425,10 +425,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var provider = new TestModelMetadataProvider(); @@ -467,10 +467,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var provider = new TestModelMetadataProvider(); @@ -508,10 +508,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var provider = new TestModelMetadataProvider(); @@ -550,10 +550,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var provider = new TestModelMetadataProvider(); @@ -590,10 +590,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "Model string" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); helper.ViewData["Property1"] = "ViewData string"; @@ -637,10 +637,10 @@ Environment.NewLine; offset: offset); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var provider = new TestModelMetadataProvider(); @@ -694,10 +694,10 @@ Environment.NewLine; offset: offset); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var provider = new TestModelMetadataProvider(); @@ -754,10 +754,10 @@ Environment.NewLine; offset: offset); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var provider = new TestModelMetadataProvider(); @@ -791,10 +791,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "Model string" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); helper.ViewData["Property1"] = "ViewData string"; @@ -815,10 +815,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "Model string" }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); @@ -840,10 +840,10 @@ Environment.NewLine; var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = propertyValue, }; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); helper.ViewData["Property1"] = "ViewData string"; @@ -871,10 +871,10 @@ Environment.NewLine; })); var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.Found("test-view", view.Object)); var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object); helper.ViewData["Property1"] = "ViewData string"; @@ -885,15 +885,15 @@ Environment.NewLine; } [Fact] - public void EditorForModel_CallsFindView_WithIsPartialAndExpectedPath() + public void EditorForModel_CallsFindView_WithExpectedPath() { // Arrange var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty())); viewEngine - .Setup(v => v.FindView(It.IsAny(), "EditorTemplates/String", /*isPartial*/ true)) + .Setup(v => v.FindView(It.IsAny(), "EditorTemplates/String", /*isMainPage*/ false)) .Returns(ViewEngineResult.Found(string.Empty, new Mock().Object)) .Verifiable(); var html = DefaultTemplatesUtilities.GetHtmlHelper(new object(), viewEngine: viewEngine.Object); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs index 1509e780a3..88a91b2c3c 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/PartialViewResultExecutorTest.cs @@ -29,11 +29,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "my-view"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, viewName, /*isPartial*/ true)) + .Setup(e => e.GetView(/*executingFilePath*/ null, viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(e => e.FindView(context, viewName, /*isPartial*/ true)) + .Setup(e => e.FindView(context, viewName, /*isMainPage*/ false)) .Returns(ViewEngineResult.Found(viewName, Mock.Of())) .Verifiable(); @@ -87,11 +87,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "myview"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ true)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("myview", expectedLocations)) .Verifiable(); viewEngine - .Setup(e => e.FindView(context, "myview", /*isPartial*/ true)) + .Setup(e => e.FindView(context, "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("myview", Enumerable.Empty())); var viewResult = new PartialViewResult @@ -122,11 +122,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "myview"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ true)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("myview", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(e => e.FindView(context, "myview", /*isPartial*/ true)) + .Setup(e => e.FindView(context, "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("myview", expectedLocations)); var viewResult = new PartialViewResult @@ -157,11 +157,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "myview"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ true)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("myview", new[] { "location1", "location2" })) .Verifiable(); viewEngine - .Setup(e => e.FindView(context, "myview", /*isPartial*/ true)) + .Setup(e => e.FindView(context, "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("myview", new[] { "location3", "location4" })); var viewResult = new PartialViewResult @@ -210,7 +210,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Assert.NotNull(listener.ViewFound.ActionContext); Assert.NotNull(listener.ViewFound.Result); Assert.NotNull(listener.ViewFound.View); - Assert.True(listener.ViewFound.IsPartial); + Assert.False(listener.ViewFound.IsMainPage); Assert.Equal("myview", listener.ViewFound.ViewName); } @@ -228,11 +228,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "myview"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ true)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("myview", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(e => e.FindView(context, "myview", /*isPartial*/ true)) + .Setup(e => e.FindView(context, "myview", /*isMainPage*/ false)) .Returns(ViewEngineResult.NotFound("myview", new string[] { "location/myview" })); var viewResult = new PartialViewResult @@ -323,13 +323,13 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ true)) + .Setup(e => e.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ false)) .Returns( - (executing, name, isPartial) => ViewEngineResult.NotFound(name, Enumerable.Empty())); + (executing, name, isMainPage) => ViewEngineResult.NotFound(name, Enumerable.Empty())); viewEngine - .Setup(e => e.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ true)) + .Setup(e => e.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ false)) .Returns( - (context, name, isPartial) => ViewEngineResult.Found(name, Mock.Of())); + (context, name, isMainPage) => ViewEngineResult.Found(name, Mock.Of())); var options = new TestOptionsManager(); options.Value.ViewEngines.Add(viewEngine.Object); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs index 9f100e10d8..eaac43241d 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewFeatures/ViewResultExecutorTest.cs @@ -29,11 +29,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "my-view"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, viewName, /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, viewName, /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(e => e.FindView(context, viewName, /*isPartial*/ false)) + .Setup(e => e.FindView(context, viewName, /*isMainPage*/ true)) .Returns(ViewEngineResult.Found(viewName, Mock.Of())) .Verifiable(); @@ -87,10 +87,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "myview"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("myview", expectedLocations)); viewEngine - .Setup(e => e.FindView(context, "myview", /*isPartial*/ false)) + .Setup(e => e.FindView(context, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("myview", Enumerable.Empty())); var viewResult = new ViewResult @@ -121,10 +121,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "myview"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("myview", Enumerable.Empty())); viewEngine - .Setup(e => e.FindView(context, "myview", /*isPartial*/ false)) + .Setup(e => e.FindView(context, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("myview", expectedLocations)); var viewResult = new ViewResult @@ -155,10 +155,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "myview"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("myview", new[] { "location1", "location2" })); viewEngine - .Setup(e => e.FindView(context, "myview", /*isPartial*/ false)) + .Setup(e => e.FindView(context, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("myview", new[] { "location3", "location4" })); var viewResult = new ViewResult @@ -207,7 +207,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures Assert.NotNull(listener.ViewFound.ActionContext); Assert.NotNull(listener.ViewFound.Result); Assert.NotNull(listener.ViewFound.View); - Assert.False(listener.ViewFound.IsPartial); + Assert.True(listener.ViewFound.IsMainPage); Assert.Equal("myview", listener.ViewFound.ViewName); } @@ -225,10 +225,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewName = "myview"; var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("myview", Enumerable.Empty())); viewEngine - .Setup(e => e.FindView(context, "myview", /*isPartial*/ false)) + .Setup(e => e.FindView(context, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("myview", new string[] { "location/myview" })); var viewResult = new ViewResult @@ -319,11 +319,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, It.IsAny(), /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, It.IsAny(), /*isMainPage*/ true)) .Returns( (path, name, partial) => ViewEngineResult.NotFound(name, Enumerable.Empty())); viewEngine - .Setup(e => e.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ false)) + .Setup(e => e.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ true)) .Returns( (context, name, partial) => ViewEngineResult.Found(name, Mock.Of())); diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs index 9a239674b3..b950f5f335 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/ViewResultTest.cs @@ -39,11 +39,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "MyView", /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "MyView", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ false)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("MyView", Enumerable.Empty())) .Verifiable(); @@ -76,11 +76,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "MyView", /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "MyView", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("MyView", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ false)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" })) .Verifiable(); @@ -115,11 +115,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "MyView", /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "MyView", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" })) .Verifiable(); viewEngine - .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isPartial*/ false)) + .Setup(v => v.FindView(It.IsAny(), It.IsAny(), /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("MyView", new[] { "Location3", "Location4" })) .Verifiable(); @@ -162,11 +162,11 @@ namespace Microsoft.AspNet.Mvc var viewEngine = new Mock(MockBehavior.Strict); viewEngine - .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isPartial*/ false)) + .Setup(e => e.GetView(/*executingFilePath*/ null, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.NotFound("myview", Enumerable.Empty())) .Verifiable(); viewEngine - .Setup(e => e.FindView(context, "myview", /*isPartial*/ false)) + .Setup(e => e.FindView(context, "myview", /*isMainPage*/ true)) .Returns(ViewEngineResult.Found("myview", view.Object)) .Verifiable(); diff --git a/test/WebSites/CompositeViewEngineWebSite/TestViewEngine.cs b/test/WebSites/CompositeViewEngineWebSite/TestViewEngine.cs index 3615009333..c9bb0a3a9e 100644 --- a/test/WebSites/CompositeViewEngineWebSite/TestViewEngine.cs +++ b/test/WebSites/CompositeViewEngineWebSite/TestViewEngine.cs @@ -10,12 +10,12 @@ namespace CompositeViewEngineWebSite { public class TestViewEngine : IViewEngine { - public ViewEngineResult FindView(ActionContext context, string viewName, bool isPartial) + public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage) { if (string.Equals(viewName, "partial-test-view", StringComparison.Ordinal) || string.Equals(viewName, "test-view", StringComparison.Ordinal)) { - var view = isPartial ? (IView)new TestPartialView() : new TestView(); + var view = isMainPage ? (IView)new TestView() : new TestPartialView(); return ViewEngineResult.Found(viewName, view); } @@ -23,7 +23,7 @@ namespace CompositeViewEngineWebSite return ViewEngineResult.NotFound(viewName, Enumerable.Empty()); } - public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isPartial) + public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage) { return ViewEngineResult.NotFound(viewPath, Enumerable.Empty()); } diff --git a/test/WebSites/RazorWebSite/Services/CustomPartialDirectoryViewLocationExpander.cs b/test/WebSites/RazorWebSite/Services/NonMainPageViewLocationExpander.cs similarity index 57% rename from test/WebSites/RazorWebSite/Services/CustomPartialDirectoryViewLocationExpander.cs rename to test/WebSites/RazorWebSite/Services/NonMainPageViewLocationExpander.cs index a55210b631..2180774b0d 100644 --- a/test/WebSites/RazorWebSite/Services/CustomPartialDirectoryViewLocationExpander.cs +++ b/test/WebSites/RazorWebSite/Services/NonMainPageViewLocationExpander.cs @@ -6,28 +6,30 @@ using Microsoft.AspNet.Mvc.Razor; namespace RazorWebSite { - public class CustomPartialDirectoryViewLocationExpander : IViewLocationExpander + public class NonMainPageViewLocationExpander : IViewLocationExpander { public void PopulateValues(ViewLocationExpanderContext context) { } - public virtual IEnumerable ExpandViewLocations(ViewLocationExpanderContext context, - IEnumerable viewLocations) + public virtual IEnumerable ExpandViewLocations( + ViewLocationExpanderContext context, + IEnumerable viewLocations) { - if (context.IsPartial) + if (context.IsMainPage) { - return ExpandViewLocationsCore(viewLocations); + return viewLocations; } - return viewLocations; + return ExpandViewLocationsCore(viewLocations); } private IEnumerable ExpandViewLocationsCore(IEnumerable viewLocations) { + yield return "/Shared-Views/{1}/{0}.cshtml"; + foreach (var location in viewLocations) { - yield return "/Shared-Views/{1}/{0}.cshtml"; yield return location; } } diff --git a/test/WebSites/RazorWebSite/Startup.cs b/test/WebSites/RazorWebSite/Startup.cs index a80a09a384..a144968783 100644 --- a/test/WebSites/RazorWebSite/Startup.cs +++ b/test/WebSites/RazorWebSite/Startup.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Globalization; using Microsoft.AspNet.Builder; using Microsoft.AspNet.Localization; -using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc.Razor; using Microsoft.Extensions.DependencyInjection; @@ -19,7 +18,7 @@ namespace RazorWebSite .AddMvc() .AddRazorOptions(options => { - options.ViewLocationExpanders.Add(new CustomPartialDirectoryViewLocationExpander()); + options.ViewLocationExpanders.Add(new NonMainPageViewLocationExpander()); }) .AddViewOptions(options => {