public void verify_adds_reminder_if_project_is_configured_with_reminders() { RavenSession.Store(new Project { Owner = "users/99", Title = "Project98", Id = "projects/98", MaxNoteIntervalInDaysBeforeReminder = 7, Description = "Description text" }); RavenSession.SaveChanges(); var target = NoteService.CreateNoteService(RavenSession, RavenSession.Load <User>("users/99")); target.RequestContext = new MockRequestContext2(); var help = new ReminderHelper(RavenSession, templateRootPath); var a = help.GetAllRemindersDueBefore(DateTime.Now); Assert.AreEqual(0, a.Count); target.OnPost(new Note { ProjectId = "projects/98", Text = "first on 98" }); var n = RavenSession.Load <Note>("notes/1"); Assert.AreEqual(n.ProjectId, "projects/98"); var r = RavenSession.Load <Reminder>("reminders/1"); Assert.AreEqual(r.ProjectId, "projects/98"); Assert.AreEqual(r.Due.ToShortDateString(), DateTime.Now.AddDays(7).ToShortDateString()); //a = (new ReminderHelper(RavenSession)).GetAllRemindersDueBefore(DateTime.Now.AddDays(9)); //Assert.AreEqual(1, a.Count); }
// // GET: /Scheduler/ public ActionResult Index() { var schedule = RavenSession.Load <ScheduleSettings>("scheduleSettings/1"); var data = new List <EmailReminderData>(); int delayHours = 4; if (schedule == null) { schedule = new ScheduleSettings { Id = "scheduleSettings/1" }; RavenSession.Store(schedule); ViewBag.Message = "This is the first run!"; ViewBag.Error = "First run, creating session"; return(View()); } if ((DateTime.Now - schedule.LastRun).TotalHours > delayHours) { try { var logic = new ReminderHelper(RavenSession, Server.MapPath("/Views/Templates/")); var reminders = logic.GetAllRemindersDueBefore(DateTime.Now); var msgs = logic.ComposeMessages(reminders); ViewBag.Messages = msgs; var emails = logic.SendEmails(msgs); ViewBag.SentMessages = emails; logic.UpdateMsgCount(reminders); } catch (Exception ex) { ViewBag.Error = ex.Message; } ViewBag.Message = "Last run: " + schedule.LastRun; if (data.Count > 0) { string emailText = GetEmailText(data); RavenSession.Store(new TempTextEmail { Text = emailText }); } schedule.LastNumberOfNotifications = data.Count; schedule.LastRun = DateTime.Now; RavenSession.SaveChanges(); } else { ViewBag.Error = "Scheduler will not run before" + (delayHours - (DateTime.Now - schedule.LastRun).TotalHours).ToString() + " hours"; } return(View(data)); }
public void verify_loads_reminders() { RavenSession.Store(new Reminder { UserId = "users/99", Due = new DateTime(2012, 10, 20), RemindersSent = 0, LastNoteText = "Created 20.10", ProjectId = "projects/99" }); RavenSession.Store(new Reminder { UserId = "users/99", Due = new DateTime(2012, 10, 19), RemindersSent = 1, LastNoteText = "Created 19.10", ProjectId = "projects/99" }); RavenSession.Store(new Reminder { UserId = "users/99", Due = new DateTime(2012, 10, 18), RemindersSent = 2, LastNoteText = "Created 18.10", ProjectId = "projects/99" }); RavenSession.SaveChanges(); var target = new ReminderHelper(RavenSession, templateRootPath); var a = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 17)); Assert.AreEqual(0, a.Count); a = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 21)); Assert.AreEqual(3, a.Count); }
public void verify_increase_sentcount() { RavenSession.Store(new Reminder { UserId = "users/99", Due = new DateTime(2012, 10, 20), RemindersSent = 0, LastNoteText = "Created 20.10", ProjectId = "projects/99" }); RavenSession.Store(new Reminder { UserId = "users/99", Due = new DateTime(2012, 10, 19), RemindersSent = 1, LastNoteText = "Created 19.10", ProjectId = "projects/99" }); RavenSession.Store(new Reminder { UserId = "users/99", Due = new DateTime(2012, 10, 18), RemindersSent = 2, LastNoteText = "Created 18.10", ProjectId = "projects/99" }); RavenSession.SaveChanges(); var target = new ReminderHelper(RavenSession, templateRootPath); var result = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 20)); Assert.AreEqual(result.Count, 2); target.UpdateMsgCount(result); RavenSession.SaveChanges(); result = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 20)); Assert.AreEqual(result.Count, 1); }
public void verify_sends_email() { RavenSession.Store(new Reminder { UserId = "users/99", Due = new DateTime(2012, 10, 20), RemindersSent = 0, LastNoteText = "Created 20.10", ProjectId = "projects/99" }); RavenSession.Store(new Reminder { UserId = "users/99", Due = new DateTime(2012, 10, 19), RemindersSent = 1, LastNoteText = "Created 19.10", ProjectId = "projects/99" }); RavenSession.Store(new Reminder { UserId = "users/99", Due = new DateTime(2012, 10, 18), RemindersSent = 2, LastNoteText = "Created 18.10", ProjectId = "projects/99" }); RavenSession.SaveChanges(); var target = new ReminderHelper(RavenSession, templateRootPath); var reminders = target.GetAllRemindersDueBefore(new DateTime(2012, 10, 20)); var msgs = target.ComposeMessages(reminders); // var emails = target.SendEmails(msgs); }