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(this.GetUnitOfWork());

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

            repository.Create(this.defaultVehicle.VehicleId,
                              inRangeReminder1);

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

            repository.Create(this.defaultVehicle.VehicleId,
                              inRangeReminder2);

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

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

            var reminders = repository.GetUpcomingReminders(
                this.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));
        }
        public void WhenDeletingReminder_ThenPersists()
        {
            var repository = new ReminderRepository(this.GetUnitOfWork());

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

            repository.Create(this.defaultVehicle.VehicleId, reminder);

            var repositoryForDelete = new ReminderRepository(this.GetUnitOfWork());

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

            repositoryForDelete.Delete(reminder.ReminderId);

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

            Assert.NotNull(returnedReminders);
            Assert.Equal(0, returnedReminders.Count());
        }
        public void WhenUpdatingReminder_ThenPersists()
        {
            var repository = new ReminderRepository(this.GetUnitOfWork());

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

            repository.Create(this.defaultVehicle.VehicleId, reminder);

            var repositoryForUpdate = new ReminderRepository(this.GetUnitOfWork());

            var reminderToUpdate = repositoryForUpdate.GetRemindersForVehicle(this.defaultVehicle.VehicleId).First();

            reminderToUpdate.Title = "updated";

            repositoryForUpdate.Update(reminderToUpdate);

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

            Assert.NotNull(returnedReminder);
            Assert.Equal("updated", returnedReminder.Title);
        }
        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);
        }
        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));

        }