Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Feb 17, 2018
1 parent 1c6d82d commit 35d5e16
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 47 deletions.
40 changes: 3 additions & 37 deletions test/Kestrel.Core.Tests/Http1ConnectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,40 +492,6 @@ public async Task TakeStartLineThrowsWhenMethodNotAllowed(string requestLine, Ht
Assert.Equal(HttpUtilities.MethodToString(allowedMethod), exception.AllowedHeader);
}

[Theory]
[InlineData("g", HttpMethod.Custom, "g")]
[InlineData("G", HttpMethod.Custom, "G")]
[InlineData("get", HttpMethod.Custom, "get")]
[InlineData("GET", HttpMethod.Get, "GET")]
[InlineData("put", HttpMethod.Custom, "put")]
[InlineData("PUT", HttpMethod.Put, "PUT")]
[InlineData("post", HttpMethod.Custom, "post")]
[InlineData("POST", HttpMethod.Post, "POST")]
[InlineData("head", HttpMethod.Custom, "head")]
[InlineData("HEAD", HttpMethod.Head, "HEAD")]
[InlineData("patch", HttpMethod.Custom, "patch")]
[InlineData("PATCH", HttpMethod.Patch, "PATCH")]
[InlineData("trace", HttpMethod.Custom, "trace")]
[InlineData("TRACE", HttpMethod.Trace, "TRACE")]
[InlineData("delete", HttpMethod.Custom, "delete")]
[InlineData("DELETE", HttpMethod.Delete, "DELETE")]
[InlineData("options", HttpMethod.Custom, "options")]
[InlineData("OPTIONS", HttpMethod.Options, "OPTIONS")]
[InlineData("connect", HttpMethod.Custom, "connect")]
[InlineData("CONNECT", HttpMethod.Connect, "CONNECT")]
[InlineData("unknown", HttpMethod.Custom, "unknown")]
[InlineData("UNKNOWN", HttpMethod.Custom, "UNKNOWN")]
public void RequestFeatureMethodSetsFrameEnum(string method, HttpMethod expectedEnum, string expectedString)
{
using (var input = new TestInput())
{
((IHttpRequestFeature)input.Http1Connection).Method = method;

Assert.Equal(expectedEnum, input.Http1Connection.Method);
Assert.Equal(expectedString, ((IHttpRequestFeature)input.Http1Connection).Method);
}
}

[Fact]
public void ProcessRequestsAsyncEnablesKeepAliveTimeout()
{
Expand Down Expand Up @@ -566,7 +532,7 @@ public async Task WriteDoesNotThrowForHeadResponse()
{
// Arrange
_http1Connection.HttpVersion = "HTTP/1.1";
((IHttpRequestFeature)_http1Connection).Method = "HEAD";
_http1Connection.Method = HttpMethod.Head;

// Act/Assert
await _http1Connection.WriteAsync(new ArraySegment<byte>(new byte[1]));
Expand All @@ -577,7 +543,7 @@ public async Task WriteAsyncDoesNotThrowForHeadResponse()
{
// Arrange
_http1Connection.HttpVersion = "HTTP/1.1";
((IHttpRequestFeature)_http1Connection).Method = "HEAD";
_http1Connection.Method = HttpMethod.Head;

// Act/Assert
await _http1Connection.WriteAsync(new ArraySegment<byte>(new byte[1]), default(CancellationToken));
Expand All @@ -588,7 +554,7 @@ public async Task ManuallySettingTransferEncodingThrowsForHeadResponse()
{
// Arrange
_http1Connection.HttpVersion = "HTTP/1.1";
((IHttpRequestFeature)_http1Connection).Method = "HEAD";
_http1Connection.Method = HttpMethod.Head;

// Act
_http1Connection.ResponseHeaders.Add("Transfer-Encoding", "chunked");
Expand Down
20 changes: 10 additions & 10 deletions test/Kestrel.Core.Tests/MessageBodyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,34 +333,34 @@ public void ForThrowsWhenFinalTransferCodingIsNotChunked()
}

[Theory]
[InlineData("POST")]
[InlineData("PUT")]
public void ForThrowsWhenMethodRequiresLengthButNoContentLengthOrTransferEncodingIsSet(string method)
[InlineData(HttpMethod.Post)]
[InlineData(HttpMethod.Put)]
public void ForThrowsWhenMethodRequiresLengthButNoContentLengthOrTransferEncodingIsSet(HttpMethod method)
{
using (var input = new TestInput())
{
((IHttpRequestFeature)input.Http1Connection).Method = method;
input.Http1Connection.Method = method;
var ex = Assert.Throws<BadHttpRequestException>(() =>
Http1MessageBody.For(HttpVersion.Http11, new HttpRequestHeaders(), input.Http1Connection));

Assert.Equal(StatusCodes.Status411LengthRequired, ex.StatusCode);
Assert.Equal(CoreStrings.FormatBadRequest_LengthRequired(method), ex.Message);
Assert.Equal(CoreStrings.FormatBadRequest_LengthRequired(((IHttpRequestFeature)input.Http1Connection).Method), ex.Message);
}
}

[Theory]
[InlineData("POST")]
[InlineData("PUT")]
public void ForThrowsWhenMethodRequiresLengthButNoContentLengthSetHttp10(string method)
[InlineData(HttpMethod.Post)]
[InlineData(HttpMethod.Put)]
public void ForThrowsWhenMethodRequiresLengthButNoContentLengthSetHttp10(HttpMethod method)
{
using (var input = new TestInput())
{
((IHttpRequestFeature)input.Http1Connection).Method = method;
input.Http1Connection.Method = method;
var ex = Assert.Throws<BadHttpRequestException>(() =>
Http1MessageBody.For(HttpVersion.Http10, new HttpRequestHeaders(), input.Http1Connection));

Assert.Equal(StatusCodes.Status400BadRequest, ex.StatusCode);
Assert.Equal(CoreStrings.FormatBadRequest_LengthRequiredHttp10(method), ex.Message);
Assert.Equal(CoreStrings.FormatBadRequest_LengthRequiredHttp10(((IHttpRequestFeature)input.Http1Connection).Method), ex.Message);
}
}

Expand Down

0 comments on commit 35d5e16

Please sign in to comment.