Provide default implementation for IHubFilter.InvokeMethodAsync (#23968)

This commit is contained in:
Brennan 2020-07-22 16:02:00 -07:00 committed by GitHub
parent e7b55df6c5
commit a8c39e9cc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 2 deletions

View File

@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.SignalR
/// <param name="invocationContext">The context for the method invocation that holds all the important information about the invoke.</param>
/// <param name="next">The next filter to run, and for the final one, the Hub invocation.</param>
/// <returns>Returns the result of the Hub method invoke.</returns>
ValueTask<object> InvokeMethodAsync(HubInvocationContext invocationContext, Func<HubInvocationContext, ValueTask<object>> next);
ValueTask<object> InvokeMethodAsync(HubInvocationContext invocationContext, Func<HubInvocationContext, ValueTask<object>> next) => next(invocationContext);
/// <summary>
/// Allows handling of the <see cref="Hub.OnConnectedAsync"/> method.

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Internal;
using Microsoft.Extensions.DependencyInjection;
@ -136,6 +135,40 @@ namespace Microsoft.AspNetCore.SignalR.Tests
}
}
[Fact]
public async Task HubFilterDoesNotNeedToImplementMethods()
{
using (StartVerifiableLog())
{
var tcsService = new TcsService();
var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services =>
{
services.AddSignalR().AddHubOptions<DynamicTestHub>(options =>
{
options.AddFilter(typeof(EmptyFilter));
});
}, LoggerFactory);
var connectionHandler = serviceProvider.GetService<HubConnectionHandler<DynamicTestHub>>();
using (var client = new TestClient())
{
var connectionHandlerTask = await client.ConnectAsync(connectionHandler);
await client.Connected.OrTimeout();
var completion = await client.InvokeAsync(nameof(DynamicTestHub.Echo), "hello");
Assert.Null(completion.Error);
Assert.Equal("hello", completion.Result);
client.Dispose();
await connectionHandlerTask.OrTimeout();
}
}
}
[Fact]
public async Task MutlipleFilters_MethodsAreCalled()
{

View File

@ -233,4 +233,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
return next(context);
}
}
public class EmptyFilter : IHubFilter
{
// Purposefully not implementing any methods
}
}