diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs index 5a605a74c..5fe9683d8 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/AddressRegistrationTests.cs @@ -570,21 +570,9 @@ public PortSupportedConditionAttribute(int port) _portSupported = new Lazy(CanBindToPort); } - public bool IsMet - { - get - { - return _portSupported.Value; - } - } + public bool IsMet => _portSupported.Value; - public string SkipReason - { - get - { - return $"Cannot bind to port {_port} on the host."; - } - } + public string SkipReason => $"Cannot bind to port {_port} on the host."; private bool CanBindToPort() { diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs index 36af57bd1..89deac4fa 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/BadHttpRequestTests.cs @@ -4,11 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Net.Sockets; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs index 40610fe4c..9bf523e42 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/EventSourceTests.cs @@ -56,7 +56,7 @@ await connection.SendAll("GET / HTTP/1.1", var stop = Assert.Single(events, e => e.EventName == "ConnectionStop"); Assert.All(new[] { "connectionId" }, p => Assert.Contains(p, stop.PayloadNames)); - Assert.Same(KestrelEventSource.Log, stop.EventSource); + Assert.Same(KestrelEventSource.Log, stop?.EventSource); } private string GetProperty(EventWrittenEventArgs data, string propName) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs index 113ddc183..223974128 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/HttpsTests.cs @@ -163,7 +163,7 @@ public async Task DoesNotThrowObjectDisposedExceptionFromWriteAsyncAfterConnecti httpContext.Abort(); try { - await httpContext.Response.WriteAsync($"hello, world"); + await httpContext.Response.WriteAsync("hello, world"); tcs.SetResult(null); } catch (Exception ex) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs index d60ae18dc..41e579c8e 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/MaxRequestBufferSizeTests.cs @@ -22,8 +22,7 @@ public class MaxRequestBufferSizeTests { private const int _dataLength = 20 * 1024 * 1024; - private static readonly string[] _requestLines = new[] - { + private static readonly string[] _requestLines = { "POST / HTTP/1.0\r\n", $"Content-Length: {_dataLength}\r\n", "\r\n" diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs index f7c1d8bc1..8a534e67c 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestHeaderLimitsTests.cs @@ -6,7 +6,6 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Testing; -using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Xunit; using Microsoft.Extensions.Primitives; using System.Collections; diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs index 10a718c1e..740cdaa77 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/RequestTests.cs @@ -131,7 +131,7 @@ public async Task DoesNotHangOnConnectionCloseRequest() { var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => { app.Run(async context => @@ -161,7 +161,7 @@ public async Task StreamsAreNotPersistedAcrossRequests() var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => { app.Run(async context => @@ -204,7 +204,7 @@ public void CanUpgradeRequestWithConnectionKeepAliveUpgradeHeader() var dataRead = false; var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => { app.Run(async context => @@ -251,29 +251,23 @@ public async Task ConnectionResetPriorToRequestIsLoggedAsDebug() .Returns(true); mockLogger .Setup(logger => logger.Log(LogLevel.Debug, _connectionStartedEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => - { - connectionStarted.Release(); - }); + .Callback(() => connectionStarted.Release()); mockLogger .Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => - { - connectionReset.Release(); - }); + .Callback(() => connectionReset.Release()); var mockLoggerFactory = new Mock(); mockLoggerFactory .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) .Returns(mockLogger.Object); mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) + .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel"))) .Returns(Mock.Of()); var builder = new WebHostBuilder() .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(context => TaskCache.CompletedTask)); using (var host = builder.Build()) @@ -311,30 +305,24 @@ public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug() .Returns(true); mockLogger .Setup(logger => logger.Log(LogLevel.Debug, _connectionKeepAliveEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => - { - requestDone.Release(); - }); + .Callback(() => requestDone.Release()); mockLogger .Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => - { - connectionReset.Release(); - }); + .Callback(() => connectionReset.Release()); var mockLoggerFactory = new Mock(); mockLoggerFactory .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) .Returns(mockLogger.Object); mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) + .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel"))) .Returns(Mock.Of()); var builder = new WebHostBuilder() .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(context => TaskCache.CompletedTask)); using (var host = builder.Build()) @@ -372,17 +360,14 @@ public async Task ConnectionResetMidRequestIsLoggedAsDebug() .Returns(true); mockLogger .Setup(logger => logger.Log(LogLevel.Debug, _connectionResetEventId, It.IsAny(), null, It.IsAny>())) - .Callback(() => - { - connectionReset.Release(); - }); + .Callback(() => connectionReset.Release()); var mockLoggerFactory = new Mock(); mockLoggerFactory .Setup(factory => factory.CreateLogger("Microsoft.AspNetCore.Server.Kestrel")) .Returns(mockLogger.Object); mockLoggerFactory - .Setup(factory => factory.CreateLogger(It.IsNotIn(new[] { "Microsoft.AspNetCore.Server.Kestrel" }))) + .Setup(factory => factory.CreateLogger(It.IsNotIn("Microsoft.AspNetCore.Server.Kestrel"))) .Returns(Mock.Of()); var requestStarted = new SemaphoreSlim(0); @@ -390,7 +375,7 @@ public async Task ConnectionResetMidRequestIsLoggedAsDebug() var builder = new WebHostBuilder() .UseLoggerFactory(mockLoggerFactory.Object) .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(async context => { requestStarted.Release(); @@ -431,7 +416,7 @@ public async Task ThrowsOnReadAfterConnectionError() var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(async context => { requestStarted.Release(); @@ -475,14 +460,14 @@ public async Task RequestAbortedTokenFiredOnClientFIN() var requestAborted = new SemaphoreSlim(0); var builder = new WebHostBuilder() .UseKestrel() - .UseUrls($"http://127.0.0.1:0") + .UseUrls("http://127.0.0.1:0") .Configure(app => app.Run(async context => { appStarted.Release(); var token = context.RequestAborted; token.Register(() => requestAborted.Release(2)); - await requestAborted.WaitAsync().TimeoutAfter(TimeSpan.FromSeconds(10)); + await requestAborted.WaitAsync(token).TimeoutAfter(TimeSpan.FromSeconds(10)); })); using (var host = builder.Build()) diff --git a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs index b0ae4f6c3..fa1402639 100644 --- a/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs +++ b/test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/ResponseTests.cs @@ -16,7 +16,6 @@ using Microsoft.AspNetCore.Server.Kestrel.Internal.Http; using Microsoft.AspNetCore.Server.Kestrel.Internal.Infrastructure; using Microsoft.AspNetCore.Testing; -using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Primitives; @@ -192,10 +191,7 @@ public async Task OnStartingThrowsWhenSetAfterResponseHasAlreadyStarted() public Task ResponseStatusCodeSetBeforeHttpContextDisposeAppException() { return ResponseStatusCodeSetBeforeHttpContextDispose( - context => - { - throw new Exception(); - }, + context => throw new Exception(), expectedClientStatusCode: HttpStatusCode.InternalServerError, expectedServerStatusCode: HttpStatusCode.InternalServerError); } @@ -230,10 +226,7 @@ public Task ResponseStatusCodeSetBeforeHttpContextDisposeRequestAbortedAppExcept public Task ResponseStatusCodeSetBeforeHttpContextDisposedRequestMalformed() { return ResponseStatusCodeSetBeforeHttpContextDispose( - context => - { - return TaskCache.CompletedTask; - }, + context => TaskCache.CompletedTask, expectedClientStatusCode: null, expectedServerStatusCode: HttpStatusCode.BadRequest, sendMalformedRequest: true); @@ -425,10 +418,7 @@ await connection.Receive( [Fact] public async Task TransferEncodingNotSetOnHeadResponse() { - using (var server = new TestServer(httpContext => - { - return TaskCache.CompletedTask; - }, new TestServiceContext())) + using (var server = new TestServer(httpContext => TaskCache.CompletedTask, new TestServiceContext())) { using (var connection = server.CreateConnection()) { @@ -437,7 +427,7 @@ await connection.Send( "", ""); await connection.Receive( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "", ""); @@ -469,7 +459,7 @@ await connection.Send( "", ""); await connection.Receive( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "", ""); @@ -506,7 +496,7 @@ await connection.Send( "", ""); await connection.Receive( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 11", "", @@ -520,8 +510,8 @@ await connection.Receive( var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( - $"Response Content-Length mismatch: too many bytes written (12 of 11).", - logMessage.Exception.Message); + "Response Content-Length mismatch: too many bytes written (12 of 11).", + logMessage?.Exception.Message); } @@ -545,7 +535,7 @@ await connection.Send( "", ""); await connection.ReceiveForcedEnd( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 11", "", @@ -555,8 +545,8 @@ await connection.ReceiveForcedEnd( var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( - $"Response Content-Length mismatch: too many bytes written (12 of 11).", - logMessage.Exception.Message); + "Response Content-Length mismatch: too many bytes written (12 of 11).", + logMessage?.Exception.Message); } [Fact] @@ -580,7 +570,7 @@ await connection.Send( "", ""); await connection.ReceiveForcedEnd( - $"HTTP/1.1 500 Internal Server Error", + "HTTP/1.1 500 Internal Server Error", "Connection: close", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 0", @@ -591,8 +581,8 @@ await connection.ReceiveForcedEnd( var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( - $"Response Content-Length mismatch: too many bytes written (12 of 5).", - logMessage.Exception.Message); + "Response Content-Length mismatch: too many bytes written (12 of 5).", + logMessage?.Exception.Message); } [Fact] @@ -615,7 +605,7 @@ await connection.Send( "", ""); await connection.ReceiveForcedEnd( - $"HTTP/1.1 500 Internal Server Error", + "HTTP/1.1 500 Internal Server Error", "Connection: close", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 0", @@ -626,8 +616,8 @@ await connection.ReceiveForcedEnd( var logMessage = Assert.Single(testLogger.Messages, message => message.LogLevel == LogLevel.Error); Assert.Equal( - $"Response Content-Length mismatch: too many bytes written (12 of 5).", - logMessage.Exception.Message); + "Response Content-Length mismatch: too many bytes written (12 of 5).", + logMessage?.Exception.Message); } [Fact] @@ -660,7 +650,7 @@ await connection.Send( // response content length, in which case the check // will be skipped. await connection.Receive( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 13", "", @@ -678,7 +668,7 @@ await connection.Receive( trace.ApplicationError( It.IsAny(), It.Is(ex => - ex.Message.Equals($"Response Content-Length mismatch: too few bytes written (12 of 13).", StringComparison.Ordinal)))); + ex.Message.Equals("Response Content-Length mismatch: too few bytes written (12 of 13).", StringComparison.Ordinal)))); } [Fact] @@ -707,7 +697,7 @@ await connection.Send( "", ""); await connection.Receive( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 12", "", @@ -787,7 +777,7 @@ await connection.Send( "", ""); await connection.Receive( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 0", "", @@ -822,7 +812,7 @@ await connection.Send( "", ""); await connection.Receive( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 13", "Transfer-Encoding: chunked", @@ -858,7 +848,7 @@ await connection.Send( "", ""); await connection.Receive( - $"HTTP/1.1 200 OK", + "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", "Content-Length: 11", "Transfer-Encoding: chunked", @@ -1233,7 +1223,7 @@ await connection.Send( await connection.Receive( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", - $"Transfer-Encoding: chunked", + "Transfer-Encoding: chunked", "", "c", "hello, world", @@ -1274,7 +1264,7 @@ await connection.Send( await connection.Receive( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", - $"Transfer-Encoding: chunked", + "Transfer-Encoding: chunked", "", "6", "hello,", @@ -1315,7 +1305,7 @@ await connection.Send( await connection.Receive( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", - $"Transfer-Encoding: chunked", + "Transfer-Encoding: chunked", "", "c", "hello, world", @@ -1355,7 +1345,7 @@ await connection.Send( await connection.Receive( "HTTP/1.1 200 OK", $"Date: {server.Context.DateHeaderValue}", - $"Transfer-Encoding: chunked", + "Transfer-Encoding: chunked", "", "6", "hello,", diff --git a/test/shared/PassThroughConnectionAdapter.cs b/test/shared/PassThroughConnectionAdapter.cs index faa688a19..35d04ab46 100644 --- a/test/shared/PassThroughConnectionAdapter.cs +++ b/test/shared/PassThroughConnectionAdapter.cs @@ -6,7 +6,6 @@ using Microsoft.AspNetCore.Http.Features; using Microsoft.AspNetCore.Server.Kestrel.Adapter; using Microsoft.AspNetCore.Server.Kestrel.Adapter.Internal; -using Microsoft.AspNetCore.Testing; namespace Microsoft.AspNetCore.Testing {