public IActionResult Feed(int userId, int animalId) { AnimalDTO animal = null; 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); } //Manager will throw exceptions to manage responses catch (InvalidOperationException) { return(NotFound($"Animal: {animalId} was not found")); } catch (ResourceNotOwnedException) { return(NotFound($"Animal: {animalId} was not found")); } catch (Exception) { return(StatusCode(500)); } animal = animalManager.FeedAnimal(userId, animalId); return(Ok(animal)); }
public void FeedAnimal_ShouldDecreaseHunger_WhenFed() { AnimalDTO animal = animalManager.FeedAnimal(1, 1); Assert.AreEqual(30, animal.Hunger); }