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

Redirects with fragment #5519

Merged
merged 21 commits into from
Dec 6, 2016
Merged

Conversation

juunas11
Copy link
Contributor

@juunas11 juunas11 commented Nov 8, 2016

Added overloads to the methods that return redirect results that allow specifying the fragment to add to the URL.

  • Added RedirectToAction, RedirectToActionPermanent, RedirectToRoute, and RedirectToRoutePermanent overloads that allow specifying the fragment
  • Added the Fragment property to RedirectToActionResult and RedirectToRouteResult
  • Modified RedirectToActionResultExecutor and RedirectToRouteResultExecutor to call the overload on UrlHelper that specifies the fragment. Left host and protocol to null as the other UrlHelper overloads do.

Addresses issue #3988

This is my first PR to MVC Core, I would be happy about any feedback :)

@dnfclas
Copy link

dnfclas commented Nov 8, 2016

Hi @juunas11, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla2.dotnetfoundation.org.

TTYL, DNFBOT;

@dnfclas
Copy link

dnfclas commented Nov 8, 2016

@juunas11, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

@Eilon
Copy link
Member

Eilon commented Nov 18, 2016

@juunas11 thanks for the PR, we'll take a look!

@dougbu assigning to you to review and merge.

Copy link
Member

@dougbu dougbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly small stuff and a bit more testing…

{
UrlHelper = Url,
UrlHelper = Url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Undo this. We like the trailing commas. Besides, let's not mix changing styles into this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not know it was a style decision :) Thanks for pointing out, will do so in the future.

{
UrlHelper = Url,
UrlHelper = Url
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here and the places below where you made this change.

@@ -1082,7 +1219,7 @@ public virtual AcceptedAtRouteResult AcceptedAtRoute(object routeValues)
/// <summary>
/// Creates a <see cref="AcceptedAtRouteResult"/> object that produces an Accepted (202) response.
/// </summary>
/// <param name="routeName">The name of the route to use for generating the URL.</param>
/// <param name="routeName">The name of the route to use for generating the URL.</param>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can undo this one if you want, left the whitespace deleter on auto :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thanking you here. Removing trailing whitespace in a file you're changing is fine.

{
}

public RedirectToActionResult(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add doc comments for this and the other new constructor overload. No need to do the same for the existing constructor overloads -- unless you're feeling industrious! 😺

@@ -53,6 +73,11 @@ public class RedirectToActionResult : ActionResult, IKeepTempDataResult

public bool Permanent { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're feeling particularly industrious, feel free to add doc comments for this property as well 😺

{
// Arrange
var expectedUrl = "/Home/SampleAction#test";
var expectedPermanentFlag = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just expectedPermanent

var httpResponse = new Mock<HttpResponse>();
httpContext
.Setup(o => o.Response)
.Returns(httpResponse.Object);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be no need to mock HttpContext or HttpResponse. Try using DefaultHttpContext and setting RequestServices instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually the way it was before I touched it :) But I'll be glad to refactor it to less setup.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess the existing tests weren't the best model to follow. Don't change them but do avoid unnecessary mocks in tests you add.

await result.ExecuteResultAsync(actionContext);

// Assert
// Verifying if Redirect was called with the specific Url and parameter flag.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "the specific Url and parameter flag" -> "the expected URL and permanent parameters"

@@ -35,11 +35,21 @@ public IActionResult RedirectToActionReturningTaskAction()
return RedirectToAction("ActionReturningTask");
}

public IActionResult RedirectToActionWithFragment()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the method below are not used. Probably should be. I'm not saying we need tests of all 8 new ControllerBase overloads but zero is too low. Suggest covering the two methods used here and the longest RedirectToActionPermanent() overload.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the nice comments, will update and get back to this when I can! 👍

@@ -83,6 +83,41 @@ public class RedirectToActionResultTest
"No route matches the supplied values.");
}

[Fact]
public async Task RedirectToAction_Execute_WithFragment_PassesCorrectValuesToRedirect()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a similar test in RedirectToRouteResultTest, perhaps covering the overload accepting permanent: true instead.

Copy link
Member

@dougbu dougbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few more comments. Also looks like a few more tests are still needed.


/// <summary>
/// Redirects to the specified route with <see cref="RedirectToRouteResult.Permanent"/> set to true
/// using the specified <paramref name="routeName"/>, and <paramref name="fragment"/>.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the comma here.

@@ -51,8 +108,16 @@ public class RedirectToActionResult : ActionResult, IKeepTempDataResult
/// </summary>
public RouteValueDictionary RouteValues { get; set; }

/// <summary>
/// Gets or sets whether the redirect is permanent.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Gets or sets an indication that …"

@@ -48,8 +104,16 @@ public RedirectToRouteResult(object routeValues)
/// </summary>
public RouteValueDictionary RouteValues { get; set; }

/// <summary>
/// Gets or sets whether the redirect is permanent.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Gets or sets an indication that …"

var httpResponse = new Mock<HttpResponse>();
httpContext
.Setup(o => o.Response)
.Returns(httpResponse.Object);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess the existing tests weren't the best model to follow. Don't change them but do avoid unnecessary mocks in tests you add.

@dougbu
Copy link
Member

dougbu commented Dec 6, 2016

@juunas11 this PR is very close. Any chance you can wrap up the few remaining comments soon?

@juunas11
Copy link
Contributor Author

juunas11 commented Dec 6, 2016

Yes, I'll try to get everything done in the following one or two days.

Joonas Westlin added 2 commits December 6, 2016 18:01
… overloads of RedirectToAction and RedirectToRoutePermanent
@juunas11
Copy link
Contributor Author

juunas11 commented Dec 6, 2016

I think I've done everything you requested, but please tell me if there is still something.

Copy link
Member

@dougbu dougbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit: Revert changes to one file and I'll get this in.

Thanks very much @juunas11

@@ -35,11 +35,21 @@ public IActionResult RedirectToActionReturningTaskAction()
return RedirectToAction("ActionReturningTask");
}

public IActionResult RedirectToActionWithFragment()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert the changes to this test controller. None of the functional tests uses the two new methods and I've decided coverage is fine with the new unit tests.

@dougbu dougbu merged commit 1dd1d49 into aspnet:dev Dec 6, 2016
@dougbu
Copy link
Member

dougbu commented Dec 6, 2016

1dd1d49

@juunas11 juunas11 deleted the redirect-to-action-with-fragment branch December 6, 2016 18:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants