Skip to content
This repository was archived by the owner on Sep 9, 2022. It is now read-only.

Commit e17c064

Browse files
committed
Added test for checking if the custom headers are copied over when compressing content
1 parent 57a5844 commit e17c064

File tree

6 files changed

+34
-2
lines changed

6 files changed

+34
-2
lines changed
Binary file not shown.
Binary file not shown.

src/Tests/Controllers/TestController.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,22 @@
66

77
using global::Tests.Models;
88

9-
using Microsoft.AspNet.WebApi.MessageHandlers.Compression.Attributes;
10-
119
public class TestController : ApiController
1210
{
1311
public async Task<HttpResponseMessage> Get()
1412
{
1513
return this.Request.CreateResponse(new TestModel("Get()"));
1614
}
1715

16+
[Route("api/test/customheader")]
17+
public async Task<HttpResponseMessage> GetCustomHeader()
18+
{
19+
var response = this.Request.CreateResponse(new TestModel("Get()"));
20+
response.Headers.Add("DataServiceVersion", "3.0");
21+
22+
return response;
23+
}
24+
1825
public async Task<HttpResponseMessage> Get(string id)
1926
{
2027
return this.Request.CreateResponse(new TestModel("Get(" + id + ")"));

src/Tests/Tests/Common/TestFixture.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ public async Task Get_WhenMessageHandlerIsConfigured_ShouldReturnCompressedConte
4141
Assert.AreEqual("Get()", result.Data);
4242
}
4343

44+
public async Task Get_WhenGivenCustomHeader_ShouldReturnCompressedContentWithCustomHeader()
45+
{
46+
var response = await this.client.GetAsync("http://localhost:55399/api/test/customheader");
47+
48+
Console.WriteLine("Content: {0}", await response.Content.ReadAsStringAsync());
49+
50+
Assert.IsTrue(response.Content.Headers.ContentEncoding.Contains("gzip"));
51+
52+
Console.WriteLine("Content-Length: {0}", response.Content.Headers.ContentLength);
53+
54+
Assert.IsTrue(response.Headers.Contains("DataServiceVersion"), "The response did not contain the DataServiceVersion header");
55+
}
56+
4457
public async Task GetImage_WhenMessageHandlerIsConfigured_ShouldReturnCompressedContent()
4558
{
4659

src/Tests/Tests/Facade/OwinHostTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ public async void Get_WhenMessageHandlerIsConfigured_ShouldReturnCompressedConte
5151
await this.testFixture.Get_WhenMessageHandlerIsConfigured_ShouldReturnCompressedContent();
5252
}
5353

54+
[Test]
55+
public async void Get_WhenGivenCustomHeader_ShouldReturnCompressedContentWithCustomHeader()
56+
{
57+
await this.testFixture.Get_WhenGivenCustomHeader_ShouldReturnCompressedContentWithCustomHeader();
58+
}
59+
5460
[Test]
5561
public async void GetImage_WhenMessageHandlerIsConfigured_ShouldReturnCompressedContent()
5662
{

src/Tests/Tests/Facade/WebHostTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public async void Get_WhenMessageHandlerIsConfigured_ShouldReturnCompressedConte
6262
await this.testFixture.Get_WhenMessageHandlerIsConfigured_ShouldReturnCompressedContent();
6363
}
6464

65+
[Test]
66+
public async void Get_WhenGivenCustomHeader_ShouldReturnCompressedContentWithCustomHeader()
67+
{
68+
await this.testFixture.Get_WhenGivenCustomHeader_ShouldReturnCompressedContentWithCustomHeader();
69+
}
70+
6571
[Test]
6672
public async void GetImage_WhenMessageHandlerIsConfigured_ShouldReturnCompressedContent()
6773
{

0 commit comments

Comments
 (0)