-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add response headers in HttpException * Add possibility to encapsulate HttpException automatically. * Update RELEASE-NOTES.md * Update stylecop * remove useless affectation * fix identation * typo * fix comments * remove using
- Loading branch information
1 parent
8e16d65
commit 3967167
Showing
38 changed files
with
385 additions
and
263 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Tiny.RestClient.Tests | ||
{ | ||
[TestClass] | ||
public class HttpExceptionTests : BaseTest | ||
{ | ||
[TestMethod] | ||
public async Task CheckIfHttpExceptionReadHeaders() | ||
{ | ||
bool exceptionThrowed = false; | ||
var client = GetClient(); | ||
try | ||
{ | ||
// Call an api not found (the ETag header is present in all responses on this server) | ||
await client.GetRequest("APIWhichNotExists").ExecuteAsync(); | ||
} | ||
catch (HttpException ex) | ||
{ | ||
exceptionThrowed = true; | ||
|
||
Assert.IsTrue(ex.ResponseHeaders.Contains("ETag"), "An header name 'ETag' must be present in response."); | ||
} | ||
|
||
Assert.IsTrue(exceptionThrowed, $"An {nameof(HttpException)} must be throwed"); | ||
} | ||
|
||
[ExpectedException(typeof(NotFoundCustomException))] | ||
[TestMethod] | ||
public async Task CheckIfEnclapsulationWorks() | ||
{ | ||
var client = GetNewClient(); | ||
client.Settings.EncapsulateHttpExceptionHandler = (ex) => | ||
{ | ||
if (ex.StatusCode == System.Net.HttpStatusCode.NotFound) | ||
{ | ||
return new NotFoundCustomException(); | ||
} | ||
|
||
return ex; | ||
}; | ||
|
||
// Call an API wich throw NotFound error | ||
await client.GetRequest("APIWhichNotExists").ExecuteAsync(); | ||
} | ||
|
||
internal class NotFoundCustomException : Exception | ||
{ | ||
} | ||
} | ||
} |
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
Oops, something went wrong.