ViewEngine shouldn't throw when it doesn't know about the extension
Fixes #984
This commit is contained in:
parent
77066a3ade
commit
fb773f4814
|
|
@ -234,22 +234,6 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
return string.Format(CultureInfo.CurrentCulture, GetString("ViewContextMustBeSet"), p0, p1);
|
return string.Format(CultureInfo.CurrentCulture, GetString("ViewContextMustBeSet"), p0, p1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// View '{0}' must have extension '{1}' when the view represents a full path.
|
|
||||||
/// </summary>
|
|
||||||
internal static string ViewMustEndInExtension
|
|
||||||
{
|
|
||||||
get { return GetString("ViewMustEndInExtension"); }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// View '{0}' must have extension '{1}' when the view represents a full path.
|
|
||||||
/// </summary>
|
|
||||||
internal static string FormatViewMustEndInExtension(object p0, object p1)
|
|
||||||
{
|
|
||||||
return string.Format(CultureInfo.CurrentCulture, GetString("ViewMustEndInExtension"), p0, p1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The method '{0}' cannot be invoked by this view.
|
/// The method '{0}' cannot be invoked by this view.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -78,16 +78,15 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
|
|
||||||
if (nameRepresentsPath)
|
if (nameRepresentsPath)
|
||||||
{
|
{
|
||||||
if (!viewName.EndsWith(ViewExtension, StringComparison.OrdinalIgnoreCase))
|
if (viewName.EndsWith(ViewExtension, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException(
|
var page = _pageFactory.CreateInstance(viewName);
|
||||||
Resources.FormatViewMustEndInExtension(viewName, ViewExtension));
|
if (page != null)
|
||||||
|
{
|
||||||
|
return CreateFoundResult(page, viewName, partial);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return ViewEngineResult.NotFound(viewName, new[] { viewName });
|
||||||
var page = _pageFactory.CreateInstance(viewName);
|
|
||||||
|
|
||||||
return page != null ? CreateFoundResult(page, viewName, partial) :
|
|
||||||
ViewEngineResult.NotFound(viewName, new[] { viewName });
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -159,9 +159,6 @@
|
||||||
<data name="ViewContextMustBeSet" xml:space="preserve">
|
<data name="ViewContextMustBeSet" xml:space="preserve">
|
||||||
<value>'{0} must be set to access '{1}'.</value>
|
<value>'{0} must be set to access '{1}'.</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="ViewMustEndInExtension" xml:space="preserve">
|
|
||||||
<value>View '{0}' must have extension '{1}' when the view represents a full path.</value>
|
|
||||||
</data>
|
|
||||||
<data name="View_MethodCannotBeCalled" xml:space="preserve">
|
<data name="View_MethodCannotBeCalled" xml:space="preserve">
|
||||||
<value>The method '{0}' cannot be invoked by this view.</value>
|
<value>The method '{0}' cannot be invoked by this view.</value>
|
||||||
</data>
|
</data>
|
||||||
|
|
|
||||||
|
|
@ -38,15 +38,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData("InvalidViewNameValues")]
|
[MemberData("InvalidViewNameValues")]
|
||||||
public void FindViewFullPathFailsWithNoCshtmlEnding(string viewName)
|
public void FindView_WithFullPathReturnsNotFound_WhenPathDoesNotMatchExtension(string viewName)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var viewEngine = CreateSearchLocationViewEngineTester();
|
var viewEngine = CreateSearchLocationViewEngineTester();
|
||||||
var context = GetActionContext(_controllerTestContext);
|
var context = GetActionContext(_controllerTestContext);
|
||||||
|
|
||||||
// Act & Assert
|
// Act
|
||||||
Assert.Throws<InvalidOperationException>(() =>
|
var result = viewEngine.FindView(context, viewName);
|
||||||
viewEngine.FindView(context, viewName));
|
|
||||||
|
// Assert
|
||||||
|
Assert.False(result.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
@ -68,15 +70,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[MemberData("InvalidViewNameValues")]
|
[MemberData("InvalidViewNameValues")]
|
||||||
public void FindPartialViewFullPathFailsWithNoCshtmlEnding(string partialViewName)
|
public void FindPartialView_WithFullPathReturnsNotFound_WhenPathDoesNotMatchExtension(string partialViewName)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var viewEngine = CreateSearchLocationViewEngineTester();
|
var viewEngine = CreateSearchLocationViewEngineTester();
|
||||||
var context = GetActionContext(_controllerTestContext);
|
var context = GetActionContext(_controllerTestContext);
|
||||||
|
|
||||||
// Act & Assert
|
// Act
|
||||||
Assert.Throws<InvalidOperationException>(() =>
|
var result = viewEngine.FindPartialView(context, partialViewName);
|
||||||
viewEngine.FindPartialView(context, partialViewName));
|
|
||||||
|
// Assert
|
||||||
|
Assert.False(result.Success);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue