From c10ac85cf2cf510f2d6ad6b3f41a446339f8e76e Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Wed, 16 Aug 2017 09:37:49 -0700 Subject: [PATCH] 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 --- test/Kestrel.Core.Tests/FrameConnectionTests.cs | 2 +- test/Kestrel.Core.Tests/FrameTests.cs | 4 ++++ test/Kestrel.Core.Tests/HttpParserTests.cs | 6 +++++- test/Kestrel.Core.Tests/HttpUtilitiesTest.cs | 5 +++-- test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs | 2 +- test/Kestrel.FunctionalTests/RequestTests.cs | 5 ++--- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/Kestrel.Core.Tests/FrameConnectionTests.cs b/test/Kestrel.Core.Tests/FrameConnectionTests.cs index 5b7afe2176..0304ce3f7f 100644 --- a/test/Kestrel.Core.Tests/FrameConnectionTests.cs +++ b/test/Kestrel.Core.Tests/FrameConnectionTests.cs @@ -543,7 +543,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests 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); Assert.True(pairs.ContainsKey("ConnectionId")); Assert.Equal(_frameConnection.ConnectionId, pairs["ConnectionId"]); diff --git a/test/Kestrel.Core.Tests/FrameTests.cs b/test/Kestrel.Core.Tests/FrameTests.cs index 0f2682fcf6..d6a1c76637 100644 --- a/test/Kestrel.Core.Tests/FrameTests.cs +++ b/test/Kestrel.Core.Tests/FrameTests.cs @@ -332,7 +332,11 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string requestLine, string expectedMethod, 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, +#pragma warning restore xUnit1026 string expectedDecodedPath, string expectedQueryString, string expectedHttpVersion) diff --git a/test/Kestrel.Core.Tests/HttpParserTests.cs b/test/Kestrel.Core.Tests/HttpParserTests.cs index d79c5c3ea2..2113d756ea 100644 --- a/test/Kestrel.Core.Tests/HttpParserTests.cs +++ b/test/Kestrel.Core.Tests/HttpParserTests.cs @@ -26,8 +26,12 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests string expectedMethod, string expectedRawTarget, 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 expectedQueryString, +#pragma warning restore xUnit1026 string expectedVersion) { var parser = CreateParser(Mock.Of()); @@ -391,7 +395,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests parser.ParseHeaders(requestHandler, buffer, out var consumed, out var examined, out var consumedBytes); var pairs = requestHandler.Headers.ToArray(); - Assert.Equal(1, pairs.Length); + Assert.Single(pairs); Assert.Equal(headerName, pairs[0].Key); Assert.Equal(expectedHeaderValue, pairs[0].Value); Assert.Equal(buffer.End, consumed); diff --git a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs index af012742cb..8966c181b0 100644 --- a/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs +++ b/test/Kestrel.Core.Tests/HttpUtilitiesTest.cs @@ -64,14 +64,15 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Tests var block = new Span(Encoding.ASCII.GetBytes(input)); // Act - HttpVersion knownVersion; - var result = block.GetKnownVersion(out knownVersion, out var length); + var result = block.GetKnownVersion(out HttpVersion knownVersion, out var length); string toString = null; if (knownVersion != HttpVersion.Unknown) { toString = HttpUtilities.VersionToString(knownVersion); } + // Assert + Assert.Equal(version, knownVersion); Assert.Equal(expectedResult, result); Assert.Equal(expectedKnownString, toString); Assert.Equal(expectedKnownString?.Length ?? 0, length); diff --git a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs index 5ef04a4392..ebf6081761 100644 --- a/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs +++ b/test/Kestrel.FunctionalTests/HttpsConnectionAdapterTests.cs @@ -232,7 +232,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests using (var client = new TcpClient()) { var stream = await OpenSslStream(client, server); - var ex = await Assert.ThrowsAsync(typeof(IOException), + var ex = await Assert.ThrowsAsync( async () => await stream.AuthenticateAsClientAsync("localhost", new X509CertificateCollection(), SslProtocols.Tls, false)); } } diff --git a/test/Kestrel.FunctionalTests/RequestTests.cs b/test/Kestrel.FunctionalTests/RequestTests.cs index 7cf85fa7ce..0177877722 100644 --- a/test/Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Kestrel.FunctionalTests/RequestTests.cs @@ -1184,9 +1184,8 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests } } - [Theory] - [MemberData(nameof(ConnectionAdapterData))] - public async Task HeadersAndStreamsAreReusedAcrossRequests(ListenOptions listenOptions) + [Fact] + public async Task HeadersAndStreamsAreReusedAcrossRequests() { var testContext = new TestServiceContext(); var streamCount = 0;