view ServerMonitorTest/ScheduleTest.cs @ 26:b5502ce8cb1f

Fix servers getting disabled at program launch if no SSH key is set, even if they have no SSH checks.
author Brad Greco <brad@bgreco.net>
date Sun, 02 Jun 2019 17:45:37 -0400
parents 3e1a2131f897
children
line wrap: on
line source

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ServerMonitorApp;

namespace ServerMonitorTest
{
    [TestClass]
    public class ScheduleTest
    {
        private Schedule secondAllDaySchedule = new Schedule(FrequencyUnits.Second, 5, new TimeSpan(0, 0, 0), new TimeSpan(23, 59, 59));
        private Schedule secondPartDaySchedule = new Schedule(FrequencyUnits.Second, 5, new TimeSpan(10, 0, 0), new TimeSpan(21, 0, 0));
        private Schedule secondSpanDaySchedule = new Schedule(FrequencyUnits.Second, 5, new TimeSpan(21, 0, 0), new TimeSpan(10, 0, 0));

        #region All day

        [TestMethod]
        public void TestAllDay1()
        {
            Assert.AreEqual(new DateTime(2000, 1, 1, 1, 0, 5),
                secondAllDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 1, 0, 0), new DateTime(2000, 1, 1, 1, 0, 1)));
        }

        [TestMethod]
        public void TestAllDay2()
        {
            Assert.AreEqual(new DateTime(2000, 1, 1, 1, 0, 15),
                secondAllDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 1, 0, 0), new DateTime(2000, 1, 1, 1, 0, 11)));
        }

        [TestMethod]
        public void TestAllDay3()
        {
            Assert.AreEqual(new DateTime(2000, 1, 1, 2, 0, 15),
                secondAllDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 1, 0, 0), new DateTime(2000, 1, 1, 2, 0, 11)));
        }

        [TestMethod]
        public void TestAllDay4()
        {
            Assert.AreEqual(new DateTime(2000, 1, 2, 0, 0, 3),
                secondAllDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 23, 59, 58), new DateTime(2000, 1, 1, 23, 59, 59)));
        }

        [TestMethod]
        public void TestAllDay5()
        {
            Assert.AreEqual(new DateTime(2000, 1, 2, 0, 0, 8),
                secondAllDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 23, 59, 58), new DateTime(2000, 1, 2, 0, 0, 4)));
        }

        #endregion

        #region Part day

        [TestMethod]
        public void TestPartDay1()
        {
            Assert.AreEqual(new DateTime(2000, 1, 1, 10, 0, 5),
                secondPartDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 10, 0, 0), new DateTime(2000, 1, 1, 10, 0, 1)));
        }

        [TestMethod]
        public void TestPartDay2()
        {
            Assert.AreEqual(new DateTime(2000, 1, 2, 10, 0, 0),
                secondPartDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 10, 0, 3), new DateTime(2000, 1, 1, 20, 59, 59)));
        }

        [TestMethod]
        public void TestPartDay3()
        {
            Assert.AreEqual(new DateTime(2000, 1, 2, 10, 0, 0),
                secondPartDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 10, 0, 3), new DateTime(2000, 1, 1, 21, 0, 0)));
        }

        #endregion

        #region Span day

        [TestMethod]
        public void TestSpanDay1()
        {
            Assert.AreEqual(new DateTime(2000, 1, 1, 1, 0, 5),
                secondSpanDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 1, 0, 0), new DateTime(2000, 1, 1, 1, 0, 1)));
        }

        [TestMethod]
        public void TestSpanDay2()
        {
            Assert.AreEqual(new DateTime(2000, 1, 2, 0, 0, 3),
                secondSpanDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 23, 59, 58), new DateTime(2000, 1, 1, 23, 59, 59)));
        }

        [TestMethod]
        public void TestSpanDay3()
        {
            Assert.AreEqual(new DateTime(2000, 1, 2, 0, 0, 8),
                secondSpanDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 23, 59, 58), new DateTime(2000, 1, 2, 0, 0, 4)));
        }

        [TestMethod]
        public void TestSpanDay4()
        {
            Assert.AreEqual(new DateTime(2000, 1, 2, 21, 0, 0),
                secondSpanDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 21, 0, 8), new DateTime(2000, 1, 2, 9, 59, 59)));
        }

        [TestMethod]
        public void TestSpanDay5()
        {
            Assert.AreEqual(new DateTime(2000, 1, 2, 21, 0, 0),
                secondSpanDaySchedule.GetNextTime(new DateTime(2000, 1, 1, 21, 0, 8), new DateTime(2000, 1, 2, 11, 0, 0)));
        }

        #endregion

    }
}