Пример #1
0
        public void DeleteAnimalType(int id)
        {
            AnimalType animalType = null;

            try
            {
                // I don't need to convert to a DTO therefore am calling repo rather than manager
                animalType = animalTypeRepository.GetAnimalTypeById(id);
            }
            //I am using .First therefore it can throw Exceptions
            //FirstOrDefault returns in the Default Value therefore am not using
            catch (InvalidOperationException)
            {
                //Handled in controller
                throw;
            }
            if (animalType != null)
            {
                animalTypeRepository.DeleteAnimalType(animalType);
            }
            else //Internal Server Error
            {
                throw new Exception();
            }
        }
        public void DeleteAnimalType_ShouldRemoveAnimal_WhenValid()
        {
            Assert.AreEqual(2, mockAnimalTypes.Count);
            AnimalType animalTypeToRemove = animalTypeRepository.GetAnimalTypeById(1);

            animalTypeRepository.DeleteAnimalType(animalTypeToRemove);
            Assert.AreEqual(1, animalTypeRepository.GetAnimalTypes().Count());
        }