コード例 #1
0
        public void TestInit()
        {
            DndTimeClock dndTimeClock = new DndTimeClock();
            DateTime     now          = DateTime.Now;

            dndTimeClock.SetTime(now);
            dndTimeClock.Advance(DndTimeSpan.FromRounds(1));
            TimeSpan difference = dndTimeClock.Time - now;

            Assert.AreEqual(6, difference.TotalSeconds);


            dndTimeClock.SetTime(now);
            dndTimeClock.Advance(new DndTimeSpan(TimeMeasure.instant, 5));
            difference = dndTimeClock.Time - now;
            Assert.AreEqual(0, difference.TotalSeconds);


            dndTimeClock.SetTime(now);
            dndTimeClock.Advance(DndTimeSpan.FromMinutes(5));
            difference = dndTimeClock.Time - now;
            Assert.AreEqual(5, difference.TotalMinutes);

            dndTimeClock.SetTime(now);
            dndTimeClock.Advance(DndTimeSpan.FromHours(3));
            difference = dndTimeClock.Time - now;
            Assert.AreEqual(3, difference.TotalHours);

            dndTimeClock.SetTime(now);
            dndTimeClock.Advance(DndTimeSpan.FromDays(2));
            difference = dndTimeClock.Time - now;
            Assert.AreEqual(2, difference.TotalDays);
        }
コード例 #2
0
 private void Rest(int hours)
 {
     resting = true;
     try
     {
         dndTimeClock.Advance(DndTimeSpan.FromHours(hours));
     }
     finally
     {
         resting = false;
     }
 }
コード例 #3
0
ファイル: AlarmTests.cs プロジェクト: surlydev/MrAnnouncerBot
        public void Test()
        {
            bool     firstAlarmFired  = false;
            bool     secondAlarmFired = false;
            DateTime firstAlarmTime   = DateTime.MinValue;
            DateTime secondAlarmTime  = DateTime.MinValue;


            void First_AlarmFired(object sender, DndTimeEventArgs ea)
            {
                firstAlarmTime  = ea.TimeClock.Time;
                firstAlarmFired = true;
            }

            void Second_AlarmFired(object sender, DndTimeEventArgs ea)
            {
                secondAlarmTime  = ea.TimeClock.Time;
                secondAlarmFired = true;
            }

            DndTimeClock dndTimeClock = new DndTimeClock();
            DateTime     startTime    = new DateTime(2000, 1, 1);

            dndTimeClock.SetTime(startTime);
            DndAlarm first = dndTimeClock.CreateAlarm(TimeSpan.FromSeconds(5), "First");

            first.AlarmFired += First_AlarmFired;
            DndAlarm second = dndTimeClock.CreateAlarm(TimeSpan.FromSeconds(15), "Second");

            second.AlarmFired += Second_AlarmFired;

            Assert.IsFalse(firstAlarmFired);
            Assert.IsFalse(secondAlarmFired);
            Assert.AreEqual(firstAlarmTime, DateTime.MinValue);
            Assert.AreEqual(secondAlarmTime, DateTime.MinValue);

            dndTimeClock.Advance(DndTimeSpan.FromSeconds(10));
            Assert.IsTrue(firstAlarmFired);
            Assert.AreEqual(firstAlarmTime, startTime + TimeSpan.FromSeconds(5));
            Assert.IsFalse(secondAlarmFired);

            dndTimeClock.Advance(DndTimeSpan.FromSeconds(10));
            Assert.IsTrue(secondAlarmFired);
            Assert.AreEqual(secondAlarmTime, startTime + TimeSpan.FromSeconds(15));
        }