Beispiel #1
0
        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);
        }
Beispiel #2
0
        public void Test_EnterRaceResultsToNonExistingRace()
        {
            RaceRepository raceRepository = RaceRepository.GetInstance();

            RaceResults raceResults = new RaceResults(driverRepository.GetAllActiveDrivers(), driverRepository.GetDriverByGoKart(16));

            raceRepository.EnterResults("AusGP", raceResults);
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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"));
        }
Beispiel #5
0
        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 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);
                }
            }
        }