-
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 * Calculate headers before send request (#90)
- Loading branch information
1 parent
3967167
commit f2a3d10
Showing
9 changed files
with
129 additions
and
3 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
24 changes: 24 additions & 0 deletions
24
Tests/Tiny.RestClient.ForTest.Api/Controllers/HeadersTestController.cs
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,24 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace Tiny.RestClient.ForTest.Api.Controllers | ||
{ | ||
[Route("api/HeadersTest")] | ||
[ApiController] | ||
public class HeadersTestController : ControllerBase | ||
{ | ||
[HttpGet("NoResponse")] | ||
public Task NoResponse() | ||
{ | ||
foreach (var header in Request.Headers) | ||
{ | ||
Response.Headers.Add("FROM_CLIENT" + header.Key, header.Value); | ||
} | ||
|
||
return Task.Delay(1); | ||
} | ||
} | ||
} |
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,43 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Tiny.RestClient.Tests | ||
{ | ||
[TestClass] | ||
public class HeaderTests : BaseTest | ||
{ | ||
[TestMethod] | ||
public async Task CalculateHeadersTest() | ||
{ | ||
var client = GetNewClient(); | ||
|
||
var headers = new Headers | ||
{ | ||
{ "Header1", "Value1" }, | ||
{ "Header2", "Value2" }, | ||
{ "Header3", "Value3" } | ||
}; | ||
|
||
client.Settings.CalculateHeadersHandler = () => | ||
{ | ||
return Task.FromResult(headers); | ||
}; | ||
|
||
await client. | ||
GetRequest("HeadersTest/NoResponse"). | ||
FillResponseHeaders(out Headers responseHeaders). | ||
ExecuteAsync(); | ||
|
||
foreach (var sendedHeader in headers) | ||
{ | ||
Assert.IsTrue(responseHeaders.Any(h => h.Key == "FROM_CLIENT" + sendedHeader.Key), $"{sendedHeader.Key} seem not passed to server side"); | ||
var responseHeader = responseHeaders.FirstOrDefault(h => h.Key == "FROM_CLIENT" + sendedHeader.Key); | ||
Assert.IsTrue(sendedHeader.Value.First() == responseHeader.Value.First(), $"Values for header {sendedHeader.Key} seem not match with values resend by server"); | ||
} | ||
} | ||
} | ||
} |
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
Binary file not shown.