var all the things (#1855)

This commit is contained in:
James Newton-King 2018-04-05 18:41:13 +12:00 committed by GitHub
parent e51852d0fc
commit f7fc2647de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 99 additions and 99 deletions

View File

@ -22,7 +22,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
public int Create() public int Create()
{ {
var hub = _activator.Create(); var hub = _activator.Create();
int result = hub.Addition(); var result = hub.Addition();
return result; return result;
} }

View File

@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.SignalR.Microbenchmarks
_hubConnection.StartAsync().GetAwaiter().GetResult(); _hubConnection.StartAsync().GetAwaiter().GetResult();
_arguments = new object[ArgumentCount]; _arguments = new object[ArgumentCount];
for (int i = 0; i < _arguments.Length; i++) for (var i = 0; i < _arguments.Length; i++)
{ {
_arguments[i] = "Hello world!"; _arguments[i] = "Hello world!";
} }

View File

@ -60,8 +60,8 @@ namespace ClientSample
try try
{ {
// Spawn send and receive logic // Spawn send and receive logic
Task receiveTask = DoReceive(); var receiveTask = DoReceive();
Task<Exception> sendTask = DoSend(); var sendTask = DoSend();
// If the sending task completes then close the receive // If the sending task completes then close the receive
// We don't need to do this in the other direction because the kestrel // We don't need to do this in the other direction because the kestrel

View File

@ -22,9 +22,9 @@ namespace SocialWeather.Pipe
var tokens = line.Split('|'); var tokens = line.Split('|');
int temperature; int temperature;
long reportTime = long.MinValue; var reportTime = long.MinValue;
Weather weather = (Weather)(-1); var weather = (Weather)(-1);
string zipCode = tokens.Length > 3 ? tokens[3] : string.Empty; var zipCode = tokens.Length > 3 ? tokens[3] : string.Empty;
if (tokens.Length == 0 || !int.TryParse(tokens[0], out temperature)) if (tokens.Length == 0 || !int.TryParse(tokens[0], out temperature))
{ {
@ -55,7 +55,7 @@ namespace SocialWeather.Pipe
var sw = new StreamWriter(stream); var sw = new StreamWriter(stream);
var line = $"{report.Temperature}|{report.ReportTime}|{(int)report.Weather}|{report.ZipCode ?? string.Empty}"; 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 encodedBytes = utf8.GetBytes(line);
var convertedBytes = Encoding.Convert(Encoding.UTF8, Encoding.ASCII, encodedBytes); var convertedBytes = Encoding.Convert(Encoding.UTF8, Encoding.ASCII, encodedBytes);

View File

@ -449,7 +449,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Client
// .NET Core 2.1 and above has a managed implementation // .NET Core 2.1 and above has a managed implementation
return true; return true;
#else #else
bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); var isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
if (!isWindows) if (!isWindows)
{ {
// Assume other OSes have websockets // Assume other OSes have websockets

View File

@ -140,7 +140,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
switch (reader.TokenType) switch (reader.TokenType)
{ {
case JsonToken.PropertyName: case JsonToken.PropertyName:
string memberName = reader.Value.ToString(); var memberName = reader.Value.ToString();
switch (memberName) switch (memberName)
{ {
@ -151,7 +151,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
JsonUtils.CheckRead(reader); JsonUtils.CheckRead(reader);
JsonUtils.EnsureArrayStart(reader); JsonUtils.EnsureArrayStart(reader);
bool completed = false; var completed = false;
availableTransport.TransferFormats = new List<string>(); availableTransport.TransferFormats = new List<string>();
while (!completed && JsonUtils.CheckRead(reader)) while (!completed && JsonUtils.CheckRead(reader))
{ {

View File

@ -126,7 +126,7 @@ namespace Microsoft.AspNetCore.Http.Connections
public async Task DisposeAsync() public async Task DisposeAsync()
{ {
Task disposeTask = Task.CompletedTask; var disposeTask = Task.CompletedTask;
try try
{ {

View File

@ -397,7 +397,7 @@ namespace Microsoft.AspNetCore.Http.Connections
private static byte[] GetNegotiatePayload(string connectionId, HttpContext context, HttpConnectionOptions options) private static byte[] GetNegotiatePayload(string connectionId, HttpContext context, HttpConnectionOptions options)
{ {
NegotiationResponse response = new NegotiationResponse(); var response = new NegotiationResponse();
response.ConnectionId = connectionId; response.ConnectionId = connectionId;
response.AvailableTransports = new List<AvailableTransport>(); response.AvailableTransports = new List<AvailableTransport>();
@ -416,7 +416,7 @@ namespace Microsoft.AspNetCore.Http.Connections
response.AvailableTransports.Add(_longPollingAvailableTransport); response.AvailableTransports.Add(_longPollingAvailableTransport);
} }
MemoryStream ms = new MemoryStream(); var ms = new MemoryStream();
NegotiateProtocol.WriteResponse(response, ms); NegotiateProtocol.WriteResponse(response, ms);
return ms.ToArray(); return ms.ToArray();

View File

@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
#if DEBUG #if DEBUG
writer._inUse = false; writer._inUse = false;
#endif #endif
for (int i = 0; i < writer._segments.Count; i++) for (var i = 0; i < writer._segments.Count; i++)
{ {
ArrayPool<byte>.Shared.Return(writer._segments[i]); ArrayPool<byte>.Shared.Return(writer._segments[i]);
} }
@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
var totalWritten = 0; var totalWritten = 0;
// Copy full segments // 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)); _segments[i].AsMemory().CopyTo(result.AsMemory(totalWritten, _segmentSize));

View File

@ -91,7 +91,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
switch (reader.TokenType) switch (reader.TokenType)
{ {
case JsonToken.PropertyName: case JsonToken.PropertyName:
string memberName = reader.Value.ToString(); var memberName = reader.Value.ToString();
switch (memberName) switch (memberName)
{ {
@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
switch (reader.TokenType) switch (reader.TokenType)
{ {
case JsonToken.PropertyName: case JsonToken.PropertyName:
string memberName = reader.Value.ToString(); var memberName = reader.Value.ToString();
switch (memberName) switch (memberName)
{ {

View File

@ -100,7 +100,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
var hasResult = false; var hasResult = false;
object result = null; object result = null;
JToken resultToken = null; JToken resultToken = null;
bool hasArguments = false; var hasArguments = false;
object[] arguments = null; object[] arguments = null;
JArray argumentsToken = null; JArray argumentsToken = null;
ExceptionDispatchInfo argumentBindingException = null; ExceptionDispatchInfo argumentBindingException = null;
@ -121,7 +121,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
switch (reader.TokenType) switch (reader.TokenType)
{ {
case JsonToken.PropertyName: case JsonToken.PropertyName:
string memberName = reader.Value.ToString(); var memberName = reader.Value.ToString();
switch (memberName) switch (memberName)
{ {
@ -319,7 +319,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
switch (reader.TokenType) switch (reader.TokenType)
{ {
case JsonToken.PropertyName: case JsonToken.PropertyName:
string propertyName = reader.Value.ToString(); var propertyName = reader.Value.ToString();
JsonUtils.CheckRead(reader); JsonUtils.CheckRead(reader);

View File

@ -75,7 +75,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
Debug.Assert(value > _buffer.Length); Debug.Assert(value > _buffer.Length);
// Extract the current buffer to be replaced. // Extract the current buffer to be replaced.
byte[] currentBuffer = _buffer; var currentBuffer = _buffer;
_buffer = null; _buffer = null;
// Determine the capacity to request for the new buffer. It should be // 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 // 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 // allowed byte array, than shrink to that (and if the required length is actually
// longer than that, we'll let the runtime throw). // longer than that, we'll let the runtime throw).
uint twiceLength = 2 * (uint)currentBuffer.Length; var twiceLength = 2 * (uint)currentBuffer.Length;
int newCapacity = twiceLength > MaxByteArrayLength ? var newCapacity = twiceLength > MaxByteArrayLength ?
(value > MaxByteArrayLength ? value : MaxByteArrayLength) : (value > MaxByteArrayLength ? value : MaxByteArrayLength) :
Math.Max(value, (int)twiceLength); Math.Max(value, (int)twiceLength);
// Get a new buffer, copy the current one to it, return the current one, and // Get a new buffer, copy the current one to it, return the current one, and
// set the new buffer as current. // set the new buffer as current.
byte[] newBuffer = ArrayPool<byte>.Shared.Rent(newCapacity); var newBuffer = ArrayPool<byte>.Shared.Rent(newCapacity);
Buffer.BlockCopy(currentBuffer, 0, newBuffer, 0, _length); Buffer.BlockCopy(currentBuffer, 0, newBuffer, 0, _length);
ArrayPool<byte>.Shared.Return(currentBuffer); ArrayPool<byte>.Shared.Return(currentBuffer);
_buffer = newBuffer; _buffer = newBuffer;
@ -132,7 +132,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
public override void WriteByte(byte value) public override void WriteByte(byte value)
{ {
int newLength = _length + 1; var newLength = _length + 1;
EnsureCapacity(newLength); EnsureCapacity(newLength);
_buffer[_length] = value; _buffer[_length] = value;
_length = newLength; _length = newLength;

View File

@ -101,7 +101,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
public Task<bool> MoveNextAsync() public Task<bool> MoveNextAsync()
{ {
ValueTask<T> result = _channel.ReadAsync(_cancellationToken); var result = _channel.ReadAsync(_cancellationToken);
if (result.IsCompletedSuccessfully) if (result.IsCompletedSuccessfully)
{ {

View File

@ -109,8 +109,8 @@ namespace Microsoft.AspNetCore.SignalR
| MethodAttributes.HideBySig | MethodAttributes.HideBySig
| MethodAttributes.NewSlot; | MethodAttributes.NewSlot;
ParameterInfo[] parameters = interfaceMethodInfo.GetParameters(); var parameters = interfaceMethodInfo.GetParameters();
Type[] paramTypes = parameters.Select(param => param.ParameterType).ToArray(); var paramTypes = parameters.Select(param => param.ParameterType).ToArray();
var methodBuilder = type.DefineMethod(interfaceMethodInfo.Name, methodAttributes); var methodBuilder = type.DefineMethod(interfaceMethodInfo.Name, methodAttributes);
@ -148,7 +148,7 @@ namespace Microsoft.AspNetCore.SignalR
generator.Emit(OpCodes.Stloc_0); generator.Emit(OpCodes.Stloc_0);
// Store each parameter in the object array // 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.Ldloc_0); // Object array loaded
generator.Emit(OpCodes.Ldc_I4, i); generator.Emit(OpCodes.Ldc_I4, i);

View File

@ -569,7 +569,7 @@ namespace Microsoft.AspNetCore.SignalR.Redis
var publishTasks = new List<Task>(connectionIds.Count); var publishTasks = new List<Task>(connectionIds.Count);
var message = new RedisInvocationMessage(target: methodName, arguments: args); var message = new RedisInvocationMessage(target: methodName, arguments: args);
foreach (string connectionId in connectionIds) foreach (var connectionId in connectionIds)
{ {
var connection = _connections[connectionId]; var connection = _connections[connectionId];
// If the connection is local we can skip sending the message through the bus since we require sticky connections. // If the connection is local we can skip sending the message through the bus since we require sticky connections.

View File

@ -559,7 +559,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
bool exists = manager.TryGetConnection(connection.ConnectionId, out _); var exists = manager.TryGetConnection(connection.ConnectionId, out _);
Assert.False(exists); Assert.False(exists);
} }
} }
@ -585,7 +585,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
bool exists = manager.TryGetConnection(connection.ConnectionId, out _); var exists = manager.TryGetConnection(connection.ConnectionId, out _);
Assert.False(exists); Assert.False(exists);
} }
} }
@ -611,7 +611,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode); Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode);
bool exists = manager.TryGetConnection(connection.ConnectionId, out _); var exists = manager.TryGetConnection(connection.ConnectionId, out _);
Assert.False(exists); Assert.False(exists);
} }
} }
@ -839,7 +839,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
await task; await task;
Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode); Assert.Equal(StatusCodes.Status200OK, context.Response.StatusCode);
bool exists = manager.TryGetConnection(connection.ConnectionId, out _); var exists = manager.TryGetConnection(connection.ConnectionId, out _);
Assert.False(exists); Assert.False(exists);
} }
} }
@ -872,7 +872,7 @@ namespace Microsoft.AspNetCore.Http.Connections.Tests
await task; await task;
Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode); Assert.Equal(StatusCodes.Status204NoContent, context.Response.StatusCode);
bool exists = manager.TryGetConnection(connection.ConnectionId, out _); var exists = manager.TryGetConnection(connection.ConnectionId, out _);
Assert.False(exists); Assert.False(exists);
} }
} }

View File

@ -92,7 +92,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact] [Fact]
public async Task ReceiveCloseMessageWithoutErrorWillCloseHubConnection() public async Task ReceiveCloseMessageWithoutErrorWillCloseHubConnection()
{ {
TaskCompletionSource<Exception> closedTcs = new TaskCompletionSource<Exception>(); var closedTcs = new TaskCompletionSource<Exception>();
var connection = new TestConnection(); var connection = new TestConnection();
var hubConnection = CreateHubConnection(connection); var hubConnection = CreateHubConnection(connection);
@ -104,7 +104,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
await connection.ReceiveJsonMessage(new { type = 7 }).OrTimeout(); await connection.ReceiveJsonMessage(new { type = 7 }).OrTimeout();
Exception closeException = await closedTcs.Task.OrTimeout(); var closeException = await closedTcs.Task.OrTimeout();
Assert.Null(closeException); Assert.Null(closeException);
} }
finally finally
@ -117,7 +117,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact] [Fact]
public async Task ReceiveCloseMessageWithErrorWillCloseHubConnection() public async Task ReceiveCloseMessageWithErrorWillCloseHubConnection()
{ {
TaskCompletionSource<Exception> closedTcs = new TaskCompletionSource<Exception>(); var closedTcs = new TaskCompletionSource<Exception>();
var connection = new TestConnection(); var connection = new TestConnection();
var hubConnection = CreateHubConnection(connection); var hubConnection = CreateHubConnection(connection);
@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
await connection.ReceiveJsonMessage(new { type = 7, error = "Error!" }).OrTimeout(); 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.NotNull(closeException);
Assert.Equal("The server closed the connection with the following error: Error!", closeException.Message); Assert.Equal("The server closed the connection with the following error: Error!", closeException.Message);
} }

View File

@ -95,7 +95,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
[Fact] [Fact]
public async Task LongPollingTransportResponseWithNoContentDoesNotStopPoll() public async Task LongPollingTransportResponseWithNoContentDoesNotStopPoll()
{ {
int requests = 0; var requests = 0;
var mockHttpHandler = new Mock<HttpMessageHandler>(); var mockHttpHandler = new Mock<HttpMessageHandler>();
mockHttpHandler.Protected() mockHttpHandler.Protected()
.Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()) .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>())

View File

@ -20,7 +20,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
reader.SetBuffer(buffer); reader.SetBuffer(buffer);
var chars = new char[1024]; 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)); Assert.Equal("Hello World", new string(chars, 0, read));
} }
@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
reader.SetBuffer(buffer); reader.SetBuffer(buffer);
var chars = new char[1024]; 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(5, read);
Assert.Equal("a\u00E4\u00E4\u00a9o", new string(chars, 0, 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); reader.SetBuffer(buffer);
var chars = new char[1024]; 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(11, read);
Assert.Equal("Hello World", new string(chars, 10, 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); reader.SetBuffer(buffer);
var chars = new char[5]; 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(5, read);
Assert.Equal("Hello", new string(chars, 0, read)); Assert.Equal("Hello", new string(chars, 0, read));
@ -97,7 +97,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
reader.SetBuffer(buffer); reader.SetBuffer(buffer);
var chars = new char[2]; 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(2, read);
Assert.Equal("\u00E4\u00E4", new string(chars, 0, read)); Assert.Equal("\u00E4\u00E4", new string(chars, 0, read));

View File

@ -85,7 +85,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
Assert.Equal(2, bufferWriter.Position); Assert.Equal(2, bufferWriter.Position);
Assert.Equal((byte)'"', bufferWriter.CurrentSegment.Span[1]); Assert.Equal((byte)'"', bufferWriter.CurrentSegment.Span[1]);
for (int i = 0; i < 2000; i++) for (var i = 0; i < 2000; i++)
{ {
textWriter.Write('\u00A3'); textWriter.Write('\u00A3');
} }
@ -100,13 +100,13 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
textWriter.Flush(); textWriter.Flush();
Assert.Equal(4004, bufferWriter.Position); 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(2004, result.Length);
Assert.Equal('[', result[0]); Assert.Equal('[', result[0]);
Assert.Equal('"', result[1]); Assert.Equal('"', result[1]);
for (int i = 0; i < 2000; i++) for (var i = 0; i < 2000; i++)
{ {
Assert.Equal('\u00A3', result[i + 2]); Assert.Equal('\u00A3', result[i + 2]);
} }
@ -118,9 +118,9 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
[Fact] [Fact]
public void WriteCharArray_SurrogatePairInMultipleCalls() 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 bufferWriter = new TestMemoryBufferWriter(4096);
var textWriter = new Utf8BufferTextWriter(); var textWriter = new Utf8BufferTextWriter();
@ -137,9 +137,9 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
Assert.Equal(4, bufferWriter.Position); 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); Assert.Equal(expectedData, actualData);
} }
@ -147,9 +147,9 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
[Fact] [Fact]
public void WriteChar_SurrogatePairInMultipleCalls() 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 bufferWriter = new TestMemoryBufferWriter(4096);
var textWriter = new Utf8BufferTextWriter(); var textWriter = new Utf8BufferTextWriter();
@ -166,9 +166,9 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
Assert.Equal(4, bufferWriter.Position); 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); Assert.Equal(expectedData, actualData);
} }
@ -180,7 +180,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
var textWriter = new Utf8BufferTextWriter(); var textWriter = new Utf8BufferTextWriter();
textWriter.SetWriter(bufferWriter); textWriter.SetWriter(bufferWriter);
char[] chars = "Hello world".ToCharArray(); var chars = "Hello world".ToCharArray();
textWriter.Write(chars, 6, 1); textWriter.Write(chars, 6, 1);
textWriter.Flush(); textWriter.Flush();
@ -196,7 +196,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
var textWriter = new Utf8BufferTextWriter(); var textWriter = new Utf8BufferTextWriter();
textWriter.SetWriter(bufferWriter); textWriter.SetWriter(bufferWriter);
char[] chars = "Hello world".ToCharArray(); var chars = "Hello world".ToCharArray();
textWriter.Write(chars); textWriter.Write(chars);
textWriter.Flush(); textWriter.Flush();
@ -229,7 +229,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
Assert.Equal("Hello", Encoding.UTF8.GetString(bufferWriter1.ToArray())); Assert.Equal("Hello", Encoding.UTF8.GetString(bufferWriter1.ToArray()));
TestMemoryBufferWriter bufferWriter2 = new TestMemoryBufferWriter(); var bufferWriter2 = new TestMemoryBufferWriter();
var textWriter2 = Utf8BufferTextWriter.Get(bufferWriter2); var textWriter2 = Utf8BufferTextWriter.Get(bufferWriter2);
textWriter2.Write("World"); textWriter2.Write("World");
@ -296,7 +296,7 @@ namespace Microsoft.AspNetCore.SignalR.Common.Tests.Internal.Protocol
var totalWritten = 0; var totalWritten = 0;
// Copy full segments // 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)); Segments[i].CopyTo(result.AsMemory(totalWritten, _segmentSize));

View File

@ -110,7 +110,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
async Task Produce() async Task Produce()
{ {
int i = 0; var i = 0;
while (true) while (true)
{ {
observable.OnNext(i++); observable.OnNext(i++);
@ -985,8 +985,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var firstClient = new TestClient()) using (var firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
@ -1020,8 +1020,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var firstClient = new TestClient()) using (var firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
@ -1055,8 +1055,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var firstClient = new TestClient()) using (var firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
@ -1095,8 +1095,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var firstClient = new TestClient()) using (var firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
@ -1131,9 +1131,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
using (var thirdClient = new TestClient()) using (var thirdClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
Task thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); var thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected, thirdClient.Connected).OrTimeout(); 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 secondClient = new TestClient())
using (var thirdClient = new TestClient()) using (var thirdClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
Task thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); var thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected, thirdClient.Connected).OrTimeout(); 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 secondClient = new TestClient(addClaimId: true))
using (var thirdClient = new TestClient(addClaimId: true)) using (var thirdClient = new TestClient(addClaimId: true))
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
Task thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler); var thirdConnectionHandlerTask = await thirdClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected, thirdClient.Connected).OrTimeout(); 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 firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
@ -1304,8 +1304,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var firstClient = new TestClient()) using (var firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
@ -1354,8 +1354,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var firstClient = new TestClient()) using (var firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
@ -1402,8 +1402,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var firstClient = new TestClient()) using (var firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); 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 firstClient = new TestClient(addClaimId: true))
using (var secondClient = new TestClient(addClaimId: true)) using (var secondClient = new TestClient(addClaimId: true))
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
@ -1493,8 +1493,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var firstClient = new TestClient()) using (var firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout();
@ -1523,8 +1523,8 @@ namespace Microsoft.AspNetCore.SignalR.Tests
using (var firstClient = new TestClient()) using (var firstClient = new TestClient())
using (var secondClient = new TestClient()) using (var secondClient = new TestClient())
{ {
Task firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await firstClient.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await secondClient.ConnectAsync(connectionHandler);
await Task.WhenAll(firstClient.Connected, secondClient.Connected).OrTimeout(); 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 client1 = new TestClient(protocol: new JsonHubProtocol()))
using (var client2 = new TestClient(protocol: new MessagePackHubProtocol())) using (var client2 = new TestClient(protocol: new MessagePackHubProtocol()))
{ {
Task firstConnectionHandlerTask = await client1.ConnectAsync(connectionHandler); var firstConnectionHandlerTask = await client1.ConnectAsync(connectionHandler);
Task secondConnectionHandlerTask = await client2.ConnectAsync(connectionHandler); var secondConnectionHandlerTask = await client2.ConnectAsync(connectionHandler);
await client1.Connected.OrTimeout(); await client1.Connected.OrTimeout();
await client2.Connected.OrTimeout(); await client2.Connected.OrTimeout();
@ -1957,7 +1957,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
await client.Connected.OrTimeout(); await client.Connected.OrTimeout();
// Echo a bunch of stuff, waiting 10ms between each, until 500ms have elapsed // 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) while ((DateTime.UtcNow - start).TotalMilliseconds <= 500.0)
{ {
await client.SendInvocationAsync("Echo", "foo").OrTimeout(); await client.SendInvocationAsync("Echo", "foo").OrTimeout();

View File

@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
{ {
ClientWebSocketOptions webSocketsOptions = null; ClientWebSocketOptions webSocketsOptions = null;
HttpOptions httpOptions = new HttpOptions(); var httpOptions = new HttpOptions();
httpOptions.Cookies.Add(new Cookie("Name", "Value", string.Empty, "fakeuri.org")); httpOptions.Cookies.Add(new Cookie("Name", "Value", string.Empty, "fakeuri.org"));
var clientCertificate = new X509Certificate(); var clientCertificate = new X509Certificate();
httpOptions.ClientCertificates.Add(clientCertificate); httpOptions.ClientCertificates.Add(clientCertificate);
@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
Assert.True(pair.Transport.Input.TryRead(out var result)); 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 // user agent version should come from version embedded in assembly metadata
var assemblyVersion = typeof(Constants) var assemblyVersion = typeof(Constants)
@ -125,7 +125,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
Assert.True(pair.Transport.Input.TryRead(out var result)); 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); Assert.Equal("XMLHttpRequest", headerValue);
} }