Test ValueTask hub methods (#12898)

This commit is contained in:
Brennan 2019-08-08 14:04:43 -07:00 committed by GitHub
parent bd01c67e88
commit 5adeaddfe6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 0 deletions

View File

@ -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()
{

View File

@ -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)