Exemple #1
0
        public void UpdateReminderTest()
        {
            var reminder = new HydrateReminder { StartDate = DateTime.Now, EndDate = DateTime.Now.AddYears(1), FrequencyInHours = 2, LastUpdatedTime = DateTime.Now, LastRunTime = DateTime.Now, Message = "Please drink water", IsPaused = false };
            var repository = new FakeHydrateRepository();
            repository.CreateOrUpdateReminder(reminder);
            reminder = repository.GetReminder();

            reminder.FrequencyInHours = 3;
            reminder.LastUpdatedTime = DateTime.Now;
            repository.CreateOrUpdateReminder(reminder);

            var reminderRetrieved = repository.GetReminder();
            Assert.IsTrue(reminder.Equals(reminderRetrieved));
        }
Exemple #2
0
        public void CreateReminderInstancesTest()
        {
            var frequencyInHours = 1;
            var reminder = new HydrateReminder { StartDate = DateTime.Now, EndDate = DateTime.Now.AddYears(1), FrequencyInHours = frequencyInHours, LastUpdatedTime = DateTime.Now, Message = "Please drink water", IsPaused = false };
            var repository = new FakeHydrateRepository();
            repository.CreateOrUpdateReminder(reminder);

            var reminderInstanceScheduler = new ReminderInstanceScheduler(repository);
            reminderInstanceScheduler.CreateReminderInstances();

            var currentInstances = reminderInstanceScheduler.ScheduledNotifications;
            Assert.IsTrue(currentInstances.Count == (reminder.EndDate.Subtract(reminder.StartDate).TotalHours / reminder.FrequencyInHours));

            var currentTime = DateTime.Now.AddHours(frequencyInHours);
            //Evaluate Instances
            foreach (var currentInstance in currentInstances)
            {
                Assert.IsTrue(currentInstance.DeliveryTime.Subtract(currentTime) < TimeSpan.FromMilliseconds(2));
                currentTime = currentTime.AddHours(frequencyInHours);
            }
        }