Пример #1
0
        public void AddRider(IRider rider)
        {
            //This method adds a rider to the race if the rider is valid.
            //If a rider is not valid, throw an exception with the appropriate message.
            //Exceptions are:
            //•	If a rider is null throw an ArgumentNullException with message "Rider cannot be null."

            if (rider == null)
            {
                throw new ArgumentNullException(nameof(rider),
                                                "Rider cannot be null.");
            }

            //•	If a rider cannot participate in the race(the rider doesn't own a motorcycle)
            //throw an ArgumentException with message "Rider {rider name} could not participate in race."

            if (!rider.CanParticipate)
            //if (rider.Motorcycle == null)
            {
                throw new ArgumentException(
                          $"Rider {rider.Name} could not participate in race.");
            }

            //•	If the rider already exists in the race throw an ArgumentNullException with message:
            //"Rider {rider name} is already added in {race name} race."

            if (this.riders.Any(r => r.Name == rider.Name))
            {
                throw new ArgumentNullException(nameof(rider),
                                                $"Rider {rider.Name} is already added in {this.Name} race.");
            }

            this.riders.Add(rider);
        }
Пример #2
0
        public string AddRiderToRace(string raceName, string riderName)
        {
            IRace race = this.raceRepository
                         .GetByName(raceName);

            if (race == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.RaceNotFound,
                              raceName));
            }

            IRider rider = this.riderRepository
                           .GetByName(riderName);

            if (rider == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.RiderNotFound,
                              riderName));
            }

            race.AddRider(rider);

            return(string.Format(
                       OutputMessages.RiderAdded,
                       riderName,
                       raceName));
        }
Пример #3
0
        public void AddRider(IRider rider)
        {
            if (rider == null)
            {
                throw new ArgumentNullException(
                          ExceptionMessages.RiderInvalid);
            }

            if (!rider.CanParticipate)
            {
                throw new ArgumentException(
                          string.Format(
                              ExceptionMessages.RiderNotParticipate,
                              rider.Name));
            }

            if (this.riders.Any(r => r.Name == rider.Name))
            {
                throw new ArgumentNullException(
                          string.Format(
                              ExceptionMessages.RiderAlreadyAdded,
                              rider.Name, this.Name));
            }

            this.riders.Add(rider);
        }
Пример #4
0
        public string StartRace(string raceName)
        {
            IRace race = this.raceRepository.GetByName(raceName);

            if (race == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName));
            }

            if (race.Riders.Count < MinParticipants)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, raceName, MinParticipants));
            }

            List <IRider> fastestRiders = race.Riders
                                          .OrderByDescending(x => x.Motorcycle.CalculateRacePoints(race.Laps))
                                          .Take(3)
                                          .ToList();

            IRider winner = fastestRiders.First();

            winner.WinRace();

            StringBuilder result = new StringBuilder();

            result.AppendLine(string.Format(OutputMessages.RiderFirstPosition, winner.Name, raceName));
            result.AppendLine(string.Format(OutputMessages.RiderSecondPosition, fastestRiders[1].Name, raceName));
            result.AppendLine(string.Format(OutputMessages.RiderThirdPosition, fastestRiders[2].Name, raceName));

            this.raceRepository.Remove(race);

            return(result.ToString().TrimEnd());
        }
Пример #5
0
        public string StartRace(string raceName)
        {
            IRace race = this.races.GetByName(raceName);

            if (race == null)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.RaceNotFound, raceName));
            }
            else if (race.Riders.Count < 3)
            {
                throw new InvalidOperationException(string.Format(ExceptionMessages.RaceInvalid, race.Name, 3));
            }

            List <IRider> winners = new List <IRider>();

            foreach (IRider rider in race.Riders.OrderByDescending(r => r.Motorcycle.CalculateRacePoints(race.Laps)).Take(3))
            {
                winners.Add(rider);
            }

            StringBuilder sb = new StringBuilder();

            IRider first  = winners[0];
            IRider second = winners[1];
            IRider third  = winners[2];

            sb.AppendLine(string.Format(OutputMessages.RiderFirstPosition, first.Name, race.Name));
            sb.AppendLine(string.Format(OutputMessages.RiderSecondPosition, second.Name, race.Name));
            sb.AppendLine(string.Format(OutputMessages.RiderThirdPosition, third.Name, race.Name));

            this.races.Remove(race);

            return(sb.ToString().TrimEnd());
        }
Пример #6
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider rider = this.riderRepository
                           .GetByName(riderName);

            if (rider == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.RiderNotFound,
                              riderName));
            }

            IMotorcycle motorcycle = this.motoRepository
                                     .GetByName(motorcycleModel);

            if (motorcycle == null)
            {
                throw new InvalidOperationException(
                          string.Format(
                              ExceptionMessages.MotorcycleNotFound,
                              motorcycleModel));
            }

            rider.AddMotorcycle(motorcycle);

            return(string.Format(
                       OutputMessages.MotorcycleAdded,
                       riderName,
                       motorcycleModel));
        }
Пример #7
0
        public string CreateRider(string riderName)
        {
            //Creates a rider with the given name and adds it to the appropriate repository.

            IRider rider = this.riderRepository
                           .GetByName(riderName);

            if (rider != null)
            {
                //If a rider with the given name already exists in the rider repository, throw an ArgumentException with message
                //"Rider {name} is already created."

                throw new ArgumentException(
                          string.Format(
                              ExceptionMessages.RiderExists,
                              riderName));
            }

            rider = this.riderFactory
                    .CreateRider(riderName);

            this.riderRepository.Add(rider);

            //The method should return the following message:
            //"Rider {name} is created."

            string result = string.Format(
                OutputMessages.RiderCreated,
                riderName);

            return(result);
        }
Пример #8
0
        public string CreateRider(string riderName)
        {
            bool isExist = this.riderRepository
                           .GetAll()
                           .Any(r => r.Name == riderName);

            if (isExist)
            {
                throw new ArgumentException(
                          string.Format(
                              ExceptionMessages.RiderExists,
                              riderName));
            }

            IRider rider = this.riderFactory
                           .CreateRider(riderName);

            this.riderRepository.Add(rider);

            string result = string.Format(
                OutputMessages.RiderCreated,
                riderName);

            return(result);
        }
        public string AddRiderToRace(string raceName, string riderName)
        {
            IRace  race  = races.GetByName(raceName);
            IRider rider = riders.GetByName(riderName);

            race.AddRider(rider);

            return(string.Format(OutputMessages.RiderAdded, rider.Name, race.Name));
        } // TODO: Repair
        public string AddRiderToRace(string raceName, string riderName)
        {
            IRace  race  = CheckIfRaceExists(raceName);
            IRider rider = CheckIfRiderExists(riderName);

            race.AddRider(rider);

            return(string.Format(OutputMessages.RiderAdded, riderName, raceName));
        }
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = CheckIfRiderExists(riderName);
            IMotorcycle motorcycle = CheckIfMotorExists(motorcycleModel);

            rider.AddMotorcycle(motorcycle);

            return(string.Format(OutputMessages.MotorcycleAdded, riderName, motorcycleModel));
        }
Пример #12
0
        public string AddRiderToRace(string raceName, string riderName)
        {
            IRace  race  = raceRepository.GetByName(raceName);
            IRider rider = riderRepository.GetByName(riderName);

            race.AddRider(rider);

            return($"{string.Format(OutputMessages.RiderAdded, riderName, raceName)}");
        }
Пример #13
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = riderRepository.GetByName(riderName);
            IMotorcycle motorcycle = motorcycleRepository.GetByName(motorcycleModel);

            rider.AddMotorcycle(motorcycle);

            return($"{string.Format(OutputMessages.MotorcycleAdded, riderName, motorcycleModel)}");
        }
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = riders.GetByName(riderName);
            IMotorcycle motorcycle = motorcycles.GetByName(motorcycleModel);

            rider.AddMotorcycle(motorcycle);

            return(string.Format(OutputMessages.MotorcycleAdded, rider.Name, motorcycle.Model));
        }
Пример #15
0
        public string CreateRider(string riderName)
        {
            IRider rider = this.riderRepository.Models.FirstOrDefault(r => r.Name == riderName);

            if (rider != null)
            {
                throw new ArgumentException(String.Format(ExceptionMessages.RiderExists, riderName));
            }
            IRider newRider = new Rider(riderName);

            this.riderRepository.Add(newRider);
            return(String.Format(OutputMessages.RiderCreated, newRider.Name));
        }
Пример #16
0
        public string CreateRider(string riderName)
        {
            IRider rider = this.riderRepository.GetByName(riderName);

            if (rider != null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.RiderExists, riderName));
            }

            rider = new Rider(riderName);
            this.riderRepository.Add(rider);

            return($"Rider {riderName} is created.");
        }
Пример #17
0
        public string CreateRider(string riderName)
        {
            IRider rider = this.riders.GetByName(riderName);

            if (rider == null)
            {
                rider = new Rider(riderName);
                this.riders.Add(rider);
                return(string.Format(OutputMessages.RiderCreated, rider.Name));
            }
            else
            {
                throw new ArgumentException(string.Format(ExceptionMessages.RiderExists, rider.Name));
            }
        }
Пример #18
0
        public string CreateRider(string riderName)
        {
            IRider rider = riderRepository.GetByName(riderName);

            if (rider != null)
            {
                throw new ArgumentException($"Rider {riderName} is already created.");
            }

            rider = new Rider(riderName);

            riderRepository.Add(rider);

            return($"Rider {riderName} is created.");
        }
Пример #19
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IMotorcycle targetMotor = motorcycleRepo.GetByName(motorcycleModel);
            IRider      targetRider = riderRepo.GetByName(riderName);

            if (targetRider == null)
            {
                throw new InvalidOperationException($"Rider {riderName} could not be found.");
            }
            if (targetMotor == null)
            {
                throw new InvalidOperationException($"Motorcycle {motorcycleModel} could not be found.");
            }
            targetRider.AddMotorcycle(targetMotor);
            return($"Rider {targetRider.Name} received motorcycle {targetMotor.Model}.");
        }
Пример #20
0
 public void AddRider(IRider rider)
 {
     if (rider == null)
     {
         throw new ArgumentNullException(ExceptionMessages.NullRiderException);
     }
     if (!rider.CanParticipate)
     {
         throw new ArgumentException(string.Format(ExceptionMessages.RiderWithNOMotorException, rider.Name));
     }
     if (riders.Any(x => x.Name == rider.Name))
     {
         throw new ArgumentNullException(string.Format(ExceptionMessages.RiderAlreadyExists, rider.Name, this.name));
     }
     riders.Add(rider);
 }
Пример #21
0
 public void AddRider(IRider rider)
 {
     if (rider == null)
     {
         throw new ArgumentException(ExceptionMessages.RiderInvalid);
     }
     if (rider.CanParticipate == false)
     {
         throw new ArgumentException(string.Format(ExceptionMessages.RiderNotParticipate, rider.Name));
     }
     if (riders.Contains(rider))
     {
         throw new ArgumentNullException(string.Format(ExceptionMessages.RiderAlreadyAdded, rider.Name, Name));
     }
     riders.Add(rider);
 }
Пример #22
0
 public void AddRider(IRider rider)
 {
     if (rider == null)
     {
         throw new ArgumentNullException(nameof(rider), "Rider cannot be null.");
     }
     if (rider.CanParticipate == false)
     {
         throw new ArgumentException($"Rider {rider.Name} could not participate in race.");
     }
     if (this.riders.Any(x => x.Name == rider.Name))
     {
         throw new ArgumentNullException($"Rider {rider.Name} is already added in {this.Name} race.");
     }
     riders.Add(rider);
 }
Пример #23
0
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = riderRepository.Models.FirstOrDefault(r => r.Name == riderName);
            IMotorcycle motorcycle = this.motorcycleRepository.Models.FirstOrDefault(m => m.Model == motorcycleModel);

            if (rider == null)
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.RiderNotFound, riderName));
            }
            if (motorcycle == null)
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.MotorcycleNotFound, motorcycleModel));
            }
            rider.AddMotorcycle(motorcycle);
            return(String.Format(OutputMessages.MotorcycleAdded, rider.Name, motorcycle.Model));
        }
Пример #24
0
        public string AddRiderToRace(string raceName, string riderName)
        {
            if ((raceRepository.Models.FirstOrDefault(r => r.Name == raceName)) == null)
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.RaceNotFound, raceName));
            }
            if (riderRepository.Models.FirstOrDefault(r => r.Name == riderName) == null)
            {
                throw new InvalidOperationException(String.Format(ExceptionMessages.RiderNotFound, riderName));
            }
            IRider rider = riderRepository.Models.FirstOrDefault(r => r.Name == riderName);
            IRace  race  = raceRepository.Models.FirstOrDefault(r => r.Name == raceName);

            race.AddRider(rider);
            return(String.Format(OutputMessages.RiderAdded, rider.Name, race.Name));
        }
Пример #25
0
 public void AddRider(IRider rider)
 {
     if (rider == null)
     {
         throw new ArgumentNullException("Rider cannot be null.");
     }
     if (!rider.CanParticipate)
     {
         throw new ArgumentException($"Rider {rider.Name} could not participate in race.");
     }
     if (this.ridersList.Where(r => r.Name == rider.Name).ToList().Count() != 0)
     {
         throw new ArgumentNullException($"Rider {rider.Name} is already added in {this.Name} race.");
     }
     this.ridersList.Add(rider);
 }
        public string CreateRider(string riderName)
        {
            IRider riderFound = this.riderRepository.GetByName(riderName);

            if (riderFound != null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.RiderExists,
                                                          riderFound.Name));
            }

            riderFound = new Rider(riderName);

            this.riderRepository.Add(riderFound);

            return(string.Format(OutputMessages.RiderCreated, riderFound.Name));
        }
Пример #27
0
        public void AddRider(IRider rider)
        {
            if (rider is null)
            {
                throw new ArgumentException(ExceptionMessages.RiderInvalid);
            }
            else if (rider.Motorcycle == null)
            {
                throw new ArgumentException(string.Format(ExceptionMessages.RiderNotParticipate, rider.Name));
            }
            else if (riders.Any(r => r.Name == rider.Name))
            {
                throw new ArgumentException(string.Format(ExceptionMessages.RiderAlreadyAdded, rider.Name, this.Name));
            }

            riders.Add(rider);
        }
        public string AddMotorcycleToRider(string riderName, string motorcycleModel)
        {
            IRider      rider      = riderRepository.Riders.FirstOrDefault(x => x.Name == riderName);
            IMotorcycle motorcycle = motorcycleRepository.GetByName(motorcycleModel);

            if (rider == null)
            {
                throw new InvalidOperationException($"Rider {riderName} could not be found.");
            }
            else if (motorcycle == null)
            {
                throw new InvalidOperationException($"Motorcycle {motorcycleModel } could not be found.");
            }

            rider.AddMotorcycle(motorcycle);
            return($"Rider {riderName} received motorcycle {motorcycleModel}.");
        }
Пример #29
0
        public void AddRider(IRider rider)
        {
            if (rider is null)
            {
                throw new ArgumentNullException(ExceptionMessages.RiderInvalid);
            }
            if (rider.CanParticipate == false)
            {
                throw new ArgumentException($"Rider {rider.Name} could not participate in race.");
            }
            if (Riders.Contains(rider))
            {
                throw new ArgumentNullException($"Rider {rider.Name} is already added in {this.name} race.");
            }

            this.riders.Add(rider);
        }
Пример #30
0
        public string AddRiderToRace(string raceName, string riderName)
        {
            IRace race = raceRepository.GetByName(raceName);

            if (race == null)
            {
                throw new InvalidOperationException($"Race {raceName} could not be found.");
            }
            IRider rider = riderRepository.GetByName(riderName);

            if (rider == null)
            {
                throw new InvalidOperationException($"Rider {riderName} could not be found.");
            }
            race.AddRider(rider);
            return($"Rider {riderName} added in {raceName} race.");
        }