Remove TestServer dependency from TestConnection.

This commit is contained in:
Cesar Blum Silveira 2016-08-02 12:26:17 -07:00
parent 4ece3f4b68
commit 138f23b246
4 changed files with 11 additions and 14 deletions

View File

@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
{ {
await connection.SendAllTryEnd(request); await connection.SendAllTryEnd(request);
await ReceiveBadRequestResponse(connection); await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue);
} }
} }
} }
@ -131,7 +131,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
{ {
await connection.SendAll(request); await connection.SendAll(request);
await ReceiveBadRequestResponse(connection); await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue);
} }
} }
} }
@ -167,7 +167,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
{ {
await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{rawHeaders}"); await connection.SendAllTryEnd($"GET / HTTP/1.1\r\n{rawHeaders}");
await ReceiveBadRequestResponse(connection); await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue);
} }
} }
} }
@ -184,7 +184,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
"H\u00eb\u00e4d\u00ebr: value", "H\u00eb\u00e4d\u00ebr: value",
"", "",
""); "");
await ReceiveBadRequestResponse(connection); await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue);
} }
} }
} }
@ -211,12 +211,12 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
using (var connection = server.CreateConnection()) using (var connection = server.CreateConnection())
{ {
await connection.SendAllTryEnd($"GET {path} HTTP/1.1\r\n"); await connection.SendAllTryEnd($"GET {path} HTTP/1.1\r\n");
await ReceiveBadRequestResponse(connection); await ReceiveBadRequestResponse(connection, server.Context.DateHeaderValue);
} }
} }
} }
private async Task ReceiveBadRequestResponse(TestConnection connection) private async Task ReceiveBadRequestResponse(TestConnection connection, string expectedDateHeaderValue)
{ {
await connection.Receive( await connection.Receive(
"HTTP/1.1 400 Bad Request", "HTTP/1.1 400 Bad Request",
@ -225,7 +225,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
"Connection: close", "Connection: close",
""); "");
await connection.ReceiveForcedEnd( await connection.ReceiveForcedEnd(
$"Date: {connection.Server.Context.DateHeaderValue}", $"Date: {expectedDateHeaderValue}",
"Content-Length: 0", "Content-Length: 0",
"", "",
""); "");

View File

@ -1191,7 +1191,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
""); "");
await connection.ReceiveEnd( await connection.ReceiveEnd(
"HTTP/1.1 200 OK", "HTTP/1.1 200 OK",
$"Date: {connection.Server.Context.DateHeaderValue}", $"Date: {server.Context.DateHeaderValue}",
$"Content-Length: {expectedPath.Length.ToString()}", $"Content-Length: {expectedPath.Length.ToString()}",
"", "",
$"{expectedPath}"); $"{expectedPath}");

View File

@ -22,14 +22,11 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
private NetworkStream _stream; private NetworkStream _stream;
private StreamReader _reader; private StreamReader _reader;
public TestConnection(TestServer server) public TestConnection(int port)
{ {
Server = server; Create(port);
Create(server.Port);
} }
public TestServer Server { get; }
public void Create(int port) public void Create(int port)
{ {
_socket = CreateConnectedLoopbackSocket(port); _socket = CreateConnectedLoopbackSocket(port);

View File

@ -58,7 +58,7 @@ namespace Microsoft.AspNetCore.Server.KestrelTests
public TestConnection CreateConnection() public TestConnection CreateConnection()
{ {
return new TestConnection(this); return new TestConnection(Port);
} }
public void Dispose() public void Dispose()