public void GetAnimalsById_ShouldReturnAnimalDTO_WhenValidId() { AnimalDTO animalDTO = animalManager.GetAnimalById(1, 1); Assert.AreEqual(1, animalDTO.Id); Assert.AreEqual("Gazza", animalDTO.Name); Assert.AreEqual(50, animalDTO.Happiness); Assert.AreEqual(50, animalDTO.Hunger); }
public IActionResult GetById(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 { animal = 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)); } return(Ok(animal)); }