public void DeleteAnimal_ShouldRemoveAnimal_WhenValid()
        {
            int animalCount = mockAnimals.Count;

            animalManager.DeleteAnimal(1);

            Assert.AreEqual(animalCount - 1, mockAnimals.Count);
            Assert.ThrowsException <InvalidOperationException>(() => animalRepository.GetAnimalById(1));
        }
        public IActionResult Delete(int userId, int animalId)
        {
            //Check if User exists
            try
            {
                userManager.GetUserById(userId);
            }
            //Manager will throw exceptions to manage responses
            catch (InvalidOperationException)
            {
                return(NotFound($"User: {userId} was not found"));
            }

            catch (Exception)
            {
                return(StatusCode(500));
            }

            try
            {
                animalManager.GetAnimalById(userId, animalId);
            }
            catch (InvalidOperationException)
            {
                return(NotFound($"Animal: {animalId} was not found"));
            }
            catch (ResourceNotOwnedException)
            {
                return(NotFound($"Animal: {animalId} was not found"));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }

            animalManager.DeleteAnimal(animalId);

            return(NoContent());
        }
Exemplo n.º 3
0
 public void Delete(int id)
 {
     _animalManager.DeleteAnimal(id);
 }
Exemplo n.º 4
0
        public string DeleteAnimal(Animal animal)
        {
            string deleteAnimal = animalManager.DeleteAnimal(animal);

            return(deleteAnimal);
        }
Exemplo n.º 5
0
 public IActionResult DeleteConfirmed(int id)
 {
     _manager.DeleteAnimal(id);
     return(RedirectToAction(nameof(Index)));
 }