This repository has been archived by the owner on Jan 24, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #371 from grumpydev/AsRedirectPathExpansion
Tweaked AsRedirect to expand the base path with ~
- Loading branch information
Showing
3 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
namespace Nancy.Tests.Unit | ||
{ | ||
using FakeItEasy; | ||
using Xunit; | ||
|
||
public class FormatterExtensionsFixture | ||
{ | ||
private readonly IResponseFormatter formatter; | ||
private readonly NancyContext context; | ||
|
||
public FormatterExtensionsFixture() | ||
{ | ||
this.context = new NancyContext(); | ||
this.formatter = new DefaultResponseFormatter(A.Fake<IRootPathProvider>(), context); | ||
} | ||
|
||
[Fact] | ||
public void Should_expand_base_path_for_redirect_if_tilde_present() | ||
{ | ||
this.context.Request = new Request( | ||
"GET", | ||
new Url | ||
{ | ||
BasePath = "/basePath", | ||
Path = "Path", | ||
Scheme = "http", | ||
}); | ||
|
||
var result = this.formatter.AsRedirect("~/test"); | ||
|
||
result.Headers["Location"].ShouldEqual("/basePath/test"); | ||
} | ||
|
||
[Fact] | ||
public void Should_leave_path_untouched_for_redirect_if_no_tilde() | ||
{ | ||
this.context.Request = new Request( | ||
"GET", | ||
new Url | ||
{ | ||
BasePath = "/basePath", | ||
Path = "Path", | ||
Scheme = "http", | ||
}); | ||
|
||
var result = this.formatter.AsRedirect("/test"); | ||
|
||
result.Headers["Location"].ShouldEqual("/test"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters