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`
This commit is contained in:
Doug Bunting 2015-11-16 16:35:45 -08:00
parent cf30bb730f
commit 3be6167aa0
33 changed files with 914 additions and 1045 deletions

View File

@ -45,12 +45,6 @@ namespace Microsoft.AspNet.Mvc.Razor
/// </summary>
string Layout { get; set; }
/// <summary>
/// Gets or sets a value that determines if the current instance of <see cref="IRazorPage"/> is being executed
/// from a partial view.
/// </summary>
bool IsPartial { get; set; }
/// <summary>
/// Gets or sets a <see cref="IPageExecutionContext"/> instance used to instrument the page execution.
/// </summary>

View File

@ -16,10 +16,10 @@ namespace Microsoft.AspNet.Mvc.Razor
/// </summary>
/// <param name="context">The <see cref="ActionContext"/>.</param>
/// <param name="pageName">The name of the page.</param>
/// <param name="isPartial">Determines if the page being found is a partial.</param>
/// <param name="isMainPage">Determines if the page being found is the main page for an action.</param>
/// <returns>The <see cref="RazorPageResult"/> of locating the page.</returns>
/// <remarks><seealso cref="IViewEngine.FindView"/>.</remarks>
RazorPageResult FindPage(ActionContext context, string pageName, bool isPartial);
RazorPageResult FindPage(ActionContext context, string pageName, bool isMainPage);
/// <summary>
/// Gets the page with the given <paramref name="pagePath"/>, relative to <paramref name="executingFilePath"/>
@ -27,10 +27,10 @@ namespace Microsoft.AspNet.Mvc.Razor
/// </summary>
/// <param name="executingFilePath">The absolute path to the currently-executing page, if any.</param>
/// <param name="pagePath">The path to the page.</param>
/// <param name="isPartial">Determines if the page being found is a partial.</param>
/// <param name="isMainPage">Determines if the page being found is the main page for an action.</param>
/// <returns>The <see cref="RazorPageResult"/> of locating the page.</returns>
/// <remarks><seealso cref="IViewEngine.GetView"/>.</remarks>
RazorPageResult GetPage(string executingFilePath, string pagePath, bool isPartial);
RazorPageResult GetPage(string executingFilePath, string pagePath, bool isMainPage);
/// <summary>
/// Converts the given <paramref name="pagePath"/> to be absolute, relative to

View File

@ -72,9 +72,6 @@ namespace Microsoft.AspNet.Mvc.Razor
/// <inheritdoc />
public string Layout { get; set; }
/// <inheritdoc />
public bool IsPartial { get; set; }
/// <summary>
/// Gets the <see cref="HtmlEncoder"/> to be used for encoding HTML.
/// </summary>
@ -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,
});
}
}

View File

@ -34,21 +34,43 @@ namespace Microsoft.AspNet.Mvc.Razor
/// </param>
/// <param name="razorPage">The <see cref="IRazorPage"/> instance to execute.</param>
/// <param name="htmlEncoder">The HTML encoder.</param>
/// <param name="isPartial">Determines if the view is to be executed as a partial.</param>
public RazorView(
IRazorViewEngine viewEngine,
IRazorPageActivator pageActivator,
IReadOnlyList<IRazorPage> 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;
}
/// <inheritdoc />
@ -63,13 +85,7 @@ namespace Microsoft.AspNet.Mvc.Razor
public IRazorPage RazorPage { get; }
/// <summary>
/// Gets a value that determines if the view is executed as a partial.
/// </summary>
public bool IsPartial { get; }
/// <summary>
/// Gets the sequence of _ViewStart <see cref="IRazorPage"/> instances
/// that are executed by this view if <see cref="IsPartial"/> is <c>false</c>.
/// Gets the sequence of _ViewStart <see cref="IRazorPage"/> instances that are executed by this view.
/// </summary>
public IReadOnlyList<IRazorPage> ViewStartPages { get; }
@ -88,16 +104,14 @@ namespace Microsoft.AspNet.Mvc.Razor
_pageExecutionFeature = context.HttpContext.Features.Get<IPageExecutionListenerFeature>();
// 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<IBufferedTextWriter> RenderPageAsync(
IRazorPage page,
ViewContext context,
bool executeViewStart)
IReadOnlyList<IRazorPage> 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<IRazorPage> 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)

View File

@ -175,7 +175,7 @@ namespace Microsoft.AspNet.Mvc.Razor
}
/// <inheritdoc />
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<string>());
}
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
}
/// <inheritdoc />
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<string>());
}
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
}
/// <inheritdoc />
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<string>());
}
var cacheResult = LocatePageFromViewLocations(context, viewName, isPartial);
return CreateViewEngineResult(cacheResult, viewName, isPartial);
var cacheResult = LocatePageFromViewLocations(context, viewName, isMainPage);
return CreateViewEngineResult(cacheResult, viewName);
}
/// <inheritdoc />
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<string>());
}
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<IChangeToken>();
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<string, string> 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<IChangeToken> 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);
}

View File

@ -16,15 +16,15 @@ namespace Microsoft.AspNet.Mvc.Razor
/// Initializes a new instance of <see cref="ViewLocationCacheKey"/>.
/// </summary>
/// <param name="viewName">The view name or path.</param>
/// <param name="isPartial">Determines if the view is a partial.</param>
/// <param name="isMainPage">Determines if the page being found is the main page for an action.</param>
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
/// <param name="viewName">The view name.</param>
/// <param name="controllerName">The controller name.</param>
/// <param name="areaName">The area name.</param>
/// <param name="isPartial">Determines if the view is a partial.</param>
/// <param name="isMainPage">Determines if the page being found is the main page for an action.</param>
/// <param name="values">Values from <see cref="IViewLocationExpander"/> instances.</param>
public ViewLocationCacheKey(
string viewName,
string controllerName,
string areaName,
bool isPartial,
bool isMainPage,
IReadOnlyDictionary<string, string> 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; }
/// <summary>
/// Determines if the view is a partial.
/// Determines if the page being found is the main page for an action.
/// </summary>
public bool IsPartial { get; }
public bool IsMainPage { get; }
/// <summary>
/// Gets the values populated by <see cref="IViewLocationExpander"/> instances.
@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.Razor
/// <inheritdoc />
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);

View File

@ -18,13 +18,13 @@ namespace Microsoft.AspNet.Mvc.Razor
/// <param name="viewName">The view name.</param>
/// <param name="controllerName">The controller name.</param>
/// <param name="areaName">The area name.</param>
/// <param name="isPartial">Determines if the view being discovered is a partial.</param>
/// <param name="isMainPage">Determines if the page being found is the main page for an action.</param>
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;
}
/// <summary>
@ -64,9 +64,9 @@ namespace Microsoft.AspNet.Mvc.Razor
public string AreaName { get; }
/// <summary>
/// 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.
/// </summary>
public bool IsPartial { get; }
public bool IsMainPage { get; }
/// <summary>
/// Gets or sets the <see cref="IDictionary{TKey, TValue}"/> that is populated with values as part of

View File

@ -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<string> searchedLocations)
@ -74,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.Diagnostics
new
{
actionContext = actionContext,
isPartial = isPartial,
isMainPage = isMainPage,
result = viewResult,
viewName = viewName,
searchedLocations = searchedLocations,

View File

@ -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;

View File

@ -25,7 +25,7 @@ namespace Microsoft.AspNet.Mvc.ViewEngines
public IReadOnlyList<IViewEngine> ViewEngines { get; }
/// <inheritdoc />
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<string> 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
}
/// <inheritdoc />
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<string> 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;

View File

@ -14,9 +14,9 @@ namespace Microsoft.AspNet.Mvc.ViewEngines
/// </summary>
/// <param name="context">The <see cref="ActionContext"/>.</param>
/// <param name="viewName">The name of the view.</param>
/// <param name="isPartial">Determines if the view being found is a partial.</param>
/// <param name="isMainPage">Determines if the page being found is the main page for an action.</param>
/// <returns>The <see cref="ViewEngineResult"/> of locating the view.</returns>
ViewEngineResult FindView(ActionContext context, string viewName, bool isPartial);
ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage);
/// <summary>
/// Gets the view with the given <paramref name="viewPath"/>, relative to <paramref name="executingFilePath"/>
@ -24,8 +24,8 @@ namespace Microsoft.AspNet.Mvc.ViewEngines
/// </summary>
/// <param name="executingFilePath">The absolute path to the currently-executing view, if any.</param>
/// <param name="viewPath">The path to the view.</param>
/// <param name="isPartial">Determines if the view being found is a partial.</param>
/// <param name="isMainPage">Determines if the page being found is the main page for an action.</param>
/// <returns>The <see cref="ViewEngineResult"/> of locating the view.</returns>
ViewEngineResult GetView(string executingFilePath, string viewPath, bool isPartial);
ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage);
}
}

View File

@ -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)

View File

@ -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);
}

View File

@ -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)

View File

@ -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

View File

@ -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<string, string>
{
{ "Index", "<expander-view><shared-views>/Shared-Views/ExpanderViews/_ExpanderPartial.cshtml</shared-views></expander-view>" },
{ "Partial", "<shared-views>/Shared-Views/ExpanderViews/_ExpanderPartial.cshtml</shared-views>" }
{
"Index",
"<expander-view><shared-views>/Shared-Views/ExpanderViews/_ExpanderPartial.cshtml</shared-views></expander-view>"
},
{
"Partial",
"<shared-views>/Shared-Views/ExpanderViews/_ExpanderPartial.cshtml</shared-views>"
},
};
}
}
[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}");

View File

@ -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<TestDiagnosticListener.BeginPageInstrumentationData>(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<TestDiagnosticListener.EndPageInstrumentationData>(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<TestDiagnosticListener.BeginPageInstrumentationData>(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<TestDiagnosticListener.EndPageInstrumentationData>(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<TestDiagnosticListener.BeginPageInstrumentationData>(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<TestDiagnosticListener.EndPageInstrumentationData>(data);
Assert.NotNull(endEvent.HttpContext);
Assert.Equal(path, endEvent.Path);
Assert.Equal(isPartial, endEvent.IsPartial);
};
Assert.Collection(adapter.PageInstrumentationData,

View File

@ -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<IRazorPageFactoryProvider>();
var page = Mock.Of<IRazorPage>();
var viewStart1 = Mock.Of<IRazorPage>();
var viewStart2 = Mock.Of<IRazorPage>();
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<RazorView>(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<IRazorPageFactoryProvider>();
var page = Mock.Of<IRazorPage>();
var viewStart = Mock.Of<IRazorPage>();
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<RazorView>(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<RazorView>(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<RazorView>(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<IRazorPageFactoryProvider>();
var page = Mock.Of<IRazorPage>();
var viewStart = Mock.Of<IRazorPage>();
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<RazorView>(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<RazorView>(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<IRazorPageFactoryProvider>();
var page = Mock.Of<IRazorPage>();
var viewStart1 = Mock.Of<IRazorPage>();
var viewStart2 = Mock.Of<IRazorPage>();
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<RazorView>(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<IRazorPageFactoryProvider>();
@ -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<IRazorPageFactoryProvider>();
@ -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<string, object> routeValues,
IEnumerable<string> 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<IRazorPage>();
@ -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<string>()))
.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<IRazorPage>();
@ -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<IRazorPage>();
@ -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<IRazorPageFactoryProvider>();
@ -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<string, object> routeValues,
IEnumerable<string> 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<IRazorPage>(MockBehavior.Strict);
page.SetupSet(p => p.IsPartial = true);
var pageFactory = new Mock<IRazorPageFactoryProvider>();
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<IRazorPageFactoryProvider>();
@ -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);

View File

@ -45,8 +45,7 @@ namespace Microsoft.AspNet.Mvc.Razor
Mock.Of<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorPageActivator>(),
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<IRazorPageActivator>(),
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<IRazorPageActivator>(),
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<string>()))
.Verifiable();
@ -433,15 +423,14 @@ namespace Microsoft.AspNet.Mvc.Razor
Mock.Of<IRazorPageActivator>(),
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<string>()))
.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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<string>()));
viewEngine
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "NestedLayout", /*isPartial*/ true))
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "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<string>()));
viewEngine
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "Layout", /*isPartial*/ true))
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "Layout", /*isMainPage*/ false))
.Returns(new RazorPageResult("Layout", baseLayout));
var view = new RazorView(
@ -730,8 +715,7 @@ namespace Microsoft.AspNet.Mvc.Razor
Mock.Of<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(p => p.GetPage(It.IsAny<string>(), "_Layout", /*isPartial*/ true))
.Setup(p => p.GetPage(It.IsAny<string>(), "_Layout", /*isMainPage*/ false))
.Returns(new RazorPageResult("_Layout", Enumerable.Empty<string>()));
viewEngine
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "_Layout", /*isPartial*/ true))
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "_Layout", /*isMainPage*/ false))
.Returns(new RazorPageResult("_Layout", layout));
var view = new RazorView(
@ -1077,8 +1056,7 @@ namespace Microsoft.AspNet.Mvc.Razor
Mock.Of<IRazorPageActivator>(),
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<IRazorViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(p => p.GetPage(It.IsAny<string>(), "_Layout", /*isPartial*/ true))
.Setup(p => p.GetPage(It.IsAny<string>(), "_Layout", /*isMainPage*/ false))
.Returns(new RazorPageResult("_Layout1", Enumerable.Empty<string>()));
viewEngine
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "_Layout", /*isPartial*/ true))
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "_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<string>()));
viewEngine
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "_Layout2", /*isPartial*/ true))
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "_Layout2", /*isMainPage*/ false))
.Returns(new RazorPageResult("_Layout2", layout2));
var view = new RazorView(
@ -1131,8 +1109,7 @@ namespace Microsoft.AspNet.Mvc.Razor
Mock.Of<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<string>()));
viewEngine
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "layout-1", /*isPartial*/ true))
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<string>()));
viewEngine
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "layout-1", /*isPartial*/ true))
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "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<IRazorPageActivator>(),
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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<string>()));
viewEngine
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "Layout", /*isPartial*/ true))
.Setup(p => p.FindPage(It.IsAny<ActionContext>(), "Layout", /*isMainPage*/ false))
.Returns(new RazorPageResult("/Layout.cshtml", layout));
var view = new RazorView(
@ -1473,8 +1445,7 @@ namespace Microsoft.AspNet.Mvc.Razor
Mock.Of<IRazorPageActivator>(),
new IRazorPage[0],
page,
new HtmlTestEncoder(),
isPartial: false);
new HtmlTestEncoder());
var viewContext = CreateViewContext(view);
viewContext.HttpContext.Features.Set<IPageExecutionListenerFeature>(feature.Object);
@ -1519,8 +1490,7 @@ namespace Microsoft.AspNet.Mvc.Razor
Mock.Of<IRazorPageActivator>(),
new IRazorPage[0],
page,
new HtmlTestEncoder(),
isPartial: true);
new HtmlTestEncoder());
var viewContext = CreateViewContext(view);
viewContext.Writer = writer;
viewContext.HttpContext.Features.Set<IPageExecutionListenerFeature>(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<IRazorViewEngine>(),
var view = new RazorView(
Mock.Of<IRazorViewEngine>(),
Mock.Of<IRazorPageActivator>(),
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<IRazorPageActivator>(),
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<IRazorPageActivator>(),
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<IRazorPageActivator>(),
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<IRazorViewEngine>(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<IRazorPageActivator>(),
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<IRazorViewEngine>(),
Mock.Of<IRazorPageActivator>(),
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<IRazorPageActivator>(),
new[] { viewStart1, viewStart2 },
page,
new HtmlTestEncoder(),
isPartial: false);
new HtmlTestEncoder());
var viewContext = CreateViewContext(view);
// Act

View File

@ -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<string> 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<string> 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<object> PageInstrumentationData { get; set; } = new List<object>();
@ -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,
});
}
}

View File

@ -39,11 +39,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<ActionContext>(), "MyView", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "MyView", /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("MyView", Enumerable.Empty<string>()))
.Verifiable();
@ -76,11 +76,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "MyView", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "MyView", /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" }))
.Verifiable();
@ -115,11 +115,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<ActionContext>(), "MyView", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "MyView", /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("MyView", new[] { "Location3", "Location4" }))
.Verifiable();
@ -163,11 +163,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "myview", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "myview", /*isMainPage*/ false))
.Returns(ViewEngineResult.Found("myview", view.Object))
.Verifiable();

View File

@ -318,11 +318,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("MyView", Enumerable.Empty<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.Found("MyView", view.Object))
.Verifiable();

View File

@ -337,11 +337,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
var model = new TestModel();
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" }))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("test-view", Enumerable.Empty<string>()))
.Verifiable();
@ -366,11 +366,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
var model = new TestModel();
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("test-view", Enumerable.Empty<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" }))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" }))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("test-view", Enumerable.Empty<string>()))
.Verifiable();
@ -455,11 +455,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
var model = new TestModel();
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("test-view", Enumerable.Empty<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("test-view", new[] { "location1", "location2" }))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("test-view", new[] { "location3", "location4" }))
.Verifiable();

View File

@ -37,11 +37,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "Components/Invoke/some-view", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "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<IViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "Components/Invoke/Default", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "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<IViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "Components/Invoke/Default", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "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<IViewEngine>(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<ActionContext>(), "Components/Invoke/some-view", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "Components/Invoke/some-view", /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("Components/Invoke/some-view", Enumerable.Empty<string>()))
.Verifiable();
@ -193,11 +193,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "Components/Invoke/some-view", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "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<IViewEngine>(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<ActionContext>(), "Components/Invoke/some-view", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "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<IViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "Components/Invoke/some-view", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "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<IViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "Components/Invoke/some-view", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "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<ICompositeViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "Components/Invoke/some-view", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "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<IViewEngine>(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<ActionContext>(), "Components/Invoke/some-view", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), expectedViewName, /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), expectedViewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.Found(expectedViewName, new Mock<IView>().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<ICompositeViewEngine>(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<IView>().Object))
.Verifiable();
var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider());

View File

@ -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<IViewEngine>(MockBehavior.Strict);
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ false))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "controller/test-view" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var view = Mock.Of<IView>();
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.Found(viewName, view));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
var view2 = Mock.Of<IView>();
var view3 = Mock.Of<IView>();
engine1
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty<string>()));
engine2
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.Found(viewName, view2));
engine3
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.Found(viewName, view3));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
engine1
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "1", "2" }));
engine2
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "3" }));
engine3
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
engine
.Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
.Returns(ViewEngineResult.NotFound(expectedViewName, new[] { expectedViewName }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var view = Mock.Of<IView>();
engine
.Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
.Returns(ViewEngineResult.Found(expectedViewName, view));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
var view2 = Mock.Of<IView>();
var view3 = Mock.Of<IView>();
engine1
.Setup(e => e.GetView("~/Index.html", viewName, isMainPage))
.Returns(ViewEngineResult.NotFound(expectedViewName, Enumerable.Empty<string>()));
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<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(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<MvcViewOptions>();
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<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "Shared/partial-view" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var view = Mock.Of<IView>();
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ false))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.Found(viewName, view));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
var view2 = Mock.Of<IView>();
var view3 = Mock.Of<IView>();
engine1
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ false))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty<string>()));
engine2
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ false))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.Found(viewName, view2));
engine3
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ false))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.Found(viewName, view3));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
@ -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<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
engine1
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ false))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "1", "2" }));
engine2
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ false))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "3" }));
engine3
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ false))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
@ -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<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
engine
.Setup(e => e.GetView("~/Index.html", viewName, isPartial))
.Returns(ViewEngineResult.NotFound(expectedViewName, new[] { expectedViewName }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var view = Mock.Of<IView>();
engine
.Setup(e => e.GetView("~/Index.html", viewName, isPartial))
.Returns(ViewEngineResult.Found(expectedViewName, view));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
var view2 = Mock.Of<IView>();
var view3 = Mock.Of<IView>();
engine1
.Setup(e => e.GetView("~/Index.html", viewName, isPartial))
.Returns(ViewEngineResult.NotFound(expectedViewName, Enumerable.Empty<string>()));
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<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(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<MvcViewOptions>();
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<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "Shared/partial-view" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var view = Mock.Of<IView>();
engine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ true))
.Returns(ViewEngineResult.Found(viewName, view));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
var view2 = Mock.Of<IView>();
var view3 = Mock.Of<IView>();
engine1
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ true))
.Returns(ViewEngineResult.NotFound(viewName, Enumerable.Empty<string>()));
engine2
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ true))
.Returns(ViewEngineResult.Found(viewName, view2));
engine3
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ true))
.Returns(ViewEngineResult.Found(viewName, view3));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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<IViewEngine>(MockBehavior.Strict);
var engine2 = new Mock<IViewEngine>(MockBehavior.Strict);
var engine3 = new Mock<IViewEngine>(MockBehavior.Strict);
engine1
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "1", "2" }));
engine2
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "3" }));
engine3
.Setup(e => e.FindView(It.IsAny<ActionContext>(), viewName, /*isPartial*/ true))
.Returns(ViewEngineResult.NotFound(viewName, new[] { "4", "5" }));
var optionsAccessor = new TestOptionsManager<MvcViewOptions>();
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();
}

View File

@ -130,10 +130,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
var model = new DefaultTemplatesUtilities.ObjectWithScaffoldColumn();
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "DisplayTemplates/String", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "DisplayTemplates/String", /*isMainPage*/ false))
.Returns(ViewEngineResult.Found(string.Empty, new Mock<IView>().Object))
.Verifiable();
var html = DefaultTemplatesUtilities.GetHtmlHelper(new object(), viewEngine: viewEngine.Object);

View File

@ -191,10 +191,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectWithScaffoldColumn();
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound("", Enumerable.Empty<string>()));
var htmlHelper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object);
@ -360,10 +360,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" };
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var helper = DefaultTemplatesUtilities.GetHtmlHelper(
model,
@ -393,10 +393,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" };
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var helper = DefaultTemplatesUtilities.GetHtmlHelper(
model,
@ -425,10 +425,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" };
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var provider = new TestModelMetadataProvider();
@ -467,10 +467,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" };
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var provider = new TestModelMetadataProvider();
@ -508,10 +508,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" };
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var provider = new TestModelMetadataProvider();
@ -550,10 +550,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "True" };
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var provider = new TestModelMetadataProvider();
@ -590,10 +590,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "Model string" };
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object);
helper.ViewData["Property1"] = "ViewData string";
@ -637,10 +637,10 @@ Environment.NewLine;
offset: offset);
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var provider = new TestModelMetadataProvider();
@ -694,10 +694,10 @@ Environment.NewLine;
offset: offset);
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var provider = new TestModelMetadataProvider();
@ -754,10 +754,10 @@ Environment.NewLine;
offset: offset);
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var provider = new TestModelMetadataProvider();
@ -791,10 +791,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = "Model string" };
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object);
@ -840,10 +840,10 @@ Environment.NewLine;
var model = new DefaultTemplatesUtilities.ObjectTemplateModel { Property1 = propertyValue, };
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
var helper = DefaultTemplatesUtilities.GetHtmlHelper(model, viewEngine.Object);
helper.ViewData["Property1"] = "ViewData string";
@ -871,10 +871,10 @@ Environment.NewLine;
}));
var viewEngine = new Mock<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*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<ICompositeViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(v => v.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns(ViewEngineResult.NotFound(string.Empty, Enumerable.Empty<string>()));
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "EditorTemplates/String", /*isPartial*/ true))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), "EditorTemplates/String", /*isMainPage*/ false))
.Returns(ViewEngineResult.Found(string.Empty, new Mock<IView>().Object))
.Verifiable();
var html = DefaultTemplatesUtilities.GetHtmlHelper(new object(), viewEngine: viewEngine.Object);

View File

@ -29,11 +29,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
var viewName = "my-view";
var viewEngine = new Mock<ICompositeViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(e => e.FindView(context, viewName, /*isPartial*/ true))
.Setup(e => e.FindView(context, viewName, /*isMainPage*/ false))
.Returns(ViewEngineResult.Found(viewName, Mock.Of<IView>()))
.Verifiable();
@ -87,11 +87,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
var viewName = "myview";
var viewEngine = new Mock<IViewEngine>(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<string>()));
var viewResult = new PartialViewResult
@ -122,11 +122,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
var viewName = "myview";
var viewEngine = new Mock<IViewEngine>(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<string>()))
.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<IViewEngine>(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<IViewEngine>(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<string>()))
.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<IViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(e => e.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ true))
.Setup(e => e.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ false))
.Returns<string, string, bool>(
(executing, name, isPartial) => ViewEngineResult.NotFound(name, Enumerable.Empty<string>()));
(executing, name, isMainPage) => ViewEngineResult.NotFound(name, Enumerable.Empty<string>()));
viewEngine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ true))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ false))
.Returns<ActionContext, string, bool>(
(context, name, isPartial) => ViewEngineResult.Found(name, Mock.Of<IView>()));
(context, name, isMainPage) => ViewEngineResult.Found(name, Mock.Of<IView>()));
var options = new TestOptionsManager<MvcViewOptions>();
options.Value.ViewEngines.Add(viewEngine.Object);

View File

@ -29,11 +29,11 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
var viewName = "my-view";
var viewEngine = new Mock<ICompositeViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(e => e.FindView(context, viewName, /*isPartial*/ false))
.Setup(e => e.FindView(context, viewName, /*isMainPage*/ true))
.Returns(ViewEngineResult.Found(viewName, Mock.Of<IView>()))
.Verifiable();
@ -87,10 +87,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
var viewName = "myview";
var viewEngine = new Mock<IViewEngine>(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<string>()));
var viewResult = new ViewResult
@ -121,10 +121,10 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
var viewName = "myview";
var viewEngine = new Mock<IViewEngine>(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<string>()));
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<IViewEngine>(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<IViewEngine>(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<string>()));
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<IViewEngine>(MockBehavior.Strict);
viewEngine
.Setup(e => e.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isPartial*/ false))
.Setup(e => e.GetView(/*executingFilePath*/ null, It.IsAny<string>(), /*isMainPage*/ true))
.Returns<string, string, bool>(
(path, name, partial) => ViewEngineResult.NotFound(name, Enumerable.Empty<string>()));
viewEngine
.Setup(e => e.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ false))
.Setup(e => e.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ true))
.Returns<ActionContext, string, bool>(
(context, name, partial) => ViewEngineResult.Found(name, Mock.Of<IView>()));

View File

@ -39,11 +39,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<ActionContext>(), It.IsAny<string>(), /*isPartial*/ false))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound("MyView", Enumerable.Empty<string>()))
.Verifiable();
@ -76,11 +76,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<string>()))
.Verifiable();
viewEngine
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isPartial*/ false))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound("MyView", new[] { "Location1", "Location2" }))
.Verifiable();
@ -115,11 +115,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<ActionContext>(), It.IsAny<string>(), /*isPartial*/ false))
.Setup(v => v.FindView(It.IsAny<ActionContext>(), It.IsAny<string>(), /*isMainPage*/ true))
.Returns(ViewEngineResult.NotFound("MyView", new[] { "Location3", "Location4" }))
.Verifiable();
@ -162,11 +162,11 @@ namespace Microsoft.AspNet.Mvc
var viewEngine = new Mock<IViewEngine>(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<string>()))
.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();

View File

@ -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<string>());
}
public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isPartial)
public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
{
return ViewEngineResult.NotFound(viewPath, Enumerable.Empty<string>());
}

View File

@ -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<string> ExpandViewLocations(ViewLocationExpanderContext context,
IEnumerable<string> viewLocations)
public virtual IEnumerable<string> ExpandViewLocations(
ViewLocationExpanderContext context,
IEnumerable<string> viewLocations)
{
if (context.IsPartial)
if (context.IsMainPage)
{
return ExpandViewLocationsCore(viewLocations);
return viewLocations;
}
return viewLocations;
return ExpandViewLocationsCore(viewLocations);
}
private IEnumerable<string> ExpandViewLocationsCore(IEnumerable<string> viewLocations)
{
yield return "/Shared-Views/{1}/{0}.cshtml";
foreach (var location in viewLocations)
{
yield return "/Shared-Views/{1}/{0}.cshtml";
yield return location;
}
}

View File

@ -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 =>
{