Example #1
0
        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();
            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);
        }