Exemplo n.º 1
0
        public void ViewFinishedRaces(IMainController _mainController, IShowFinishedRacesView inForm)
        {
            RaceRepository _raceRepository = RaceRepository.GetInstance();

            List <Race> finRaces = _raceRepository.GetAllFinishedRaces();

            inForm.ShowModaless(_mainController, finRaces);
        }
Exemplo n.º 2
0
        public void Test_EnterRaceResultsToNonExistingRace()
        {
            RaceRepository raceRepository = RaceRepository.GetInstance();

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

            raceRepository.EnterResults("AusGP", raceResults);
        }
Exemplo n.º 3
0
        public void ViewUpcomingRaces(IMainController _mainController, IShowUpcomingRacesView inForm)
        {
            RaceRepository _raceRepository = RaceRepository.GetInstance();

            List <Race> upRaces = _raceRepository.GetAllUnfinishedRaces();

            inForm.ShowModaless(_mainController, upRaces);
        }
Exemplo n.º 4
0
        public void Test_AddingSameRaceReferenceTwice()
        {
            RaceRepository raceRepository = RaceRepository.GetInstance();

            Race race = new Race(raceRepository.GetNewID(), "BahGP", new DateTime(2020, 3, 22), trackRepository.GetTrackByName("Bahrein International Circuit"));

            raceRepository.AddRace(race);
            raceRepository.AddRace(race);
        }
Exemplo n.º 5
0
        public void Test_AddTwoRacesWithSameName()
        {
            RaceRepository raceRepository = RaceRepository.GetInstance();

            Race race1 = new Race(raceRepository.GetNewID(), "BahGP", new DateTime(2020, 3, 22), trackRepository.GetTrackByName("Bahrein International Circuit"));
            Race race2 = new Race(raceRepository.GetNewID(), "BahGP", new DateTime(2020, 3, 15), trackRepository.GetTrackByName("Melbourne Grand Prix Circuit"));


            raceRepository.AddRace(race1);
            raceRepository.AddRace(race2);
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
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"));
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
0
        public void AddRace(IAddRaceView inForm)
        {
            RaceRepository  raceRepository  = RaceRepository.GetInstance();
            TrackRepository trackRepository = TrackRepository.GetInstance();

            if (inForm.ShowViewModal(trackRepository.GetAllActiveTracks()) == true)
            {
                try
                {
                    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 RaceTrack = trackRepository.GetTrackByName(RaceTrackName);

                    int ID = raceRepository.GetNewID();

                    Race newRace = RaceFactory.CreateRace(ID, Name, Date, RaceTrack);

                    raceRepository.AddRace(newRace);
                }
                catch (TrackNotFoundException)
                {
                    MessageBox.Show("Selected track not found! Try again.");
                }
                catch (RaceAlreadyExistsException)
                {
                    MessageBox.Show("Race already exists! Try again.");
                }
                catch (ArgumentException ex)
                {
                    MessageBox.Show(ex.Message + " Try again.");
                }
            }
        }
Exemplo n.º 11
0
        static void Main()
        {
            WindowFormsFactory _formsFactory = new WindowFormsFactory();

            DriverRepository _driverRepository = DriverRepository.GetInstance();
            TrackRepository  _trackRepository  = TrackRepository.GetInstance();
            RaceRepository   _raceRepository   = RaceRepository.GetInstance();


            MainController _mainController = new MainController(_formsFactory, _driverRepository, _trackRepository, _raceRepository);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new GoKartChamp.PresentationLayer.formMainWindow(_mainController));
        }
Exemplo n.º 12
0
        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);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
0
 public formViewFinishedRaces()
 {
     InitializeComponent();
     _raceRepository = RaceRepository.GetInstance();
 }
Exemplo n.º 15
0
        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);
                }
            }
        }
Exemplo n.º 16
0
 public formViewStandings()
 {
     InitializeComponent();
     _driverRepository = DriverRepository.GetInstance();
     _raceRepository   = RaceRepository.GetInstance();
 }
Exemplo n.º 17
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.");
            }
        }
Exemplo n.º 18
0
 public formViewUpcomingRaces()
 {
     InitializeComponent();
     _raceRepository = RaceRepository.GetInstance();
 }