コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: dupop/audio-reminder
        public void Test_WorkdayReminder_1hourAfterRing_NextShouldbeTomorrow()
        {
            ReminderEntity weekly8am = CreateWeekly8amReminder();
            var            calc      = new NextReminderOccurenceCalculator();

            DateTime now2 = new DateTime(2020, 4, 13, 9, 0, 0);
            DateTime expectedNextOccurence2 = new DateTime(2020, 4, 14, 8, 0, 0);

            TestNextReminderOccurenceCalculation(weekly8am, calc, now2, expectedNextOccurence2);
        }
コード例 #2
0
ファイル: UnitTest1.cs プロジェクト: dupop/audio-reminder
        public void Test_WorkdayReminder_1hourBeforeRing_NextShouldbeToday()
        {
            ReminderEntity weekly8am = CreateWeekly8amReminder();
            var            calc      = new NextReminderOccurenceCalculator();

            DateTime now3 = new DateTime(2020, 4, 13, 7, 0, 0);
            DateTime expectedNextOccurence3 = new DateTime(2020, 4, 13, 8, 0, 0);

            TestNextReminderOccurenceCalculation(weekly8am, calc, now3, expectedNextOccurence3);
        }
コード例 #3
0
ファイル: UnitTest1.cs プロジェクト: dupop/audio-reminder
        public void Test_WorkdayReminder_OnSunday_NextShouldbeMonday()
        {
            ReminderEntity weekly8am = CreateWeekly8amReminder();
            var            calc      = new NextReminderOccurenceCalculator();


            DateTime now1 = new DateTime(2020, 4, 13, 7, 0, 0);
            DateTime expectedNextOccurence1 = new DateTime(2020, 4, 13, 8, 0, 0);

            TestNextReminderOccurenceCalculation(weekly8am, calc, now1, expectedNextOccurence1);
        }
コード例 #4
0
        //todo: all these return statements are risky, they prevent the only chance for the user the make next step and don't give him another chance. e.g. if snooze feautre is disabled while ringing form is open, and than user clicks snooze
        //todo: when component is disabled we skip all processing, not just going to next state, review this once more to bse sure that this is ok. Same for snooze, snooze elapsed,
        //todo: hide snooze button if that feature is disabled(Ringer can call service via WCF webservice to check is snooze is enabled), we will probably need to handle closing the form as dismiss, not snooze. We also need to prevent accidental closing of form on escape button.
        //todo: validation if reminders as paramters to dismiss and snooze, are indeed excepted (or we first expect some other), or just remove them (less safe)
        public void DismissReminder(ReminderEntity reminderEntity)
        {
            DateTime now = DateTime.UtcNow;

            if (UserState != UserInteractionState.WaitingUserResponse)
            {
                Log.Logger.Error($"Ignoring attempt to dismiss reminder [name = {reminderEntity.Name}] because current scheduler state is {UserState} instead od WaitingUserResponse");
                return;
            }

            // Protection of some kind of double dismis request (maybe by multiple ringing windows or something else) that would cause next occurance of reminder to be skipped
            if (!ValidateReminderShouldBeRinging(reminderEntity, now))
            {
                return;
            }

            if (reminderEntity.IsRepeatable())
            {
                //setting next ringing of the reminder on its first next occurence by its schedule
                DateTime nextReminderRinging = new NextReminderOccurenceCalculator().GetNextReminderOccurence(reminderEntity, now).Value;
                reminderEntity.ScheduledTime = nextReminderRinging;
            }
            else
            {
                reminderEntity.Dismissed = true;
            }

            ElapsedActiveReminders.RemoveAll(r => r.Name == reminderEntity.Name);

            //TODO: test this - we are here potenitally calling ringer again before response for Dismissing is returned.
            GoToRingingOrIdleState(now);

            //indirectly also triggers UpdateReminderList on this object //TODO: what are effects of that, probably none?
            //TODO: immediate notifying of this change to NextReminderNOtifier is not needed. Should it be prevented or it produces no harm, as it only gives us duplicate reminders here?
            FilePersistenceAdapters.RemiderFilePersistence.OnEntitesChanged();
        }
コード例 #5
0
ファイル: UnitTest1.cs プロジェクト: dupop/audio-reminder
        private static void TestNextReminderOccurenceCalculation(ReminderEntity weekly8am, NextReminderOccurenceCalculator calc, DateTime now, DateTime expectedNextOccurence)
        {
            var actualnextOccurence = calc.GetNextReminderOccurence(weekly8am, now).Value;

            Assert.AreEqual(expectedNextOccurence, actualnextOccurence);
        }