public void Dispose_ServiceIsStopped()
        {
            // Arrange
            var systemInformationProvider = new Mock<ISystemInformationProvider>();
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();
            var messageQueueFeeder = new SystemInformationMessageQueueFeeder(systemInformationProvider.Object, workQueue.Object);
            var messageQueueFeederTask = new Task(messageQueueFeeder.Start);
            messageQueueFeederTask.Start();
            Thread.Sleep(500);

            // Act
            messageQueueFeeder.Dispose();
            Task.WaitAll(messageQueueFeederTask);

            // Assert
            Assert.AreEqual(ServiceStatus.Stopped, messageQueueFeeder.GetStatus());
        }
        public void GetStatus_ServiceIsNotStarted_ResultIs_Stopped()
        {
            // Arrange
            var systemInformationProvider = new Mock<ISystemInformationProvider>();
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();

            var messageQueueFeeder = new SystemInformationMessageQueueFeeder(systemInformationProvider.Object, workQueue.Object);

            // Act
            var result = messageQueueFeeder.GetStatus();

            // Assert
            Assert.AreEqual(ServiceStatus.Stopped, result);
        }
        public void Stop_EndsARunningService()
        {
            // Arrange
            int durationInMilliseconds = SystemInformationMessageQueueFeeder.SendIntervalInMilliseconds * 3;

            var systemInformationProvider = new Mock<ISystemInformationProvider>();
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();

            var messageQueueFeeder = new SystemInformationMessageQueueFeeder(systemInformationProvider.Object, workQueue.Object);
            var messageQueueFeederTask = new Task(messageQueueFeeder.Start);
            messageQueueFeederTask.Start();

            // Act
            Thread.Sleep(durationInMilliseconds);

            messageQueueFeeder.Stop();

            // Assert
            Assert.AreEqual(ServiceStatus.Stopped, messageQueueFeeder.GetStatus());
        }
        public void Stop_ServiceIsStopped_StatusIsNotChanged()
        {
            // Arrange
            var systemInformationProvider = new Mock<ISystemInformationProvider>();
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();

            var messageQueueFeeder = new SystemInformationMessageQueueFeeder(systemInformationProvider.Object, workQueue.Object);
            var messageQueueFeederTask = new Task(messageQueueFeeder.Start);
            messageQueueFeederTask.Start();
            messageQueueFeeder.Stop();

            var statusBeforeStop = messageQueueFeeder.GetStatus();

            // Act
            messageQueueFeeder.Stop();
            var statusAfterStop = messageQueueFeeder.GetStatus();

            // Assert
            Assert.AreEqual(statusBeforeStop, statusAfterStop);
        }
        public void Resume_ServiceIsStopped_StatusIsStillStopped()
        {
            // Arrange
            var systemInformationProvider = new Mock<ISystemInformationProvider>();
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();

            using (var messageQueueFeeder = new SystemInformationMessageQueueFeeder(systemInformationProvider.Object, workQueue.Object))
            {
                var messageQueueFeederTask = new Task(messageQueueFeeder.Start);
                messageQueueFeederTask.Start();
                messageQueueFeeder.Stop();

                // Act
                messageQueueFeeder.Resume();

                // Assert
                Assert.AreEqual(ServiceStatus.Stopped, messageQueueFeeder.GetStatus());
            }
        }
        public void Resume_ServiceIsRunning_StatusIsNotChanged()
        {
            // Arrange
            var systemInformationProvider = new Mock<ISystemInformationProvider>();
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();

            using (var messageQueueFeeder = new SystemInformationMessageQueueFeeder(systemInformationProvider.Object, workQueue.Object))
            {
                var messageQueueFeederTask = new Task(messageQueueFeeder.Start);
                messageQueueFeederTask.Start();

                var statusBeforeResume = messageQueueFeeder.GetStatus();

                // Act
                messageQueueFeeder.Resume();
                var statusAfterResume = messageQueueFeeder.GetStatus();

                // Assert
                Assert.AreEqual(statusBeforeResume, statusAfterResume);
            }
        }
        public void Resume_ServiceIsPaused_StatusIsChangedToRunning()
        {
            // Arrange
            var systemInformationProvider = new Mock<ISystemInformationProvider>();
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();

            using (var messageQueueFeeder = new SystemInformationMessageQueueFeeder(systemInformationProvider.Object, workQueue.Object))
            {
                var messageQueueFeederTask = new Task(messageQueueFeeder.Start);
                messageQueueFeederTask.Start();

                Thread.Sleep(500);
                messageQueueFeeder.Pause();

                // Act
                Thread.Sleep(500);
                messageQueueFeeder.Resume();

                // Assert
                Assert.AreEqual(ServiceStatus.Running, messageQueueFeeder.GetStatus());
            }
        }
        public void Pause_ServiceIsRunning_StatusIsChangedToPaused()
        {
            // Arrange
            int durationInMilliseconds = SystemInformationMessageQueueFeeder.SendIntervalInMilliseconds * 3;

            var systemInformationProvider = new Mock<ISystemInformationProvider>();
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();

            using (var messageQueueFeeder = new SystemInformationMessageQueueFeeder(systemInformationProvider.Object, workQueue.Object))
            {
                var messageQueueFeederTask = new Task(messageQueueFeeder.Start);
                messageQueueFeederTask.Start();
                Thread.Sleep(durationInMilliseconds);

                // Act
                messageQueueFeeder.Pause();
                var statusAfterPause = messageQueueFeeder.GetStatus();

                // Assert
                Assert.AreEqual(ServiceStatus.Paused, statusAfterPause);
            }
        }
        public void GetStatus_ServiceIsStarted_ResultIs_Running()
        {
            // Arrange
            var systemInformationProvider = new Mock<ISystemInformationProvider>();
            var workQueue = new Mock<IMessageQueue<SystemInformation>>();

            var messageQueueFeeder = new SystemInformationMessageQueueFeeder(systemInformationProvider.Object, workQueue.Object);
            var messageQueueFeederTask = new Task(messageQueueFeeder.Start);
            messageQueueFeederTask.Start();

            Thread.Sleep(3000);

            // Act
            var result = messageQueueFeeder.GetStatus();

            // Assert
            Assert.AreEqual(ServiceStatus.Running, result);
        }