public void Test_AddRace() { RaceRepository raceRepository = RaceRepository.GetInstance(); Race race = new Race(raceRepository.GetNewID(), "AusGP", new DateTime(2020, 3, 15), trackRepository.GetTrackByName("Melbourne Grand Prix Circuit")); raceRepository.AddRace(race); Race getRace = raceRepository.GetRaceByName("AusGP"); Assert.IsInstanceOfType(getRace, typeof(Race)); }
public void Test_EnterRaceResults() { RaceRepository raceRepository = RaceRepository.GetInstance(); Race race = new Race(raceRepository.GetNewID(), "AusGP", new DateTime(2020, 3, 15), trackRepository.GetTrackByName("Melbourne Grand Prix Circuit")); raceRepository.AddRace(race); RaceResults raceResults = new RaceResults(driverRepository.GetAllActiveDrivers(), driverRepository.GetDriverByGoKart(16)); raceRepository.EnterResults("AusGP", raceResults); Assert.IsTrue(raceRepository.GetRaceByName("AusGP").Finished); }
public void Test_EditRace() { RaceRepository raceRepository = RaceRepository.GetInstance(); Race race = new Race(raceRepository.GetNewID(), "AusGP", new DateTime(2020, 3, 15), trackRepository.GetTrackByName("Melbourne Grand Prix Circuit")); raceRepository.AddRace(race); raceRepository.UpdateRace(race.ID, "Nova utrka", new DateTime(2903, 1, 23), trackRepository.GetTrackByName("Bahrein International Circuit")); Race update = raceRepository.GetRaceByName("Nova utrka"); Assert.AreEqual("Bahrein", update.Track.Location); }
public void Test_TryToRemoveFinishedRace() { RaceRepository raceRepository = RaceRepository.GetInstance(); Race race = new Race(raceRepository.GetNewID(), "BelGP", new DateTime(2020, 3, 22), trackRepository.GetTrackByName("Spa-Francorchhamps")); raceRepository.AddRace(race); RaceResults raceResults = new RaceResults(driverRepository.GetAllActiveDrivers(), driverRepository.GetDriverByGoKart(5)); raceRepository.EnterResults("BelGP", raceResults); raceRepository.RemoveRace(raceRepository.GetRaceByName("BelGP")); }
public void Test_GetDriverWithFastestLapInRace() { RaceRepository raceRepository = RaceRepository.GetInstance(); Race race = new Race(raceRepository.GetNewID(), "BahGP", new DateTime(2020, 3, 22), trackRepository.GetTrackByName("Bahrein International Circuit")); raceRepository.AddRace(race); RaceResults raceResults = new RaceResults(driverRepository.GetAllActiveDrivers(), driverRepository.GetDriverByGoKart(5)); raceRepository.EnterResults("BahGP", raceResults); Race getRace = raceRepository.GetRaceByName("BahGP"); Assert.AreEqual(5, getRace.Results.FastestLap.GoKart); }
public void ViewRaceResults(IShowRaceResultsView inForm, string inRaceName) { RaceRepository _raceRepository = RaceRepository.GetInstance(); Race _race = _raceRepository.GetRaceByName(inRaceName); RaceResults _raceResult = _raceRepository.GetRaceResults(inRaceName); List <Driver> positions = _raceResult._positions; Driver fastestLap = _raceResult.FastestLap; List <int> points = _raceRepository.GetPoints(); inForm.ShowModaless(_race, positions, fastestLap, points); }
public void EditRace(IEditRaceView inForm, string raceName) { RaceRepository _raceRepository = RaceRepository.GetInstance(); TrackRepository _trackRepository = TrackRepository.GetInstance(); List <Track> tracks = _trackRepository.GetAllActiveTracks(); try { Race race = _raceRepository.GetRaceByName(raceName); int result = inForm.ShowViewModal(tracks, race); if (result == 1) { string Name = inForm.RaceName; if (string.IsNullOrEmpty(Name)) { throw new ArgumentException("Race name is not selected!"); } DateTime Date = inForm.RaceDate; if (Date < DateTime.Today) { throw new ArgumentException("Selected date is in the past!"); } string RaceTrackName = inForm.RaceTrackName; if (string.IsNullOrEmpty(RaceTrackName)) { throw new ArgumentException("Track name is not properly selected!"); } Track track = _trackRepository.GetTrackByName(RaceTrackName); _raceRepository.UpdateRace(race.ID, Name, Date, track); } else if (result == 2) { _raceRepository.RemoveRace(race); } } catch (RaceAlreadyExistsException) { MessageBox.Show("Race name is not available!"); } catch (RaceNotFoundException) { MessageBox.Show("Race not found!"); } catch (RaceAlreadyFinishedException) { MessageBox.Show("Race already finished! Can not be deleted!"); } catch (TrackNotFoundException) { MessageBox.Show("Track not found!"); } catch (ArgumentException ex) { MessageBox.Show(ex.Message + " Try again."); } }
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); } } }