Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

ViewEngine shouldn't throw when it doesn't know about the extension #994

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions src/Microsoft.AspNet.Mvc.Razor/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 7 additions & 8 deletions src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,15 @@ private ViewEngineResult CreateViewEngineResult(ActionContext context,

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
{
Expand Down
3 changes: 0 additions & 3 deletions src/Microsoft.AspNet.Mvc.Razor/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
20 changes: 12 additions & 8 deletions test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ public static IEnumerable<string[]> InvalidViewNameValues

[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]
Expand All @@ -68,15 +70,17 @@ public void FindViewFullPathSucceedsWithCshtmlEnding(string viewName)

[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]
Expand Down