public async Task TestPostAnimalOwnershipInappropriateId() { var controller = new AnimalOwnershipsController(context); AnimalOwnership ownedAnimal = context.AnimalOwnership.Find(ID_TO_FIND); ownedAnimal.AnimalId = INAPPROPRIATE_ID_TO_FIND; var newOwnedAnimal = await controller.PostAnimalOwnership(ownedAnimal); // Assert var actionResult = Assert.IsType <ActionResult <AnimalOwnership> >(newOwnedAnimal); Assert.IsType <NotFoundResult>(actionResult.Result); }
public async Task TestPostAnimalOwnershipAppropriateId() { var controller = new AnimalOwnershipsController(context); AnimalOwnership ownedAnimal = context.AnimalOwnership.Find(ID_TO_FIND); ownedAnimal.Id = EXPECTED_SIZE_OF_ALL + 1; ownedAnimal.Name = CHANGED_TEXT; var newOwnedAnimal = await controller.PostAnimalOwnership(ownedAnimal); var actionResult = Assert.IsType <ActionResult <AnimalOwnership> >(newOwnedAnimal); Assert.IsType <CreatedAtActionResult>(actionResult.Result); Assert.NotNull(actionResult); long expectedSize = EXPECTED_SIZE_OF_ALL + 1; ownedAnimal = context.AnimalOwnership.Find(expectedSize); Assert.Equal(CHANGED_TEXT, ownedAnimal.Name); Assert.Equal(expectedSize, ownedAnimal.Id); }
public async Task TestPostAnimalOwnershipAppropriateIdResetDefaults() { var controller = new AnimalOwnershipsController(context); AnimalOwnership ownedAnimal = context.AnimalOwnership.Find(ID_TO_FIND); //Increment the values ownedAnimal.Feed(); ownedAnimal.Stroke(); ownedAnimal.Id = EXPECTED_SIZE_OF_ALL + 1; ownedAnimal.Name = CHANGED_TEXT; var newOwnedAnimal = await controller.PostAnimalOwnership(ownedAnimal); var actionResult = Assert.IsType <ActionResult <AnimalOwnership> >(newOwnedAnimal); Assert.IsType <CreatedAtActionResult>(actionResult.Result); Assert.NotNull(actionResult); long expectedSize = EXPECTED_SIZE_OF_ALL + 1; ownedAnimal = context.AnimalOwnership.Find(expectedSize); Assert.Equal(CHANGED_TEXT, ownedAnimal.Name); Assert.Equal(expectedSize, ownedAnimal.Id); Assert.Equal(ownedAnimal.Animal.HungerDefault, ownedAnimal.Hunger); Assert.Equal(ownedAnimal.Animal.HappinessDefault, ownedAnimal.Happiness); }