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()); }
public void Delete(int id) { _animalManager.DeleteAnimal(id); }
public string DeleteAnimal(Animal animal) { string deleteAnimal = animalManager.DeleteAnimal(animal); return(deleteAnimal); }
public IActionResult DeleteConfirmed(int id) { _manager.DeleteAnimal(id); return(RedirectToAction(nameof(Index))); }