File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
src/Microsoft.AspNet.SignalR.Core
tests/Microsoft.AspNet.SignalR.Tests/Server/Hubs Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -9,14 +9,21 @@ namespace Microsoft.AspNet.SignalR
99 /// </summary>
1010 public abstract class Hub < T > : Hub where T : class
1111 {
12+ // This allows the typed Client property to be settable for testing
13+ private IHubCallerConnectionContext < T > _testClients ;
14+
1215 /// <summary>
1316 /// Gets a dynamic object that represents all clients connected to this hub (not hub instance).
1417 /// </summary>
1518 public new IHubCallerConnectionContext < T > Clients
1619 {
1720 get
1821 {
19- return new TypedHubCallerConnectionContext < T > ( base . Clients ) ;
22+ return _testClients ?? new TypedHubCallerConnectionContext < T > ( base . Clients ) ;
23+ }
24+ set
25+ {
26+ _testClients = value ;
2027 }
2128 }
2229 }
Original file line number Diff line number Diff line change @@ -134,6 +134,23 @@ public void TypedHubsCanExplicitelyImplementIHub()
134134 all . VerifyAll ( ) ;
135135 }
136136
137+ [ Fact ]
138+ public void TypedIHubCallerConnectionContextIsSettable ( )
139+ {
140+ // https://github.com/SignalR/SignalR/issues/3299
141+ var mockClients = new Mock < IHubCallerConnectionContext < IClientContract > > ( ) ;
142+ var all = new Mock < IClientContract > ( ) ;
143+ all . Setup ( m => m . send ( "foo" ) ) ;
144+ mockClients . Setup ( m => m . All ) . Returns ( all . Object ) ;
145+
146+ var hub = new MyTypedIHub ( ) ;
147+ hub . Clients = mockClients . Object ;
148+ hub . Send ( "foo" ) ;
149+
150+ mockClients . VerifyAll ( ) ;
151+ all . VerifyAll ( ) ;
152+ }
153+
137154 private class MyTestableHub : Hub
138155 {
139156 public void Send ( string messages )
You can’t perform that action at this time.
0 commit comments