-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow adding empty value for URL segments
- Loading branch information
1 parent
ba2ebac
commit 40b9416
Showing
17 changed files
with
330 additions
and
322 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,23 @@ | ||
namespace RestSharp.Tests.Headers; | ||
|
||
public class DefaultHeaderTests { | ||
const string BaseUrl = "http://localhost:8888/"; | ||
|
||
[Fact] | ||
public void AddDefaultHeadersUsingDictionary() { | ||
var headers = new Dictionary<string, string> { | ||
{ KnownHeaders.ContentType, ContentType.Json }, | ||
{ KnownHeaders.Accept, ContentType.Json }, | ||
{ KnownHeaders.ContentEncoding, "gzip, deflate" } | ||
}; | ||
|
||
var expected = headers.Select(x => new HeaderParameter(x.Key, x.Value)); | ||
|
||
using var client = new RestClient(BaseUrl); | ||
client.AddDefaultHeaders(headers); | ||
|
||
var actual = client.DefaultParameters.Select(x => x as HeaderParameter); | ||
expected.Should().BeSubsetOf(actual); | ||
} | ||
|
||
} |
4 changes: 2 additions & 2 deletions
4
test/RestSharp.Tests/AddRangeTests.cs → ...stSharp.Tests/Headers/HeaderRangeTests.cs
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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...p.Tests/ObjectParameterTests.ArrayData.cs → ...ameters/ObjectParameterTests.ArrayData.cs
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
2 changes: 1 addition & 1 deletion
2
...arp.Tests/ObjectParameterTests.CsvData.cs → ...arameters/ObjectParameterTests.CsvData.cs
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
2 changes: 1 addition & 1 deletion
2
...sts/ObjectParameterTests.FormattedData.cs → ...ers/ObjectParameterTests.FormattedData.cs
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
2 changes: 1 addition & 1 deletion
2
...p.Tests/ObjectParameterTests.NamedData.cs → ...ameters/ObjectParameterTests.NamedData.cs
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
2 changes: 1 addition & 1 deletion
2
test/RestSharp.Tests/ObjectParameterTests.cs → ....Tests/Parameters/ObjectParameterTests.cs
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
2 changes: 1 addition & 1 deletion
2
...stSharp.Tests/ParameterValidationTests.cs → ...ts/Parameters/ParameterValidationTests.cs
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
21 changes: 2 additions & 19 deletions
21
test/RestSharp.Tests/ParametersTests.cs → ...Sharp.Tests/Parameters/UrlSegmentTests.cs
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
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,197 @@ | ||
namespace RestSharp.Tests; | ||
|
||
public partial class UrlBuilderTests { | ||
[Fact] | ||
public void GET_with_empty_base_and_query_parameters_without_encoding() { | ||
var request = new RestRequest($"{Base}/{Resource}?param1=value1") | ||
.AddQueryParameter("foo", "bar,baz", false); | ||
var expected = new Uri($"{Base}/{Resource}?param1=value1&foo=bar,baz"); | ||
|
||
using var client = new RestClient(); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_empty_base_and_resource_containing_tokens() { | ||
var request = new RestRequest($"{Base}/{Resource}/{{foo}}"); | ||
request.AddUrlSegment("foo", "bar"); | ||
|
||
using var client = new RestClient(); | ||
|
||
var expected = new Uri($"{Base}/{Resource}/bar"); | ||
var output = client.BuildUri(request); | ||
|
||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_empty_request() { | ||
var request = new RestRequest(); | ||
var expected = new Uri(Base); | ||
|
||
using var client = new RestClient(new Uri(Base)); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_empty_request_and_bare_hostname() { | ||
var request = new RestRequest(); | ||
var expected = new Uri(Base); | ||
|
||
using var client = new RestClient(new Uri(Base)); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_empty_request_and_query_parameters_without_encoding() { | ||
var request = new RestRequest(); | ||
request.AddQueryParameter("foo", "bar,baz", false); | ||
var expected = new Uri($"{Base}/{Resource}?param1=value1&foo=bar,baz"); | ||
|
||
using var client = new RestClient($"{Base}/{Resource}?param1=value1"); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_Invalid_Url_string_throws_exception() | ||
=> Assert.Throws<UriFormatException>( | ||
() => { _ = new RestClient("invalid url"); } | ||
); | ||
|
||
[Fact] | ||
public void GET_with_leading_slash() { | ||
var request = new RestRequest($"/{Resource}"); | ||
var expected = new Uri($"{Base}/{Resource}"); | ||
|
||
using var client = new RestClient(new Uri(Base)); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_leading_slash_and_baseurl_trailing_slash() { | ||
var request = new RestRequest($"/{Resource}"); | ||
request.AddParameter("foo", "bar"); | ||
var expected = new Uri($"{Base}/{Resource}?foo=bar"); | ||
|
||
using var client = new RestClient(new Uri(Base)); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_multiple_instances_of_same_key() { | ||
var request = new RestRequest("v1/people/~/network/updates"); | ||
request.AddParameter("type", "STAT"); | ||
request.AddParameter("type", "PICT"); | ||
request.AddParameter("count", "50"); | ||
request.AddParameter("start", "50"); | ||
var expected = new Uri("https://api.linkedin.com/v1/people/~/network/updates?type=STAT&type=PICT&count=50&start=50"); | ||
|
||
using var client = new RestClient("https://api.linkedin.com"); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_resource_containing_null_token() { | ||
var request = new RestRequest($"/{Resource}/{{foo}}"); | ||
Assert.Throws<ArgumentNullException>(() => request.AddUrlSegment("foo", null!)); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_resource_containing_slashes() { | ||
var request = new RestRequest($"{Resource}/foo"); | ||
var expected = new Uri($"{Base}/{Resource}/foo"); | ||
|
||
using var client = new RestClient(new Uri(Base)); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_resource_containing_tokens() { | ||
var request = new RestRequest($"{Resource}/{{foo}}"); | ||
request.AddUrlSegment("foo", "bar"); | ||
var expected = new Uri($"{Base}/{Resource}/bar"); | ||
|
||
using var client = new RestClient(new Uri(Base)); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_Uri_and_resource_containing_tokens() { | ||
var request = new RestRequest($"/{{foo}}/{Resource}/{{baz}}"); | ||
request.AddUrlSegment("foo", "bar"); | ||
request.AddUrlSegment("baz", "bat"); | ||
var expected = new Uri($"{Base}/bar/{Resource}/bat"); | ||
|
||
using var client = new RestClient(Base); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_Uri_containing_tokens() { | ||
var request = new RestRequest(); | ||
request.AddUrlSegment("foo", "bar"); | ||
var expected = new Uri(Base); | ||
|
||
using var client = new RestClient(Base); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_Url_string_and_resource_containing_tokens() { | ||
var request = new RestRequest($"{Resource}/{{baz}}"); | ||
request.AddUrlSegment("foo", "bar"); | ||
request.AddUrlSegment("baz", "bat"); | ||
var expected = new Uri($"{Base}/bar/{Resource}/bat"); | ||
|
||
using var client = new RestClient($"{Base}/{{foo}}"); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_with_Url_string_containing_tokens() { | ||
var request = new RestRequest(); | ||
request.AddUrlSegment("foo", "bar"); | ||
var expected = new Uri($"{Base}/bar"); | ||
|
||
using var client = new RestClient($"{Base}/{{foo}}"); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
|
||
[Fact] | ||
public void GET_wth_trailing_slash_and_query_parameters() { | ||
var request = new RestRequest($"/{Resource}/"); | ||
request.AddParameter("foo", "bar"); | ||
var expected = new Uri($"{Base}/{Resource}/?foo=bar"); | ||
|
||
using var client = new RestClient(Base); | ||
|
||
var output = client.BuildUri(request); | ||
Assert.Equal(expected, output); | ||
} | ||
} |
Oops, something went wrong.