-
-
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.
Add more tests for PUT and POST (#1688)
* Made `AddJsonBody` and `AddXmlBody` generic with class constraint so that people don't use them to add strings * Added an option to disable the charset (`RestClientOptions.DisableCharset`)
- Loading branch information
1 parent
3e36e84
commit 8b388fb
Showing
9 changed files
with
231 additions
and
32 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
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
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,49 @@ | ||
using System.Text.Json; | ||
using RestSharp.IntegrationTests.Fixtures; | ||
|
||
namespace RestSharp.IntegrationTests; | ||
|
||
[Collection(nameof(TestServerCollection))] | ||
public class PutTests { | ||
readonly ITestOutputHelper _output; | ||
readonly RestClient _client; | ||
|
||
static readonly JsonSerializerOptions Options = new(JsonSerializerDefaults.Web); | ||
|
||
public PutTests(TestServerFixture fixture, ITestOutputHelper output) { | ||
_output = output; | ||
_client = new RestClient(fixture.Server.Url); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_put_json_body() { | ||
var body = new TestRequest("foo", 100); | ||
var request = new RestRequest("content").AddJsonBody(body); | ||
var response = await _client.PutAsync(request); | ||
|
||
var expected = JsonSerializer.Serialize(body, Options); | ||
response!.Content.Should().Be(expected); | ||
} | ||
|
||
[Fact] | ||
public async Task Should_put_json_body_using_extension() { | ||
var body = new TestRequest("foo", 100); | ||
var response = await _client.PutJsonAsync<TestRequest, TestRequest>("content", body); | ||
response.Should().BeEquivalentTo(response); | ||
} | ||
|
||
[Fact] | ||
public async Task Can_Timeout_PUT_Async() { | ||
var request = new RestRequest("timeout", Method.Put).AddBody("Body_Content"); | ||
|
||
// Half the value of ResponseHandler.Timeout | ||
request.Timeout = 200; | ||
|
||
var response = await _client.ExecuteAsync(request); | ||
|
||
Assert.Equal(ResponseStatus.TimedOut, response.ResponseStatus); | ||
} | ||
|
||
} | ||
|
||
record TestRequest(string Data, int Number); |
Oops, something went wrong.