Beispiel #1
0
        public void ScheduleShutdown()
        {
            IEnumerable <DateTime> shutdownHistory = shutdownHistoryStorage.GetAll();

            if (!shutdownHistory.Any())
            {
                logger.LogInformation("shutdown history is empty");
                return;
            }

            DateTime NextForecastedShutdownTime = nightlyShutdownCalculator.GetNextShutdown(shutdownHistory);
            DateTime nextShutdownTime           = AddBuffer(NextForecastedShutdownTime, minutes: 10);

            ExecuteDailyShutdownAt(nextShutdownTime);
            logger.LogInformation($"Shutdown was scheduled to happen at: {nextShutdownTime}");
        }
Beispiel #2
0
        public void UpdateShutdownHistory_WhenLastShutdownOccuredAtDaytime_ThenNotAddedToShutdownHistoryStorage(DateTime lastSystemShutdown)
        {
            var systemInformationMock = new Mock <ISystemInformation>();

            systemInformationMock.Setup(s => s.GetLastSystemShutdown()).Returns(lastSystemShutdown);
            NightlyShutdownHistoryUpdater sut = new NightlyShutdownHistoryUpdater(systemInformationMock.Object, shutdownHistoryStorage);

            sut.UpdateShutdownHistory();

            Assert.Empty(shutdownHistoryStorage.GetAll());
        }
Beispiel #3
0
        public void UpdateShutdownHistory()
        {
            DateTime lastSystemShutdown = systemInformation.GetLastSystemShutdown();

            if (!IsHourOfNight(lastSystemShutdown))
            {
                return;
            }

            shutdownHistoryStorage.Add(lastSystemShutdown);

            IEnumerable <DateTime> times = shutdownHistoryStorage.GetAll(IsHourOfNight);

            if (times.Count() > HISTORY_MAX_SIZE)
            {
                shutdownHistoryStorage.Remove(times.Min());
            }
        }
Beispiel #4
0
        public void GetAll_WhenDatetimesInStorage_ThenReturnedWithCorrectValues()
        {
            IEnumerable <DateTime> times = shutdownHistoryStorage.GetAll();

            Assert.Equal(3, times.Count());
        }