title: SignalR hub unit test
body: <p>I have created a SignalR hub and I want to unit test this hub. I have created multiple tests already, and when I fire them one by one they all succeed. But when I run them all at once a test is failing. The reason for failing is that this test is using a hub method that checks if some List has at least one value. The list should be empty in this test, but because other tests are running the list is filled by them. </p>
  
  <p>How can I run this tests so each have their own instance of the hub?</p>
  
  <p>As you can see below in the TryConnect() method it checks if the List ConnectedUsers is set and if there are more then <em>MaxConnectedUsers</em> in that list. In the test that is failing the list shouldn't be set and filled... but it is, because of other tests that are running.</p>
  
  <p>How can I correctly test this?</p>
  
  <p>For each test I create a mocked hub:</p>
  
  <pre><code>[TestMethod]
  public void InitChat_Available()
  {
    HubWrapper hub = new HubWrapper();
    hub.TryConnect();
  
    Assert.AreEqual(1, hub.callerResponse.Count);
    Assert.IsFalse((bool)hub.callerResponse[0]);
  }
  </code></pre>
  
  <p>Init Method (Called in the HubWrapper constructor):</p>
  
  <pre><code>public void Init(string[] clientIds)
          {
              var connectionId = Guid.NewGuid().ToString();
              var mockClients = new Mock&lt;IHubCallerConnectionContext&lt;dynamic&gt;&gt;();
              var groupManagerMock = new Mock&lt;IGroupManager&gt;();
  
              Clients = mockClients.Object;
  
          caller.finishedInit = new Action&lt;bool&gt;((isAvailable) =&gt; callerResponse.Add(isAvailable));
  
              mockClients.Setup(m =&gt; m.Caller).Returns((ExpandoObject)caller);
              Groups = groupManagerMock.Object;
              Dictionary&lt;string, object&gt; environment = new Dictionary&lt;string, object&gt;();
              environment.Add("server.RemoteIpAddress", "127.0.0.10");
              Context = new HubCallerContext(request: new ServerRequest(environment), connectionId: connectionId);
          }
  </code></pre>
  
  <p>Hub TryConnect():</p>
  
  <pre><code>public void InitChat(string clientId)
          {
              bool isChatAvailable = (ConnectedUsers != null &amp;&amp; ConnectedUsers.Count &lt; MaxConnectedUsers);
  
              Clients.Caller.finishedInit(isChatAvailable);
          }
  </code></pre>
  
  <p><em>I've removed some (for this issue) unnecessary code.</em></p>