public void Resume_ServiceIsRunning_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); var statusBeforeResume = messageQueueWorker.GetStatus(); // Act messageQueueWorker.Resume(); Thread.Sleep(500); var statusAfterResume = messageQueueWorker.GetStatus(); // Assert Assert.AreEqual(statusBeforeResume, statusAfterResume); } }
public void Dispose_ServiceIsStopped() { // Arrange var maxWaitTime = SystemInformationMessageQueueWorker.WorkIntervalInMilliseconds * 3; var systemInformationSender = new Mock <ISystemInformationSender>(); var workQueue = new Mock <IMessageQueue <SystemInformation> >(); workQueue.Setup(w => w.IsEmpty()).Returns(true); var errorQueue = new Mock <IMessageQueue <SystemInformation> >(); var messageQueueWorker = new SystemInformationMessageQueueWorker(systemInformationSender.Object, workQueue.Object, errorQueue.Object); var workerTaks = new Task(messageQueueWorker.Start); workerTaks.Start(); Thread.Sleep(500); // Act messageQueueWorker.Dispose(); Task.WaitAll(new[] { workerTaks }, maxWaitTime); // Assert Assert.AreEqual(ServiceStatus.Stopped, messageQueueWorker.GetStatus()); }
public void GetStatus_ServiceIsPaused_ResultIsPaused() { // 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(); Thread.Sleep(500); // Act var status = messageQueueWorker.GetStatus(); // Assert Assert.AreEqual(ServiceStatus.Paused, status); } }
public void Stop_ServiceIsNotStartet_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 statusBefore = messageQueueWorker.GetStatus(); // Act messageQueueWorker.Stop(); var statusAfter = messageQueueWorker.GetStatus(); // Assert Assert.AreEqual(statusBefore, statusAfter); } }
public void Constructor_InitialStatusIsStopped() { // 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> >(); // Act using (var messageQueueWorker = new SystemInformationMessageQueueWorker(systemInformationSender.Object, workQueue.Object, errorQueue.Object)) { // Assert Assert.AreEqual(ServiceStatus.Stopped, messageQueueWorker.GetStatus()); } }