Fix SignalR tests
This commit is contained in:
parent
3e841cf3d2
commit
093ade9ed6
|
|
@ -337,7 +337,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
await connection.StartAsync().OrTimeout();
|
||||
|
||||
var channel = await connection.StreamAsChannelAsync<int>("Stream", 5).OrTimeout();
|
||||
var results = await channel.ReadAllAsync().OrTimeout();
|
||||
var results = await channel.ReadAndCollectAllAsync().OrTimeout();
|
||||
|
||||
Assert.Equal(new[] { 0, 1, 2, 3, 4 }, results.ToArray());
|
||||
}
|
||||
|
|
@ -375,7 +375,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
Assert.Equal("2", await channel.ReadAsync().AsTask().OrTimeout());
|
||||
channelWriter.Writer.Complete();
|
||||
|
||||
var results = await channel.ReadAllAsync().OrTimeout();
|
||||
var results = await channel.ReadAndCollectAllAsync().OrTimeout();
|
||||
Assert.Empty(results);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -420,7 +420,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
|
||||
cts.Cancel();
|
||||
|
||||
var results = await channel.ReadAllAsync(suppressExceptions: true).OrTimeout();
|
||||
var results = await channel.ReadAndCollectAllAsync(suppressExceptions: true).OrTimeout();
|
||||
|
||||
Assert.True(results.Count > 0 && results.Count < 1000);
|
||||
|
||||
|
|
@ -488,7 +488,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
await connection.StartAsync().OrTimeout();
|
||||
var channel = await connection.StreamAsChannelAsync<int>("StreamException").OrTimeout();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync().OrTimeout());
|
||||
Assert.Equal("An unexpected error occurred invoking 'StreamException' on the server. InvalidOperationException: Error occurred while streaming.", ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -654,7 +654,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
await connection.StartAsync().OrTimeout();
|
||||
|
||||
var channel = await connection.StreamAsChannelAsync<int>("!@#$%");
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync().OrTimeout());
|
||||
Assert.Equal("Failed to invoke '!@#$%' due to an error on the server. HubException: Method does not exist.", ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -688,7 +688,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
await connection.StartAsync().OrTimeout();
|
||||
|
||||
var channel = await connection.StreamAsChannelAsync<int>("Stream", 42, 42);
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync().OrTimeout());
|
||||
Assert.Equal("Failed to invoke 'Stream' due to an error on the server. InvalidDataException: Invocation provides 2 argument(s) but target expects 1.", ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -722,7 +722,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
await connection.StartAsync().OrTimeout();
|
||||
|
||||
var channel = await connection.StreamAsChannelAsync<int>("Stream", "xyz");
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync().OrTimeout());
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync().OrTimeout());
|
||||
Assert.Equal("Failed to invoke 'Stream' due to an error on the server. InvalidDataException: Error binding arguments. Make sure that the types of the provided values match the types of the hub method being invoked.", ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -755,7 +755,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
{
|
||||
await connection.StartAsync().OrTimeout();
|
||||
var channel = await connection.StreamAsChannelAsync<int>("HelloWorld").OrTimeout();
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync()).OrTimeout();
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync()).OrTimeout();
|
||||
Assert.Equal("The client attempted to invoke the non-streaming 'HelloWorld' method with a streaming invocation.", ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -821,7 +821,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.FunctionalTests
|
|||
{
|
||||
await connection.StartAsync().OrTimeout();
|
||||
var channel = await connection.StreamAsChannelAsync<int>("StreamBroken").OrTimeout();
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAllAsync()).OrTimeout();
|
||||
var ex = await Assert.ThrowsAsync<HubException>(() => channel.ReadAndCollectAllAsync()).OrTimeout();
|
||||
Assert.Equal("The value returned by the streaming method 'StreamBroken' is not a ChannelReader<>.", ex.Message);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
[Fact]
|
||||
public async Task ClientIsOkayReceivingMinorVersionInHandshake()
|
||||
{
|
||||
// We're just testing that the client doesn't fail when a minor version is added to the handshake
|
||||
// We're just testing that the client doesn't fail when a minor version is added to the handshake
|
||||
// The client doesn't actually use that version anywhere yet so there's nothing else to test at this time
|
||||
|
||||
var connection = new TestConnection(autoHandshake: false);
|
||||
|
|
@ -228,7 +228,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
|
||||
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3 }).OrTimeout();
|
||||
|
||||
Assert.Empty(await channel.ReadAllAsync());
|
||||
Assert.Empty(await channel.ReadAndCollectAllAsync().OrTimeout());
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -295,7 +295,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
|
||||
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3, result = "Oops" }).OrTimeout();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await channel.ReadAllAsync().OrTimeout());
|
||||
var ex = await Assert.ThrowsAsync<InvalidOperationException>(async () => await channel.ReadAndCollectAllAsync().OrTimeout());
|
||||
Assert.Equal("Server provided a result in a completion response to a streamed invocation.", ex.Message);
|
||||
}
|
||||
finally
|
||||
|
|
@ -318,7 +318,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
|
||||
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3, error = "An error occurred" }).OrTimeout();
|
||||
|
||||
var ex = await Assert.ThrowsAsync<HubException>(async () => await channel.ReadAllAsync().OrTimeout());
|
||||
var ex = await Assert.ThrowsAsync<HubException>(async () => await channel.ReadAndCollectAllAsync().OrTimeout());
|
||||
Assert.Equal("An error occurred", ex.Message);
|
||||
}
|
||||
finally
|
||||
|
|
@ -367,7 +367,7 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 2, item = "3" }).OrTimeout();
|
||||
await connection.ReceiveJsonMessage(new { invocationId = "1", type = 3 }).OrTimeout();
|
||||
|
||||
var notifications = await channel.ReadAllAsync().OrTimeout();
|
||||
var notifications = await channel.ReadAndCollectAllAsync().OrTimeout();
|
||||
|
||||
Assert.Equal(new[] { "1", "2", "3", }, notifications.ToArray());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace System.Threading.Channels
|
||||
{
|
||||
public static class ChannelExtensions
|
||||
{
|
||||
public static async Task<List<T>> ReadAllAsync<T>(this ChannelReader<T> channel, bool suppressExceptions = false)
|
||||
public static async Task<List<T>> ReadAndCollectAllAsync<T>(this ChannelReader<T> channel, bool suppressExceptions = false)
|
||||
{
|
||||
var list = new List<T>();
|
||||
try
|
||||
|
|
|
|||
Loading…
Reference in New Issue