public void TestWithPositiveSalary()
        {
            var  errorMessage = string.Empty;
            bool result       = SalaryValidator.Validate(2000, out errorMessage);

            Assert.IsTrue(result);
            Assert.IsEmpty(errorMessage);
        }
        public void TestWithNegativeSalary()
        {
            var  errorMessage = string.Empty;
            bool result       = SalaryValidator.Validate(-1000, out errorMessage);

            Assert.IsFalse(result);
            Assert.IsNotNull(errorMessage);
            Assert.IsNotEmpty(errorMessage);
        }
示例#3
0
 public void validationTest_InCaseSalaryIsHigh()
 {
     try
     {
         SalaryValidator salaryValidator = new SalaryValidator(2000000);
         salaryValidator.validation();
         Assert.Fail("Nem dob kivételt magas fizetésre!");
     }
     catch (HighSalaryException) { }
 }
示例#4
0
 public void validationTest_InCaseSalaryIsNegtive()
 {
     try
     {
         SalaryValidator salaryValidator = new SalaryValidator(-1000);
         salaryValidator.validation();
         Assert.Fail("Nem dob kivételt negatív fizetésre!");
     }
     catch (NegativeSalaryException) { }
 }
示例#5
0
 public void validationTest_InCaseSalaryIsZero()
 {
     try
     {
         SalaryValidator salaryValidator = new SalaryValidator(0);
         salaryValidator.validation();
         Assert.Fail("Nem dob kivételt nulla fizetésre!");
     }
     catch (SalaryZeroException) { }
 }
        protected override IEnumerable <ValidationError> Validation()
        {
            var result = Enumerable.Empty <ValidationError>();

            var validationErrors = SalaryValidator.Validate(this);

            if (!validationErrors.IsNullOrEmpty())
            {
                result = result.Concat(validationErrors);
            }

            if (!secondPhaseErrors.IsNullOrEmpty())
            {
                result = result.Concat(secondPhaseErrors);
            }

            return(result);
        }
示例#7
0
 public void setSalary(int salary)
 {
     try
     {
         SalaryValidator salaryValidator = new SalaryValidator(salary);
         salaryValidator.validation();
         this.salary = salary;
     }
     catch (SalaryZeroException e)
     {
         Debug.WriteLine(e.Message);
         throw new RacerException(e.Message + "\n" + salary);
     }
     catch (NegativeSalaryException e)
     {
         Debug.WriteLine(e.Message);
         throw new RacerException(e.Message + "\n" + salary);
     }
     catch (HighSalaryException e)
     {
         Debug.WriteLine(e.Message);
         throw new RacerException(e.Message + "\n" + salary);
     }
 }
        /// <summary>
        /// Versenyző hozzáadása a csapathoz
        /// Ellenörizze, hogy az argumentumbeli számadadok megfelelő formátumuak-e, ha nem dobjon kivételt
        /// NameValidator, AgeValidator és SalaryValidatorral ellenörizze az adatokat. Ha valamelyik nem jó, dobjon kivételt
        /// Alsóbb rétegek segítségével, ellenörizze, hogy az adott nevű és életkorú versenyző tagja-e a csapatnak, ha igen dobjon kivételt
        /// Alsóbb rétegek segítségével kérje, le a következő versenyző ID-jét
        /// Hozza létre az új Racert-t. Az alsóbb rétegek kivételeit kapja el, és adja tovább
        /// Adja hozzá az új versenyzőt a csapathoz. Kapja el az elsó rétegek kivételeit és adja tovább
        /// </summary>
        /// <param name="teamName">A csapat neve</param>
        /// <param name="racerName">A versenyző neve</param>
        /// <param name="racerAge">A versenyző életkora</param>
        /// <param name="racerSalary">A versenyző bérköltsége</param>
        public void addRacerToTeam(string teamName, string racerName, string racerAge, string racerSalary)
        {
            if (!int.TryParse(racerAge, out int racerAgeNumber))
            {
                throw new ControllerException("Életkor nem megfelelő formátumú!");
            }

            if (!int.TryParse(racerSalary, out int racerSalaryNumber))
            {
                throw new ControllerException("Fizetés nem megfelelő formátumú!");
            }

            try
            {
                NameValidator nv = new NameValidator(racerName);
                nv.validation();
            }
            catch (NameNotValidNameIsEmptyException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (NameNotValidFirstLetterProblemException e)
            {
                throw new ControllerException(e.Message);
            }

            try
            {
                AgeValidator av = new AgeValidator(racerAgeNumber);
                av.validation();
            }
            catch (AgeIsZeroException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (AgeUnderMinimumAgeException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (AgeAboveMaximumAgeException e)
            {
                throw new ControllerException(e.Message);
            }

            try
            {
                SalaryValidator sv = new SalaryValidator(racerSalaryNumber);
                sv.validation();
            }
            catch (SalaryZeroException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (NegativeSalaryException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (HighSalaryException e)
            {
                throw new ControllerException(e.Message);
            }

            Racer providedRacer = new Racer(0, racerName, racerAgeNumber, 1);

            var existingInTeam = teamService.getRacerFromTheTeam(teamName).Contains(providedRacer);

            if (existingInTeam)
            {
                throw new ControllerException("Már tagja a csapatnak a versenyző!");
            }

            int   id       = teamService.getNextRacerId();
            Racer newRacer = null;

            try
            {
                newRacer = new Racer(id, racerName, racerAgeNumber, racerSalaryNumber);
            }
            catch (NameNotValidNameIsEmptyException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (NameNotValidFirstLetterProblemException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (AgeIsZeroException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (AgeAboveMaximumAgeException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (AgeUnderMinimumAgeException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (SalaryZeroException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (NegativeSalaryException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (HighSalaryException e)
            {
                throw new ControllerException(e.Message);
            }

            try
            {
                teamService.addReacerToTeam(teamName, newRacer);
            }
            catch (TeamException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (F1Exception e)
            {
                throw new ControllerException(e.Message);
            }
        }
        /// <summary>
        /// Versenyző adatainak módosítása
        /// Kösse be a Validatorokkat a metódusba!
        /// </summary>
        /// <param name="teamName">A csapat neve</param>
        /// <param name="oldRacerName">A versenyző régi neve</param>
        /// <param name="racerName">A versenyző új neve</param>
        /// <param name="racerAge">A versenyző új neve</param>
        /// <param name="racerSalary">A versenyző költsége</param>
        public void updateRacerInTeam(string teamName, string oldRacerName, string racerName, string racerAge, string racerSalary)
        {
            int racerAgeNumber = 0;

            if (!int.TryParse(racerAge, out racerAgeNumber))
            {
                throw new ControllerException("A megadott életkor nem megfelelő alakú szám!");
            }
            int racerSalaryNumber = 0;

            if (!int.TryParse(racerSalary, out racerSalaryNumber))
            {
                throw new ControllerException("A megadott fizetés nem megfelelő alakú szám!");
            }
            if (teamService.existRacer(racerName, racerAgeNumber))
            {
                throw new ControllerException("Már létezik " + racerName + " nevű versenyző, aki " + racerAge + " éves.");
            }

            try
            {
                NameValidator nv = new NameValidator(racerName);
                nv.validation();
            }
            catch (NameNotValidNameIsEmptyException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (NameNotValidFirstLetterProblemException e)
            {
                throw new ControllerException(e.Message);
            }

            try
            {
                AgeValidator av = new AgeValidator(racerAgeNumber);
                av.validation();
            }
            catch (AgeIsZeroException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (AgeUnderMinimumAgeException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (AgeAboveMaximumAgeException e)
            {
                throw new ControllerException(e.Message);
            }

            try
            {
                SalaryValidator sv = new SalaryValidator(racerSalaryNumber);
                sv.validation();
            }
            catch (SalaryZeroException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (NegativeSalaryException e)
            {
                throw new ControllerException(e.Message);
            }
            catch (HighSalaryException e)
            {
                throw new ControllerException(e.Message);
            }

            try
            {
                int racerId = teamService.getRacerId(teamName, oldRacerName);
                if (racerId > 0)
                {
                    Racer newRacer = new Racer(racerId, racerName, racerAgeNumber, racerSalaryNumber);
                    teamService.updateReacerInTeam(teamName, oldRacerName, newRacer);
                }
                else
                {
                    throw new ControllerException("A megadott versenyőjnek nem találom az azonosítáját");
                }
            }
            catch (TeamServiceExeption tse)
            {
                throw new ControllerException(tse.Message);
            }
            catch (RacerException re)
            {
                throw new ControllerException(re.Message);
            }
        }
示例#10
0
        public Racer(int id, string name, int age, int salary)
        {
            this.id = id;

            try
            {
                NameValidator validator = new NameValidator(name);
                validator.validation();
                this.name = name;
            }
            catch (NameNotValidNameIsEmptyException e)
            {
                Debug.WriteLine(e.Message);
                throw new RacerException(e.Message + "\n" + name);
            }
            catch (NameNotValidFirstLetterProblemException e)
            {
                Debug.WriteLine(e.Message);
                throw new RacerException(e.Message + "\n" + name);
            }

            try
            {
                AgeValidator ageValidator = new AgeValidator(age);
                ageValidator.validation();
                this.age = age;
            }
            catch (AgeIsZeroException e)
            {
                Debug.WriteLine(e.Message);
                throw new RacerException(e.Message + "\n" + age);
            }
            catch (AgeUnderMinimumAgeException e)
            {
                Debug.WriteLine(e.Message);
                throw new RacerException(e.Message + "\n" + age);
            }
            catch (AgeAboveMaximumAgeException e)
            {
                Debug.WriteLine(e.Message);
                throw new RacerException(e.Message + "\n" + age);
            }

            try
            {
                SalaryValidator salaryValidator = new SalaryValidator(salary);
                salaryValidator.validation();
                this.salary = salary;
            }
            catch (SalaryZeroException e)
            {
                Debug.WriteLine(e.Message);
                throw new RacerException(e.Message + "\n" + salary);
            }
            catch (NegativeSalaryException e)
            {
                Debug.WriteLine(e.Message);
                throw new RacerException(e.Message + "\n" + salary);
            }
            catch (HighSalaryException e)
            {
                Debug.WriteLine(e.Message);
                throw new RacerException(e.Message + "\n" + salary);
            }
        }