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 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."); } }