Skip to content

Commit

Permalink
Added new request method: COPY
Browse files Browse the repository at this point in the history
  • Loading branch information
smietanka committed Dec 2, 2017
1 parent ef2744c commit b2493c6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The `RestSharp` package is now signed so there is no need to install `RestSharp.
* Supports custom serialization and deserialization via ISerializer and IDeserializer
* Fuzzy element name matching ('product_id' in XML/JSON will match C# property named 'ProductId')
* Automatic detection of type of content returned
* GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE supported
* GET, POST, PUT, PATCH, HEAD, OPTIONS, DELETE, COPY supported
* Other non-standard HTTP methods also supported
* OAuth 1, OAuth 2, Basic, NTLM and Parameter-based Authenticators included
* Supports custom authentication schemes via IAuthenticator
Expand Down
20 changes: 20 additions & 0 deletions RestSharp.IntegrationTests/AsyncRequestBodyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,26 @@ public void Can_Be_Added_To_PATCH_Request()
AssertHasRequestBody(contentType, bodyData);
}

[Test]
public void Can_Be_Added_To_COPY_Request()
{
const Method httpMethod = Method.COPY;

RestRequest request = new RestRequest(RequestBodyCapturer.Resource, httpMethod);

const string contentType = "text/plain";
const string bodyData = "abc123 foo bar baz BING!";

request.AddParameter(contentType, bodyData, ParameterType.RequestBody);

ManualResetEvent resetEvent = new ManualResetEvent(false);

_client.ExecuteAsync(request, response => resetEvent.Set());
resetEvent.WaitOne();

AssertHasRequestBody(contentType, bodyData);
}

private static void AssertHasNoRequestBody()
{
Assert.Null(RequestBodyCapturer.CapturedContentType);
Expand Down
21 changes: 21 additions & 0 deletions RestSharp.IntegrationTests/RequestBodyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ public void Can_Be_Added_To_PATCH_Request()
}
}

[Test]
public void Can_Be_Added_To_COPY_Request()
{
const Method httpMethod = Method.COPY;

using (SimpleServer.Create(BASE_URL, Handlers.Generic<RequestBodyCapturer>()))
{
RestClient client = new RestClient(BASE_URL);
RestRequest request = new RestRequest(RequestBodyCapturer.RESOURCE, httpMethod);

const string contentType = "text/plain";
const string bodyData = "abc123 foo bar baz BING!";

request.AddParameter(contentType, bodyData, ParameterType.RequestBody);

client.Execute(request);

AssertHasRequestBody(contentType, bodyData);
}
}

private static void AssertHasNoRequestBody()
{
Assert.Null(RequestBodyCapturer.CapturedContentType);
Expand Down
1 change: 1 addition & 0 deletions RestSharp/Enum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public enum Method
OPTIONS,
PATCH,
MERGE,
COPY
}

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions RestSharp/RestClient.Async.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public virtual RestRequestAsyncHandle ExecuteAsync(IRestRequest request,

switch (request.Method)
{
case Method.COPY:
case Method.MERGE:
case Method.PATCH:
case Method.POST:
Expand Down
1 change: 1 addition & 0 deletions RestSharp/RestClient.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public virtual IRestResponse Execute(IRestRequest request)

switch (request.Method)
{
case Method.COPY:
case Method.POST:
case Method.PUT:
case Method.PATCH:
Expand Down

0 comments on commit b2493c6

Please sign in to comment.