Provide default implementation for IHubFilter.InvokeMethodAsync (#23968)
This commit is contained in:
parent
e7b55df6c5
commit
a8c39e9cc5
|
|
@ -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="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>
|
/// <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>
|
/// <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>
|
/// <summary>
|
||||||
/// Allows handling of the <see cref="Hub.OnConnectedAsync"/> method.
|
/// Allows handling of the <see cref="Hub.OnConnectedAsync"/> method.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Internal;
|
using Microsoft.AspNetCore.Internal;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
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]
|
[Fact]
|
||||||
public async Task MutlipleFilters_MethodsAreCalled()
|
public async Task MutlipleFilters_MethodsAreCalled()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -233,4 +233,9 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
return next(context);
|
return next(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class EmptyFilter : IHubFilter
|
||||||
|
{
|
||||||
|
// Purposefully not implementing any methods
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue