Skip to content

Commit 90e70fc

Browse files
authored
V109 (#2010)
* Fixes some documentation Adds more Parameter Tests * Makes the new tests more readable and understandable * Fixes Documentation per request
1 parent 27272f3 commit 90e70fc

File tree

3 files changed

+105
-4
lines changed

3 files changed

+105
-4
lines changed

src/RestSharp/Enum.cs

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
14+
using System.Net;
1415

1516
namespace RestSharp;
1617

@@ -19,9 +20,44 @@ namespace RestSharp;
1920
/// </summary>
2021
public enum ParameterType {
2122
/// <summary>
22-
/// Cookie parameter
23+
/// A <see cref="Parameter"/> that will added to the QueryString for GET, DELETE, OPTIONS and HEAD requests; and form for POST and PUT requests.
2324
/// </summary>
24-
GetOrPost, UrlSegment, HttpHeader, RequestBody, QueryString
25+
/// <remarks>
26+
/// See <see cref="GetOrPostParameter"/>.
27+
/// </remarks>
28+
GetOrPost,
29+
30+
/// <summary>
31+
/// A <see cref="Parameter"/> that will be added to part of the url by replacing a <c>{placeholder}</c> within the absolute path.
32+
/// </summary>
33+
/// <remarks>
34+
/// See <see cref="UrlSegmentParameter"/>.
35+
/// </remarks>
36+
UrlSegment,
37+
38+
/// <summary>
39+
/// A <see cref="Parameter"/> that will be added as a request header
40+
/// </summary>
41+
/// <remarks>
42+
/// See <see cref="HeaderParameter"/>.
43+
/// </remarks>
44+
HttpHeader,
45+
46+
/// <summary>
47+
/// A <see cref="Parameter"/> that will be added to the request body
48+
/// </summary>
49+
/// <remarks>
50+
/// See <see cref="BodyParameter"/>.
51+
/// </remarks>
52+
RequestBody,
53+
54+
/// <summary>
55+
/// A <see cref="Parameter"/> that will be added to the query string
56+
/// </summary>
57+
/// <remarks>
58+
/// See <see cref="QueryParameter"/>.
59+
/// </remarks>
60+
QueryString
2561
}
2662

2763
/// <summary>
@@ -55,4 +91,29 @@ public struct DateFormat {
5591
/// <summary>
5692
/// Status for responses (surprised?)
5793
/// </summary>
58-
public enum ResponseStatus { None, Completed, Error, TimedOut, Aborted }
94+
public enum ResponseStatus {
95+
/// <summary>
96+
/// Not Applicable, for when the Request has not yet been made
97+
/// </summary>
98+
None,
99+
100+
/// <summary>
101+
/// <see cref="ResponseStatus"/> for when the request is passes as a result of <see cref="HttpResponseMessage.IsSuccessStatusCode"/> being true, or when the response is <see cref="HttpStatusCode.NotFound"/>
102+
/// </summary>
103+
Completed,
104+
105+
/// <summary>
106+
/// <see cref="ResponseStatus"/> for when the request fails due as a result of <see cref="HttpResponseMessage.IsSuccessStatusCode"/> being false except for the case when the response is <see cref="HttpStatusCode.NotFound"/>
107+
/// </summary>
108+
Error,
109+
110+
/// <summary>
111+
/// <see cref="ResponseStatus"/> for when the Operation is cancelled due to the request taking longer than the length of time prescribed by <see cref="RestRequest.Timeout"/> or due to the <see cref="HttpClient"/> timing out.
112+
/// </summary>
113+
TimedOut,
114+
115+
/// <summary>
116+
/// <see cref="ResponseStatus"/> for when the Operation is cancelled, due to reasons other than <see cref="TimedOut"/>
117+
/// </summary>
118+
Aborted
119+
}

src/RestSharp/Parameters/UrlSegmentParameter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace RestSharp;
1616

1717
public record UrlSegmentParameter : NamedParameter {
1818
/// <summary>
19-
/// Instantiates a new query parameter instance that will be added to the request URL part of the query string.
19+
/// Instantiates a new query parameter instance that will be added to the request URL by replacing part of the absolute path.
2020
/// The request resource should have a placeholder {name} that will be replaced with the parameter value when the request is made.
2121
/// </summary>
2222
/// <param name="name">Parameter name</param>

test/RestSharp.Tests/ParametersTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections;
2+
using System.IO;
23

34
namespace RestSharp.Tests;
45

@@ -26,10 +27,49 @@ public void AddDefaultHeadersUsingDictionary() {
2627
public void AddUrlSegmentWithInt() {
2728
const string name = "foo";
2829

30+
2931
var request = new RestRequest().AddUrlSegment(name, 1);
3032
var actual = request.Parameters.FirstOrDefault(x => x.Name == name);
3133
var expected = new UrlSegmentParameter(name, "1");
3234

3335
expected.Should().BeEquivalentTo(actual);
3436
}
37+
38+
[Fact]
39+
public void AddUrlSegmentModifiesUrlSegmentWithInt() {
40+
const string name = "foo";
41+
var pathTemplate = "/{0}/resource";
42+
var path = String.Format(pathTemplate, "{" + name + "}");
43+
var urlSegmentValue = 1;
44+
45+
var request = new RestRequest(path).AddUrlSegment(name, urlSegmentValue);
46+
47+
var expected = String.Format(pathTemplate, urlSegmentValue);
48+
49+
var client = new RestClient(BaseUrl);
50+
51+
var actual = client.BuildUri(request).AbsolutePath;
52+
53+
54+
expected.Should().BeEquivalentTo(actual);
55+
}
56+
57+
[Fact]
58+
public void AddUrlSegmentModifiesUrlSegmentWithString() {
59+
const string name = "foo";
60+
var pathTemplate = "/{0}/resource";
61+
var path = String.Format(pathTemplate, "{" + name + "}");
62+
var urlSegmentValue = "bar";
63+
64+
var request = new RestRequest(path).AddUrlSegment(name, urlSegmentValue);
65+
66+
var expected = String.Format(pathTemplate, urlSegmentValue);
67+
68+
var client = new RestClient(BaseUrl);
69+
70+
var actual = client.BuildUri(request).AbsolutePath;
71+
72+
expected.Should().BeEquivalentTo(actual);
73+
74+
}
3575
}

0 commit comments

Comments
 (0)