private static int CompareReminders(Reminder x, Reminder y)
        {
            if (x == null && y == null)
            {
                return 0;
            }
            else if (x != null && y == null)
            {
                return -1; // I want non-null values first
            }
            else if (x == null && y != null)
            {
                return 1; // I want non-null values first
            }
            else
            {
                int result = CompareDueDate(x, y);

                if (result == 0)
                {
                    result = CompareDueDistance(x, y);

                    if (result == 0)
                    {
                        result = x.ReminderId.CompareTo(y.ReminderId);
                    }
                }

                return result;
            }
        }
 public ImminentReminderModel(Vehicle vehicle, Reminder reminder, bool isOverdue)
 {
     IsOverdue = isOverdue;
     _vehicle = vehicle;
     _reminder = reminder;
     _summary = new ReminderSummaryModel(reminder);
 }
        public ReminderResource(Reminder reminder, VehicleModel vehicle, UrlHelper url)
        {
            reminder.CalculateIsOverdue(vehicle.Odometer ?? 0);

            Title = reminder.Title;
            Remarks = reminder.Remarks;
            DueDate = reminder.DueDate;
            DueDistance = reminder.DueDistance;
            IsFulfilled = reminder.IsFulfilled;
            IsOverdue = reminder.IsOverdue;
            Update = url.Patch<PatchReminderController>(new {reminder.VehicleId, reminder.ReminderId});
        }
        static ReminderModel ToViewModel(Reminder source)
        {
            if (source == null)
            {
                return null;
            }

            return new ReminderModel
                       {
                           DueDate = source.DueDate,
                           DueDistance = source.DueDistance,
                           Remarks = source.Remarks,
                           ReminderId = source.ReminderId,
                           Title = source.Title,
                           VehicleId = source.VehicleId,
                           IsFulfilled = source.IsFulfilled
                       };
        }
        public void WhenCreatingReminder_ThenPersists()
        {
            var repository = new ReminderRepository();

            Reminder reminder = new Reminder()
                                    {
                                        DueDate = DateTime.UtcNow.AddDays(30),
                                        DueDistance = 1000,
                                        Title = "Test Reminder"
                                    };

            repository.Create(defaultVehicle.VehicleId, reminder);

            var repositoryForVerification = new ReminderRepository();
            var returnedReminder =
                repositoryForVerification.GetRemindersForVehicle(defaultVehicle.VehicleId).First();

            Assert.NotNull(returnedReminder);
            Assert.Equal("Test Reminder", returnedReminder.Title);
        }
Exemple #6
0
 public ReminderSummaryModel(Reminder reminder)
 {
     _reminder = reminder;
 }
        public void WhenDeletingReminder_ThenPersists()
        {
            var repository = new ReminderRepository();

            Reminder reminder = new Reminder()
                                    {
                                        DueDate = DateTime.UtcNow.AddDays(30),
                                        DueDistance = 1000,
                                        Title = "Test Reminder"
                                    };

            repository.Create(defaultVehicle.VehicleId, reminder);

            var repositoryForDelete = new ReminderRepository();

            Assert.Equal(1, repositoryForDelete.GetRemindersForVehicle(defaultVehicle.VehicleId).Count());

            repositoryForDelete.Delete(reminder.ReminderId);

            var repositoryForVerification = new ReminderRepository();
            var returnedReminders = repositoryForVerification.GetRemindersForVehicle(defaultVehicle.VehicleId);

            Assert.NotNull(returnedReminders);
            Assert.Equal(0, returnedReminders.Count());
        }
        public void WhenRetrievingUpcomingReminders_ThenRemindersInDueDateRangeRetrieved()
        {
            DateTime dateStart = DateTime.UtcNow;
            DateTime dateEnd = DateTime.UtcNow.AddDays(5);
            int odometer = 1000;
            int warningThreshold = 500;
            int outsideOdometerRange = odometer + warningThreshold + 1;

            var repository = new ReminderRepository();

            // reminders just inside range
            var inRangeReminder1 = new Reminder()
                               {
                                   DueDate = dateStart.AddDays(1),
                                   DueDistance = outsideOdometerRange,
                                   Title = "UpcomingReminder"
                               };
            repository.Create(defaultVehicle.VehicleId,
                                inRangeReminder1);

            var inRangeReminder2 = new Reminder()
                                {
                                    DueDate = dateEnd.AddDays(-1),
                                    DueDistance = outsideOdometerRange,
                                    Title = "UpcomingReminder1"
                                };
            repository.Create(defaultVehicle.VehicleId,
                    inRangeReminder2);

            // reminders just outside of range
            repository.Create(defaultVehicle.VehicleId,
                              new Reminder()
                              {
                                  DueDate = dateStart.AddDays(-1),
                                  DueDistance = outsideOdometerRange,
                                  Title = "OutsideRangeReminder1"
                              });

            repository.Create(defaultVehicle.VehicleId,
                              new Reminder()
                              {
                                  DueDate = dateEnd.AddDays(1),
                                  DueDistance = outsideOdometerRange,
                                  Title = "OutsideRangeReminder2"
                              });

            var reminders = repository.GetUpcomingReminders(
                defaultVehicle.VehicleId,
                dateStart,
                dateEnd,
                odometer,
                warningThreshold
                );

            Assert.Equal(2, reminders.Count());
            Assert.True(reminders.Any(r => r.ReminderId == inRangeReminder1.ReminderId));
            Assert.True(reminders.Any(r => r.ReminderId == inRangeReminder2.ReminderId));

        }
        private static IEnumerable<Reminder> GetListOfReminders()
        {
            var currentDate = DateTime.UtcNow;
            var reminders = new List<Reminder>
                                {
                                    new Reminder
                                        {
                                            ReminderId = 1,
                                            DueDate = currentDate.AddDays(300),
                                            DueDistance = CurrentOdometer + 10000,
                                            Title = "Future Reminder"
                                        },
                                    new Reminder
                                        {
                                            ReminderId = 2,
                                            DueDate = currentDate.AddDays(15),
                                            DueDistance = CurrentOdometer + 10000,
                                            Title = "Upcoming by Date Reminder"
                                        },
                                    new Reminder
                                        {
                                            ReminderId = 3,
                                            DueDate = currentDate.AddDays(300),
                                            DueDistance = CurrentOdometer + 499,
                                            Title = "Upcoming by Mileage Reminder"
                                        },
                                    new Reminder
                                        {
                                            ReminderId = 4,
                                            DueDate = currentDate.AddDays(-5),
                                            DueDistance = CurrentOdometer + 10000,
                                            Title = "Overdue By Date"
                                        },
                                    new Reminder
                                        {
                                            ReminderId = 5,
                                            DueDate = currentDate.AddDays(30),
                                            DueDistance = CurrentOdometer - 10,
                                            Title = "OverDue By Mileage"
                                        },
                                    new Reminder
                                        {
                                            ReminderId = 6,
                                            DueDate = DateTime.UtcNow.AddDays(-1),
                                            DueDistance = CurrentOdometer - 1,
                                            Title = "Overdue by date and mileage"
                                        },
                                    new Reminder
                                        {
                                            ReminderId = 7,
                                            DueDate = DateTime.UtcNow.AddDays(45),
                                            DueDistance = null,
                                            Title = "Not Upcoming or Overdue and DueDistance null"
                                        },
                                };

            var fulfilledReminder = new Reminder
                                        {
                                            ReminderId = 7,
                                            DueDate = DateTime.UtcNow.AddDays(-1),
                                            DueDistance = CurrentOdometer - 1,
                                            Title = "Fulfilled reminder",
                                            IsFulfilled = true
                                        };

            reminders.Add(fulfilledReminder);
            return reminders.AsEnumerable();
        }
 public ReminderSummaryModel(Reminder reminder)
 {
     _reminder = reminder;
 }
 private static int CompareDueDistance(Reminder x, Reminder y)
 {
     if (!x.DueDistance.HasValue && !y.DueDistance.HasValue)
     {
         return 0;
     }
     else if (x.DueDistance.HasValue && !y.DueDistance.HasValue)
     {
         return -1; // I want non-null values first
     }
     else if (!x.DueDistance.HasValue && y.DueDistance.HasValue)
     {
         return 1; // I want non-null values first
     }
     else
     {
         return x.DueDistance.Value.CompareTo(y.DueDistance.Value);
     }
 }
Exemple #12
0
 public ReminderSummaryModel(Reminder reminder, bool isOvedue)
 {
     _reminder = reminder;
     _isOvedue = isOvedue;
 }