Example #1
0
 public StopwatchViewModel()
 {
     stopwatchModel = new StopwatchModel();
     stopwatchModel.PropertyChanged += OnModelChanged;
     ElapsedTime         = "00:00.00";
     ButtonStartStopText = "Start";
     ButtonResetEnabled  = true;
 }
Example #2
0
 public StopwatchViewModel()
 {
     stopWatch                 = new StopwatchModel();
     dispatcherTimer           = new DispatcherTimer();
     dispatcherTimer.Tick     += DispatcherTimer_Tick;
     dispatcherTimer.Interval  = new TimeSpan(100000);
     stopWatch.LapTimeUpdated += StopWatch_LapTimeUpdated;
 }
        public StopwatchViewModel()
        {
            _stopwatchModel = new StopwatchModel();
            _stopwatchModel.LapTimeUpdated += _stopwatch_LapTimeUpdated;

            _timer          = new DispatcherTimer();
            _timer.Tick    += _timer_Tick;
            _timer.Interval = TimeSpan.FromMilliseconds(50);
            _timer.Start();
        }
        public void StartStopwatchTest_CreateStopwathAndWaitTime_StopwathTimeAndWaitTimeShouldBeEquals()
        {
            // Arranges
            StopwatchModel stopwatch  = new StopwatchModel();
            int            timeWaitMs = 23650;

            // Act
            stopwatch.Start();
            Thread.Sleep(timeWaitMs);
            stopwatch.Stop();

            // Assert
            Assert.True(MillisCompare(stopwatch.TotalStopwatchTime.TotalMilliseconds, timeWaitMs));
        }
        public void ResetTest_CreateStopwathAfterStartAndStop_TimeFromStartAndCountLapsShouldBeZero()
        {
            // Arranges
            StopwatchModel stopwatch = new StopwatchModel();

            // Act
            stopwatch.Start();
            Thread.Sleep(100);
            stopwatch.Stop();
            stopwatch.Reset();

            // Assert
            Assert.Equal(stopwatch.TotalStopwatchTime, TimeSpan.Zero);
            Assert.Equal(0, stopwatch.CountLaps);
        }
        public void StartNewLapTest_CreateStopwatchStartAndStartNewLap_TimerOldLapShouldBeSameAsRealTime()
        {
            // Arranges
            StopwatchModel stopwatch  = new StopwatchModel();
            int            timeWaitMs = 2000;

            // Act
            stopwatch.Start();
            Thread.Sleep(timeWaitMs);
            stopwatch.StartNewLap();
            Thread.Sleep(timeWaitMs);
            stopwatch.Stop();

            // Assert
            Assert.True(MillisCompare(stopwatch.TimeOfEachLap[stopwatch.TimeOfEachLap.Count - 1].LapTime.TotalMilliseconds, timeWaitMs));
        }
        public void CorrespondenceLapsToRealAmountTest_CreateStopwatchStartAndStartFiveNewLap_CountLapsSouldBeRealAmount()
        {
            // Arranges
            StopwatchModel stopwatch  = new StopwatchModel();
            int            realAmount = 5;

            // Act
            stopwatch.Start();
            for (int i = 0; i < realAmount; i++)
            {
                stopwatch.StartNewLap();
            }
            stopwatch.Stop();

            // Assert
            Assert.Equal(stopwatch.CountLaps, realAmount);
        }
        public void StopwatchPauseTest_CreateStopwatchAfterStartAndStopWithDelay_AfterPauseTimeShouldNotChanged()
        {
            // Arranges
            StopwatchModel stopwatch        = new StopwatchModel();
            int            timeWaitMs       = 2000;
            double         concreteTimeStop = 0;

            // Act
            stopwatch.Start();
            Thread.Sleep(timeWaitMs);
            stopwatch.Stop();
            concreteTimeStop = stopwatch.TotalStopwatchTime.TotalMilliseconds;
            Thread.Sleep(timeWaitMs);

            // Assert
            Assert.True(MillisCompare(concreteTimeStop, stopwatch.TotalStopwatchTime.TotalMilliseconds));
        }
        public void StopwatchResumeTest_CreateStopwatchAfterrStartAndStopWithDelayOfTwoTimes_AfterStopTimeShouldBeEqualSummDelay()
        {
            // Arranges
            StopwatchModel stopwatch = new StopwatchModel();
            int            timeWaitMsFirst = 1200, timeWaitMsSecond = 600;

            // Act
            stopwatch.Start();
            Thread.Sleep(timeWaitMsFirst);
            stopwatch.Stop();
            Thread.Sleep(timeWaitMsSecond);
            stopwatch.Start();
            Thread.Sleep(timeWaitMsSecond);
            stopwatch.Stop();

            // Assert
            Assert.True(this.MillisCompare(timeWaitMsFirst + timeWaitMsSecond, stopwatch.TotalStopwatchTime.TotalMilliseconds));
        }
Example #10
0
 private void ResetStopwatch()
 {
     stopwatchModel = new StopwatchModel();
     stopwatchModel.PropertyChanged += OnModelChanged;
     ElapsedTime = "00:00.00";
 }
Example #11
0
 public void Cleanup()
 {
     _model = null;
 }
Example #12
0
 private void CheckPaused(StopwatchModel model)
 {
     Assert.IsFalse(model.IsRunning, "Stopwatch is running");
     Assert.IsFalse(model.IsStopped, "Stopwatch is stopped");
     Assert.IsTrue(model.IsPaused, "Stopwatch isn't paused");
 }
Example #13
0
 public void Init()
 {
     _model = new StopwatchModel();
 }