Example #1
0
        /// <summary>Validations done to an entity before it is saved.</summary>
        /// <param name="validateEntity">The entity to validate.</param>
        /// <exception cref="GTSport_DT.Manufacturers.ManufacturerNameNotSetException">
        /// When the name is not filled.
        /// </exception>
        /// <exception cref="GTSport_DT.Manufacturers.ManufacturerCountryKeyNotSetException">
        /// When the country key is not filled.
        /// </exception>
        /// <exception cref="GTSport_DT.Manufacturers.ManufacturerNameAlreadyExistsException">
        /// When the name already exists for another manufacturer.
        /// </exception>
        /// <exception cref="CountryNotFoundException">
        /// When the country key is not found in the country table.
        /// </exception>
        public override void ValidateSave(Manufacturer validateEntity)
        {
            if (String.IsNullOrWhiteSpace(validateEntity.Name))
            {
                throw new ManufacturerNameNotSetException(ManufacturerNameNotSetException.ManufacturerNameNotSetMsg);
            }

            if (String.IsNullOrWhiteSpace(validateEntity.CountryKey))
            {
                throw new ManufacturerCountryKeyNotSetException(ManufacturerCountryKeyNotSetException.ManufacturerCountryKeyNotSetMsg);
            }

            Manufacturer manufacturer = manufacturersRepository.GetByName(validateEntity.Name);

            if (manufacturer != null)
            {
                if (String.IsNullOrWhiteSpace(validateEntity.PrimaryKey) ||
                    manufacturer.PrimaryKey != validateEntity.PrimaryKey)
                {
                    throw new ManufacturerNameAlreadyExistsException(ManufacturerNameAlreadyExistsException.ManufacturerNameAlreadyExistsMsg);
                }
            }

            Country country = countriesRepository.GetById(validateEntity.CountryKey);

            if (country == null)
            {
                throw new CountryNotFoundException(CountryNotFoundException.CountryKeyNotFoundMsg, validateEntity.CountryKey);
            }
        }
        public void A070_GetByName()
        {
            Manufacturer manufacturer = manufacturersRepository.GetByName(Manufacturer2.Name);

            Assert.AreEqual(Manufacturer2.PrimaryKey, manufacturer.PrimaryKey);
        }