Add fixes for problems discovered by xunit.analyzers (#1999)

* Add fixes to tests for problems discovered by xunit.analyzers 0.6.1

* PR feedback. Add comments about why we have a #pragma
This commit is contained in:
Nate McMaster 2017-08-16 09:37:49 -07:00 committed by GitHub
parent 5c775073a4
commit c10ac85cf2
6 changed files with 16 additions and 8 deletions

View File

@ -543,7 +543,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
await _frameConnection.StopAsync().TimeoutAfter(TimeSpan.FromSeconds(5)); await _frameConnection.StopAsync().TimeoutAfter(TimeSpan.FromSeconds(5));
Assert.Equal(1, scopeObjects.Count); Assert.Single(scopeObjects);
var pairs = scopeObjects[0].ToDictionary(p => p.Key, p => p.Value); var pairs = scopeObjects[0].ToDictionary(p => p.Key, p => p.Value);
Assert.True(pairs.ContainsKey("ConnectionId")); Assert.True(pairs.ContainsKey("ConnectionId"));
Assert.Equal(_frameConnection.ConnectionId, pairs["ConnectionId"]); Assert.Equal(_frameConnection.ConnectionId, pairs["ConnectionId"]);

View File

@ -332,7 +332,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
string requestLine, string requestLine,
string expectedMethod, string expectedMethod,
string expectedRawTarget, string expectedRawTarget,
// This warns that theory methods should use all of their parameters,
// but this method is using a shared data collection with HttpParserTests.ParsesRequestLine and others.
#pragma warning disable xUnit1026
string expectedRawPath, string expectedRawPath,
#pragma warning restore xUnit1026
string expectedDecodedPath, string expectedDecodedPath,
string expectedQueryString, string expectedQueryString,
string expectedHttpVersion) string expectedHttpVersion)

View File

@ -26,8 +26,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
string expectedMethod, string expectedMethod,
string expectedRawTarget, string expectedRawTarget,
string expectedRawPath, string expectedRawPath,
// This warns that theory methods should use all of their parameters,
// but this method is using a shared data collection with FrameTests.TakeStartLineSetsFrameProperties and others.
#pragma warning disable xUnit1026
string expectedDecodedPath, string expectedDecodedPath,
string expectedQueryString, string expectedQueryString,
#pragma warning restore xUnit1026
string expectedVersion) string expectedVersion)
{ {
var parser = CreateParser(Mock.Of<IKestrelTrace>()); var parser = CreateParser(Mock.Of<IKestrelTrace>());
@ -391,7 +395,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes);
var pairs = requestHandler.Headers.ToArray(); var pairs = requestHandler.Headers.ToArray();
Assert.Equal(1, pairs.Length); Assert.Single(pairs);
Assert.Equal(headerName, pairs[0].Key); Assert.Equal(headerName, pairs[0].Key);
Assert.Equal(expectedHeaderValue, pairs[0].Value); Assert.Equal(expectedHeaderValue, pairs[0].Value);
Assert.Equal(buffer.End, consumed); Assert.Equal(buffer.End, consumed);

View File

@ -64,14 +64,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests
var block = new Span<byte>(Encoding.ASCII.GetBytes(input)); var block = new Span<byte>(Encoding.ASCII.GetBytes(input));
// Act // Act
HttpVersion knownVersion; var result = block.GetKnownVersion(out HttpVersion knownVersion, out var length);
var result = block.GetKnownVersion(out knownVersion, out var length);
string toString = null; string toString = null;
if (knownVersion != HttpVersion.Unknown) if (knownVersion != HttpVersion.Unknown)
{ {
toString = HttpUtilities.VersionToString(knownVersion); toString = HttpUtilities.VersionToString(knownVersion);
} }
// Assert // Assert
Assert.Equal(version, knownVersion);
Assert.Equal(expectedResult, result); Assert.Equal(expectedResult, result);
Assert.Equal(expectedKnownString, toString); Assert.Equal(expectedKnownString, toString);
Assert.Equal(expectedKnownString?.Length ?? 0, length); Assert.Equal(expectedKnownString?.Length ?? 0, length);

View File

@ -232,7 +232,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
using (var client = new TcpClient()) using (var client = new TcpClient())
{ {
var stream = await OpenSslStream(client, server); var stream = await OpenSslStream(client, server);
var ex = await Assert.ThrowsAsync(typeof(IOException), var ex = await Assert.ThrowsAsync<IOException>(
async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false)); async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false));
} }
} }

View File

@ -1184,9 +1184,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
} }
} }
[Theory] [Fact]
[MemberData(nameof(ConnectionAdapterData))] public async Task HeadersAndStreamsAreReusedAcrossRequests()
public async Task HeadersAndStreamsAreReusedAcrossRequests(ListenOptions listenOptions)
{ {
var testContext = new TestServiceContext(); var testContext = new TestServiceContext();
var streamCount = 0; var streamCount = 0;