@@ -103,4 +103,68 @@ public async Task ThrowsWhenParallelHubInvokesNotEnabled()
103
103
}
104
104
}
105
105
}
106
+
107
+ [ Fact ]
108
+ public async Task CanUseClientResultsWithIHubContext ( )
109
+ {
110
+ using ( StartVerifiableLog ( ) )
111
+ {
112
+ var serviceProvider = HubConnectionHandlerTestUtils . CreateServiceProvider ( null , LoggerFactory ) ;
113
+ var connectionHandler = serviceProvider . GetService < HubConnectionHandler < MethodHub > > ( ) ;
114
+
115
+ using var client = new TestClient ( ) ;
116
+
117
+ var connectionHandlerTask = await client . ConnectAsync ( connectionHandler ) ;
118
+
119
+ // Wait for a connection, or for the endpoint to fail.
120
+ await client . Connected . OrThrowIfOtherFails ( connectionHandlerTask ) . DefaultTimeout ( ) ;
121
+
122
+ var context = serviceProvider . GetRequiredService < IHubContext < MethodHub > > ( ) ;
123
+ var resultTask = context . Clients . Single ( client . Connection . ConnectionId ) . InvokeAsync < int > ( "GetClientResult" , 1 ) ;
124
+
125
+ var message = await client . ReadAsync ( ) . DefaultTimeout ( ) ;
126
+ var invocation = Assert . IsType < InvocationMessage > ( message ) ;
127
+
128
+ Assert . Single ( invocation . Arguments ) ;
129
+ Assert . Equal ( 1L , invocation . Arguments [ 0 ] ) ;
130
+ Assert . Equal ( "GetClientResult" , invocation . Target ) ;
131
+
132
+ await client . SendHubMessageAsync ( CompletionMessage . WithResult ( invocation . InvocationId , 2 ) ) . DefaultTimeout ( ) ;
133
+
134
+ var result = await resultTask . DefaultTimeout ( ) ;
135
+ Assert . Equal ( 2 , result ) ;
136
+ }
137
+ }
138
+
139
+ [ Fact ]
140
+ public async Task CanUseClientResultsWithIHubContextT ( )
141
+ {
142
+ using ( StartVerifiableLog ( ) )
143
+ {
144
+ var serviceProvider = HubConnectionHandlerTestUtils . CreateServiceProvider ( null , LoggerFactory ) ;
145
+ var connectionHandler = serviceProvider . GetService < HubConnectionHandler < HubT > > ( ) ;
146
+
147
+ using var client = new TestClient ( ) ;
148
+
149
+ var connectionHandlerTask = await client . ConnectAsync ( connectionHandler ) ;
150
+
151
+ // Wait for a connection, or for the endpoint to fail.
152
+ await client . Connected . OrThrowIfOtherFails ( connectionHandlerTask ) . DefaultTimeout ( ) ;
153
+
154
+ var context = serviceProvider . GetRequiredService < IHubContext < HubT , Test > > ( ) ;
155
+ var resultTask = context . Clients . Single ( client . Connection . ConnectionId ) . GetClientResult ( 1 ) ;
156
+
157
+ var message = await client . ReadAsync ( ) . DefaultTimeout ( ) ;
158
+ var invocation = Assert . IsType < InvocationMessage > ( message ) ;
159
+
160
+ Assert . Single ( invocation . Arguments ) ;
161
+ Assert . Equal ( 1L , invocation . Arguments [ 0 ] ) ;
162
+ Assert . Equal ( "GetClientResult" , invocation . Target ) ;
163
+
164
+ await client . SendHubMessageAsync ( CompletionMessage . WithResult ( invocation . InvocationId , 2 ) ) . DefaultTimeout ( ) ;
165
+
166
+ var result = await resultTask . DefaultTimeout ( ) ;
167
+ Assert . Equal ( 2 , result ) ;
168
+ }
169
+ }
106
170
}
0 commit comments