@@ -4500,6 +4500,60 @@ public async Task SpecificHubOptionForMaximumReceiveMessageSizeIsUsedOverGlobalH
4500
4500
}
4501
4501
}
4502
4502
4503
+ [ Fact ]
4504
+ public async Task CanSendThroughIHubContext ( )
4505
+ {
4506
+ using ( StartVerifiableLog ( ) )
4507
+ {
4508
+ var serviceProvider = HubConnectionHandlerTestUtils . CreateServiceProvider ( null , LoggerFactory ) ;
4509
+ var connectionHandler = serviceProvider . GetService < HubConnectionHandler < MethodHub > > ( ) ;
4510
+
4511
+ using var client = new TestClient ( ) ;
4512
+
4513
+ var connectionHandlerTask = await client . ConnectAsync ( connectionHandler ) ;
4514
+
4515
+ // Wait for a connection, or for the endpoint to fail.
4516
+ await client . Connected . OrThrowIfOtherFails ( connectionHandlerTask ) . DefaultTimeout ( ) ;
4517
+
4518
+ IHubContext context = serviceProvider . GetRequiredService < IHubContext < MethodHub > > ( ) ;
4519
+ await context . Clients . All . SendAsync ( "Send" , "test" ) ;
4520
+
4521
+ var message = await client . ReadAsync ( ) . DefaultTimeout ( ) ;
4522
+ var invocation = Assert . IsType < InvocationMessage > ( message ) ;
4523
+
4524
+ Assert . Single ( invocation . Arguments ) ;
4525
+ Assert . Equal ( "test" , invocation . Arguments [ 0 ] ) ;
4526
+ Assert . Equal ( "Send" , invocation . Target ) ;
4527
+ }
4528
+ }
4529
+
4530
+ [ Fact ]
4531
+ public async Task CanSendThroughIHubContextBaseHub ( )
4532
+ {
4533
+ using ( StartVerifiableLog ( ) )
4534
+ {
4535
+ var serviceProvider = HubConnectionHandlerTestUtils . CreateServiceProvider ( null , LoggerFactory ) ;
4536
+ var connectionHandler = serviceProvider . GetService < HubConnectionHandler < MethodHub > > ( ) ;
4537
+
4538
+ using var client = new TestClient ( ) ;
4539
+
4540
+ var connectionHandlerTask = await client . ConnectAsync ( connectionHandler ) ;
4541
+
4542
+ // Wait for a connection, or for the endpoint to fail.
4543
+ await client . Connected . OrThrowIfOtherFails ( connectionHandlerTask ) . DefaultTimeout ( ) ;
4544
+
4545
+ IHubContext < TestHub > context = serviceProvider . GetRequiredService < IHubContext < MethodHub > > ( ) ;
4546
+ await context . Clients . All . SendAsync ( "Send" , "test" ) ;
4547
+
4548
+ var message = await client . ReadAsync ( ) . DefaultTimeout ( ) ;
4549
+ var invocation = Assert . IsType < InvocationMessage > ( message ) ;
4550
+
4551
+ Assert . Single ( invocation . Arguments ) ;
4552
+ Assert . Equal ( "test" , invocation . Arguments [ 0 ] ) ;
4553
+ Assert . Equal ( "Send" , invocation . Target ) ;
4554
+ }
4555
+ }
4556
+
4503
4557
private class CustomHubActivator < THub > : IHubActivator < THub > where THub : Hub
4504
4558
{
4505
4559
public int ReleaseCount ;
0 commit comments