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);
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// The method '{0}' cannot be invoked by this view.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -78,16 +78,15 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
if (nameRepresentsPath)
|
||||
{
|
||||
if (!viewName.EndsWith(ViewExtension, StringComparison.OrdinalIgnoreCase))
|
||||
if (viewName.EndsWith(ViewExtension, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
Resources.FormatViewMustEndInExtension(viewName, ViewExtension));
|
||||
var page = _pageFactory.CreateInstance(viewName);
|
||||
if (page != null)
|
||||
{
|
||||
return CreateFoundResult(page, viewName, partial);
|
||||
}
|
||||
}
|
||||
|
||||
var page = _pageFactory.CreateInstance(viewName);
|
||||
|
||||
return page != null ? CreateFoundResult(page, viewName, partial) :
|
||||
ViewEngineResult.NotFound(viewName, new[] { viewName });
|
||||
return ViewEngineResult.NotFound(viewName, new[] { viewName });
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -159,9 +159,6 @@
|
|||
<data name="ViewContextMustBeSet" xml:space="preserve">
|
||||
<value>'{0} must be set to access '{1}'.</value>
|
||||
</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">
|
||||
<value>The method '{0}' cannot be invoked by this view.</value>
|
||||
</data>
|
||||
|
|
|
|||
|
|
@ -38,15 +38,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
|
||||
[Theory]
|
||||
[MemberData("InvalidViewNameValues")]
|
||||
public void FindViewFullPathFailsWithNoCshtmlEnding(string viewName)
|
||||
public void FindView_WithFullPathReturnsNotFound_WhenPathDoesNotMatchExtension(string viewName)
|
||||
{
|
||||
// Arrange
|
||||
var viewEngine = CreateSearchLocationViewEngineTester();
|
||||
var context = GetActionContext(_controllerTestContext);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
viewEngine.FindView(context, viewName));
|
||||
// Act
|
||||
var result = viewEngine.FindView(context, viewName);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.Success);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
@ -68,15 +70,17 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
|
||||
[Theory]
|
||||
[MemberData("InvalidViewNameValues")]
|
||||
public void FindPartialViewFullPathFailsWithNoCshtmlEnding(string partialViewName)
|
||||
public void FindPartialView_WithFullPathReturnsNotFound_WhenPathDoesNotMatchExtension(string partialViewName)
|
||||
{
|
||||
// Arrange
|
||||
var viewEngine = CreateSearchLocationViewEngineTester();
|
||||
var context = GetActionContext(_controllerTestContext);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<InvalidOperationException>(() =>
|
||||
viewEngine.FindPartialView(context, partialViewName));
|
||||
// Act
|
||||
var result = viewEngine.FindPartialView(context, partialViewName);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.Success);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
|
|
|||
Loading…
Reference in New Issue