parent
36e272fdc2
commit
1a8ac88da7
|
|
@ -328,7 +328,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// <returns>The created <see cref="NoContentResult"/> object for the response.</returns>
|
||||
[NonAction]
|
||||
public virtual NoContentResult NoContent()
|
||||
{
|
||||
{
|
||||
return new NoContentResult();
|
||||
}
|
||||
|
||||
|
|
@ -387,6 +387,42 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
return new RedirectResult(url, permanent: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RedirectResult"/> object with <see cref="RedirectResult.Permanent"/> set to false
|
||||
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status307TemporaryRedirect"/>)
|
||||
/// 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 RedirectPreserveMethod(string url)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url));
|
||||
}
|
||||
|
||||
return new RedirectResult(url: url, permanent: false, preserveMethod: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="RedirectResult"/> object with <see cref="RedirectResult.Permanent"/> set to true
|
||||
/// and <see cref="RedirectResult.PreserveMethod"/> set to true (<see cref="StatusCodes.Status308PermanentRedirect"/>)
|
||||
/// 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 RedirectPermanentPreserveMethod(string url)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(url));
|
||||
}
|
||||
|
||||
return new RedirectResult(url: url, permanent: true, preserveMethod: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalRedirectResult"/> object that redirects
|
||||
/// (<see cref="StatusCodes.Status302Found"/>) to the specified local <paramref name="localUrl"/>.
|
||||
|
|
@ -421,6 +457,42 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
return new LocalRedirectResult(localUrl, permanent: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalRedirectResult"/> object with <see cref="LocalRedirectResult.Permanent"/> set to
|
||||
/// false and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
|
||||
/// (<see cref="StatusCodes.Status307TemporaryRedirect"/>) using the specified <paramref name="localUrl"/>.
|
||||
/// </summary>
|
||||
/// <param name="localUrl">The local URL to redirect to.</param>
|
||||
/// <returns>The created <see cref="LocalRedirectResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public virtual LocalRedirectResult LocalRedirectPreserveMethod(string localUrl)
|
||||
{
|
||||
if (string.IsNullOrEmpty(localUrl))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(localUrl));
|
||||
}
|
||||
|
||||
return new LocalRedirectResult(localUrl: localUrl, permanent: false, preserveMethod: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="LocalRedirectResult"/> object with <see cref="LocalRedirectResult.Permanent"/> set to
|
||||
/// true and <see cref="LocalRedirectResult.PreserveMethod"/> set to true
|
||||
/// (<see cref="StatusCodes.Status308PermanentRedirect"/>) using the specified <paramref name="localUrl"/>.
|
||||
/// </summary>
|
||||
/// <param name="localUrl">The local URL to redirect to.</param>
|
||||
/// <returns>The created <see cref="LocalRedirectResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public virtual LocalRedirectResult LocalRedirectPermanentPreserveMethod(string localUrl)
|
||||
{
|
||||
if (string.IsNullOrEmpty(localUrl))
|
||||
{
|
||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(localUrl));
|
||||
}
|
||||
|
||||
return new LocalRedirectResult(localUrl: localUrl, permanent: true, preserveMethod: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified action using the <paramref name="actionName"/>.
|
||||
/// </summary>
|
||||
|
|
@ -514,6 +586,36 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified action with
|
||||
/// <see cref="RedirectToActionResult.Permanent"/> set to false and <see cref="RedirectToActionResult.PreserveMethod"/>
|
||||
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
|
||||
/// <paramref name="routeValues"/>, and <paramref name="fragment"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <param name="controllerName">The name of the controller.</param>
|
||||
/// <param name="routeValues">The route data to use for generating the URL.</param>
|
||||
/// <param name="fragment">The fragment to add to the URL.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public virtual RedirectToActionResult RedirectToActionPreserveMethod(
|
||||
string actionName = null,
|
||||
string controllerName = null,
|
||||
object routeValues = null,
|
||||
string fragment = null)
|
||||
{
|
||||
return new RedirectToActionResult(
|
||||
actionName: actionName,
|
||||
controllerName: controllerName,
|
||||
routeValues: routeValues,
|
||||
permanent: false,
|
||||
preserveMethod: true,
|
||||
fragment: fragment)
|
||||
{
|
||||
UrlHelper = Url,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified action with
|
||||
/// <see cref="RedirectToActionResult.Permanent"/> set to true using the specified <paramref name="actionName"/>.
|
||||
|
|
@ -618,6 +720,36 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects (<see cref="StatusCodes.Status308PermanentRedirect"/>) to the specified action with
|
||||
/// <see cref="RedirectToActionResult.Permanent"/> set to true and <see cref="RedirectToActionResult.PreserveMethod"/>
|
||||
/// set to true, using the specified <paramref name="actionName"/>, <paramref name="controllerName"/>,
|
||||
/// <paramref name="routeValues"/>, and <paramref name="fragment"/>.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action.</param>
|
||||
/// <param name="controllerName">The name of the controller.</param>
|
||||
/// <param name="routeValues">The route data to use for generating the URL.</param>
|
||||
/// <param name="fragment">The fragment to add to the URL.</param>
|
||||
/// <returns>The created <see cref="RedirectToActionResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public virtual RedirectToActionResult RedirectToActionPermanentPreserveMethod(
|
||||
string actionName = null,
|
||||
string controllerName = null,
|
||||
object routeValues = null,
|
||||
string fragment = null)
|
||||
{
|
||||
return new RedirectToActionResult(
|
||||
actionName: actionName,
|
||||
controllerName: controllerName,
|
||||
routeValues: routeValues,
|
||||
permanent: true,
|
||||
preserveMethod: true,
|
||||
fragment: fragment)
|
||||
{
|
||||
UrlHelper = Url,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects (<see cref="StatusCodes.Status302Found"/>) to the specified route using the specified <paramref name="routeName"/>.
|
||||
/// </summary>
|
||||
|
|
@ -686,6 +818,32 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects (<see cref="StatusCodes.Status307TemporaryRedirect"/>) to the specified route with
|
||||
/// <see cref="RedirectToRouteResult.Permanent"/> set to false and <see cref="RedirectToRouteResult.PreserveMethod"/>
|
||||
/// set to true, using the specified <paramref name="routeName"/>, <paramref name="routeValues"/>, and <paramref name="fragment"/>.
|
||||
/// </summary>
|
||||
/// <param name="routeName">The name of the route.</param>
|
||||
/// <param name="routeValues">The route data to use for generating the URL.</param>
|
||||
/// <param name="fragment">The fragment to add to the URL.</param>
|
||||
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public virtual RedirectToRouteResult RedirectToRoutePreserveMethod(
|
||||
string routeName = null,
|
||||
object routeValues = null,
|
||||
string fragment = null)
|
||||
{
|
||||
return new RedirectToRouteResult(
|
||||
routeName: routeName,
|
||||
routeValues: routeValues,
|
||||
permanent: false,
|
||||
preserveMethod: true,
|
||||
fragment: fragment)
|
||||
{
|
||||
UrlHelper = Url,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects (<see cref="StatusCodes.Status301MovedPermanently"/>) to the specified route with
|
||||
/// <see cref="RedirectToRouteResult.Permanent"/> set to true using the specified <paramref name="routeName"/>.
|
||||
|
|
@ -759,6 +917,32 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects (<see cref="StatusCodes.Status308PermanentRedirect"/>) to the specified route with
|
||||
/// <see cref="RedirectToRouteResult.Permanent"/> set to true and <see cref="RedirectToRouteResult.PreserveMethod"/>
|
||||
/// set to true, using the specified <paramref name="routeName"/>, <paramref name="routeValues"/>, and <paramref name="fragment"/>.
|
||||
/// </summary>
|
||||
/// <param name="routeName">The name of the route.</param>
|
||||
/// <param name="routeValues">The route data to use for generating the URL.</param>
|
||||
/// <param name="fragment">The fragment to add to the URL.</param>
|
||||
/// <returns>The created <see cref="RedirectToRouteResult"/> for the response.</returns>
|
||||
[NonAction]
|
||||
public virtual RedirectToRouteResult RedirectToRoutePermanentPreserveMethod(
|
||||
string routeName = null,
|
||||
object routeValues = null,
|
||||
string fragment = null)
|
||||
{
|
||||
return new RedirectToRouteResult(
|
||||
routeName: routeName,
|
||||
routeValues: routeValues,
|
||||
permanent: true,
|
||||
preserveMethod: true,
|
||||
fragment: fragment)
|
||||
{
|
||||
UrlHelper = Url,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a file with the specified <paramref name="fileContents" /> as content
|
||||
/// (<see cref="StatusCodes.Status200OK"/>) and the specified <paramref name="contentType" /> as the Content-Type.
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Core;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
||||
{
|
||||
|
|
@ -42,7 +44,17 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
|
||||
destinationUrl = urlHelper.Content(result.Url);
|
||||
_logger.LocalRedirectResultExecuting(destinationUrl);
|
||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||
|
||||
if (result.PreserveMethod)
|
||||
{
|
||||
context.HttpContext.Response.StatusCode = result.Permanent ?
|
||||
StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
|
||||
context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,10 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
||||
{
|
||||
|
|
@ -40,7 +42,17 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
}
|
||||
|
||||
_logger.RedirectResultExecuting(destinationUrl);
|
||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||
|
||||
if (result.PreserveMethod)
|
||||
{
|
||||
context.HttpContext.Response.StatusCode = result.Permanent ?
|
||||
StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
|
||||
context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Core;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
||||
{
|
||||
|
|
@ -46,7 +48,17 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
}
|
||||
|
||||
_logger.RedirectToActionResultExecuting(destinationUrl);
|
||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||
|
||||
if (result.PreserveMethod)
|
||||
{
|
||||
context.HttpContext.Response.StatusCode = result.Permanent ?
|
||||
StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
|
||||
context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2,9 +2,11 @@
|
|||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc.Core;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
|
||||
namespace Microsoft.AspNetCore.Mvc.Internal
|
||||
{
|
||||
|
|
@ -45,7 +47,17 @@ namespace Microsoft.AspNetCore.Mvc.Internal
|
|||
}
|
||||
|
||||
_logger.RedirectToRouteResultExecuting(destinationUrl, result.RouteName);
|
||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||
|
||||
if (result.PreserveMethod)
|
||||
{
|
||||
context.HttpContext.Response.StatusCode = result.Permanent ?
|
||||
StatusCodes.Status308PermanentRedirect : StatusCodes.Status307TemporaryRedirect;
|
||||
context.HttpContext.Response.Headers[HeaderNames.Location] = destinationUrl;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.HttpContext.Response.Redirect(destinationUrl, result.Permanent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,8 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
namespace Microsoft.AspNetCore.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="ActionResult"/> that returns a redirect to the supplied local URL.
|
||||
/// An <see cref="ActionResult"/> that returns a Found (302), Moved Permanently (301), Temporary Redirect (307),
|
||||
/// or Permanent Redirect (308) response with a Location header to the supplied local URL.
|
||||
/// </summary>
|
||||
public class LocalRedirectResult : ActionResult
|
||||
{
|
||||
|
|
@ -32,6 +33,18 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// <param name="localUrl">The local URL to redirect to.</param>
|
||||
/// <param name="permanent">Specifies whether the redirect should be permanent (301) or temporary (302).</param>
|
||||
public LocalRedirectResult(string localUrl, bool permanent)
|
||||
: this(localUrl, permanent, preserveMethod: false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LocalRedirectResult"/> class with the values
|
||||
/// provided.
|
||||
/// </summary>
|
||||
/// <param name="localUrl">The local URL to redirect to.</param>
|
||||
/// <param name="permanent">Specifies whether the redirect should be permanent (301) or temporary (302).</param>
|
||||
/// <param name="preserveMethod">If set to true, make the temporary redirect (307) or permanent redirect (308) preserve the intial request's method.</param>
|
||||
public LocalRedirectResult(string localUrl, bool permanent, bool preserveMethod)
|
||||
{
|
||||
if (string.IsNullOrEmpty(localUrl))
|
||||
{
|
||||
|
|
@ -39,6 +52,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
}
|
||||
|
||||
Permanent = permanent;
|
||||
PreserveMethod = preserveMethod;
|
||||
Url = localUrl;
|
||||
}
|
||||
|
||||
|
|
@ -47,6 +61,11 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// </summary>
|
||||
public bool Permanent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an indication that the redirect preserves the initial request method.
|
||||
/// </summary>
|
||||
public bool PreserveMethod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the local URL to redirect to.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -9,10 +9,19 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
|
||||
namespace Microsoft.AspNetCore.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="ActionResult"/> that returns a Found (302), Moved Permanently (301), Temporary Redirect (307),
|
||||
/// or Permanent Redirect (308) response with a Location header to the supplied URL.
|
||||
/// </summary>
|
||||
public class RedirectResult : ActionResult, IKeepTempDataResult
|
||||
{
|
||||
private string _url;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RedirectResult"/> class with the values
|
||||
/// provided.
|
||||
/// </summary>
|
||||
/// <param name="url">The local URL to redirect to.</param>
|
||||
public RedirectResult(string url)
|
||||
: this(url, permanent: false)
|
||||
{
|
||||
|
|
@ -22,7 +31,25 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RedirectResult"/> class with the values
|
||||
/// provided.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to redirect to.</param>
|
||||
/// <param name="permanent">Specifies whether the redirect should be permanent (301) or temporary (302).</param>
|
||||
public RedirectResult(string url, bool permanent)
|
||||
: this(url, permanent, preserveMethod: false)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RedirectResult"/> class with the values
|
||||
/// provided.
|
||||
/// </summary>
|
||||
/// <param name="url">The URL to redirect to.</param>
|
||||
/// <param name="permanent">Specifies whether the redirect should be permanent (301) or temporary (302).</param>
|
||||
/// <param name="preserveMethod">If set to true, make the temporary redirect (307) or permanent redirect (308) preserve the intial request method.</param>
|
||||
public RedirectResult(string url, bool permanent, bool preserveMethod)
|
||||
{
|
||||
if (url == null)
|
||||
{
|
||||
|
|
@ -35,11 +62,23 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
}
|
||||
|
||||
Permanent = permanent;
|
||||
PreserveMethod = preserveMethod;
|
||||
Url = url;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value that specifies that the redirect should be permanent if true or temporary if false.
|
||||
/// </summary>
|
||||
public bool Permanent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an indication that the redirect preserves the initial request method.
|
||||
/// </summary>
|
||||
public bool PreserveMethod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the URL to redirect to.
|
||||
/// </summary>
|
||||
public string Url
|
||||
{
|
||||
get
|
||||
|
|
@ -57,8 +96,12 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="IUrlHelper"/> for this result.
|
||||
/// </summary>
|
||||
public IUrlHelper UrlHelper { get; set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void ExecuteResult(ActionContext context)
|
||||
{
|
||||
if (context == null)
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
namespace Microsoft.AspNetCore.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="ActionResult"/> that returns a Found (302)
|
||||
/// or Moved Permanently (301) response with a Location header.
|
||||
/// An <see cref="ActionResult"/> that returns a Found (302), Moved Permanently (301), Temporary Redirect (307),
|
||||
/// or Permanent Redirect (308) response with a Location header.
|
||||
/// Targets a controller action.
|
||||
/// </summary>
|
||||
public class RedirectToActionResult : ActionResult, IKeepTempDataResult
|
||||
|
|
@ -65,6 +65,25 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RedirectToActionResult"/> with the values
|
||||
/// provided.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action to use for generating the URL.</param>
|
||||
/// <param name="controllerName">The name of the controller to use for generating the URL.</param>
|
||||
/// <param name="routeValues">The route data to use for generating the URL.</param>
|
||||
/// <param name="permanent">If set to true, makes the redirect permanent (301). Otherwise a temporary redirect is used (302).</param>
|
||||
/// <param name="preserveMethod">If set to true, make the temporary redirect (307) or permanent redirect (308) preserve the intial request method.</param>
|
||||
public RedirectToActionResult(
|
||||
string actionName,
|
||||
string controllerName,
|
||||
object routeValues,
|
||||
bool permanent,
|
||||
bool preserveMethod)
|
||||
: this(actionName, controllerName, routeValues, permanent, preserveMethod, fragment: null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RedirectToActionResult"/> with the values
|
||||
/// provided.
|
||||
|
|
@ -80,11 +99,33 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
object routeValues,
|
||||
bool permanent,
|
||||
string fragment)
|
||||
: this(actionName, controllerName, routeValues, permanent, preserveMethod: false, fragment: fragment)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RedirectToActionResult"/> with the values
|
||||
/// provided.
|
||||
/// </summary>
|
||||
/// <param name="actionName">The name of the action to use for generating the URL.</param>
|
||||
/// <param name="controllerName">The name of the controller to use for generating the URL.</param>
|
||||
/// <param name="routeValues">The route data to use for generating the URL.</param>
|
||||
/// <param name="permanent">If set to true, makes the redirect permanent (301). Otherwise a temporary redirect is used (302).</param>
|
||||
/// <param name="preserveMethod">If set to true, make the temporary redirect (307) and permanent redirect (308) preserve the intial request method.</param>
|
||||
/// <param name="fragment">The fragment to add to the URL.</param>
|
||||
public RedirectToActionResult(
|
||||
string actionName,
|
||||
string controllerName,
|
||||
object routeValues,
|
||||
bool permanent,
|
||||
bool preserveMethod,
|
||||
string fragment)
|
||||
{
|
||||
ActionName = actionName;
|
||||
ControllerName = controllerName;
|
||||
RouteValues = routeValues == null ? null : new RouteValueDictionary(routeValues);
|
||||
Permanent = permanent;
|
||||
PreserveMethod = preserveMethod;
|
||||
Fragment = fragment;
|
||||
}
|
||||
|
||||
|
|
@ -113,6 +154,11 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// </summary>
|
||||
public bool Permanent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an indication that the redirect preserves the initial request method.
|
||||
/// </summary>
|
||||
public bool PreserveMethod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the fragment to add to the URL.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ using Microsoft.Extensions.DependencyInjection;
|
|||
namespace Microsoft.AspNetCore.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// An <see cref="ActionResult"/> that returns a Found (302)
|
||||
/// or Moved Permanently (301) response with a Location header.
|
||||
/// An <see cref="ActionResult"/> that returns a Found (302), Moved Permanently (301), Temporary Redirect (307),
|
||||
/// or Permanent Redirect (308) response with a Location header.
|
||||
/// Targets a registered route.
|
||||
/// </summary>
|
||||
public class RedirectToRouteResult : ActionResult, IKeepTempDataResult
|
||||
|
|
@ -54,6 +54,23 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RedirectToRouteResult"/> with the values
|
||||
/// provided.
|
||||
/// </summary>
|
||||
/// <param name="routeName">The name of the route.</param>
|
||||
/// <param name="routeValues">The parameters for the route.</param>
|
||||
/// <param name="permanent">If set to true, makes the redirect permanent (301). Otherwise a temporary redirect is used (302).</param>
|
||||
/// <param name="preserveMethod">If set to true, make the temporary redirect (307) or permanent redirect (308) preserve the intial request method.</param>
|
||||
public RedirectToRouteResult(
|
||||
string routeName,
|
||||
object routeValues,
|
||||
bool permanent,
|
||||
bool preserveMethod)
|
||||
: this(routeName, routeValues, permanent, preserveMethod, fragment: null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RedirectToRouteResult"/> with the values
|
||||
/// provided.
|
||||
|
|
@ -82,9 +99,29 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
object routeValues,
|
||||
bool permanent,
|
||||
string fragment)
|
||||
: this(routeName, routeValues, permanent, preserveMethod: false, fragment: fragment)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RedirectToRouteResult"/> with the values
|
||||
/// provided.
|
||||
/// </summary>
|
||||
/// <param name="routeName">The name of the route.</param>
|
||||
/// <param name="routeValues">The parameters for the route.</param>
|
||||
/// <param name="permanent">If set to true, makes the redirect permanent (301). Otherwise a temporary redirect is used (302).</param>
|
||||
/// <param name="preserveMethod">If set to true, make the temporary redirect (307) or permanent redirect (308) preserve the intial request method.</param>
|
||||
/// <param name="fragment">The fragment to add to the URL.</param>
|
||||
public RedirectToRouteResult(
|
||||
string routeName,
|
||||
object routeValues,
|
||||
bool permanent,
|
||||
bool preserveMethod,
|
||||
string fragment)
|
||||
{
|
||||
RouteName = routeName;
|
||||
RouteValues = routeValues == null ? null : new RouteValueDictionary(routeValues);
|
||||
PreserveMethod = preserveMethod;
|
||||
Permanent = permanent;
|
||||
Fragment = fragment;
|
||||
}
|
||||
|
|
@ -109,6 +146,11 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
/// </summary>
|
||||
public bool Permanent { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets an indication that the redirect preserves the initial request method.
|
||||
/// </summary>
|
||||
public bool PreserveMethod { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the fragment to add to the URL.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal;
|
|||
using Microsoft.AspNetCore.Mvc.Formatters;
|
||||
using Microsoft.AspNetCore.Mvc.Internal;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Test;
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;
|
||||
using Microsoft.AspNetCore.Mvc.TestCommon;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
|
|
@ -52,6 +51,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectResult>(result);
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
|
@ -68,6 +68,41 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectResult>(result);
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectPermanent_WithParameterUrl_SetsRedirectResultPreserveMethodAndSameUrl()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = controller.RedirectPreserveMethod(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectResult>(result);
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectPermanent_WithParameterUrl_SetsRedirectResultPermanentPreserveMethodAndSameUrl()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = controller.RedirectPermanentPreserveMethod(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectResult>(result);
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
|
@ -85,6 +120,19 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
() => controller.Redirect(url: url), "url");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
public void RedirectPreserveMethod_WithParameter_NullOrEmptyUrl_Throws(string url)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act & Assert
|
||||
ExceptionAssert.ThrowsArgumentNullOrEmpty(
|
||||
() => controller.RedirectPreserveMethod(url: url), "url");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalRedirect_WithParameterUrl_SetsLocalRedirectResultWithSameUrl()
|
||||
{
|
||||
|
|
@ -97,6 +145,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<LocalRedirectResult>(result);
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
|
@ -113,6 +162,41 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<LocalRedirectResult>(result);
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalRedirectPermanent_WithParameterUrl_SetsLocalRedirectResultPreserveMethodWithSameUrl()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = controller.LocalRedirectPreserveMethod(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<LocalRedirectResult>(result);
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void LocalRedirectPermanent_WithParameterUrl_SetsLocalRedirectResultPermanentPreservesMethodWithSameUrl()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = controller.LocalRedirectPermanentPreserveMethod(url);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<LocalRedirectResult>(result);
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
|
@ -130,6 +214,32 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
() => controller.LocalRedirect(localUrl: url), "localUrl");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
public void LocalRedirectPreserveMethod_WithParameter_NullOrEmptyUrl_Throws(string url)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act & Assert
|
||||
ExceptionAssert.ThrowsArgumentNullOrEmpty(
|
||||
() => controller.LocalRedirectPreserveMethod(localUrl: url), "localUrl");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
public void LocalRedirectPermanentPreserveMethod_WithParameter_NullOrEmptyUrl_Throws(string url)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act & Assert
|
||||
ExceptionAssert.ThrowsArgumentNullOrEmpty(
|
||||
() => controller.LocalRedirectPermanentPreserveMethod(localUrl: url), "localUrl");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
|
|
@ -143,6 +253,19 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
() => controller.RedirectPermanent(url: url), "url");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(null)]
|
||||
[InlineData("")]
|
||||
public void RedirectPermanentPreserveMethod_WithParameter_NullOrEmptyUrl_Throws(string url)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act & Assert
|
||||
ExceptionAssert.ThrowsArgumentNullOrEmpty(
|
||||
() => controller.RedirectPermanentPreserveMethod(url: url), "url");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectToAction_WithParameterActionName_SetsResultActionName()
|
||||
{
|
||||
|
|
@ -154,6 +277,23 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectToActionPreserveMethod_WithParameterActionName_SetsResultActionName()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultTemporary = controller.RedirectToActionPreserveMethod(actionName: "SampleAction");
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.True(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
}
|
||||
|
|
@ -169,6 +309,23 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.False(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectToActionPermanentPreserveMethod_WithParameterActionName_SetsResultActionNameAndPermanent()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToActionPermanentPreserveMethod(actionName: "SampleAction");
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
}
|
||||
|
|
@ -187,6 +344,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
Assert.Equal(controllerName, resultTemporary.ControllerName);
|
||||
|
|
@ -196,8 +354,27 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
[InlineData("SampleController")]
|
||||
public void RedirectToActionPermanent_WithParameterActionAndControllerName_SetsEqualNames(
|
||||
string controllerName)
|
||||
public void RedirectToActionPreserveMethod_WithParameterActionAndControllerName_SetsEqualNames(string controllerName)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultTemporary = controller.RedirectToActionPreserveMethod(actionName: "SampleAction", controllerName: controllerName);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.True(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
Assert.Equal(controllerName, resultTemporary.ControllerName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
[InlineData("SampleController")]
|
||||
public void RedirectToActionPermanent_WithParameterActionAndControllerName_SetsEqualNames(string controllerName)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
|
@ -207,6 +384,27 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.False(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
Assert.Equal(controllerName, resultPermanent.ControllerName);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData(null)]
|
||||
[InlineData("SampleController")]
|
||||
public void RedirectToActionPermanentPreserveMethod_WithParameterActionAndControllerName_SetsEqualNames(string controllerName)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToActionPermanentPreserveMethod(actionName: "SampleAction", controllerName: controllerName);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
Assert.Equal(controllerName, resultPermanent.ControllerName);
|
||||
|
|
@ -226,6 +424,31 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
Assert.Equal("SampleController", resultTemporary.ControllerName);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToActionPreserveMethod_WithParameterActionControllerRouteValues_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultTemporary = controller.RedirectToActionPreserveMethod(
|
||||
actionName: "SampleAction",
|
||||
controllerName: "SampleController",
|
||||
routeValues: routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.True(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal("SampleAction", resultTemporary.ActionName);
|
||||
Assert.Equal("SampleController", resultTemporary.ControllerName);
|
||||
|
|
@ -249,6 +472,31 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.False(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
Assert.Equal("SampleController", resultPermanent.ControllerName);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToActionPermanentPreserveMethod_WithParameterActionControllerRouteValues_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToActionPermanentPreserveMethod(
|
||||
actionName: "SampleAction",
|
||||
controllerName: "SampleController",
|
||||
routeValues: routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal("SampleAction", resultPermanent.ActionName);
|
||||
Assert.Equal("SampleController", resultPermanent.ControllerName);
|
||||
|
|
@ -269,6 +517,27 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Null(resultTemporary.ActionName);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToActionPreserveMethod_WithParameterActionAndRouteValues_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultTemporary = controller.RedirectToActionPreserveMethod(actionName: null, routeValues: routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultTemporary);
|
||||
Assert.True(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Null(resultTemporary.ActionName);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
|
|
@ -291,6 +560,32 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(result);
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Equal(expectedAction, result.ActionName);
|
||||
Assert.Equal(expectedRouteValues, result.RouteValues);
|
||||
Assert.Equal(expectedController, result.ControllerName);
|
||||
Assert.Equal(expectedFragment, result.Fragment);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToActionPreserveMethod_WithParameterActionAndControllerAndRouteValuesAndFragment_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expectedRouteValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var expectedAction = "Action";
|
||||
var expectedController = "Home";
|
||||
var expectedFragment = "test";
|
||||
|
||||
// Act
|
||||
var result = controller.RedirectToActionPreserveMethod("Action", "Home", routeValues, "test");
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(result);
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Equal(expectedAction, result.ActionName);
|
||||
Assert.Equal(expectedRouteValues, result.RouteValues);
|
||||
|
|
@ -312,6 +607,27 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.False(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Null(resultPermanent.ActionName);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToActionPermanentPreserveMethod_WithParameterActionAndRouteValues_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToActionPermanentPreserveMethod(actionName: null, routeValues: routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Null(resultPermanent.ActionName);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
|
|
@ -330,10 +646,40 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
var expectedFragment = "test";
|
||||
|
||||
// Act
|
||||
var result = controller.RedirectToActionPermanent("Action", "Home", routeValues, "test");
|
||||
var result = controller.RedirectToActionPermanent("Action", "Home", routeValues, fragment: "test");
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(result);
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Equal(expectedAction, result.ActionName);
|
||||
Assert.Equal(expectedRouteValues, result.RouteValues);
|
||||
Assert.Equal(expectedController, result.ControllerName);
|
||||
Assert.Equal(expectedFragment, result.Fragment);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToActionPermanentPreserveMethod_WithParameterActionAndControllerAndRouteValuesAndFragment_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expectedRouteValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var expectedAction = "Action";
|
||||
var expectedController = "Home";
|
||||
var expectedFragment = "test";
|
||||
|
||||
// Act
|
||||
var result = controller.RedirectToActionPermanentPreserveMethod(
|
||||
actionName: "Action",
|
||||
controllerName: "Home",
|
||||
routeValues: routeValues,
|
||||
fragment: "test");
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToActionResult>(result);
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Equal(expectedAction, result.ActionName);
|
||||
Assert.Equal(expectedRouteValues, result.RouteValues);
|
||||
|
|
@ -355,6 +701,26 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoutePreserveMethod_WithParameterRouteValues_SetsResultEqualRouteValues(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultTemporary = controller.RedirectToRoutePreserveMethod(routeValues: routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.True(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
}
|
||||
|
|
@ -375,6 +741,30 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(result);
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Equal(expectedRoute, result.RouteName);
|
||||
Assert.Equal(expectedRouteValues, result.RouteValues);
|
||||
Assert.Equal(expectedFragment, result.Fragment);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoutePreserveMethod_WithParameterRouteNameAndRouteValuesAndFragment_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expectedRouteValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var expectedRoute = "TestRoute";
|
||||
var expectedFragment = "test";
|
||||
|
||||
// Act
|
||||
var result = controller.RedirectToRoutePreserveMethod(routeName: "TestRoute", routeValues: routeValues, fragment: "test");
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(result);
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Equal(expectedRoute, result.RouteName);
|
||||
Assert.Equal(expectedRouteValues, result.RouteValues);
|
||||
|
|
@ -395,6 +785,26 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.False(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoutePermanentPreserveMethod_WithParameterRouteValues_SetsResultEqualRouteValuesAndPermanent(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToRoutePermanentPreserveMethod(routeValues: routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
}
|
||||
|
|
@ -415,6 +825,30 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(result);
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Equal(expectedRoute, result.RouteName);
|
||||
Assert.Equal(expectedRouteValues, result.RouteValues);
|
||||
Assert.Equal(expectedFragment, result.Fragment);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoutePermanentPreserveMethod_WithParameterRouteNameAndRouteValuesAndFragment_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expectedRouteValues)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var expectedRoute = "TestRoute";
|
||||
var expectedFragment = "test";
|
||||
|
||||
// Act
|
||||
var result = controller.RedirectToRoutePermanentPreserveMethod(routeName: "TestRoute", routeValues: routeValues, fragment: "test");
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(result);
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Equal(expectedRoute, result.RouteName);
|
||||
Assert.Equal(expectedRouteValues, result.RouteValues);
|
||||
|
|
@ -433,6 +867,24 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Same(routeName, resultTemporary.RouteName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectToRoutePreserveMethod_WithParameterRouteName_SetsResultSameRouteName()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var routeName = "CustomRouteName";
|
||||
|
||||
// Act;
|
||||
var resultTemporary = controller.RedirectToRoutePreserveMethod(routeName: routeName);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.True(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Same(routeName, resultTemporary.RouteName);
|
||||
}
|
||||
|
|
@ -449,6 +901,24 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.False(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Same(routeName, resultPermanent.RouteName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectToRoutePermanentPreserveMethod_WithParameterRouteName_SetsResultSameRouteNameAndPermanent()
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var routeName = "CustomRouteName";
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToRoutePermanentPreserveMethod(routeName: routeName);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Same(routeName, resultPermanent.RouteName);
|
||||
}
|
||||
|
|
@ -468,6 +938,28 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.False(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Same(routeName, resultTemporary.RouteName);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoutePreserveMethod_WithParameterRouteNameAndRouteValues_SetsResultSameRouteNameAndRouteValues(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var routeName = "CustomRouteName";
|
||||
|
||||
// Act
|
||||
var resultTemporary = controller.RedirectToRoutePreserveMethod(routeName: routeName, routeValues: routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultTemporary);
|
||||
Assert.True(resultTemporary.PreserveMethod);
|
||||
Assert.False(resultTemporary.Permanent);
|
||||
Assert.Same(routeName, resultTemporary.RouteName);
|
||||
Assert.Equal(expected, resultTemporary.RouteValues);
|
||||
|
|
@ -488,6 +980,28 @@ namespace Microsoft.AspNetCore.Mvc.Core.Test
|
|||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.False(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Same(routeName, resultPermanent.RouteName);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(RedirectTestData))]
|
||||
public void RedirectToRoutePermanentPreserveMethod_WithParameterRouteNameAndRouteValues_SetsResultProperties(
|
||||
object routeValues,
|
||||
IEnumerable<KeyValuePair<string, object>> expected)
|
||||
{
|
||||
// Arrange
|
||||
var controller = new TestableController();
|
||||
var routeName = "CustomRouteName";
|
||||
|
||||
// Act
|
||||
var resultPermanent = controller.RedirectToRoutePermanentPreserveMethod(routeName: routeName, routeValues: routeValues);
|
||||
|
||||
// Assert
|
||||
Assert.IsType<RedirectToRouteResult>(resultPermanent);
|
||||
Assert.True(resultPermanent.PreserveMethod);
|
||||
Assert.True(resultPermanent.Permanent);
|
||||
Assert.Same(routeName, resultPermanent.RouteName);
|
||||
Assert.Equal(expected, resultPermanent.RouteValues);
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
public class LocalRedirectResultTest
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WithParameterUrl_SetsResultUrlAndNotPermanent()
|
||||
public void Constructor_WithParameterUrl_SetsResultUrlAndNotPermanentOrPreserveMethod()
|
||||
{
|
||||
// Arrange
|
||||
var url = "/test/url";
|
||||
|
|
@ -27,12 +27,13 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
var result = new LocalRedirectResult(url);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WithParameterUrlAndPermanent_SetsResultUrlAndPermanent()
|
||||
public void Constructor_WithParameterUrlAndPermanent_SetsResultUrlAndPermanentNotPreserveMethod()
|
||||
{
|
||||
// Arrange
|
||||
var url = "/test/url";
|
||||
|
|
@ -41,6 +42,22 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
var result = new LocalRedirectResult(url, permanent: true);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WithParameterUrlAndPermanent_SetsResultUrlPermanentAndPreserveMethod()
|
||||
{
|
||||
// Arrange
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = new LocalRedirectResult(url, permanent: true, preserveMethod: true);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
public class RedirectResultTest
|
||||
{
|
||||
[Fact]
|
||||
public void RedirectResult_Constructor_WithParameterUrl_SetsResultUrlAndNotPermanent()
|
||||
public void RedirectResult_Constructor_WithParameterUrl_SetsResultUrlAndNotPermanentOrPreserveMethod()
|
||||
{
|
||||
// Arrange
|
||||
var url = "/test/url";
|
||||
|
|
@ -27,12 +27,13 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
var result = new RedirectResult(url);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.False(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectResult_Constructor_WithParameterUrlAndPermanent_SetsResultUrlAndPermanent()
|
||||
public void RedirectResult_Constructor_WithParameterUrlAndPermanent_SetsResultUrlAndPermanentNotPreserveMethod()
|
||||
{
|
||||
// Arrange
|
||||
var url = "/test/url";
|
||||
|
|
@ -41,6 +42,22 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
var result = new RedirectResult(url, permanent: true);
|
||||
|
||||
// Assert
|
||||
Assert.False(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RedirectResult_Constructor_WithParameterUrlPermanentAndPreservesMethod_SetsResultUrlPermanentAndPreservesMethod()
|
||||
{
|
||||
// Arrange
|
||||
var url = "/test/url";
|
||||
|
||||
// Act
|
||||
var result = new RedirectResult(url, permanent: true, preserveMethod: true);
|
||||
|
||||
// Assert
|
||||
Assert.True(result.PreserveMethod);
|
||||
Assert.True(result.Permanent);
|
||||
Assert.Same(url, result.Url);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -111,6 +111,34 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task RedirectToAction_Execute_WithFragment_PassesCorrectValuesToRedirect_WithPreserveMethod()
|
||||
{
|
||||
// Arrange
|
||||
var expectedUrl = "/Home/SampleAction#test";
|
||||
var expectedStatusCode = StatusCodes.Status307TemporaryRedirect;
|
||||
|
||||
var httpContext = new DefaultHttpContext
|
||||
{
|
||||
RequestServices = CreateServices().BuildServiceProvider(),
|
||||
};
|
||||
|
||||
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||
|
||||
var urlHelper = GetMockUrlHelper(expectedUrl);
|
||||
var result = new RedirectToActionResult("SampleAction", "Home", null, false, true, "test")
|
||||
{
|
||||
UrlHelper = urlHelper,
|
||||
};
|
||||
|
||||
// Act
|
||||
await result.ExecuteResultAsync(actionContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode);
|
||||
Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
|
||||
}
|
||||
|
||||
private static IUrlHelper GetMockUrlHelper(string returnValue)
|
||||
{
|
||||
var urlHelper = new Mock<IUrlHelper>();
|
||||
|
|
|
|||
|
|
@ -141,6 +141,31 @@ namespace Microsoft.AspNetCore.Mvc
|
|||
Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ExecuteResultAsync_WithFragment_PassesCorrectValuesToRedirect_WithPreserveMethod()
|
||||
{
|
||||
// Arrange
|
||||
var expectedUrl = "/SampleAction#test";
|
||||
var expectedStatusCode = StatusCodes.Status308PermanentRedirect;
|
||||
|
||||
var httpContext = GetHttpContext();
|
||||
|
||||
var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||
|
||||
var urlHelper = GetMockUrlHelper(expectedUrl);
|
||||
var result = new RedirectToRouteResult("Sample", null, true, true, "test")
|
||||
{
|
||||
UrlHelper = urlHelper,
|
||||
};
|
||||
|
||||
// Act
|
||||
await result.ExecuteResultAsync(actionContext);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode);
|
||||
Assert.Equal(expectedUrl, httpContext.Response.Headers["Location"]);
|
||||
}
|
||||
|
||||
private static HttpContext GetHttpContext(IUrlHelperFactory factory = null)
|
||||
{
|
||||
var services = CreateServices(factory);
|
||||
|
|
|
|||
Loading…
Reference in New Issue