diff --git a/src/RestSharp/Enum.cs b/src/RestSharp/Enum.cs index e046d4864..fd584bc8c 100644 --- a/src/RestSharp/Enum.cs +++ b/src/RestSharp/Enum.cs @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +using System.Net; namespace RestSharp; @@ -19,9 +20,44 @@ namespace RestSharp; /// public enum ParameterType { /// - /// Cookie parameter + /// A that will added to the QueryString for GET, DELETE, OPTIONS and HEAD requests; and form for POST and PUT requests. /// - GetOrPost, UrlSegment, HttpHeader, RequestBody, QueryString + /// + /// See . + /// + GetOrPost, + + /// + /// A that will be added to part of the url by replacing a {placeholder} within the absolute path. + /// + /// + /// See . + /// + UrlSegment, + + /// + /// A that will be added as a request header + /// + /// + /// See . + /// + HttpHeader, + + /// + /// A that will be added to the request body + /// + /// + /// See . + /// + RequestBody, + + /// + /// A that will be added to the query string + /// + /// + /// See . + /// + QueryString } /// @@ -55,4 +91,29 @@ public struct DateFormat { /// /// Status for responses (surprised?) /// -public enum ResponseStatus { None, Completed, Error, TimedOut, Aborted } \ No newline at end of file +public enum ResponseStatus { + /// + /// Not Applicable, for when the Request has not yet been made + /// + None, + + /// + /// for when the request is passes as a result of being true, or when the response is + /// + Completed, + + /// + /// for when the request fails due as a result of being false except for the case when the response is + /// + Error, + + /// + /// for when the Operation is cancelled due to the request taking longer than the length of time prescribed by or due to the timing out. + /// + TimedOut, + + /// + /// for when the Operation is cancelled, due to reasons other than + /// + Aborted +} \ No newline at end of file diff --git a/src/RestSharp/Parameters/UrlSegmentParameter.cs b/src/RestSharp/Parameters/UrlSegmentParameter.cs index 04b60d65c..deb0b3bdc 100644 --- a/src/RestSharp/Parameters/UrlSegmentParameter.cs +++ b/src/RestSharp/Parameters/UrlSegmentParameter.cs @@ -16,7 +16,7 @@ namespace RestSharp; public record UrlSegmentParameter : NamedParameter { /// - /// Instantiates a new query parameter instance that will be added to the request URL part of the query string. + /// Instantiates a new query parameter instance that will be added to the request URL by replacing part of the absolute path. /// The request resource should have a placeholder {name} that will be replaced with the parameter value when the request is made. /// /// Parameter name diff --git a/test/RestSharp.Tests/ParametersTests.cs b/test/RestSharp.Tests/ParametersTests.cs index 8bfc6edf3..719e96ed5 100644 --- a/test/RestSharp.Tests/ParametersTests.cs +++ b/test/RestSharp.Tests/ParametersTests.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.IO; namespace RestSharp.Tests; @@ -26,10 +27,49 @@ public void AddDefaultHeadersUsingDictionary() { public void AddUrlSegmentWithInt() { const string name = "foo"; + var request = new RestRequest().AddUrlSegment(name, 1); var actual = request.Parameters.FirstOrDefault(x => x.Name == name); var expected = new UrlSegmentParameter(name, "1"); expected.Should().BeEquivalentTo(actual); } + + [Fact] + public void AddUrlSegmentModifiesUrlSegmentWithInt() { + const string name = "foo"; + var pathTemplate = "/{0}/resource"; + var path = String.Format(pathTemplate, "{" + name + "}"); + var urlSegmentValue = 1; + + var request = new RestRequest(path).AddUrlSegment(name, urlSegmentValue); + + var expected = String.Format(pathTemplate, urlSegmentValue); + + var client = new RestClient(BaseUrl); + + var actual = client.BuildUri(request).AbsolutePath; + + + expected.Should().BeEquivalentTo(actual); + } + + [Fact] + public void AddUrlSegmentModifiesUrlSegmentWithString() { + const string name = "foo"; + var pathTemplate = "/{0}/resource"; + var path = String.Format(pathTemplate, "{" + name + "}"); + var urlSegmentValue = "bar"; + + var request = new RestRequest(path).AddUrlSegment(name, urlSegmentValue); + + var expected = String.Format(pathTemplate, urlSegmentValue); + + var client = new RestClient(BaseUrl); + + var actual = client.BuildUri(request).AbsolutePath; + + expected.Should().BeEquivalentTo(actual); + + } } \ No newline at end of file