private async Task AssertMethodsCalled(IServiceProvider serviceProvider, TcsService tcsService) { var connectionHandler = serviceProvider.GetService <HubConnectionHandler <MethodHub> >(); using (var client = new TestClient()) { var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await tcsService.StartedMethod.Task.DefaultTimeout(); await client.Connected.DefaultTimeout(); await tcsService.EndMethod.Task.DefaultTimeout(); tcsService.Reset(); var message = await client.InvokeAsync(nameof(MethodHub.Echo), "Hello world!").DefaultTimeout(); await tcsService.EndMethod.Task.DefaultTimeout(); tcsService.Reset(); Assert.Null(message.Error); client.Dispose(); await connectionHandlerTask.DefaultTimeout(); await tcsService.EndMethod.Task.DefaultTimeout(); } }
public async Task MixingTypeAndInstanceHubSpecificFilters_MethodsAreCalled() { using (StartVerifiableLog()) { var tcsService1 = new TcsService(); var tcsService2 = new TcsService(); var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services.AddSignalR() .AddHubOptions <MethodHub>(options => { options.AddFilter(new VerifyMethodFilter(tcsService1)); options.AddFilter <VerifyMethodFilter>(); }); services.AddSingleton(tcsService2); }, LoggerFactory); var connectionHandler = serviceProvider.GetService <HubConnectionHandler <MethodHub> >(); using (var client = new TestClient()) { var connectionHandlerTask = await client.ConnectAsync(connectionHandler); await tcsService1.StartedMethod.Task.DefaultTimeout(); await tcsService2.StartedMethod.Task.DefaultTimeout(); await client.Connected.DefaultTimeout(); await tcsService1.EndMethod.Task.DefaultTimeout(); await tcsService2.EndMethod.Task.DefaultTimeout(); tcsService1.Reset(); tcsService2.Reset(); var message = await client.InvokeAsync(nameof(MethodHub.Echo), "Hello world!").DefaultTimeout(); await tcsService1.EndMethod.Task.DefaultTimeout(); await tcsService2.EndMethod.Task.DefaultTimeout(); tcsService1.Reset(); tcsService2.Reset(); Assert.Null(message.Error); client.Dispose(); await connectionHandlerTask.DefaultTimeout(); await tcsService1.EndMethod.Task.DefaultTimeout(); await tcsService2.EndMethod.Task.DefaultTimeout(); } } }
public async Task FiltersWithIAsyncDisposableAreDisposed() { using (StartVerifiableLog()) { var tcsService = new TcsService(); var serviceProvider = HubConnectionHandlerTestUtils.CreateServiceProvider(services => { services.AddSignalR(options => { options.EnableDetailedErrors = true; options.AddFilter <AsyncDisposableFilter>(); }); services.AddSingleton(tcsService); }, LoggerFactory); var connectionHandler = serviceProvider.GetService <HubConnectionHandler <MethodHub> >(); using (var client = new TestClient()) { var connectionHandlerTask = await client.ConnectAsync(connectionHandler); // OnConnectedAsync creates and destroys the filter await tcsService.StartedMethod.Task.DefaultTimeout(); tcsService.Reset(); var message = await client.InvokeAsync("Echo", "Hello"); Assert.Equal("Hello", message.Result); await tcsService.StartedMethod.Task.DefaultTimeout(); tcsService.Reset(); client.Dispose(); // OnDisconnectedAsync creates and destroys the filter await tcsService.StartedMethod.Task.DefaultTimeout(); await connectionHandlerTask.DefaultTimeout(); } } }