Example #1
0
        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);
        }
Example #2
0
        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.");
            }
        }