示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }