Skip to content

Commit d5739bb

Browse files
committed
Merge branch 'finbourne-dev' into dev
2 parents 25922ce + 40b9416 commit d5739bb

17 files changed

+356
-323
lines changed

Diff for: src/RestSharp/Parameters/UrlSegmentParameter.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
using System.Text.RegularExpressions;
16+
using RestSharp.Extensions;
1617

1718
namespace RestSharp;
1819

@@ -26,10 +27,11 @@ public partial record UrlSegmentParameter : NamedParameter {
2627
/// <param name="name">Parameter name</param>
2728
/// <param name="value">Parameter value</param>
2829
/// <param name="encode">Optional: encode the value, default is true</param>
29-
public UrlSegmentParameter(string name, string value, bool encode = true)
30+
/// <param name="replaceEncodedSlash">Optional: whether to replace all %2f and %2F in the parameter value with '/', default is true</param>
31+
public UrlSegmentParameter(string name, string value, bool encode = true, bool replaceEncodedSlash = true)
3032
: base(
3133
name,
32-
RegexPattern.Replace(Ensure.NotEmptyString(value, nameof(value)), "/"),
34+
value.IsEmpty() ? value : replaceEncodedSlash ? RegexPattern.Replace(value, "/") : value,
3335
ParameterType.UrlSegment,
3436
encode
3537
) { }

Diff for: test/RestSharp.Tests/Headers/DefaultHeaderTests.cs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace RestSharp.Tests.Headers;
2+
3+
public class DefaultHeaderTests {
4+
const string BaseUrl = "http://localhost:8888/";
5+
6+
[Fact]
7+
public void AddDefaultHeadersUsingDictionary() {
8+
var headers = new Dictionary<string, string> {
9+
{ KnownHeaders.ContentType, ContentType.Json },
10+
{ KnownHeaders.Accept, ContentType.Json },
11+
{ KnownHeaders.ContentEncoding, "gzip, deflate" }
12+
};
13+
14+
var expected = headers.Select(x => new HeaderParameter(x.Key, x.Value));
15+
16+
using var client = new RestClient(BaseUrl);
17+
client.AddDefaultHeaders(headers);
18+
19+
var actual = client.DefaultParameters.Select(x => x as HeaderParameter);
20+
expected.Should().BeSubsetOf(actual);
21+
}
22+
23+
}

Diff for: test/RestSharp.Tests/AddRangeTests.cs renamed to test/RestSharp.Tests/Headers/HeaderRangeTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
namespace RestSharp.Tests;
1+
namespace RestSharp.Tests.Parameters;
22

3-
public class AddRangeTests {
3+
public class HeaderRangeTests {
44
[Fact]
55
public async Task ShouldParseOutLongRangeSpecifier() {
66
using var restClient = new RestClient("http://localhost");

Diff for: test/RestSharp.Tests/ObjectParameterTests.ArrayData.cs renamed to test/RestSharp.Tests/Parameters/ObjectParameterTests.ArrayData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace RestSharp.Tests;
1+
namespace RestSharp.Tests.Parameters;
22

33
public partial class ObjectParameterTests {
44
sealed record ArrayData<TEnumerable>([property: RequestProperty(ArrayQueryType = RequestArrayQueryType.ArrayParameters)] TEnumerable Array) where TEnumerable : notnull;

Diff for: test/RestSharp.Tests/ObjectParameterTests.CsvData.cs renamed to test/RestSharp.Tests/Parameters/ObjectParameterTests.CsvData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace RestSharp.Tests;
1+
namespace RestSharp.Tests.Parameters;
22

33
public partial class ObjectParameterTests {
44
sealed record CsvData<TEnumerable>([property: RequestProperty(ArrayQueryType = RequestArrayQueryType.CommaSeparated)] TEnumerable Csv) where TEnumerable : notnull;

Diff for: test/RestSharp.Tests/ObjectParameterTests.FormattedData.cs renamed to test/RestSharp.Tests/Parameters/ObjectParameterTests.FormattedData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace RestSharp.Tests;
1+
namespace RestSharp.Tests.Parameters;
22

33
public partial class ObjectParameterTests {
44
sealed record FormattedData<TDateTime>([property: RequestProperty(Format = "hh:mm tt")] TDateTime FormattedParameter) where TDateTime : notnull;

Diff for: test/RestSharp.Tests/ObjectParameterTests.NamedData.cs renamed to test/RestSharp.Tests/Parameters/ObjectParameterTests.NamedData.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace RestSharp.Tests;
1+
namespace RestSharp.Tests.Parameters;
22

33
public partial class ObjectParameterTests {
44
sealed record NamedData([property: RequestProperty(Name = "CustomName")] object NamedParameter);

Diff for: test/RestSharp.Tests/ObjectParameterTests.cs renamed to test/RestSharp.Tests/Parameters/ObjectParameterTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Collections;
22
using System.Globalization;
33

4-
namespace RestSharp.Tests;
4+
namespace RestSharp.Tests.Parameters;
55

66
public partial class ObjectParameterTests {
77
public ObjectParameterTests() => Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

Diff for: test/RestSharp.Tests/ParameterValidationTests.cs renamed to test/RestSharp.Tests/Parameters/ParameterValidationTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace RestSharp.Tests;
1+
namespace RestSharp.Tests.Parameters;
22

33
public class ParameterValidationTests {
44
[Fact]

Diff for: test/RestSharp.Tests/ParametersTests.cs renamed to test/RestSharp.Tests/Parameters/UrlSegmentTests.cs

+26-19
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,8 @@
1-
namespace RestSharp.Tests;
1+
namespace RestSharp.Tests.Parameters;
22

3-
public class ParametersTests {
3+
public class UrlSegmentTests {
44
const string BaseUrl = "http://localhost:8888/";
55

6-
[Fact]
7-
public void AddDefaultHeadersUsingDictionary() {
8-
var headers = new Dictionary<string, string> {
9-
{ KnownHeaders.ContentType, ContentType.Json },
10-
{ KnownHeaders.Accept, ContentType.Json },
11-
{ KnownHeaders.ContentEncoding, "gzip, deflate" }
12-
};
13-
14-
var expected = headers.Select(x => new HeaderParameter(x.Key, x.Value));
15-
16-
using var client = new RestClient(BaseUrl);
17-
client.AddDefaultHeaders(headers);
18-
19-
var actual = client.DefaultParameters.Select(x => x as HeaderParameter);
20-
expected.Should().BeSubsetOf(actual);
21-
}
22-
236
[Fact]
247
public void AddUrlSegmentWithInt() {
258
const string name = "foo";
@@ -63,4 +46,28 @@ public void AddUrlSegmentModifiesUrlSegmentWithString() {
6346

6447
expected.Should().BeEquivalentTo(actual);
6548
}
49+
50+
[Theory]
51+
[InlineData("bar%2fBAR")]
52+
[InlineData("bar%2FBAR")]
53+
public void UrlSegmentParameter_WithValueWithEncodedSlash_WillReplaceEncodedSlashByDefault(string inputValue) {
54+
var urlSegmentParameter = new UrlSegmentParameter("foo", inputValue);
55+
urlSegmentParameter.Value.Should().BeEquivalentTo("bar/BAR");
56+
}
57+
58+
[Theory]
59+
[InlineData("bar%2fBAR")]
60+
[InlineData("bar%2FBAR")]
61+
public void UrlSegmentParameter_WithValueWithEncodedSlash_CanReplaceEncodedSlash(string inputValue) {
62+
var urlSegmentParameter = new UrlSegmentParameter("foo", inputValue, replaceEncodedSlash: true);
63+
urlSegmentParameter.Value.Should().BeEquivalentTo("bar/BAR");
64+
}
65+
66+
[Theory]
67+
[InlineData("bar%2fBAR")]
68+
[InlineData("bar%2FBAR")]
69+
public void UrlSegmentParameter_WithValueWithEncodedSlash_CanLeaveEncodedSlash(string inputValue) {
70+
var urlSegmentParameter = new UrlSegmentParameter("foo", inputValue, replaceEncodedSlash: false);
71+
urlSegmentParameter.Value.Should().BeEquivalentTo(inputValue);
72+
}
6673
}

Diff for: test/RestSharp.Tests/RestClientTests.cs

-32
Original file line numberDiff line numberDiff line change
@@ -32,38 +32,6 @@ public async Task ConfigureHttp_will_set_proxy_to_null_with_no_exceptions_When_n
3232
await client.ExecuteAsync(req);
3333
}
3434

35-
[Fact]
36-
public void BuildUri_should_build_with_passing_link_as_Uri() {
37-
// arrange
38-
var relative = new Uri("/foo/bar/baz", UriKind.Relative);
39-
var absoluteUri = new Uri(new Uri(BaseUrl), relative);
40-
var req = new RestRequest(absoluteUri);
41-
42-
// act
43-
using var client = new RestClient();
44-
45-
var builtUri = client.BuildUri(req);
46-
47-
// assert
48-
absoluteUri.Should().Be(builtUri);
49-
}
50-
51-
[Fact]
52-
public void BuildUri_should_build_with_passing_link_as_Uri_with_set_BaseUrl() {
53-
// arrange
54-
var baseUrl = new Uri(BaseUrl);
55-
var relative = new Uri("/foo/bar/baz", UriKind.Relative);
56-
var req = new RestRequest(relative);
57-
58-
// act
59-
using var client = new RestClient(baseUrl);
60-
61-
var builtUri = client.BuildUri(req);
62-
63-
// assert
64-
new Uri(baseUrl, relative).Should().Be(builtUri);
65-
}
66-
6735
[Fact]
6836
public void UseJson_leaves_only_json_serializer() {
6937
// arrange

Diff for: test/RestSharp.Tests/RestSharp.Tests.csproj

+4-10
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,11 @@
2929
<None Update="SampleData\underscore_prefix.json" CopyToOutputDirectory="PreserveNewest"/>
3030
</ItemGroup>
3131
<ItemGroup>
32-
<Compile Update="ObjectParameterTests.ArrayData.cs">
33-
<DependentUpon>ObjectParameterTests.cs</DependentUpon>
32+
<Compile Update="UrlBuilderTests.Get.cs">
33+
<DependentUpon>UrlBuilderTests.cs</DependentUpon>
3434
</Compile>
35-
<Compile Update="ObjectParameterTests.CsvData.cs">
36-
<DependentUpon>ObjectParameterTests.cs</DependentUpon>
37-
</Compile>
38-
<Compile Update="ObjectParameterTests.FormattedData.cs">
39-
<DependentUpon>ObjectParameterTests.cs</DependentUpon>
40-
</Compile>
41-
<Compile Update="ObjectParameterTests.NamedData.cs">
42-
<DependentUpon>ObjectParameterTests.cs</DependentUpon>
35+
<Compile Update="UrlBuilderTests.Post.cs">
36+
<DependentUpon>UrlBuilderTests.cs</DependentUpon>
4337
</Compile>
4438
</ItemGroup>
4539
</Project>

0 commit comments

Comments
 (0)