-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhance MiniZipHttpException to include request details
- Loading branch information
1 parent
69c8e59
commit 74163ed
Showing
5 changed files
with
154 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Knapcode.MiniZip | ||
{ | ||
public class HttpMessageExtensionTest | ||
{ | ||
public class TheToHttpExceptionAsyncMethod | ||
{ | ||
[Fact] | ||
public async Task PutsRequestAndResponseInExceptionMessage() | ||
{ | ||
// Arrange | ||
var request = new HttpRequestMessage(HttpMethod.Put, "https://www.example.com/v3/index.json"); | ||
request.Headers.TryAddWithoutValidation("User-Agent", "my fake UA"); | ||
request.Content = new StringContent("my test content\nand the second line too."); | ||
request.Content.Headers.TryAddWithoutValidation("X-Content-Header", "I'm here too!"); | ||
|
||
var response = new HttpResponseMessage(HttpStatusCode.BadRequest); | ||
response.ReasonPhrase = "Not good request"; | ||
response.Headers.Age = TimeSpan.FromDays(9001); | ||
response.Content = new StringContent("This is the super cool response."); | ||
response.RequestMessage = request; | ||
|
||
// Act | ||
var exception = await response.ToHttpExceptionAsync("The request failed I guess?"); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); | ||
Assert.Equal("Not good request", exception.ReasonPhrase); | ||
Assert.Null(exception.InnerException); | ||
Assert.Equal( | ||
"The request failed I guess?\r\n\r\n=== Request ===\r\nPUT https://www.example.com/v3/index.json HTTP/1.1\r\nUser-Agent: my\r\nUser-Agent: fake\r\nUser-Agent: UA\r\nContent-Type: text/plain; charset=utf-8\r\nX-Content-Header: I'm here too!\r\n\r\nmy test content\nand the second line too.\r\n\r\n=== Response ===\r\nHTTP/1.1 400 Not good request\r\nAge: 777686400\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nThis is the super cool response.\r\n\r\n", | ||
exception.Message); | ||
} | ||
} | ||
} | ||
} |
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