From 62956530aee33c79878e161bc2972e0dd9ddc1de Mon Sep 17 00:00:00 2001 From: BrennanConroy Date: Tue, 13 Mar 2018 15:04:11 -0700 Subject: [PATCH] Rename StreamAsync to StreamAsChannelAsync (#1587) --- .../HubConnection.cs | 8 ++-- .../HubConnectionExtensions.StreamAsync.cs | 48 +++++++++---------- .../InvocationRequest.cs | 2 +- .../HubConnectionTests.cs | 18 +++---- .../HubConnectionProtocolTests.cs | 12 ++--- .../HubConnectionTests.cs | 6 +-- 6 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs index 238070dd69..b78db1999f 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnection.cs @@ -157,16 +157,16 @@ namespace Microsoft.AspNetCore.SignalR.Client return new Subscription(invocationHandler, invocationList); } - public async Task> StreamAsync(string methodName, Type returnType, object[] args, CancellationToken cancellationToken = default) + public async Task> StreamAsChannelAsync(string methodName, Type returnType, object[] args, CancellationToken cancellationToken = default) { - return await StreamAsyncCore(methodName, returnType, args, cancellationToken).ForceAsync(); + return await StreamAsChannelAsyncCore(methodName, returnType, args, cancellationToken).ForceAsync(); } - private async Task> StreamAsyncCore(string methodName, Type returnType, object[] args, CancellationToken cancellationToken) + private async Task> StreamAsChannelAsyncCore(string methodName, Type returnType, object[] args, CancellationToken cancellationToken) { if (!_startCalled) { - throw new InvalidOperationException($"The '{nameof(StreamAsync)}' method cannot be called before the connection has been started."); + throw new InvalidOperationException($"The '{nameof(StreamAsChannelAsync)}' method cannot be called before the connection has been started."); } var invokeCts = new CancellationTokenSource(); diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnectionExtensions.StreamAsync.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnectionExtensions.StreamAsync.cs index 81eec09974..0356e70669 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnectionExtensions.StreamAsync.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/HubConnectionExtensions.StreamAsync.cs @@ -10,69 +10,69 @@ namespace Microsoft.AspNetCore.SignalR.Client { public static partial class HubConnectionExtensions { - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, Array.Empty(), cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, Array.Empty(), cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1 }, cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1, arg2 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1, arg2 }, cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1, arg2, arg3 }, cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1, arg2, arg3, arg4 }, cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5 }, cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6 }, cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7 }, cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 }, cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 }, cancellationToken); } - public static Task> StreamAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default) + public static Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object arg1, object arg2, object arg3, object arg4, object arg5, object arg6, object arg7, object arg8, object arg9, object arg10, CancellationToken cancellationToken = default) { - return hubConnection.StreamAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken); + return hubConnection.StreamAsChannelAsync(methodName, new object[] { arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10 }, cancellationToken); } - public static async Task> StreamAsync(this HubConnection hubConnection, string methodName, object[] args, CancellationToken cancellationToken = default) + public static async Task> StreamAsChannelAsync(this HubConnection hubConnection, string methodName, object[] args, CancellationToken cancellationToken = default) { if (hubConnection == null) { throw new ArgumentNullException(nameof(hubConnection)); } - var inputChannel = await hubConnection.StreamAsync(methodName, typeof(TResult), args, cancellationToken); + var inputChannel = await hubConnection.StreamAsChannelAsync(methodName, typeof(TResult), args, cancellationToken); var outputChannel = Channel.CreateUnbounded(); // Local function to provide a way to run async code as fire-and-forget diff --git a/src/Microsoft.AspNetCore.SignalR.Client.Core/InvocationRequest.cs b/src/Microsoft.AspNetCore.SignalR.Client.Core/InvocationRequest.cs index 1c773596b8..7d6054bed1 100644 --- a/src/Microsoft.AspNetCore.SignalR.Client.Core/InvocationRequest.cs +++ b/src/Microsoft.AspNetCore.SignalR.Client.Core/InvocationRequest.cs @@ -157,7 +157,7 @@ namespace Microsoft.AspNetCore.SignalR.Client public override ValueTask StreamItem(object item) { Log.StreamItemOnNonStreamInvocation(Logger, InvocationId); - _completionSource.TrySetException(new InvalidOperationException($"Streaming hub methods must be invoked with the '{nameof(HubConnection)}.{nameof(HubConnection.StreamAsync)}' method.")); + _completionSource.TrySetException(new InvalidOperationException($"Streaming hub methods must be invoked with the '{nameof(HubConnection)}.{nameof(HubConnection.StreamAsChannelAsync)}' method.")); // We "delivered" the stream item successfully as far as the caller cares return new ValueTask(true); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs index 5b721360b8..e207678f57 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.FunctionalTests/HubConnectionTests.cs @@ -300,7 +300,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { await connection.StartAsync().OrTimeout(); - var channel = await connection.StreamAsync("Stream", 5).OrTimeout(); + var channel = await connection.StreamAsChannelAsync("Stream", 5).OrTimeout(); var results = await channel.ReadAllAsync().OrTimeout(); Assert.Equal(new[] { 0, 1, 2, 3, 4 }, results.ToArray()); @@ -331,7 +331,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests var cts = new CancellationTokenSource(); - var channel = await connection.StreamAsync("Stream", 1000, cts.Token).OrTimeout(); + var channel = await connection.StreamAsChannelAsync("Stream", 1000, cts.Token).OrTimeout(); await channel.WaitToReadAsync().AsTask().OrTimeout(); cts.Cancel(); @@ -367,7 +367,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests var cts = new CancellationTokenSource(); cts.Cancel(); - var channel = await connection.StreamAsync("Stream", 5, cts.Token).OrTimeout(); + var channel = await connection.StreamAsChannelAsync("Stream", 5, cts.Token).OrTimeout(); await Assert.ThrowsAnyAsync(() => channel.WaitToReadAsync().AsTask().OrTimeout()); } @@ -394,7 +394,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests try { await connection.StartAsync().OrTimeout(); - var channel = await connection.StreamAsync("StreamException").OrTimeout(); + var channel = await connection.StreamAsChannelAsync("StreamException").OrTimeout(); var ex = await Assert.ThrowsAsync(() => channel.ReadAllAsync().OrTimeout()); Assert.Equal("An unexpected error occurred invoking 'StreamException' on the server. InvalidOperationException: Error occurred while streaming.", ex.Message); @@ -504,7 +504,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { await connection.StartAsync().OrTimeout(); - var channel = await connection.StreamAsync("!@#$%"); + var channel = await connection.StreamAsChannelAsync("!@#$%"); var ex = await Assert.ThrowsAsync(() => channel.ReadAllAsync().OrTimeout()); Assert.Equal("Unknown hub method '!@#$%'", ex.Message); } @@ -533,7 +533,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { await connection.StartAsync().OrTimeout(); - var channel = await connection.StreamAsync("Stream", 42, 42); + var channel = await connection.StreamAsChannelAsync("Stream", 42, 42); var ex = await Assert.ThrowsAsync(() => channel.ReadAllAsync().OrTimeout()); Assert.Equal("Failed to invoke 'Stream'. Invocation provides 2 argument(s) but target expects 1.", ex.Message); } @@ -561,7 +561,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests { await connection.StartAsync().OrTimeout(); - var channel = await connection.StreamAsync("Stream", "xyz"); + var channel = await connection.StreamAsChannelAsync("Stream", "xyz"); var ex = await Assert.ThrowsAsync(() => channel.ReadAllAsync().OrTimeout()); Assert.StartsWith("Failed to invoke 'Stream'. Error binding arguments. Make sure that the types of the provided values match the types of the hub method being invoked.", ex.Message); } @@ -588,7 +588,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests try { await connection.StartAsync().OrTimeout(); - var channel = await connection.StreamAsync("HelloWorld").OrTimeout(); + var channel = await connection.StreamAsChannelAsync("HelloWorld").OrTimeout(); var ex = await Assert.ThrowsAsync(() => channel.ReadAllAsync()).OrTimeout(); Assert.Equal("The client attempted to invoke the non-streaming 'HelloWorld' method in a streaming fashion.", ex.Message); } @@ -642,7 +642,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests try { await connection.StartAsync().OrTimeout(); - var channel = await connection.StreamAsync("StreamBroken").OrTimeout(); + var channel = await connection.StreamAsChannelAsync("StreamBroken").OrTimeout(); var ex = await Assert.ThrowsAsync(() => channel.ReadAllAsync()).OrTimeout(); Assert.Equal("The value returned by the streaming method 'StreamBroken' is null, does not implement the IObservable<> interface or is not a ReadableChannel<>.", ex.Message); } diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionProtocolTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionProtocolTests.cs index 490cb5bf4f..7c1916d8a0 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionProtocolTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionProtocolTests.cs @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests { await hubConnection.StartAsync(); - var channel = await hubConnection.StreamAsync("Foo"); + var channel = await hubConnection.StreamAsChannelAsync("Foo"); // skip negotiation await connection.ReadSentTextMessageAsync().OrTimeout(); @@ -146,7 +146,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests { await hubConnection.StartAsync(); - var channel = await hubConnection.StreamAsync("Foo"); + var channel = await hubConnection.StreamAsChannelAsync("Foo"); await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3 }).OrTimeout(); @@ -213,7 +213,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests { await hubConnection.StartAsync(); - var channel = await hubConnection.StreamAsync("Foo"); + var channel = await hubConnection.StreamAsChannelAsync("Foo"); await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3, result = "Oops" }).OrTimeout(); @@ -236,7 +236,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests { await hubConnection.StartAsync(); - var channel = await hubConnection.StreamAsync("Foo"); + var channel = await hubConnection.StreamAsChannelAsync("Foo"); await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3, error = "An error occurred" }).OrTimeout(); @@ -264,7 +264,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests await connection.ReceiveJsonMessage(new { invocationId = "1", type = 2, item = 42 }).OrTimeout(); var ex = await Assert.ThrowsAsync(() => invokeTask).OrTimeout(); - Assert.Equal("Streaming hub methods must be invoked with the 'HubConnection.StreamAsync' method.", ex.Message); + Assert.Equal("Streaming hub methods must be invoked with the 'HubConnection.StreamAsChannelAsync' method.", ex.Message); } finally { @@ -282,7 +282,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests { await hubConnection.StartAsync(); - var channel = await hubConnection.StreamAsync("Foo"); + var channel = await hubConnection.StreamAsChannelAsync("Foo"); await connection.ReceiveJsonMessage(new { invocationId = "1", type = 2, item = "1" }).OrTimeout(); await connection.ReceiveJsonMessage(new { invocationId = "1", type = 2, item = "2" }).OrTimeout(); diff --git a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs index cdd20a25f0..94ff151401 100644 --- a/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs +++ b/test/Microsoft.AspNetCore.SignalR.Client.Tests/HubConnectionTests.cs @@ -142,7 +142,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests await hubConnection.StartAsync(); await hubConnection.DisposeAsync(); var exception = await Assert.ThrowsAsync( - () => hubConnection.StreamAsync("test")); + () => hubConnection.StreamAsChannelAsync("test")); Assert.Equal("Connection has been terminated.", exception.Message); } @@ -154,9 +154,9 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests var hubConnection = new HubConnection(connection, new JsonHubProtocol(), new LoggerFactory()); var exception = await Assert.ThrowsAsync( - () => hubConnection.StreamAsync("test")); + () => hubConnection.StreamAsChannelAsync("test")); - Assert.Equal("The 'StreamAsync' method cannot be called before the connection has been started.", exception.Message); + Assert.Equal("The 'StreamAsChannelAsync' method cannot be called before the connection has been started.", exception.Message); } [Fact]