-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
b2031e0
commit c7eebdf
Showing
5 changed files
with
81 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Net; | ||
using RestSharp.IntegrationTests.Fixtures; | ||
|
||
namespace RestSharp.IntegrationTests; | ||
|
||
[Collection(nameof(TestServerCollection))] | ||
public class RequestFailureTests { | ||
readonly RestClient _client; | ||
readonly TestServerFixture _fixture; | ||
|
||
public RequestFailureTests(TestServerFixture fixture) { | ||
_client = new RestClient(fixture.Server.Url); | ||
_fixture = fixture; | ||
} | ||
|
||
[Fact] | ||
public async Task Handles_GET_Request_Errors() { | ||
var request = new RestRequest("status?code=404"); | ||
var response = await _client.ExecuteAsync(request); | ||
|
||
response.StatusCode.Should().Be(HttpStatusCode.NotFound); | ||
} | ||
|
||
[Fact] | ||
public async Task Handles_GET_Request_Errors_With_Response_Type() { | ||
var request = new RestRequest("status?code=404"); | ||
var response = await _client.ExecuteAsync<Response>(request); | ||
|
||
response.StatusCode.Should().Be(HttpStatusCode.NotFound); | ||
response.Data.Should().Be(null); | ||
} | ||
|
||
[Fact] | ||
public async Task Throws_on_unsuccessful_call() { | ||
var client = new RestClient(new RestClientOptions(_fixture.Server.Url) { ThrowOnAnyError = true }); | ||
var request = new RestRequest("status?code=404"); | ||
|
||
var task = () => client.ExecuteAsync<Response>(request); | ||
await task.Should().ThrowExactlyAsync<HttpRequestException>(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAsync_throws_on_unsuccessful_call() { | ||
var request = new RestRequest("status?code=404"); | ||
|
||
var task = () => _client.GetAsync(request); | ||
await task.Should().ThrowExactlyAsync<HttpRequestException>(); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAsync_generic_throws_on_unsuccessful_call() { | ||
var request = new RestRequest("status?code=404"); | ||
|
||
var task = () => _client.GetAsync<Response>(request); | ||
await task.Should().ThrowExactlyAsync<HttpRequestException>(); | ||
} | ||
|
||
class Response { | ||
public string Message { get; set; } | ||
} | ||
} |
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