Test ValueTask hub methods (#12898)
This commit is contained in:
parent
bd01c67e88
commit
5adeaddfe6
|
|
@ -91,6 +91,16 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
return 43;
|
||||
}
|
||||
|
||||
public ValueTask ValueTaskMethod()
|
||||
{
|
||||
return new ValueTask(Task.CompletedTask);
|
||||
}
|
||||
|
||||
public ValueTask<int> ValueTaskValueMethod()
|
||||
{
|
||||
return new ValueTask<int>(43);
|
||||
}
|
||||
|
||||
[HubMethodName("RenamedMethod")]
|
||||
public int ATestMethodThatIsRenamedByTheAttribute()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -814,6 +814,57 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HubMethodCanReturnValueFromValueTask()
|
||||
{
|
||||
using (StartVerifiableLog())
|
||||
{
|
||||
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
|
||||
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient())
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
|
||||
var result = (await client.InvokeAsync(nameof(MethodHub.ValueTaskValueMethod)).OrTimeout()).Result;
|
||||
|
||||
// json serializer makes this a long
|
||||
Assert.Equal(43L, result);
|
||||
|
||||
// kill the connection
|
||||
client.Dispose();
|
||||
|
||||
await connectionHandlerTask.OrTimeout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HubMethodCanReturnValueTask()
|
||||
{
|
||||
using (StartVerifiableLog())
|
||||
{
|
||||
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(null, LoggerFactory);
|
||||
|
||||
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<MethodHub>>();
|
||||
|
||||
using (var client = new TestClient())
|
||||
{
|
||||
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
|
||||
|
||||
var result = (await client.InvokeAsync(nameof(MethodHub.ValueTaskMethod)).OrTimeout()).Result;
|
||||
|
||||
Assert.Null(result);
|
||||
|
||||
// kill the connection
|
||||
client.Dispose();
|
||||
|
||||
await connectionHandlerTask.OrTimeout();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(HubTypes))]
|
||||
public async Task HubMethodsAreCaseInsensitive(Type hubType)
|
||||
|
|
|
|||
Loading…
Reference in New Issue