public void Pause_ServiceIsPaused_StatusIsNotChanged() { // Arrange var systemInformationSender = new Mock <ISystemInformationSender>(); var workQueue = new Mock <IMessageQueue <SystemInformation> >(); workQueue.Setup(w => w.Dequeue()).Returns(new SystemInformationQueueItem(new SystemInformation())); var errorQueue = new Mock <IMessageQueue <SystemInformation> >(); using (var messageQueueWorker = new SystemInformationMessageQueueWorker(systemInformationSender.Object, workQueue.Object, errorQueue.Object)) { var workerTaks = new Task(messageQueueWorker.Start); workerTaks.Start(); Thread.Sleep(500); messageQueueWorker.Pause(); var statusBefore = messageQueueWorker.GetStatus(); Thread.Sleep(500); // Act messageQueueWorker.Pause(); var statusAfter = messageQueueWorker.GetStatus(); // Assert Assert.AreEqual(statusBefore, statusAfter); } }
public void Pause_RunFor6Intervals_PauseIsCalledAfter3Intervals_SendIsCalledAtMostThreeTimes() { // Arrange int durationInMilliseconds = SystemInformationMessageQueueWorker.WorkIntervalInMilliseconds * 6; var systemInformationSender = new Mock <ISystemInformationSender>(); var workQueue = new Mock <IMessageQueue <SystemInformation> >(); workQueue.Setup(w => w.Dequeue()).Returns(new SystemInformationQueueItem(new SystemInformation())); var errorQueue = new Mock <IMessageQueue <SystemInformation> >(); using (var messageQueueWorker = new SystemInformationMessageQueueWorker(systemInformationSender.Object, workQueue.Object, errorQueue.Object)) { // Act var workerTaks = new Task(messageQueueWorker.Start); workerTaks.Start(); Thread.Sleep(durationInMilliseconds / 2); messageQueueWorker.Pause(); // Assert systemInformationSender.Verify(s => s.Send(It.IsAny <SystemInformation>()), Times.AtMost(3)); } }