public void ShouldNotAllowZeroOrMinusMinute()
        {
            var lapTimeViewModel = new LapTimeViewModel();

            Assert.That(() => lapTimeViewModel.Minute = -1, Throws.TypeOf<ArgumentException>().With.Message.EqualTo("Minute must be larger than 0"));
            Assert.That(() => lapTimeViewModel.Minute = 0, Throws.TypeOf<ArgumentException>().With.Message.EqualTo("Minute must be larger than 0"));
        }
        public LapTimeInputPage()
        {
            InitializeComponent();

            InitializeLoopingLists();
            BackKeyPress += LapTimeInputPage_BackKeyPress;
            ViewModel = new LapTimeViewModel();
        }
        public void ShouldConstructFromMilliseconds()
        {
            var viewModel = new LapTimeViewModel(105123);

            Assert.That(viewModel.Minute, Is.EqualTo(1));
            Assert.That(viewModel.Seconds, Is.EqualTo(45));
            Assert.That(viewModel.Milliseconds, Is.EqualTo(123));
        }
        public void ShouldSetLapTime()
        {
            var lapTimeViewModel = new LapTimeViewModel { Minute = 1, Seconds = 55, Milliseconds = 444};

            Assert.That(lapTimeViewModel.Minute, Is.EqualTo(1));
            Assert.That(lapTimeViewModel.Seconds, Is.EqualTo(55));
            Assert.That(lapTimeViewModel.Milliseconds, Is.EqualTo(444));
            Assert.That(lapTimeViewModel.ToString(), Is.EqualTo("1:55.444"));
        }
        public void ShouldCalculateThirdSectorFromLapTimeAndFirstAndSecondSectors()
        {
            var lapTime = new LapTimeViewModel {Minute = 1, Seconds = 45, Milliseconds = 674 }; // 105674 milliseconds
            var firstSector = new SectorTimeViewModel {Seconds = 35, Milliseconds = 342 };  // 35342 milliseconds
            var secondSector = new SectorTimeViewModel {Seconds = 42, Milliseconds = 714 }; // 42714 milliseconds

            var viewModel = new MainViewModel {LapTime = lapTime, FirstSector = firstSector, SecondSector = secondSector};

            var thirdSector = viewModel.ThirdSector;

            // 3rd sector should be 27618 milliseconds
            Assert.That(thirdSector.Seconds, Is.EqualTo(27));
            Assert.That(thirdSector.Milliseconds, Is.EqualTo(618));
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            var queryString = NavigationContext.QueryString;

            if (queryString.ContainsKey("time"))
            {
                ViewModel = new LapTimeViewModel(int.Parse(queryString["time"]));
                MinuteList.SelectedIndex = ViewModel.Minute;
                SecondList.SelectedIndex = ViewModel.Seconds;
                MillisecondList1.SelectedIndex = (ViewModel.Milliseconds / 100);
                MillisecondList2.SelectedIndex = ((ViewModel.Milliseconds % 100) / 10);
                MillisecondList3.SelectedIndex = (ViewModel.Milliseconds % 10);
            }

            base.OnNavigatedTo(e);
        }
 public MainViewModel()
 {
     LapTime = new LapTimeViewModel();
     FirstSector = new SectorTimeViewModel();
     SecondSector = new SectorTimeViewModel();
 }
        public void ShouldNotAllowSecondsLargerThanFiftyNine()
        {
            var lapTimeViewModel = new LapTimeViewModel { Seconds = 2 };

            Assert.That(() => lapTimeViewModel.Seconds = 60, Throws.TypeOf<ArgumentException>().With.Message.EqualTo("Seconds must be between 0 and 59"));
        }
        public void ShouldNotAllowMinuteLargerThanTwo()
        {
            var lapTimeViewModel = new LapTimeViewModel { Minute = 2 };

            Assert.That(() => lapTimeViewModel.Minute = 3, Throws.TypeOf<ArgumentException>().With.Message.EqualTo("Minute cannot be larger than 2"));
        }
        public void ShouldNotAllowMinusSeconds()
        {
            var lapTimeViewModel = new LapTimeViewModel { Seconds = 0 };

            Assert.That(() => lapTimeViewModel.Seconds = -1, Throws.TypeOf<ArgumentException>().With.Message.EqualTo("Seconds must be between 0 and 59"));
        }
        public void ShouldNotAllowMillesecondsLargerThanNineHundredsAndNintyNine()
        {
            var lapTimeViewModel = new LapTimeViewModel { Milliseconds = 2 };

            Assert.That(() => lapTimeViewModel.Milliseconds = 1000, Throws.TypeOf<ArgumentException>().With.Message.EqualTo("Milliseconds must be between 0 and 999"));
        }
        public void ShouldConvertToMilliseconds()
        {
            var lapTimeViewModel = new LapTimeViewModel {Minute = 1, Seconds = 45, Milliseconds = 555};

            Assert.That(lapTimeViewModel.ToMilliseconds(), Is.EqualTo(105555));
        }