I am writing a client that sends a “server signal” to the server every second. The client calls the WCF service in the background thread to report on its activity.
How unit test is this? I need to wait a couple of seconds and check if the corresponding method is called several times?
Could this be some kind of scenario? Maybe I should not worry about the continuous call of the service throughout the life cycle of clients?
I can test one call to the WCF service, but it does not test the "heart rate pattern".
I am using the TDD approach. (C #, NUnit, Moq)
Any suggestions or examples?
EDIT:
I think this was not clear enough.
This is a much simpler version of what I have:
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();
}
}
... and this is my test:
[Test]
public void Heartbeat_called_twice_after_2_seconds()
{
var mockFeedService = new Mock<FeedService>();
Thread.Sleep(2000);
mockFeedService.Verify(x => x.SendHeartBeat(), Times.AtLeast(2));
}
:
1) ? ?
2) ?