Skip to content
This repository
Browse code

Throw if CreateProxy called after the connection is started.

  • Loading branch information...
commit 89eb8e492c6362f32b375845eb14fda229011a06 1 parent 23dd63a
David Fowler authored July 19, 2012
5  SignalR.Client/Hubs/HubConnection.cs
@@ -91,6 +91,11 @@ protected override string OnSending()
91 91
         /// <returns>A <see cref="IHubProxy"/></returns>
92 92
         public IHubProxy CreateProxy(string hubName)
93 93
         {
  94
+            if (State != ConnectionState.Disconnected)
  95
+            {
  96
+                throw new InvalidOperationException("Proxies cannot be added after the connection has been started.");
  97
+            }
  98
+
94 99
             HubProxy hubProxy;
95 100
             if (!_hubs.TryGetValue(hubName, out hubProxy))
96 101
             {
18  SignalR.Tests/HubFacts.cs
@@ -254,5 +254,23 @@ public void DynamicInvokeTest()
254 254
             Assert.True(wh.WaitOne(TimeSpan.FromSeconds(5)));
255 255
             connection.Stop();
256 256
         }
  257
+
  258
+        [Fact]
  259
+        public void CreateProxyAfterConnectionStartsThrows()
  260
+        {
  261
+            var host = new MemoryHost();
  262
+            host.MapHubs();
  263
+            var connection = new Client.Hubs.HubConnection("http://site/");
  264
+
  265
+            try
  266
+            {
  267
+                connection.Start(host).Wait();
  268
+                Assert.Throws<InvalidOperationException>(() => connection.CreateProxy("demo"));
  269
+            }
  270
+            finally
  271
+            {
  272
+                connection.Stop();
  273
+            }
  274
+        }
257 275
     }
258 276
 }

0 notes on commit 89eb8e4

Please sign in to comment.
Something went wrong with that request. Please try again.