public void ReadReminderTest() { using (var cs = new CherryService()) { cs.PluginRepository.RegisterPlugin(new FakeReminderPlugin()); cs.PluginRepository.RegisterPlugin(new PomodoroSensor()); cs.PluginRepository.RegisterPlugin(new RemindersCorePlugin()); cs.PluginRepository.RegisterPlugin(new ReminderPluginsRepository()); cs.PluginRepository.RegisterPlugin(new FakeTimeProvider()); cs.PluginRepository.RegisterPlugin(new FakeWindowsController()); cs.PluginRepository.RegisterPlugin(new DatabaseController()); var csr = new StringReader("<cherryTomato><config>" + "<reminders><reminder typeName=\"FakeReminder\" /></reminders>" + "</config></cherryTomato>"); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); cs.LoadConfiguration(csr); var allReminders = cs.PluginRepository.CherryCommands["Get All Reminders"].Do(null) as IEnumerable <IReminder>; Assert.That(allReminders.FirstOrDefault().TypeName, Is.EqualTo("FakeReminder")); } }
public void PomodoroAllEventsTest() { var cs = new CherryService(); var ftp = new FakeTimeProvider { Now = new DateTime(2009, 05, 13) }; var ps = new PomodoroSensor(); cs.PluginRepository.RegisterPlugin(ftp); cs.PluginRepository.RegisterPlugin(ps); cs.PluginRepository.RegisterPlugin(new DatabaseController()); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); var eventChecker = new EventFiredChecker(cs); eventChecker.WaitFor("Pomodoro Started", "Pomodoro Finishing", "Pomodoro Finished"); Assert.IsTrue((bool)eventChecker.InvokeCommand("Start Pomodoro", null)); eventChecker.AssertFired("Pomodoro Started"); eventChecker.AssertNotFired("Pomodoro Finishing", "Pomodoro Finished"); ftp.AdvanceMinutes(25); Assert.IsTrue((bool)eventChecker.InvokeCommand("Stop Pomodoro", null)); eventChecker.AssertFired("Pomodoro Finishing", "Pomodoro Finished"); eventChecker.Reset(); Assert.IsTrue((bool)eventChecker.InvokeCommand("Start Pomodoro", null)); eventChecker.AssertFired("Pomodoro Started"); eventChecker.AssertNotFired("Pomodoro Finishing", "Pomodoro Finished"); ftp.AdvanceMinutes(25); Assert.IsTrue((bool)eventChecker.InvokeCommand("Void Pomodoro", null)); eventChecker.AssertFired("Pomodoro Finishing", "Pomodoro Finished"); }
public void TestCondition() { var cond = new TimeOfDayCondition() { StartTime = TimeSpan.FromHours(8), EndTime = TimeSpan.FromHours(9), ShouldBeWithin = true, }; var checker = new CherryTomato.Reminders.TimeOfDayConditionChecker.TimeOfDayConditionChecker(); var cs = new CherryService(); cs.PluginRepository.RegisterPlugin(checker); var tp = new FakeTimeProvider(); cs.PluginRepository.RegisterPlugin(tp); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); tp.Now = DateTime.Today.AddHours(8).AddMinutes(1); Assert.IsTrue(checker.IsTrue(cond)); tp.Now = DateTime.Today.AddHours(9).AddMinutes(1); Assert.IsFalse(checker.IsTrue(cond)); cond.ShouldBeWithin = false; Assert.IsTrue(checker.IsTrue(cond)); tp.Now = DateTime.Today.AddHours(8).AddMinutes(1); Assert.IsFalse(checker.IsTrue(cond)); }
public void LoadConfigTest() { var dbFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\cherrytomato\\database.sqlite"; var ver = new Version(Application.ProductVersion); var configString = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<cherryTomato>\r\n" + " <hasRun />\r\n" + " <newestKnownVersion major=\"" + ver.Major + "\" minor=\"" + ver.Minor + "\" />\r\n" + " <databaseFile path=\"" + dbFile + "\" />\r\n" + " <config />\r\n" + "</cherryTomato>"; var reader = new StringReader(configString); using (var cs = new CherryService()) { var vc = new VersionChecker(); cs.PluginRepository.RegisterPlugin(new PomodoroSensor()); cs.PluginRepository.RegisterPlugin(new FakeTimeProvider()); cs.PluginRepository.RegisterPlugin(new DatabaseController()); var fr = new FirstRunSensor(); cs.PluginRepository.RegisterPlugin(fr); cs.PluginRepository.RegisterPlugin(vc); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); cs.LoadConfiguration(reader); Assert.AreEqual(true, fr.HasRun); Assert.AreEqual(ver.Major, vc.NewestKnownVersion.Major); Assert.AreEqual(ver.Minor, vc.NewestKnownVersion.Minor); } }
public void SaveConfigTest() { var ver = new Version(Application.ProductVersion); var dbFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\cherrytomato\\database.sqlite"; using (var cs = new CherryService()) { var csw = new StringWriter(); cs.PluginRepository.RegisterPlugin(new VersionChecker()); cs.PluginRepository.RegisterPlugin(new FakeTimeProvider()); cs.PluginRepository.RegisterPlugin(new PomodoroSensor()); cs.PluginRepository.RegisterPlugin(new DatabaseController()); cs.PluginRepository.RegisterPlugin(new FirstRunSensor()); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); cs.SaveConfiguration(csw); var expected = "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n" + "<cherryTomato>\r\n" + " <config>\r\n" + " <plugins />\r\n" + " </config>\r\n" + " <newestKnownVersion major=\"" + ver.Major + "\" minor=\"" + ver.Minor + "\" />\r\n" + " <databaseFile path=\"" + dbFile + "\" />\r\n" + " <hasRun />\r\n" + "</cherryTomato>"; var actual = csw.GetStringBuilder().ToString(); Assert.That(actual, Is.EqualTo(expected)); } }
public void SimpleTest() { var fpaws = new FakeProcessAndWindowSpy(); var ftp = new FakeTimeProvider { Now = new DateTime(2009, 05, 13) }; var ats = new CherryTomato.ActiveTaskSensor.ActiveTaskSensor(fpaws); var cs = new CherryService(); var ps = new PomodoroSensor(); cs.PluginRepository.RegisterPlugin(ftp); cs.PluginRepository.RegisterPlugin(ats); cs.PluginRepository.RegisterPlugin(ps); cs.PluginRepository.RegisterPlugin(new DatabaseController()); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); fpaws.ActiveTask = new TaskRegistration { TaskName = "Task1", ProcessName = "Task1" }; ps.StartPomodoroInternal(); fpaws.ActiveTask = new TaskRegistration { TaskName = "Task1", ProcessName = "Task1" }; ats.CountActiveTask(); ftp.AdvanceMinutes(10); ats.CountActiveTask(); fpaws.ActiveTask = new TaskRegistration { TaskName = "Task2", ProcessName = "Task2" }; ats.CountActiveTask(); }
public void SimpleTest() { var cs = new CherryService(); //cs.PluginRepository.RegisterPlugin(new IconController()); cs.PluginRepository.RegisterPlugin(new PomodoroSensor()); var pe = new PomodoroEvaluationForm(cs.PluginRepository); pe.ShowDialog(); }
public void PomodoroTest() { using (var cs = new CherryService()) { var ps = new PomodoroSensor(); cs.PluginRepository.RegisterPlugin(ps); var tp = new FakeTimeProvider(); cs.PluginRepository.RegisterPlugin(tp); cs.PluginRepository.RegisterPlugin(new FakeWindowsController()); cs.PluginRepository.RegisterPlugin(new FakeSettingsController()); var ic = new IconController(); cs.PluginRepository.RegisterPlugin(ic); cs.PluginRepository.RegisterPlugin(new DatabaseController()); var im = new FakeImController(); cs.PluginRepository.RegisterPlugin(im); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); cs.PluginRepository.CherryCommands["Start Pomodoro"].Do(null); ic.UpdateToolTipTextMessage(); Assert.True(ps.CurrentlyInPomodoro); Assert.That(ps.GetCurrentStatusData().Remaining.Minutes, Is.EqualTo(25)); Assert.That(im.InPomodoro); Assert.That(ps.GetCurrentStatusData().MinutesLeft, Is.EqualTo(25)); Assert.IsTrue(ic.ToolTipText.StartsWith("In pomodoro. 25 minutes left")); tp.AdvanceMinutes(3); ic.UpdateToolTipTextMessage(); Assert.True(ps.CurrentlyInPomodoro); Assert.That(ps.GetCurrentStatusData().Remaining.Minutes, Is.EqualTo(22)); Assert.That(ps.GetCurrentStatusData().MinutesLeft, Is.EqualTo(22)); Assert.IsTrue(ic.ToolTipText.StartsWith("In pomodoro. 22 minutes left")); tp.AdvanceMinutes(22); ps.StopPomodoroInternal(true); Assert.That(ic.ToolTipText, Is.EqualTo("Pomodoro completed")); // Poll eniough times to make icon controller stop flashing. ic.StopFlashing(); tp.AdvanceMinutes(10); ic.UpdateToolTipTextMessage(); //Assert.That(cs.GetTimeSinceLastPomodoro().TotalMinutes, Is.EqualTo(10)); Assert.That(im.InPomodoro, Is.False); Assert.IsTrue(ic.ToolTipText.StartsWith("Out of pomodoro for 10 minutes")); tp.AdvanceMinutes(59); ic.UpdateToolTipTextMessage(); Assert.IsTrue(ic.ToolTipText.StartsWith("Out of pomodoro for 1 hour")); } }
public void SaveConfigTest() { using (var cs = new CherryService()) { var irp = new IntervalReminderPlugin(); cs.PluginRepository.RegisterPlugin(new FakeIconController()); cs.PluginRepository.RegisterPlugin(irp); cs.PluginRepository.RegisterPlugin(new CherryTomato.Core.SoundController.SoundController()); cs.PluginRepository.RegisterPlugin(new CherryTomato.Reminders.SystrayIconNotifier.IconNotifier()); cs.PluginRepository.RegisterPlugin(new CherryTomato.Reminders.SoundNotifier.SoundNotifier()); cs.PluginRepository.RegisterPlugin(new NotifyPluginsRepository()); cs.PluginRepository.RegisterPlugin(new ConditionCheckerPluginsRepository()); cs.PluginRepository.RegisterPlugin(new FakeTimeProvider()); cs.PluginRepository.RegisterPlugin(new FakeWindowsController()); cs.PluginRepository.RegisterPlugin(new DatabaseController()); cs.PluginRepository.RegisterPlugin(new PomodoroSensor()); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); var ir = new CherryTomato.Reminders.IntervalReminder.IntervalReminder(cs.PluginRepository) { FromInterval = new TimeSpan(0, 0, 17, 0), ToInterval = new TimeSpan(0, 0, 18, 0), Enabled = false, Name = "name", Description = "description", CompositeNotification = new CompositeNotification(cs.PluginRepository, new IconNotification { Enabled = true, NotificationText = "ToolTipText", FlashCount = 5, FlashIconPath = "res://pomodoro.ico" }, new SoundNotification { SoundPath = "spacey.wav" }), }; var xd = new XmlDocument(); var remindersElement = xd.CreateElement("reminders"); irp.SaveReminder(ir, remindersElement); var expectedConfig = "<reminders>" + "<reminder enabled=\"False\" typeName=\"Interval Reminder\" name=\"name\" fromInterval=\"00:17:00\" toInterval=\"00:18:00\">" + "<description>description</description>" + "<compositeNotification>" + "<notification typeName=\"IconNotification\" enabled=\"True\" notificationText=\"ToolTipText\" flashIconPath=\"res://pomodoro.ico\" flashCount=\"5\" />" + "<notification typeName=\"SoundNotification\" enabled=\"False\" soundPath=\"spacey.wav\" />" + "</compositeNotification>" + "<compositeCondition />" + "</reminder>" + "</reminders>"; Assert.That(remindersElement.OuterXml, Is.EqualTo(expectedConfig)); }; }
public void LoadConfigTest() { using (var cs = new CherryService()) { var irp = new IntervalReminderPlugin(); var configString = "<cherryTomato><config><reminders>" + "<reminder enabled=\"True\" typeName=\"Interval Reminder\" name=\"name\" fromInterval=\"00:17:00\" toInterval=\"00:18:00\">" + "<compositeNotification>" + "<notification typeName=\"IconNotification\" enabled=\"True\" flashIconPath=\"res://pomodoro.ico\" flashCount=\"5\" notificationText=\"notificationtext\" />" + "<notification typeName=\"SoundNotification\" enabled=\"True\" soundPath=\"spacey.wav\" />" + "</compositeNotification>" + "<description>description</description>" + "</reminder>" + "</reminders></config></cherryTomato>"; cs.PluginRepository.RegisterPlugin(new FakeIconController()); cs.PluginRepository.RegisterPlugin(irp); cs.PluginRepository.RegisterPlugin(new CherryTomato.Core.SoundController.SoundController()); cs.PluginRepository.RegisterPlugin(new CherryTomato.Reminders.SystrayIconNotifier.IconNotifier()); cs.PluginRepository.RegisterPlugin(new CherryTomato.Reminders.SoundNotifier.SoundNotifier()); cs.PluginRepository.RegisterPlugin(new NotifyPluginsRepository()); cs.PluginRepository.RegisterPlugin(new ConditionCheckerPluginsRepository()); cs.PluginRepository.RegisterPlugin(new FakeTimeProvider()); cs.PluginRepository.RegisterPlugin(new FakeWindowsController()); cs.PluginRepository.RegisterPlugin(new PomodoroSensor()); cs.PluginRepository.RegisterPlugin(new DatabaseController()); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); var xd = new XmlDocument(); xd.LoadXml(configString); var reminderElement = (XmlElement)xd.SelectSingleNode("cherryTomato/config/reminders/reminder"); var ir = (CherryTomato.Reminders.IntervalReminder.IntervalReminder)irp.LoadReminder(reminderElement); Assert.That(ir.Name, Is.EqualTo("name")); Assert.That(ir.Enabled); Assert.That(ir.FromInterval, Is.EqualTo(new TimeSpan(0, 0, 17, 0))); Assert.That(ir.ToInterval, Is.EqualTo(new TimeSpan(0, 0, 18, 0))); Assert.That(ir.CompositeNotification.GetNotification("IconNotification").Enabled); Assert.That( ((IconNotification)ir.CompositeNotification.GetNotification("IconNotification")) .FlashCount, Is.EqualTo(5)); Assert.That( ((IconNotification)ir.CompositeNotification.GetNotification("IconNotification")) .FlashIconPath, Is.EqualTo("res://pomodoro.ico")); Assert.That(ir.CompositeNotification.GetNotification("SoundNotification").Enabled); Assert.That( ((SoundNotification) ir.CompositeNotification.GetNotification("SoundNotification")).SoundPath, Is.EqualTo("spacey.wav")); Assert.That(ir.Description, Is.EqualTo("description")); } }
public void HasRunTest() { using (var cs = new CherryService()) { cs.PluginRepository.RegisterPlugin(new PomodoroSensor()); var fr = new FirstRunSensor(); cs.PluginRepository.RegisterPlugin(fr); cs.PluginRepository.RegisterPlugin(new FakeTimeProvider()); cs.PluginRepository.RegisterPlugin(new DatabaseController()); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); var csr = new StringReader("<cherryTomato><hasRun /></cherryTomato>"); cs.LoadConfiguration(csr); Assert.That(fr.HasRun, Is.True); } }
public void SimpleTest() { var cs = new CherryService(); var ftp = new FakeTimeProvider { Now = new DateTime(2009, 05, 13) }; var ps = new PomodoroSensor(); cs.PluginRepository.RegisterPlugin(ftp); cs.PluginRepository.RegisterPlugin(ps); cs.PluginRepository.RegisterPlugin(new DatabaseController()); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); ps.ConnectToDatabase(dbCon); // Create a couple of fake pomodoros.. One for yesterday and two for today. dbCon.ExecuteNonQuery( "insert into PomodoroRegistrations (TimeStamp, Duration, Evaluation) values (@p1, @p2, @p3);", new DateTime(2009, 05, 12), new TimeSpan(0, 0, 25, 0).Ticks, 5); dbCon.ExecuteNonQuery( "insert into PomodoroRegistrations (TimeStamp, Duration, Evaluation) values (@p1, @p2, @p3);", new DateTime(2009, 05, 13, 12, 30, 0), new TimeSpan(0, 0, 25, 0).Ticks, 5); dbCon.ExecuteNonQuery( "insert into PomodoroRegistrations (TimeStamp, Duration, Evaluation) values (@p1, @p2, @p3);", new DateTime(2009, 05, 13, 13, 30, 0), new TimeSpan(0, 0, 25, 0).Ticks, 5); // And connect again to load those into memory ps.ConnectToDatabase(dbCon); // There are two pomodoros for today. 5 points each. Assert.That(ps.TodayProductivity.Pomodoros, Is.EqualTo(2)); Assert.That(ps.TodayProductivity.Rating, Is.EqualTo(10)); ps.StartPomodoroInternal(); ftp.AdvanceMinutes(10); ps.StopPomodoroInternal(false); }
private void Launch(string configFilePath) { Application.ApplicationExit += Application_ApplicationExit; this.cherryService = new CherryService(); this.cherryService.PluginRepository.RegisterPlugins(); if (configFilePath == null) { configFilePath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"cherrytomato\settings.xml"); } this.cherryService.InitializeCherryServiceEventsAndCommands(); this.cherryService.PluginRepository.TieEvents(); this.cherryService.LoadConfiguration(configFilePath); this.cherryService.Start(); }
public void ManualFlashTest() { var cs = new CherryService(); var tp = new TimeProvider(); var ps = new PomodoroSensor(); var ic = new IconController(); var icn = new CherryTomato.Reminders.SystrayIconNotifier.IconNotifier(); cs.PluginRepository.RegisterPlugin(tp); cs.PluginRepository.RegisterPlugin(ps); cs.PluginRepository.RegisterPlugin(ic); cs.PluginRepository.RegisterPlugin(icn); cs.InitializeCherryServiceEventsAndCommands(); cs.PluginRepository.TieEvents(); icn.Notify(new IconNotification { FlashCount = 10, FlashIconPath = "res://pomodoro.ico", NotificationText = "Flash test" }); Assert.That(MessageBox.Show("Did the icon flash?", "Manual assert", MessageBoxButtons.YesNo), Is.EqualTo(DialogResult.Yes)); cs.Dispose(); }
public EventFiredChecker(CherryService cs) { this.cherryService = cs; }