parent
cf22fe1973
commit
4c9f19aafc
|
|
@ -19,7 +19,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
private IViewEngine _viewEngine;
|
||||
|
||||
[NonAction]
|
||||
public void Initialize(IServiceProvider serviceProvider, IViewEngine viewEngine)
|
||||
public virtual void Initialize(IServiceProvider serviceProvider, IViewEngine viewEngine)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_viewEngine = viewEngine;
|
||||
|
|
@ -73,27 +73,48 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ViewResult"/> object that renders a view to the response.
|
||||
/// </summary>
|
||||
/// <returns>The created <see cref="ViewResult"/> object for the response.</returns>
|
||||
[NonAction]
|
||||
public ViewResult View()
|
||||
public virtual ViewResult View()
|
||||
{
|
||||
return View(view: null);
|
||||
return View(viewName: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ViewResult"/> object by specifying a <paramref name="viewName"/>.
|
||||
/// </summary>
|
||||
/// <param name="viewName">The name of the view that is rendered to the response.</param>
|
||||
/// <returns>The created <see cref="ViewResult"/> object for the response.</returns>
|
||||
[NonAction]
|
||||
public ViewResult View(string view)
|
||||
public virtual ViewResult View(string viewName)
|
||||
{
|
||||
return View(view, model: null);
|
||||
return View(viewName, model: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ViewResult"/> object by specifying a <paramref name="model"/>
|
||||
/// to be rendered by the view.
|
||||
/// </summary>
|
||||
/// <param name="model">The model that is rendered by the view.</param>
|
||||
/// <returns>The created <see cref="ViewResult"/> object for the response.</returns>
|
||||
[NonAction]
|
||||
// TODO #110: May need <TModel> here and in the overload below.
|
||||
public ViewResult View(object model)
|
||||
public virtual ViewResult View(object model)
|
||||
{
|
||||
return View(view: null, model: model);
|
||||
return View(viewName: null, model: model);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ViewResult"/> object by specifying a <paramref name="viewName"/>
|
||||
/// and the <paramref name="model"/> to be rendered by the view.
|
||||
/// </summary>
|
||||
/// <param name="viewName">The name of the view that is rendered to the response.</param>
|
||||
/// <param name="model">The model that is rendered by the view.</param>
|
||||
/// <returns>The created <see cref="ViewResult"/> object for the response.</returns>
|
||||
[NonAction]
|
||||
public ViewResult View(string view, object model)
|
||||
public virtual ViewResult View(string viewName, object model)
|
||||
{
|
||||
// Do not override ViewData.Model unless passed a non-null value.
|
||||
if (model != null)
|
||||
|
|
@ -103,25 +124,45 @@ namespace Microsoft.AspNet.Mvc
|
|||
|
||||
return new ViewResult(_serviceProvider, _viewEngine)
|
||||
{
|
||||
ViewName = view,
|
||||
ViewName = viewName,
|
||||
ViewData = ViewData,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ContentResult"/> object by specifying a <paramref name="content"/> string.
|
||||
/// </summary>
|
||||
/// <param name="content">The content to write to the response.</param>
|
||||
/// <returns>The created <see cref="ContentResult"/> object for the response.</returns>
|
||||
[NonAction]
|
||||
public ContentResult Content(string content)
|
||||
public virtual ContentResult Content(string content)
|
||||
{
|
||||
return Content(content, contentType: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ContentResult"/> object by specifying a <paramref name="content"/> string
|
||||
/// and a content type.
|
||||
/// </summary>
|
||||
/// <param name="content">The content to write to the response.</param>
|
||||
/// <param name="contentType">The content type (MIME type).</param>
|
||||
/// <returns>The created <see cref="ContentResult"/> object for the response.</returns>
|
||||
[NonAction]
|
||||
public ContentResult Content(string content, string contentType)
|
||||
public virtual ContentResult Content(string content, string contentType)
|
||||
{
|
||||
return Content(content, contentType, contentEncoding: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="ContentResult"/> object by specifying a <paramref name="content"/> string,
|
||||
/// a <paramref name="contentType"/>, and <paramref name="contentEncoding"/>.
|
||||
/// </summary>
|
||||
/// <param name="content">The content to write to the response.</param>
|
||||
/// <param name="contentType">The content type (MIME type).</param>
|
||||
/// <param name="contentEncoding">The content encoding.</param>
|
||||
/// <returns>The created <see cref="ContentResult"/> object for the response.</returns>
|
||||
[NonAction]
|
||||
public ContentResult Content(string content, string contentType, Encoding contentEncoding)
|
||||
public virtual ContentResult Content(string content, string contentType, Encoding contentEncoding)
|
||||
{
|
||||
var result = new ContentResult
|
||||
{
|
||||
|
|
@ -141,12 +182,24 @@ namespace Microsoft.AspNet.Mvc
|
|||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="JsonResult"/> object that serializes the specified <paramref name="data"/> object
|
||||
/// to JSON.
|
||||
/// </summary>
|
||||
/// <param name="data">The object to serialize.</param>
|
||||
/// <returns>The created <see cref="JsonResult"/> that serializes the specified <paramref name="data"/>
|
||||
/// to JSON format for the response.</returns>
|
||||
[NonAction]
|
||||
public JsonResult Json(object value)
|
||||
public virtual JsonResult Json(object data)
|
||||
{
|
||||
return new JsonResult(value);
|
||||
return new JsonResult(data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RedirectResult"/> object that redirects to the specified <paramref name="url"/>.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to redirect to.</param>
|
||||
/// <returns>The created <see cref="RedirectResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public virtual RedirectResult Redirect(string url)
|
||||
{
|
||||
|
|
@ -158,6 +211,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
return new RedirectResult(url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RedirectResult"/> object with <see cref="RedirectResult.Permanent"/> set to true
|
||||
/// using the specified <paramref name="url"/>.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to redirect to.</param>
|
||||
/// <returns>The created <see cref="RedirectResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public virtual RedirectResult RedirectPermanent(string url)
|
||||
{
|
||||
|
|
@ -169,104 +228,211 @@ namespace Microsoft.AspNet.Mvc
|
|||
return new RedirectResult(url, permanent: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified action using the <paramref name="actionName"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToActionResult RedirectToAction(string actionName)
|
||||
public virtual RedirectToActionResult RedirectToAction(string actionName)
|
||||
{
|
||||
return RedirectToAction(actionName, routeValues: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified action using the <paramref name="actionName"/>
|
||||
/// and <paramref name="routeValues"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <param name="routeValues">The parameters for a route.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToActionResult RedirectToAction(string actionName, object routeValues)
|
||||
public virtual RedirectToActionResult RedirectToAction(string actionName, object routeValues)
|
||||
{
|
||||
return RedirectToAction(actionName, controllerName: null, routeValues: routeValues);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified action using the <paramref name="actionName"/>
|
||||
/// and the <paramref name="controllerName"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <param name="controllerName">The name of the controller.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToActionResult RedirectToAction(string actionName, string controllerName)
|
||||
public virtual RedirectToActionResult RedirectToAction(string actionName, string controllerName)
|
||||
{
|
||||
return RedirectToAction(actionName, controllerName, routeValues: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified action using the specified <paramref name="actionName"/>,
|
||||
/// <paramref name="controllerName"/>, and <paramref name="routeValues"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <param name="controllerName">The name of the controller.</param>
|
||||
/// <param name="routeValues">The parameters for a route.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToActionResult RedirectToAction(string actionName, string controllerName,
|
||||
public virtual RedirectToActionResult RedirectToAction(string actionName, string controllerName,
|
||||
object routeValues)
|
||||
{
|
||||
return new RedirectToActionResult(Url, actionName, controllerName,
|
||||
TypeHelper.ObjectToDictionary(routeValues));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified action with <see cref="RedirectToActionResult.Permanent"/> set to true
|
||||
/// using the specified <paramref name="actionName"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToActionResult RedirectToActionPermanent(string actionName)
|
||||
public virtual RedirectToActionResult RedirectToActionPermanent(string actionName)
|
||||
{
|
||||
return RedirectToActionPermanent(actionName, routeValues: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified action with <see cref="RedirectToActionResult.Permanent"/> set to true
|
||||
/// using the specified <paramref name="actionName"/> and <paramref name="routeValues"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <param name="routeValues">The parameters for a route.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToActionResult RedirectToActionPermanent(string actionName, object routeValues)
|
||||
public virtual RedirectToActionResult RedirectToActionPermanent(string actionName, object routeValues)
|
||||
{
|
||||
return RedirectToActionPermanent(actionName, controllerName: null, routeValues: routeValues);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified action with <see cref="RedirectToActionResult.Permanent"/> set to true
|
||||
/// using the specified <paramref name="actionName"/> and <paramref name="controllerName"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <param name="controllerName">The name of the controller.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToActionResult RedirectToActionPermanent(string actionName, string controllerName)
|
||||
public virtual RedirectToActionResult RedirectToActionPermanent(string actionName, string controllerName)
|
||||
{
|
||||
return RedirectToActionPermanent(actionName, controllerName, routeValues: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified action with <see cref="RedirectToActionResult.Permanent"/> set to true
|
||||
/// using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
|
||||
/// and <paramref name="routeValues"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <param name="controllerName">The name of the controller.</param>
|
||||
/// <param name="routeValues">The parameters for a route.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToActionResult RedirectToActionPermanent(string actionName, string controllerName,
|
||||
public virtual RedirectToActionResult RedirectToActionPermanent(string actionName, string controllerName,
|
||||
object routeValues)
|
||||
{
|
||||
return new RedirectToActionResult(Url, actionName, controllerName,
|
||||
TypeHelper.ObjectToDictionary(routeValues), permanent: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified route using the specified <paramref name="routeName"/>.
|
||||
/// </summary>
|
||||
/// <param name="routeName">The name of the route.</param>
|
||||
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToRouteResult RedirectToRoute(string routeName)
|
||||
public virtual RedirectToRouteResult RedirectToRoute(string routeName)
|
||||
{
|
||||
return RedirectToRoute(routeName, routeValues: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified route using the specified <paramref name="routeValues"/>.
|
||||
/// </summary>
|
||||
/// <param name="routeValues">The parameters for a route.</param>
|
||||
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToRouteResult RedirectToRoute(object routeValues)
|
||||
public virtual RedirectToRouteResult RedirectToRoute(object routeValues)
|
||||
{
|
||||
return RedirectToRoute(routeName: null, routeValues: routeValues);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified route using the specified <paramref name="routeName"/>
|
||||
/// and <paramref name="routeValues"/>.
|
||||
/// </summary>
|
||||
/// <param name="routeName">The name of the route.</param>
|
||||
/// <param name="routeValues">The parameters for a route.</param>
|
||||
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToRouteResult RedirectToRoute(string routeName, object routeValues)
|
||||
public virtual RedirectToRouteResult RedirectToRoute(string routeName, object routeValues)
|
||||
{
|
||||
return new RedirectToRouteResult(Url, routeName, routeValues);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified route with <see cref="RedirectToRouteResult.Permanent"/> set to true
|
||||
/// using the specified <paramref name="routeName"/>.
|
||||
/// </summary>
|
||||
/// <param name="routeName">The name of the route.</param>
|
||||
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToRouteResult RedirectToRoutePermanent(string routeName)
|
||||
public virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName)
|
||||
{
|
||||
return RedirectToRoutePermanent(routeName, routeValues: null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified route with <see cref="RedirectToRouteResult.Permanent"/> set to true
|
||||
/// using the specified <paramref name="routeValues"/>.
|
||||
/// </summary>
|
||||
/// <param name="routeValues">The parameters for a route.</param>
|
||||
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToRouteResult RedirectToRoutePermanent(object routeValues)
|
||||
public virtual RedirectToRouteResult RedirectToRoutePermanent(object routeValues)
|
||||
{
|
||||
return RedirectToRoutePermanent(routeName: null, routeValues: routeValues);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the specified route with <see cref="RedirectToRouteResult.Permanent"/> set to true
|
||||
/// using the specified <paramref name="routeName"/> and <paramref name="routeValues"/>.
|
||||
/// </summary>
|
||||
/// <param name="routeName">The name of the route.</param>
|
||||
/// <param name="routeValues">The parameters for a route.</param>
|
||||
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public RedirectToRouteResult RedirectToRoutePermanent(string routeName, object routeValues)
|
||||
public virtual RedirectToRouteResult RedirectToRoutePermanent(string routeName, object routeValues)
|
||||
{
|
||||
return new RedirectToRouteResult(Url, routeName, routeValues, permanent: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before the action method is invoked.
|
||||
/// </summary>
|
||||
/// <param name="context">The action executing context.</param>
|
||||
[NonAction]
|
||||
public virtual void OnActionExecuting([NotNull] ActionExecutingContext context)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after the action method is invoked.
|
||||
/// </summary>
|
||||
/// <param name="context">The action executed context.</param>
|
||||
[NonAction]
|
||||
public virtual void OnActionExecuted([NotNull] ActionExecutedContext context)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called before the action method is invoked.
|
||||
/// </summary>
|
||||
/// <param name="context">The action executing context.</param>
|
||||
/// <param name="next">The <see cref="ActionExecutionDelegate"/> to execute. Invoke this delegate in the body
|
||||
/// of <see cref="OnActionExecutionAsync" /> to continue execution of the action.</param>
|
||||
/// <returns>A <see cref="Task"/> instance.</returns>
|
||||
[NonAction]
|
||||
public virtual async Task OnActionExecutionAsync(
|
||||
[NotNull] ActionExecutingContext context,
|
||||
|
|
|
|||
|
|
@ -14,6 +14,34 @@ namespace Microsoft.AspNet.Mvc.Core.Test
|
|||
{
|
||||
public class RedirectResultTest
|
||||
{
|
||||
[Fact]
|
||||
public void RedirectResult_Constructor_WithParameterUrl_SetsResultUrlAndNotPermanent()
|
||||
{
|
||||
// Arrange
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = new RedirectResult(url);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectResult_Constructor_WithParameterUrlAndPermanent_SetsResultUrlAndPermanent()
|
||||
{
|
||||
// Arrange
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = new RedirectResult(url, permanent: true);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", "/Home/About", "/Home/About")]
|
||||
[InlineData("/myapproot", "/test", "/test")]
|
||||
|
|
|
|||
|
|
@ -52,37 +52,41 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void Redirect_Temporary_SetsSameUrl()
|
||||
public void Redirect_WithParameterUrl_SetsRedirectResultSameUrl()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = controller.Redirect("sample\\url");
|
||||
var result = controller.Redirect(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectResult>(result);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Equal("sample\\url", result.Url);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Redirect_Permanent_SetsSameUrl()
|
||||
public void RedirectPermanent_WithParameterUrl_SetsRedirectResultPermanentAndSameUrl()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = controller.RedirectPermanent("sample\\url");
|
||||
var result = controller.RedirectPermanent(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectResult>(result);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Equal("sample\\url", result.Url);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
public void Redirect_NullOrEmptyUrl_Throws(string url)
|
||||
public void Redirect_WithParameter_NullOrEmptyUrl_Throws(string url)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -95,7 +99,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
public void RedirectPermanent_NullOrEmptyUrl_Throws(string url)
|
||||
public void RedirectPermanent_WithParameter_NullOrEmptyUrl_Throws(string url)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -106,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectToAction_Temporary_Returns_SameAction()
|
||||
public void RedirectToAction_WithParameterActionName_SetsResultActionName()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -115,12 +119,13 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var resultTemporary = controller.RedirectToAction("SampleAction");
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectToAction_Permanent_Returns_SameAction()
|
||||
public void RedirectToActionPermanent_WithParameterActionName_SetsResultActionNameAndPermanent()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -129,6 +134,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var resultPermanent = controller.RedirectToActionPermanent("SampleAction");
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
}
|
||||
|
|
@ -137,7 +143,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
[InlineData("SampleController")]
|
||||
public void RedirectToAction_Temporary_Returns_SameController(string controllerName)
|
||||
public void RedirectToAction_WithParameterActionAndControllerName_SetsEqualNames(string controllerName)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -146,6 +152,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var resultTemporary = controller.RedirectToAction("SampleAction", controllerName);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
Assert.Equal(controllerName, resultTemporary.ControllerName);
|
||||
|
|
@ -155,7 +162,8 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
[InlineData("SampleController")]
|
||||
public void RedirectToAction_Permanent_Returns_SameController(string controllerName)
|
||||
public void RedirectToActionPermanent_WithParameterActionAndControllerName_SetsEqualNames(
|
||||
string controllerName)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -164,6 +172,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var resultPermanent = controller.RedirectToActionPermanent("SampleAction", controllerName);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
Assert.Equal(controllerName, resultPermanent.ControllerName);
|
||||
|
|
@ -171,7 +180,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
|
||||
[Theory]
|
||||
[MemberData("RedirectTestData")]
|
||||
public void RedirectToAction_Temporary_Returns_SameActionControllerAndRouteValues(object routeValues)
|
||||
public void RedirectToAction_WithParameterActionControllerRouteValues_SetsResultProperties(object routeValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -180,6 +189,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var resultTemporary = controller.RedirectToAction("SampleAction", "SampleController", routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
Assert.Equal("SampleController", resultTemporary.ControllerName);
|
||||
|
|
@ -188,15 +198,20 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
|
||||
[Theory]
|
||||
[MemberData("RedirectTestData")]
|
||||
public void RedirectToAction_Permanent_Returns_SameActionControllerAndRouteValues(object routeValues)
|
||||
public void RedirectToActionPermanent_WithParameterActionControllerRouteValues_SetsResultProperties(
|
||||
object routeValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToActionPermanent("SampleAction", "SampleController", routeValues);
|
||||
var resultPermanent = controller.RedirectToActionPermanent(
|
||||
"SampleAction",
|
||||
"SampleController",
|
||||
routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
Assert.Equal("SampleController", resultPermanent.ControllerName);
|
||||
|
|
@ -205,7 +220,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
|
||||
[Theory]
|
||||
[MemberData("RedirectTestData")]
|
||||
public void RedirectToAction_Temporary_Returns_SameActionAndRouteValues(object routeValues)
|
||||
public void RedirectToAction_WithParameterActionAndRouteValues_SetsResultProperties(object routeValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -214,6 +229,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var resultTemporary = controller.RedirectToAction(actionName: null, routeValues: routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Null(resultTemporary.ActionName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultTemporary.RouteValues);
|
||||
|
|
@ -221,7 +237,8 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
|
||||
[Theory]
|
||||
[MemberData("RedirectTestData")]
|
||||
public void RedirectToAction_Permanent_Returns_SameActionAndRouteValues(object routeValues)
|
||||
public void RedirectToActionPermanent_WithParameterActionAndRouteValues_SetsResultProperties(
|
||||
object routeValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -230,6 +247,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var resultPermanent = controller.RedirectToActionPermanent(null, routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Null(resultPermanent.ActionName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultPermanent.RouteValues);
|
||||
|
|
@ -237,7 +255,7 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
|
||||
[Theory]
|
||||
[MemberData("RedirectTestData")]
|
||||
public void RedirectToRoute_Temporary_Returns_SameRouteValues(object routeValues)
|
||||
public void RedirectToRoute_WithParameterRouteValues_SetsResultEqualRouteValues(object routeValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -246,13 +264,15 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var resultTemporary = controller.RedirectToRoute(routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData("RedirectTestData")]
|
||||
public void RedirectToRoute_Permanent_Returns_SameRouteValues(object routeValues)
|
||||
public void RedirectToRoutePermanent_WithParameterRouteValues_SetsResultEqualRouteValuesAndPermanent(
|
||||
object routeValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
|
|
@ -261,10 +281,81 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
var resultPermanent = controller.RedirectToRoutePermanent(routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectToRoute_WithParameterRouteName_SetsResultSameRouteName()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
var routeName = "CustomRouteName";
|
||||
|
||||
// Act
|
||||
var resultTemporary = controller.RedirectToRoute(routeName);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Same(routeName, resultTemporary.RouteName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectToRoutePermanent_WithParameterRouteName_SetsResultSameRouteNameAndPermanent()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
var routeName = "CustomRouteName";
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToRoutePermanent(routeName);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Same(routeName, resultPermanent.RouteName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData("RedirectTestData")]
|
||||
public void RedirectToRoute_WithParameterRouteNameAndRouteValues_SetsResultSameRouteNameAndRouteValues(
|
||||
object routeValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
var routeName = "CustomRouteName";
|
||||
|
||||
// Act
|
||||
var resultTemporary = controller.RedirectToRoute(routeName, routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Same(routeName, resultTemporary.RouteName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData("RedirectTestData")]
|
||||
public void RedirectToRoutePermanent_WithParameterRouteNameAndRouteValues_SetsResultProperties(
|
||||
object routeValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new Controller();
|
||||
var routeName = "CustomRouteName";
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToRoutePermanent(routeName, routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Same(routeName, resultPermanent.RouteName);
|
||||
Assert.Equal(TypeHelper.ObjectToDictionary(routeValues), resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData("PublicNormalMethodsFromController")]
|
||||
public void NonActionAttribute_IsOnEveryPublicNormalMethodFromController(MethodInfo method)
|
||||
|
|
@ -419,14 +510,17 @@ namespace Microsoft.AspNet.Mvc.Test
|
|||
get
|
||||
{
|
||||
yield return new object[] { null };
|
||||
yield return
|
||||
new object[] {
|
||||
new Dictionary<string, string>() { { "hello", "world" } }
|
||||
yield return new object[]
|
||||
{
|
||||
new Dictionary<string, string>() { { "hello", "world" } },
|
||||
};
|
||||
yield return
|
||||
new object[] {
|
||||
new RouteValueDictionary(new Dictionary<string, string>() {
|
||||
{ "test", "case" }, { "sample", "route" } })
|
||||
yield return new object[]
|
||||
{
|
||||
new RouteValueDictionary(new Dictionary<string, string>()
|
||||
{
|
||||
{ "test", "case" },
|
||||
{ "sample", "route" },
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue