Skip to content

Commit

Permalink
Merge pull request #225 from sergey-litvinov-work/fixed-self-encoding
Browse files Browse the repository at this point in the history
Fixed issue with encoding for `links.self` item
  • Loading branch information
joukevandermaas authored Oct 23, 2019
2 parents d578a65 + 466f48b commit 126e952
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
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

0 comments on commit 126e952

Please sign in to comment.