public ClubResource AddClub(ClubDto clubDto)
        {
            #region Checks

            if (clubDto == null)
            {
                throw new ClubCannotBeNullException();
            }

            var clubValidator    = new ClubValidator();
            var validationResult = clubValidator.Validate(clubDto);

            if (!validationResult.IsValid)
            {
                throw new ClubIsNotValidException(validationResult.Errors.First().ErrorMessage);
            }

            #endregion

            var newClub = _mapper.Map <Club>(clubDto);

            _context.Clubs.Add(newClub);
            _context.SaveChanges();

            var clubResource = _mapper.Map <ClubResource>(newClub);
            return(clubResource);
        }
예제 #2
0
        public void RouteConstrint_Club_validator_test()
        {
            var validator = new ClubValidator();

            // Valid Country
            Assert.IsTrue(validator.IsValid("ØSF"), "ØSF should be valid");

            // Invalid Country
            Assert.IsFalse(validator.IsValid("OST"), "OSF should not validate");
        }
예제 #3
0
        public void RouteConstrint_Club_validator_test()
        {
            var validator = new ClubValidator();

            // Valid Country
            Assert.IsTrue(validator.IsValid("ØSF"), "ØSF should be valid");

            // Invalid Country
            Assert.IsFalse(validator.IsValid("OST"), "OSF should not validate");
        }