@@ -992,6 +992,58 @@ public async Task HubsCanAddAndSendToGroup(Type hubType)
992992 }
993993 }
994994
995+ [ Theory ]
996+ [ MemberData ( nameof ( HubTypes ) ) ]
997+ public async Task SendToGroupExcept ( Type hubType )
998+ {
999+ var serviceProvider = CreateServiceProvider ( ) ;
1000+
1001+ dynamic endPoint = serviceProvider . GetService ( GetEndPointType ( hubType ) ) ;
1002+
1003+ using ( var firstClient = new TestClient ( ) )
1004+ using ( var secondClient = new TestClient ( ) )
1005+ {
1006+ Task firstEndPointTask = endPoint . OnConnectedAsync ( firstClient . Connection ) ;
1007+ Task secondEndPointTask = endPoint . OnConnectedAsync ( secondClient . Connection ) ;
1008+
1009+ await Task . WhenAll ( firstClient . Connected , secondClient . Connected ) . OrTimeout ( ) ;
1010+
1011+ var result = ( await firstClient . InvokeAsync ( "GroupExceptSendMethod" , "testGroup" , "test" ) . OrTimeout ( ) ) . Result ;
1012+
1013+ // check that 'firstConnection' hasn't received the group send
1014+ Assert . Null ( firstClient . TryRead ( ) ) ;
1015+
1016+ // check that 'secondConnection' hasn't received the group send
1017+ Assert . Null ( secondClient . TryRead ( ) ) ;
1018+
1019+ await firstClient . InvokeAsync ( nameof ( MethodHub . GroupAddMethod ) , "testGroup" ) . OrTimeout ( ) ;
1020+ await secondClient . InvokeAsync ( nameof ( MethodHub . GroupAddMethod ) , "testGroup" ) . OrTimeout ( ) ;
1021+
1022+ var excludedIds = new List < string > { firstClient . Connection . ConnectionId } ;
1023+
1024+ await firstClient . SendInvocationAsync ( "GroupExceptSendMethod" , "testGroup" , "test" , excludedIds ) . OrTimeout ( ) ;
1025+
1026+ // check that 'secondConnection' has received the group send
1027+ var hubMessage = await secondClient . ReadAsync ( ) . OrTimeout ( ) ;
1028+ var invocation = Assert . IsType < InvocationMessage > ( hubMessage ) ;
1029+ Assert . Equal ( "Send" , invocation . Target ) ;
1030+ Assert . Single ( invocation . Arguments ) ;
1031+ Assert . Equal ( "test" , invocation . Arguments [ 0 ] ) ;
1032+
1033+ // Check that first client only got the completion message
1034+ hubMessage = await firstClient . ReadAsync ( ) . OrTimeout ( ) ;
1035+ Assert . IsType < CompletionMessage > ( hubMessage ) ;
1036+
1037+ Assert . Null ( firstClient . TryRead ( ) ) ;
1038+
1039+ // kill the connections
1040+ firstClient . Dispose ( ) ;
1041+ secondClient . Dispose ( ) ;
1042+
1043+ await Task . WhenAll ( firstEndPointTask , secondEndPointTask ) . OrTimeout ( ) ;
1044+ }
1045+ }
1046+
9951047 [ Fact ]
9961048 public async Task RemoveFromGroupWhenNotInGroupDoesNotFail ( )
9971049 {
@@ -1626,6 +1678,11 @@ public Task GroupSendMethod(string groupName, string message)
16261678 return Clients . Group ( groupName ) . Send ( message ) ;
16271679 }
16281680
1681+ public Task GroupExceptSendMethod ( string groupName , string message , IReadOnlyList < string > excludedIds )
1682+ {
1683+ return Clients . GroupExcept ( groupName , excludedIds ) . Send ( message ) ;
1684+ }
1685+
16291686 public Task BroadcastMethod ( string message )
16301687 {
16311688 return Clients . All . Broadcast ( message ) ;
@@ -1814,6 +1871,11 @@ public Task GroupSendMethod(string groupName, string message)
18141871 return Clients . Group ( groupName ) . Send ( message ) ;
18151872 }
18161873
1874+ public Task GroupExceptSendMethod ( string groupName , string message , IReadOnlyList < string > excludedIds )
1875+ {
1876+ return Clients . GroupExcept ( groupName , excludedIds ) . Send ( message ) ;
1877+ }
1878+
18171879 public Task BroadcastMethod ( string message )
18181880 {
18191881 return Clients . All . Broadcast ( message ) ;
@@ -1945,6 +2007,11 @@ public Task GroupSendMethod(string groupName, string message)
19452007 return Clients . Group ( groupName ) . InvokeAsync ( "Send" , message ) ;
19462008 }
19472009
2010+ public Task GroupExceptSendMethod ( string groupName , string message , IReadOnlyList < string > excludedIds )
2011+ {
2012+ return Clients . GroupExcept ( groupName , excludedIds ) . InvokeAsync ( "Send" , message ) ;
2013+ }
2014+
19482015 public Task BroadcastMethod ( string message )
19492016 {
19502017 return Clients . All . InvokeAsync ( "Broadcast" , message ) ;
0 commit comments