Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with encoding for links.self item #225

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Saule/Serialization/ResourceSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private JToken CreateTopLevelLinks(int count)
// to preserve back compatibility if Self is enabled, then we also render it. Or if TopSelf is enabled
if (_resource.LinkType.HasFlag(LinkType.TopSelf) || _resource.LinkType.HasFlag(LinkType.Self))
{
result.Add("self", _baseUrl.AbsoluteUri);
result.Add("self", _baseUrl.ToString());
}

var queryStrings = new PaginationQuery(_paginationContext, _value);
Expand Down
39 changes: 39 additions & 0 deletions Tests/Serialization/UrlConstructionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,45 @@ public void SelfLinkNoPort()
Assert.Equal("http://localhost/api/people/123", selfLink);
}

[Fact(DisplayName = "Adds top level self link without any port for https")]
public void SelfLinkNoPortHttps()
{
var target = new ResourceSerializer(Get.Person(), new PersonResource(),
new Uri("https://localhost:443/api/people/123"), DefaultPathBuilder, null, null, null);
var result = target.Serialize();
_output.WriteLine(result.ToString());

var selfLink = result["links"].Value<string>("self");

Assert.Equal("https://localhost/api/people/123", selfLink);
}

[Fact(DisplayName = "Adds top level self link without any port and with correct encoding")]
public void SelfLinkNoEncoding()
{
var target = new ResourceSerializer(Get.Person(), new PersonResource(),
new Uri("https://localhost:443/api/people?page[number]=1&page[size]=10"), DefaultPathBuilder, null, null, null);
var result = target.Serialize();
_output.WriteLine(result.ToString());

var selfLink = result["links"].Value<string>("self");

Assert.Equal("https://localhost/api/people?page[number]=1&page[size]=10", selfLink);
}

[Fact(DisplayName = "Adds top level self link without any port and with correct encoding based on already encoded value")]
public void SelfLinkNoEncodingBasedOnEncoded()
{
var target = new ResourceSerializer(Get.Person(), new PersonResource(),
new Uri("https://localhost:443/api/people?page%5Bnumber%5D=1&page%5Bsize%5D=10"), DefaultPathBuilder, null, null, null);
var result = target.Serialize();
_output.WriteLine(result.ToString());

var selfLink = result["links"].Value<string>("self");

Assert.Equal("https://localhost/api/people?page[number]=1&page[size]=10", selfLink);
}

[Fact(DisplayName = "Adds top level self link if only LinkType.TopSelf is specified")]
public void TopLinkOnlyLink()
{
Expand Down