Exemple #1
0
        public void IdleMode_OnStoppingFromAnyMode()
        {
            IClock clock = new Pomodoro.Model.Clock();

            clock.StartWork();
            clock.Stop();
            Assert.AreEqual(Mode.Idle, clock.Mode);

            clock.StartShortBreak();
            clock.Stop();
            Assert.AreEqual(Mode.Idle, clock.Mode);

            clock.StartLongBreak();
            clock.Stop();
            Assert.AreEqual(Mode.Idle, clock.Mode);
        }
Exemple #2
0
        public void IsRunning_ReturnsTrue_OnlyWhenRunning()
        {
            IClock clock = new Pomodoro.Model.Clock(_testDuration);

            clock.StartWork();
            Assert.IsTrue(clock.IsRunning);
            clock.Stop();
            Assert.IsFalse(clock.IsRunning);

            clock.StartShortBreak();
            Assert.IsTrue(clock.IsRunning);
            clock.Stop();
            Assert.IsFalse(clock.IsRunning);

            clock.StartLongBreak();
            Assert.IsTrue(clock.IsRunning);
            clock.Stop();
            Assert.IsFalse(clock.IsRunning);
        }
Exemple #3
0
        public void Stop_PriorToStartingAgain()
        {
            bool begin = true; // at the beginning, stopped will be false and its okay.
            bool stopped = false;

            bool workStarted = false;
            bool shortBreakStarted = false;
            bool longBreakStarted = false;

            Action test = () =>
            {
                IClock clock = new Pomodoro.Model.Clock(_testDuration);

                clock.Stopped += (sender, e) => { stopped = true; };
                clock.WorkStarted += (sender, e) =>
                {
                    if (begin)
                        begin = false;
                    else
                        Assert.IsTrue(stopped);

                    workStarted = true;
                    stopped = false;
                };
                clock.ShortBreakStarted += (sender, e) =>
                {
                    if (begin)
                        begin = false;
                    else
                        Assert.IsTrue(stopped);

                    shortBreakStarted = true;
                    stopped = false;
                };
                clock.LongBreakStarted += (sender, e) =>
                {
                    if (begin)
                        begin = false;
                    else
                        Assert.IsTrue(stopped);

                    longBreakStarted = true;
                    stopped = false;
                };

                clock.StartWork();
                clock.StartShortBreak();
                clock.StartLongBreak();
                clock.StartWork();
                clock.StartLongBreak();
                clock.StartShortBreak();
                clock.StartWork();
                clock.Stop();
            };

            DispatcherHelper.ExecuteOnDispatcherThread(test, millisecondsToWait: 20);
            Assert.IsTrue(workStarted);
            Assert.IsTrue(shortBreakStarted);
            Assert.IsTrue(longBreakStarted);
        }
Exemple #4
0
        public void ShortBreakMode_OnStartingShortBreak()
        {
            IClock clock = new Pomodoro.Model.Clock();

            clock.StartWork();
            clock.StartShortBreak();
            Assert.AreEqual(Mode.ShortBreak, clock.Mode);
        }
Exemple #5
0
        public void ShortBreakingEvent_ShouldProvide_ElapsedAndRemainingTime()
        {
            int elapsed_ms = 0;
            int remaining_ms = 0;

            Action test = () =>
            {
                IClock clock = new Pomodoro.Model.Clock(_testDuration); // ShortBreak = 2ms

                bool firstTime = true;
                clock.ShortBreaking += (sender, e) =>
                {
                    if (firstTime)
                    {
                        firstTime = false;

                        elapsed_ms = e.Elapsed_ms;
                        remaining_ms = e.Remaining_ms;
                    }
                };

                clock.StartShortBreak();
            };

            DispatcherHelper.ExecuteOnDispatcherThread(test, millisecondsToWait: 20);
            Assert.AreEqual(1, elapsed_ms);
            Assert.AreEqual((int)_testDuration.ShortBreak.TotalMilliseconds - elapsed_ms, remaining_ms);
        }
Exemple #6
0
        public void RaiseStoppedEvent_AfterShortBreakElapsed()
        {
            bool eventRaised = false;

            Action test = () =>
            {
                IClock clock = new Pomodoro.Model.Clock(_testDuration); // ShortBreak = 2ms
                clock.Stopped += (sender, e) => { eventRaised = true; };
                clock.StartShortBreak();
            };

            DispatcherHelper.ExecuteOnDispatcherThread(test, millisecondsToWait: 20);
            Assert.IsTrue(eventRaised);
        }
Exemple #7
0
        public void RaiseShortBreakStartedEvent_OnStartingShortBreak()
        {
            IClock clock = new Pomodoro.Model.Clock(_testDuration);

            bool eventReceived = false;
            clock.ShortBreakStarted += (sender, e) =>
                {
                    eventReceived = true;
                };

            clock.StartShortBreak();
            Assert.IsTrue(eventReceived);
        }
Exemple #8
0
        public void RaiseShortBreakingEvent_EveryMillisecond_OnStartingShortBreak()
        {
            int eventCount = 0;

            Action test = () =>
            {
                IClock clock = new Pomodoro.Model.Clock(_testDuration); // ShortBreak = 2ms
                clock.ShortBreaking += (sender, e) => { eventCount++; };
                clock.StartShortBreak();
            };

            DispatcherHelper.ExecuteOnDispatcherThread(test, millisecondsToWait: 20);
            Assert.AreEqual(2, eventCount);
        }