public void A010_SaveNewTest() { countriesRepository.SaveAndFlush(Country1); Country countryCheck = countriesRepository.GetById(Country1.PrimaryKey); Assert.IsNotNull(countryCheck); Assert.AreEqual(Country1.PrimaryKey, countryCheck.PrimaryKey); Assert.AreEqual(Country1.Description, countryCheck.Description); Assert.AreEqual(Country1.RegionKey, countryCheck.RegionKey); }
/// <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); } }