From f7fc2647de0f91fbe6322aec95b334ad1437f427 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Thu, 5 Apr 2018 18:41:13 +1200 Subject: [PATCH] var all the things (#1855) --- .../DefaultHubActivatorBenchmark.cs | 2 +- .../HubConnectionSendBenchmark.cs | 2 +- samples/ClientSample/Tcp/TcpConnection.cs | 4 +- .../Pipe/PipeWeatherStreamFormatter.cs | 8 +-- .../HttpConnection.cs | 2 +- .../Internal/NegotiateProtocol.cs | 4 +- .../HttpConnectionContext.cs | 2 +- .../HttpConnectionDispatcher.cs | 4 +- .../Internal/MemoryBufferWriter.cs | 4 +- .../Internal/Protocol/HandshakeProtocol.cs | 4 +- .../Internal/Protocol/JsonHubProtocol.cs | 6 +- .../Protocol/LimitArrayPoolWriteStream.cs | 10 +-- .../Internal/AsyncEnumeratorAdapters.cs | 2 +- .../TypedClientBuilder.cs | 6 +- .../RedisHubLifetimeManager.cs | 2 +- .../HttpConnectionDispatcherTests.cs | 10 +-- .../HubConnectionTests.Protocol.cs | 8 +-- .../LongPollingTransportTests.cs | 2 +- .../Protocol/Utf8BufferTextReaderTests.cs | 10 +-- .../Protocol/Utf8BufferTextWriterTests.cs | 30 ++++---- .../HubConnectionHandlerTests.cs | 70 +++++++++---------- .../WebSocketsTransportTests.cs | 6 +- 22 files changed, 99 insertions(+), 99 deletions(-) diff --git a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubActivatorBenchmark.cs b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubActivatorBenchmark.cs index d7c95f80f3..d8e38f9ade 100644 --- a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubActivatorBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/DefaultHubActivatorBenchmark.cs @@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks public int Create() { var hub = _activator.Create(); - int result = hub.Addition(); + var result = hub.Addition(); return result; } diff --git a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/HubConnectionSendBenchmark.cs b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/HubConnectionSendBenchmark.cs index 6902aa2e6b..3d0b2cf0f4 100644 --- a/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/HubConnectionSendBenchmark.cs +++ b/benchmarks/Microsoft.AspNetCore.SignalR.Microbenchmarks/HubConnectionSendBenchmark.cs @@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks _hubConnection.StartAsync().GetAwaiter().GetResult(); _arguments = new object[ArgumentCount]; - for (int i = 0; i < _arguments.Length; i++) + for (var i = 0; i < _arguments.Length; i++) { _arguments[i] = "Hello world!"; } diff --git a/samples/ClientSample/Tcp/TcpConnection.cs b/samples/ClientSample/Tcp/TcpConnection.cs index a053486a7e..aa713c01d6 100644 --- a/samples/ClientSample/Tcp/TcpConnection.cs +++ b/samples/ClientSample/Tcp/TcpConnection.cs @@ -60,8 +60,8 @@ namespace ClientSample try { // Spawn send and receive logic - Task receiveTask = DoReceive(); - Task sendTask = DoSend(); + var receiveTask = DoReceive(); + var sendTask = DoSend(); // If the sending task completes then close the receive // We don't need to do this in the other direction because the kestrel diff --git a/samples/SocialWeather/Pipe/PipeWeatherStreamFormatter.cs b/samples/SocialWeather/Pipe/PipeWeatherStreamFormatter.cs index 78f2210102..efb11d442c 100644 --- a/samples/SocialWeather/Pipe/PipeWeatherStreamFormatter.cs +++ b/samples/SocialWeather/Pipe/PipeWeatherStreamFormatter.cs @@ -22,9 +22,9 @@ namespace SocialWeather.Pipe var tokens = line.Split('|'); int temperature; - long reportTime = long.MinValue; - Weather weather = (Weather)(-1); - string zipCode = tokens.Length > 3 ? tokens[3] : string.Empty; + var reportTime = long.MinValue; + var weather = (Weather)(-1); + var zipCode = tokens.Length > 3 ? tokens[3] : string.Empty; if (tokens.Length == 0 || !int.TryParse(tokens[0], out temperature)) { @@ -55,7 +55,7 @@ namespace SocialWeather.Pipe var sw = new StreamWriter(stream); var line = $"{report.Temperature}|{report.ReportTime}|{(int)report.Weather}|{report.ZipCode ?? string.Empty}"; - Encoding utf8 = Encoding.UTF8; + var utf8 = Encoding.UTF8; var encodedBytes = utf8.GetBytes(line); var convertedBytes = Encoding.Convert(Encoding.UTF8, Encoding.ASCII, encodedBytes); diff --git a/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.cs b/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.cs index 50d8a984d8..a26bc27e43 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Client/HttpConnection.cs @@ -449,7 +449,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Client // .NET Core 2.1 and above has a managed implementation return true; #else - bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); if (!isWindows) { // Assume other OSes have websockets diff --git a/src/Microsoft.AspNetCore.Http.Connections.Common/Internal/NegotiateProtocol.cs b/src/Microsoft.AspNetCore.Http.Connections.Common/Internal/NegotiateProtocol.cs index a8ba5e66fa..ef77fb53fc 100644 --- a/src/Microsoft.AspNetCore.Http.Connections.Common/Internal/NegotiateProtocol.cs +++ b/src/Microsoft.AspNetCore.Http.Connections.Common/Internal/NegotiateProtocol.cs @@ -140,7 +140,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal switch (reader.TokenType) { case JsonToken.PropertyName: - string memberName = reader.Value.ToString(); + var memberName = reader.Value.ToString(); switch (memberName) { @@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal JsonUtils.CheckRead(reader); JsonUtils.EnsureArrayStart(reader); - bool completed = false; + var completed = false; availableTransport.TransferFormats = new List(); while (!completed && JsonUtils.CheckRead(reader)) { diff --git a/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionContext.cs b/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionContext.cs index bcbd63bf1c..8b6109e6c2 100644 --- a/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionContext.cs +++ b/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionContext.cs @@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Http.Connections public async Task DisposeAsync() { - Task disposeTask = Task.CompletedTask; + var disposeTask = Task.CompletedTask; try { diff --git a/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionDispatcher.cs b/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionDispatcher.cs index 6a68677f78..c04a805f08 100644 --- a/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionDispatcher.cs +++ b/src/Microsoft.AspNetCore.Http.Connections/HttpConnectionDispatcher.cs @@ -397,7 +397,7 @@ namespace Microsoft.AspNetCore.Http.Connections private static byte[] GetNegotiatePayload(string connectionId, HttpContext context, HttpConnectionOptions options) { - NegotiationResponse response = new NegotiationResponse(); + var response = new NegotiationResponse(); response.ConnectionId = connectionId; response.AvailableTransports = new List(); @@ -416,7 +416,7 @@ namespace Microsoft.AspNetCore.Http.Connections response.AvailableTransports.Add(_longPollingAvailableTransport); } - MemoryStream ms = new MemoryStream(); + var ms = new MemoryStream(); NegotiateProtocol.WriteResponse(response, ms); return ms.ToArray(); diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/MemoryBufferWriter.cs b/src/Microsoft.AspNetCore.SignalR.Common/Internal/MemoryBufferWriter.cs index 60ecf21e7f..3331ee9e12 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/MemoryBufferWriter.cs +++ b/src/Microsoft.AspNetCore.SignalR.Common/Internal/MemoryBufferWriter.cs @@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal #if DEBUG writer._inUse = false; #endif - for (int i = 0; i < writer._segments.Count; i++) + for (var i = 0; i < writer._segments.Count; i++) { ArrayPool.Shared.Return(writer._segments[i]); } @@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal var totalWritten = 0; // Copy full segments - for (int i = 0; i < _segments.Count - 1; i++) + for (var i = 0; i < _segments.Count - 1; i++) { _segments[i].AsMemory().CopyTo(result.AsMemory(totalWritten, _segmentSize)); diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/HandshakeProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/HandshakeProtocol.cs index 932d502c65..4cd127c35f 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/HandshakeProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/HandshakeProtocol.cs @@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol switch (reader.TokenType) { case JsonToken.PropertyName: - string memberName = reader.Value.ToString(); + var memberName = reader.Value.ToString(); switch (memberName) { @@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol switch (reader.TokenType) { case JsonToken.PropertyName: - string memberName = reader.Value.ToString(); + var memberName = reader.Value.ToString(); switch (memberName) { diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/JsonHubProtocol.cs b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/JsonHubProtocol.cs index 913ae76230..0e886b8ef2 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/JsonHubProtocol.cs +++ b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/JsonHubProtocol.cs @@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol var hasResult = false; object result = null; JToken resultToken = null; - bool hasArguments = false; + var hasArguments = false; object[] arguments = null; JArray argumentsToken = null; ExceptionDispatchInfo argumentBindingException = null; @@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol switch (reader.TokenType) { case JsonToken.PropertyName: - string memberName = reader.Value.ToString(); + var memberName = reader.Value.ToString(); switch (memberName) { @@ -319,7 +319,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol switch (reader.TokenType) { case JsonToken.PropertyName: - string propertyName = reader.Value.ToString(); + var propertyName = reader.Value.ToString(); JsonUtils.CheckRead(reader); diff --git a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/LimitArrayPoolWriteStream.cs b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/LimitArrayPoolWriteStream.cs index 7a114f0ef6..257ee1ca6b 100644 --- a/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/LimitArrayPoolWriteStream.cs +++ b/src/Microsoft.AspNetCore.SignalR.Common/Internal/Protocol/LimitArrayPoolWriteStream.cs @@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol Debug.Assert(value > _buffer.Length); // Extract the current buffer to be replaced. - byte[] currentBuffer = _buffer; + var currentBuffer = _buffer; _buffer = null; // Determine the capacity to request for the new buffer. It should be @@ -83,14 +83,14 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol // value is more than that. If the new value would put it longer than the max // allowed byte array, than shrink to that (and if the required length is actually // longer than that, we'll let the runtime throw). - uint twiceLength = 2 * (uint)currentBuffer.Length; - int newCapacity = twiceLength > MaxByteArrayLength ? + var twiceLength = 2 * (uint)currentBuffer.Length; + var newCapacity = twiceLength > MaxByteArrayLength ? (value > MaxByteArrayLength ? value : MaxByteArrayLength) : Math.Max(value, (int)twiceLength); // Get a new buffer, copy the current one to it, return the current one, and // set the new buffer as current. - byte[] newBuffer = ArrayPool.Shared.Rent(newCapacity); + var newBuffer = ArrayPool.Shared.Rent(newCapacity); Buffer.BlockCopy(currentBuffer, 0, newBuffer, 0, _length); ArrayPool.Shared.Return(currentBuffer); _buffer = newBuffer; @@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol public override void WriteByte(byte value) { - int newLength = _length + 1; + var newLength = _length + 1; EnsureCapacity(newLength); _buffer[_length] = value; _length = newLength; diff --git a/src/Microsoft.AspNetCore.SignalR.Core/Internal/AsyncEnumeratorAdapters.cs b/src/Microsoft.AspNetCore.SignalR.Core/Internal/AsyncEnumeratorAdapters.cs index 966431e4df..a04eafba56 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/Internal/AsyncEnumeratorAdapters.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/Internal/AsyncEnumeratorAdapters.cs @@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal public Task MoveNextAsync() { - ValueTask result = _channel.ReadAsync(_cancellationToken); + var result = _channel.ReadAsync(_cancellationToken); if (result.IsCompletedSuccessfully) { diff --git a/src/Microsoft.AspNetCore.SignalR.Core/TypedClientBuilder.cs b/src/Microsoft.AspNetCore.SignalR.Core/TypedClientBuilder.cs index 2513586d53..83bc3e45ac 100644 --- a/src/Microsoft.AspNetCore.SignalR.Core/TypedClientBuilder.cs +++ b/src/Microsoft.AspNetCore.SignalR.Core/TypedClientBuilder.cs @@ -109,8 +109,8 @@ namespace Microsoft.AspNetCore.SignalR | MethodAttributes.HideBySig | MethodAttributes.NewSlot; - ParameterInfo[] parameters = interfaceMethodInfo.GetParameters(); - Type[] paramTypes = parameters.Select(param => param.ParameterType).ToArray(); + var parameters = interfaceMethodInfo.GetParameters(); + var paramTypes = parameters.Select(param => param.ParameterType).ToArray(); var methodBuilder = type.DefineMethod(interfaceMethodInfo.Name, methodAttributes); @@ -148,7 +148,7 @@ namespace Microsoft.AspNetCore.SignalR generator.Emit(OpCodes.Stloc_0); // Store each parameter in the object array - for (int i = 0; i < paramTypes.Length; i++) + for (var i = 0; i < paramTypes.Length; i++) { generator.Emit(OpCodes.Ldloc_0); // Object array loaded generator.Emit(OpCodes.Ldc_I4, i); diff --git a/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs b/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs index 568e2be14e..08e63ade67 100644 --- a/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs +++ b/src/Microsoft.AspNetCore.SignalR.Redis/RedisHubLifetimeManager.cs @@ -569,7 +569,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis var publishTasks = new List(connectionIds.Count); var message = new RedisInvocationMessage(target: methodName, arguments: args); - foreach (string connectionId in connectionIds) + foreach (var connectionId in connectionIds) { var connection = _connections[connectionId]; // If the connection is local we can skip sending the message through the bus since we require sticky connections. diff --git a/test/Microsoft.AspNetCore.Http.Connections.Tests/HttpConnectionDispatcherTests.cs b/test/Microsoft.AspNetCore.Http.Connections.Tests/HttpConnectionDispatcherTests.cs index c0ad8e56c4..50f2a60327 100644 --- a/test/Microsoft.AspNetCore.Http.Connections.Tests/HttpConnectionDispatcherTests.cs +++ b/test/Microsoft.AspNetCore.Http.Connections.Tests/HttpConnectionDispatcherTests.cs @@ -559,7 +559,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); - bool exists = manager.TryGetConnection(connection.ConnectionId, out _); + var exists = manager.TryGetConnection(connection.ConnectionId, out _); Assert.False(exists); } } @@ -585,7 +585,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); - bool exists = manager.TryGetConnection(connection.ConnectionId, out _); + var exists = manager.TryGetConnection(connection.ConnectionId, out _); Assert.False(exists); } } @@ -611,7 +611,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode); - bool exists = manager.TryGetConnection(connection.ConnectionId, out _); + var exists = manager.TryGetConnection(connection.ConnectionId, out _); Assert.False(exists); } } @@ -839,7 +839,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests await task; Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); - bool exists = manager.TryGetConnection(connection.ConnectionId, out _); + var exists = manager.TryGetConnection(connection.ConnectionId, out _); Assert.False(exists); } } @@ -872,7 +872,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests await task; Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode); - bool exists = manager.TryGetConnection(connection.ConnectionId, out _); + var exists = manager.TryGetConnection(connection.ConnectionId, out _); Assert.False(exists); } } diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Protocol.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Protocol.cs index 336e8d95e1..39019b8aaa 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Protocol.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.Protocol.cs @@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests [Fact] public async Task ReceiveCloseMessageWithoutErrorWillCloseHubConnection() { - TaskCompletionSource closedTcs = new TaskCompletionSource(); + var closedTcs = new TaskCompletionSource(); var connection = new TestConnection(); var hubConnection = CreateHubConnection(connection); @@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests await connection.ReceiveJsonMessage(new { type = 7 }).OrTimeout(); - Exception closeException = await closedTcs.Task.OrTimeout(); + var closeException = await closedTcs.Task.OrTimeout(); Assert.Null(closeException); } finally @@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests [Fact] public async Task ReceiveCloseMessageWithErrorWillCloseHubConnection() { - TaskCompletionSource closedTcs = new TaskCompletionSource(); + var closedTcs = new TaskCompletionSource(); var connection = new TestConnection(); var hubConnection = CreateHubConnection(connection); @@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests await connection.ReceiveJsonMessage(new { type = 7, error = "Error!" }).OrTimeout(); - Exception closeException = await closedTcs.Task.OrTimeout(); + var closeException = await closedTcs.Task.OrTimeout(); Assert.NotNull(closeException); Assert.Equal("The server closed the connection with the following error: Error!", closeException.Message); } diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs index a97bfbcce9..c4103d2e2a 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/LongPollingTransportTests.cs @@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests [Fact] public async Task LongPollingTransportResponseWithNoContentDoesNotStopPoll() { - int requests = 0; + var requests = 0; var mockHttpHandler = new Mock(); mockHttpHandler.Protected() .Setup>("SendAsync", ItExpr.IsAny(), ItExpr.IsAny()) diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/Utf8BufferTextReaderTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/Utf8BufferTextReaderTests.cs index 511240e6cc..be5c6c2cac 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/Utf8BufferTextReaderTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/Utf8BufferTextReaderTests.cs @@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol reader.SetBuffer(buffer); var chars = new char[1024]; - int read = reader.Read(chars, 0, chars.Length); + var read = reader.Read(chars, 0, chars.Length); Assert.Equal("Hello World", new string(chars, 0, read)); } @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol reader.SetBuffer(buffer); var chars = new char[1024]; - int read = reader.Read(chars, 0, chars.Length); + var read = reader.Read(chars, 0, chars.Length); Assert.Equal(5, read); Assert.Equal("a\u00E4\u00E4\u00a9o", new string(chars, 0, read)); @@ -51,7 +51,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol reader.SetBuffer(buffer); var chars = new char[1024]; - int read = reader.Read(chars, 10, chars.Length - 10); + var read = reader.Read(chars, 10, chars.Length - 10); Assert.Equal(11, read); Assert.Equal("Hello World", new string(chars, 10, read)); @@ -65,7 +65,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol reader.SetBuffer(buffer); var chars = new char[5]; - int read = reader.Read(chars, 0, chars.Length); + var read = reader.Read(chars, 0, chars.Length); Assert.Equal(5, read); Assert.Equal("Hello", new string(chars, 0, read)); @@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol reader.SetBuffer(buffer); var chars = new char[2]; - int read = reader.Read(chars, 0, chars.Length); + var read = reader.Read(chars, 0, chars.Length); Assert.Equal(2, read); Assert.Equal("\u00E4\u00E4", new string(chars, 0, read)); diff --git a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/Utf8BufferTextWriterTests.cs b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/Utf8BufferTextWriterTests.cs index b47b71c723..b225704d31 100644 --- a/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/Utf8BufferTextWriterTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Common.Tests/Internal/Protocol/Utf8BufferTextWriterTests.cs @@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol Assert.Equal(2, bufferWriter.Position); Assert.Equal((byte)'"', bufferWriter.CurrentSegment.Span[1]); - for (int i = 0; i < 2000; i++) + for (var i = 0; i < 2000; i++) { textWriter.Write('\u00A3'); } @@ -100,13 +100,13 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol textWriter.Flush(); Assert.Equal(4004, bufferWriter.Position); - string result = Encoding.UTF8.GetString(bufferWriter.CurrentSegment.Slice(0, bufferWriter.Position).ToArray()); + var result = Encoding.UTF8.GetString(bufferWriter.CurrentSegment.Slice(0, bufferWriter.Position).ToArray()); Assert.Equal(2004, result.Length); Assert.Equal('[', result[0]); Assert.Equal('"', result[1]); - for (int i = 0; i < 2000; i++) + for (var i = 0; i < 2000; i++) { Assert.Equal('\u00A3', result[i + 2]); } @@ -118,9 +118,9 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol [Fact] public void WriteCharArray_SurrogatePairInMultipleCalls() { - string fourCircles = char.ConvertFromUtf32(0x1F01C); + var fourCircles = char.ConvertFromUtf32(0x1F01C); - char[] chars = fourCircles.ToCharArray(); + var chars = fourCircles.ToCharArray(); var bufferWriter = new TestMemoryBufferWriter(4096); var textWriter = new Utf8BufferTextWriter(); @@ -137,9 +137,9 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol Assert.Equal(4, bufferWriter.Position); - byte[] expectedData = Encoding.UTF8.GetBytes(fourCircles); + var expectedData = Encoding.UTF8.GetBytes(fourCircles); - byte[] actualData = bufferWriter.CurrentSegment.Slice(0, 4).ToArray(); + var actualData = bufferWriter.CurrentSegment.Slice(0, 4).ToArray(); Assert.Equal(expectedData, actualData); } @@ -147,9 +147,9 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol [Fact] public void WriteChar_SurrogatePairInMultipleCalls() { - string fourCircles = char.ConvertFromUtf32(0x1F01C); + var fourCircles = char.ConvertFromUtf32(0x1F01C); - char[] chars = fourCircles.ToCharArray(); + var chars = fourCircles.ToCharArray(); var bufferWriter = new TestMemoryBufferWriter(4096); var textWriter = new Utf8BufferTextWriter(); @@ -166,9 +166,9 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol Assert.Equal(4, bufferWriter.Position); - byte[] expectedData = Encoding.UTF8.GetBytes(fourCircles); + var expectedData = Encoding.UTF8.GetBytes(fourCircles); - byte[] actualData = bufferWriter.CurrentSegment.Slice(0, 4).ToArray(); + var actualData = bufferWriter.CurrentSegment.Slice(0, 4).ToArray(); Assert.Equal(expectedData, actualData); } @@ -180,7 +180,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol var textWriter = new Utf8BufferTextWriter(); textWriter.SetWriter(bufferWriter); - char[] chars = "Hello world".ToCharArray(); + var chars = "Hello world".ToCharArray(); textWriter.Write(chars, 6, 1); textWriter.Flush(); @@ -196,7 +196,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol var textWriter = new Utf8BufferTextWriter(); textWriter.SetWriter(bufferWriter); - char[] chars = "Hello world".ToCharArray(); + var chars = "Hello world".ToCharArray(); textWriter.Write(chars); textWriter.Flush(); @@ -229,7 +229,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol Assert.Equal("Hello", Encoding.UTF8.GetString(bufferWriter1.ToArray())); - TestMemoryBufferWriter bufferWriter2 = new TestMemoryBufferWriter(); + var bufferWriter2 = new TestMemoryBufferWriter(); var textWriter2 = Utf8BufferTextWriter.Get(bufferWriter2); textWriter2.Write("World"); @@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol var totalWritten = 0; // Copy full segments - for (int i = 0; i < Segments.Count - 1; i++) + for (var i = 0; i < Segments.Count - 1; i++) { Segments[i].CopyTo(result.AsMemory(totalWritten, _segmentSize)); diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.cs index 81d6126e16..4d758f4fc7 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/HubConnectionHandlerTests.cs @@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests async Task Produce() { - int i = 0; + var i = 0; while (true) { observable.OnNext(i++); @@ -985,8 +985,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1020,8 +1020,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1055,8 +1055,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1095,8 +1095,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1131,9 +1131,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var secondClient = new TestClient()) using (var thirdClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); - Task thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected, thirdClient.Connected).OrTimeout(); @@ -1174,9 +1174,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var secondClient = new TestClient()) using (var thirdClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); - Task thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected, thirdClient.Connected).OrTimeout(); @@ -1219,9 +1219,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var secondClient = new TestClient(addClaimId: true)) using (var thirdClient = new TestClient(addClaimId: true)) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); - Task thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected, thirdClient.Connected).OrTimeout(); @@ -1263,8 +1263,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1304,8 +1304,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1354,8 +1354,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1402,8 +1402,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1462,8 +1462,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient(addClaimId: true)) using (var secondClient = new TestClient(addClaimId: true)) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1493,8 +1493,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1523,8 +1523,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var firstClient = new TestClient()) using (var secondClient = new TestClient()) { - Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); @@ -1656,8 +1656,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests using (var client1 = new TestClient(protocol: new JsonHubProtocol())) using (var client2 = new TestClient(protocol: new MessagePackHubProtocol())) { - Task firstConnectionHandlerTask = await client1.ConnectAsync(connectionHandler); - Task secondConnectionHandlerTask = await client2.ConnectAsync(connectionHandler); + var firstConnectionHandlerTask = await client1.ConnectAsync(connectionHandler); + var secondConnectionHandlerTask = await client2.ConnectAsync(connectionHandler); await client1.Connected.OrTimeout(); await client2.Connected.OrTimeout(); @@ -1957,7 +1957,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests await client.Connected.OrTimeout(); // Echo a bunch of stuff, waiting 10ms between each, until 500ms have elapsed - DateTime start = DateTime.UtcNow; + var start = DateTime.UtcNow; while ((DateTime.UtcNow - start).TotalMilliseconds <= 500.0) { await client.SendInvocationAsync("Echo", "foo").OrTimeout(); diff --git a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs index 3ea8e9c0c0..489f4a4757 100644 --- a/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Tests/WebSocketsTransportTests.cs @@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests { ClientWebSocketOptions webSocketsOptions = null; - HttpOptions httpOptions = new HttpOptions(); + var httpOptions = new HttpOptions(); httpOptions.Cookies.Add(new Cookie("Name", "Value", string.Empty, "fakeuri.org")); var clientCertificate = new X509Certificate(); httpOptions.ClientCertificates.Add(clientCertificate); @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests Assert.True(pair.Transport.Input.TryRead(out var result)); - string userAgent = Encoding.UTF8.GetString(result.Buffer.ToArray()); + var userAgent = Encoding.UTF8.GetString(result.Buffer.ToArray()); // user agent version should come from version embedded in assembly metadata var assemblyVersion = typeof(Constants) @@ -125,7 +125,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests Assert.True(pair.Transport.Input.TryRead(out var result)); - string headerValue = Encoding.UTF8.GetString(result.Buffer.ToArray()); + var headerValue = Encoding.UTF8.GetString(result.Buffer.ToArray()); Assert.Equal("XMLHttpRequest", headerValue); }