diff --git a/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs b/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs
index c1864fa5c0..a2375db19e 100644
--- a/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs
+++ b/src/Microsoft.AspNet.Mvc.Razor/RazorViewEngine.cs
@@ -3,10 +3,10 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Globalization;
using Microsoft.AspNet.Mvc.Razor.OptionDescriptors;
using Microsoft.AspNet.Mvc.Rendering;
-using Microsoft.AspNet.PageExecutionInstrumentation;
using Microsoft.Framework.DependencyInjection;
namespace Microsoft.AspNet.Mvc.Razor
@@ -69,15 +69,25 @@ namespace Microsoft.AspNet.Mvc.Razor
///
public ViewEngineResult FindView([NotNull] ActionContext context,
- [NotNull] string viewName)
+ string viewName)
{
+ if (string.IsNullOrEmpty(viewName))
+ {
+ throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(viewName));
+ }
+
return CreateViewEngineResult(context, viewName, partial: false);
}
///
public ViewEngineResult FindPartialView([NotNull] ActionContext context,
- [NotNull] string partialViewName)
+ string partialViewName)
{
+ if (string.IsNullOrEmpty(partialViewName))
+ {
+ throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(partialViewName));
+ }
+
return CreateViewEngineResult(context, partialViewName, partial: true);
}
@@ -191,6 +201,7 @@ namespace Microsoft.AspNet.Mvc.Razor
private static bool IsSpecificPath(string name)
{
+ Debug.Assert(!string.IsNullOrEmpty(name));
return name[0] == '~' || name[0] == '/';
}
}
diff --git a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineTest.cs b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineTest.cs
index b8602d9238..e1c8f01837 100644
--- a/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Razor.Test/RazorViewEngineTest.cs
@@ -8,6 +8,7 @@ using Microsoft.AspNet.Mvc.Razor.OptionDescriptors;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.PipelineCore;
using Microsoft.AspNet.Routing;
+using Microsoft.AspNet.Testing;
using Moq;
using Xunit;
@@ -37,6 +38,19 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
}
}
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ public void FindView_ThrowsIfViewNameIsNullOrEmpty(string viewName)
+ {
+ // Arrange
+ var viewEngine = CreateViewEngine();
+ var context = GetActionContext(_controllerTestContext);
+
+ // Act & Assert
+ ExceptionAssert.ThrowsArgumentNullOrEmpty(() => viewEngine.FindView(context, viewName), "viewName");
+ }
+
[Theory]
[MemberData(nameof(InvalidViewNameValues))]
public void FindView_WithFullPathReturnsNotFound_WhenPathDoesNotMatchExtension(string viewName)
@@ -69,6 +83,20 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
Assert.False(result.Success);
}
+ [Theory]
+ [InlineData(null)]
+ [InlineData("")]
+ public void FindPartialView_ThrowsIfViewNameIsNullOrEmpty(string partialViewName)
+ {
+ // Arrange
+ var viewEngine = CreateViewEngine();
+ var context = GetActionContext(_controllerTestContext);
+
+ // Act & Assert
+ ExceptionAssert.ThrowsArgumentNullOrEmpty(() => viewEngine.FindPartialView(context, partialViewName),
+ "partialViewName");
+ }
+
[Theory]
[MemberData(nameof(InvalidViewNameValues))]
public void FindPartialView_WithFullPathReturnsNotFound_WhenPathDoesNotMatchExtension(string partialViewName)