title: How to unit test the heartbeat pattern?
body: <p>I am writing a client which sends a "heartbeat signal" to the server every second. The client calls a WCF service in the background thread to report its activity.</p>
  
  <p>How to unit test this? Do I need to wait for a couple of seconds and check if appropriate method was called several times?</p>
  
  <p>Should it be some sort of scenario test instead? Maybe I shouldn't be worried about calling the service continuously through the whole clients lifetime cycle?</p>
  
  <p>I can test a single call to WCF service but it doesn't test the "heartbeat pattern".</p>
  
  <p>I am using TDD approach. (C#, NUnit, Moq)</p>
  
  <p>Any suggestions or examples?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I think it wasn't clear enough.</p>
  
  <p>This is a much simpler version of what I have:</p>
  
  <pre><code>public class FeedService
  {
     private Timer t;
  
     public FeedService()
     {
        t.Interval = 1000;
        t.Elapsed += TimerElapsed;
        t.Start();
     }
  
     private void TimerElapsed(object sender, ElapsedEventArgs e)
     {
        t.Stop();
        SendHeartbeat();
        t.Start();
     }
  }
  </code></pre>
  
  <p>...and this is my test:</p>
  
  <pre><code>[Test]
  public void Heartbeat_called_twice_after_2_seconds()
  {
    var mockFeedService = new Mock&lt;FeedService&gt;();
  
    Thread.Sleep(2000);
    mockFeedService.Verify(x =&gt; x.SendHeartBeat(), Times.AtLeast(2));
  }
  </code></pre>
  
  <p>I have a two questions:<br>
  1) Why my test always fails? What I am doing wrong?<br>
  2) Should I test it at all?</p>