public void ProcessesStore_Refresh_ShouldVisitRepoGetAllOnce()
        {
            var store = new ProcessesStore(ProcessRepo.Object);

            store.Refresh();

            ProcessRepo.Verify(r => r.GetAll(), Times.Once);
        }
        public void ProcessesStore_GetAll_ShouldReturnEmptyCollection()
        {
            var testProcs = new IProcessModel[] { new ProcessModel() };

            ProcessRepo.Setup(r => r.GetAll()).Returns(testProcs);

            var store = new ProcessesStore(ProcessRepo.Object);
            var procs = store.GetAll();

            Assert.That(procs, Is.InstanceOf(typeof(IEnumerable <IProcessModel>)));
            Assert.That(!procs.Any());
        }
        public void ProcessesStore_GetAll_ShouldReturnCollectionFromRepoAfterRefresh()
        {
            var testProcs = new IProcessModel[] { new ProcessModel() };

            ProcessRepo.Setup(r => r.GetAll()).Returns(testProcs);

            var store = new ProcessesStore(ProcessRepo.Object);

            store.Refresh();
            var procs = store.GetAll();

            Assert.That(procs, Is.EqualTo(testProcs));
        }
        /// <summary>
        /// This method is called when the <see cref="T:Microsoft.Extensions.Hosting.IHostedService" />
        /// starts. The implementation should return a task that represents the lifetime of the long
        /// running operation(s) being performed.
        /// </summary>
        ///
        /// <param name="stoppingToken">    Triggered when
        ///                                 <see cref="M:Microsoft.Extensions.Hosting.IHostedService.StopAsync(System.Threading.CancellationToken)" />
        ///                                 is called. </param>
        ///
        /// <returns>
        /// A <see cref="T:System.Threading.Tasks.Task" /> that represents the long running operations.
        /// </returns>
        ///
        /// <seealso cref="M:Microsoft.Extensions.Hosting.BackgroundService.ExecuteAsync(CancellationToken)"/>

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            Logger.Log(LogLevel.Trace, "ProcessRefresherService:ExecuteAsync Service Starting");

            do
            {
                ProcessesStore.Refresh();
                NotificationsProcessor.SendNotifications();

                await Task.Delay(Configuration.ProcessesListRefreshPeriod, stoppingToken);
            }while (!stoppingToken.IsCancellationRequested);

            Logger.Log(LogLevel.Trace, "ProcessRefresherService:ExecuteAsync Service Stopping");
        }
        /// <summary>   Sends the notifications with the list of messages from processes which exceeded load limits. </summary>
        ///
        /// <seealso cref="M:ProcessViewer.Persistence.Stores.Abstract.IProcessesStore.SendNotifications()"/>

        public void SendNotifications()
        {
            var messages = LoadCheckerRunner.GetNotifications(ProcessesStore.GetAll());

            if (messages == null)
            {
                return;
            }

            foreach (var notificationMessage in messages)
            {
                ProcessHighLoad?
                .Invoke(this, new ProcessHighLoadEventArgs(
                            notificationMessage));
            }
        }