Exemplo n.º 1
0
        public void IdleMode_OnDurationElapseOfAnyMode()
        {
            IClock clock = new Pomodoro.Model.Clock(_testDuration);

            clock.StartWork();
            //while (clock.IsRunning) ;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the MainWindow class.
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            IClock clock = new Clock();
            _vm = new MainViewModel(clock);
            this.DataContext = _vm;
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void LongBreakingEvent_ShouldProvide_ElapsedAndRemainingTime()
        {
            int elapsed_ms = 0;
            int remaining_ms = 0;

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

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

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

                clock.StartLongBreak();
            };

            DispatcherHelper.ExecuteOnDispatcherThread(test, millisecondsToWait: 20);
            Assert.AreEqual(1, elapsed_ms);
            Assert.AreEqual((int)_testDuration.LongBreak.TotalMilliseconds - elapsed_ms, remaining_ms);
        }
Exemplo n.º 6
0
        public void WorkMode_OnStartingWork()
        {
            IClock clock = new Pomodoro.Model.Clock();

            clock.StartWork();
            Assert.AreEqual(Mode.Work, clock.Mode);
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 public void Stopping_MultipleTimes_Allowed()
 {
     IClock clock = new Pomodoro.Model.Clock();
     clock.Stop();
     Assert.AreEqual(Mode.Idle, clock.Mode);
     clock.Stop();
     Assert.AreEqual(Mode.Idle, clock.Mode);
     clock.Stop();
     Assert.AreEqual(Mode.Idle, clock.Mode);
 }
Exemplo n.º 9
0
        public void IdleMode_AtConstruction()
        {
            IClock clock = new Pomodoro.Model.Clock();

            Assert.AreEqual(Mode.Idle, clock.Mode);
        }
Exemplo n.º 10
0
        public void ShortBreakMode_OnStartingShortBreak()
        {
            IClock clock = new Pomodoro.Model.Clock();

            clock.StartWork();
            clock.StartShortBreak();
            Assert.AreEqual(Mode.ShortBreak, clock.Mode);
        }
Exemplo n.º 11
0
        public void RaiseWorkStartedEvent_OnStartingWork()
        {
            IClock clock = new Pomodoro.Model.Clock(_testDuration);

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

            clock.StartWork();
            Assert.IsTrue(eventReceived);
        }
Exemplo n.º 12
0
 public void DefaultDuration_ShouldBe_DefaultOfClockDuration()
 {
     IClock clock = new Pomodoro.Model.Clock();
     Assert.AreSame(Pomodoro.Model.ClockDuration.Default, clock.Duration);
 }
Exemplo n.º 13
0
        public void RaiseWorkingEvent_EveryMillisecond_OnStartingWork()
        {
            int eventCount = 0;

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

            DispatcherHelper.ExecuteOnDispatcherThread(test, millisecondsToWait: 20);
            Assert.AreEqual(2, eventCount);
        }
Exemplo n.º 14
0
        public void RaiseStoppedEvent_AfterWorkDurationElapsed()
        {
            bool eventRaised = false;

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

            DispatcherHelper.ExecuteOnDispatcherThread(test, millisecondsToWait: 20);
            Assert.IsTrue(eventRaised);
        }
Exemplo n.º 15
0
        public void OverridingDuration_Allowed_DuringConstruction()
        {
            IClockDuration duration = new Pomodoro.Model.ClockDuration(workDuration_minutes: 20, shortBreak_minutes: 4, longBreak_minutes: 10);
            IClock clock = new Pomodoro.Model.Clock(duration);

            Assert.AreSame(duration, clock.Duration);
        }