public void Test_FirstPlaceInStandings() { DriverRepository driverRepository = DriverRepository.GetInstance(); driverRepository.AddDriver(new Driver(16, "Charles", "Leclerc")); driverRepository.AddDriver(new Driver(5, "Sebastian", "Vettel")); driverRepository.AddDriver(new Driver(44, "Lewis", "Hamilton")); driverRepository.AddDriver(new Driver(77, "Valteri", "Bottas")); driverRepository.AddDriver(new Driver(3, "Max", "Verstapen")); driverRepository.AddDriver(new Driver(55, "Carlos", "Seinz")); driverRepository.AddPoints(16, 10); driverRepository.AddPoints(5, 15); driverRepository.AddPoints(44, 20); driverRepository.AddPoints(77, 12); driverRepository.AddPoints(3, 10); Driver best = Standings.GetStandings(driverRepository.GetAllActiveDrivers())[0]; Assert.AreEqual(44, best.GoKart); }
public void LoadDefaultModel() { _driverRepository.AddDriver(new Driver(16, "Charles", "Leclerc")); _driverRepository.AddDriver(new Driver(5, "Sebastian", "Vettel")); _driverRepository.AddDriver(new Driver(44, "Lewis", "Hamilton")); _driverRepository.AddDriver(new Driver(77, "Valteri", "Bottas")); _driverRepository.AddDriver(new Driver(3, "Max", "Verstapen")); _driverRepository.AddDriver(new Driver(55, "Carlos", "Seinz")); _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Melbourne Grand Prix Circuit", "Australia", 5303000)); _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Bahrein International Circuit", "Bahrein", 5412000)); _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Spa-Francorchhamps", "Belgium", 7004000)); _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Shangai International Circuit", "China", 5451000)); _trackRepository.AddTrack(new Track(_trackRepository.GetNewID(), "Hanoi Circuit", "Vietnam", 5607000)); _raceRepository.AddRace(new Race(_raceRepository.GetNewID(), "Australia GP", new DateTime(2020, 3, 15), _trackRepository.GetTrackByName("Melbourne Grand Prix Circuit"))); _raceRepository.AddRace(new Race(_raceRepository.GetNewID(), "Bahrein GP", new DateTime(2020, 3, 22), _trackRepository.GetTrackByName("Bahrein International Circuit"))); _raceRepository.AddRace(new Race(_raceRepository.GetNewID(), "Vietnam GP", new DateTime(2020, 4, 5), _trackRepository.GetTrackByName("Hanoi Circuit"))); _raceRepository.AddRace(new Race(_raceRepository.GetNewID(), "China GP", new DateTime(2020, 4, 19), _trackRepository.GetTrackByName("Shangai International Circuit"))); RaceResults raceResults = new RaceResults(_driverRepository.GetAllActiveDrivers(), _driverRepository.GetDriverByGoKart(16)); _raceRepository.EnterResults("Australia GP", raceResults); _driverRepository.AddPoints(16, 26); _driverRepository.AddPoints(5, 18); _driverRepository.AddPoints(44, 15); _driverRepository.AddPoints(77, 12); _driverRepository.AddPoints(3, 10); _driverRepository.AddPoints(55, 8); }
public void Test_AddPoints() { DriverRepository driverRepository = DriverRepository.GetInstance(); Driver driver = new Driver(16, "Charles", "Leclerc"); driverRepository.AddDriver(driver); Driver dri = driverRepository.GetDriverByGoKart(16); Assert.AreEqual(0, dri.Points); driverRepository.AddPoints(16, 25); Driver dri2 = driverRepository.GetDriverByGoKart(16); Assert.AreEqual(25, dri2.Points); driverRepository.AddPoints(16, 10); dri2 = driverRepository.GetDriverByGoKart(16); Assert.AreEqual(35, dri2.Points); }
public void EnterRaceResults(IEnterResultsView inForm) { RaceRepository raceRepository = RaceRepository.GetInstance(); DriverRepository driverRepository = DriverRepository.GetInstance(); if (inForm.ShowViewModal(raceRepository.GetAllUnfinishedRaces(), driverRepository.GetAllActiveDrivers()) == true) { try { string RaceName = inForm.RaceName; if (string.IsNullOrEmpty(RaceName)) { throw new ArgumentException("Race name is not selected!"); } Race inRace = raceRepository.GetRaceByName(RaceName); string result = inForm.Result; if (string.IsNullOrEmpty(result)) { throw new ArgumentException("Race standings is empty! Fill the textbox!"); } List <int> driversResultsInt = this.ParseRaceStandings(result, driverRepository); int fastestLap = -1; if (Int32.TryParse(inForm.FastestLap, out fastestLap) == false) { throw new ArgumentException("The fastest lap result is not entered correctly!"); } if (!driversResultsInt.Contains(fastestLap)) { throw new ArgumentException("The fastest lap driver was not in the race!"); } List <Driver> driversResults = new List <Driver>(); List <int> points = raceRepository.GetPoints(); for (int i = 0; i < driversResultsInt.Count(); ++i) { int id = driversResultsInt[i]; int point = points[i]; Driver dr = driverRepository.AddPoints(id, point); driversResults.Add(dr); } Driver inFastestLap = driverRepository.AddPoints(fastestLap, 1); RaceResults results = RaceFactory.CreateResults(driversResults, inFastestLap); raceRepository.EnterResults(inRace.Name, results); } catch (RaceNotFoundException) { MessageBox.Show("Picked race doesn't exist!"); } catch (ArgumentException ex) { MessageBox.Show(ex.Message + " Try again."); } catch (DriverNotFoundException) { MessageBox.Show("Driver doesn't exist!"); } catch (Exception ex) { MessageBox.Show("Error:" + ex); } } }