示例#1
0
        public async Task TestGetAllAnimalOwnership()
        {
            var controller   = new AnimalOwnershipsController(context);
            var ownedAnimals = await controller.GetAnimalOwnership();

            Assert.Equal(EXPECTED_SIZE_OF_ALL, ownedAnimals.Value.Count());
        }
示例#2
0
        public async Task TestGetAnimalOwnershipInappropriateId()
        {
            var controller  = new AnimalOwnershipsController(context);
            var ownedAnimal = await controller.GetAnimalOwnership(INAPPROPRIATE_ID_TO_FIND);

            // Assert
            var actionResult = Assert.IsType <ActionResult <AnimalOwnership> >(ownedAnimal);

            Assert.IsType <NotFoundResult>(actionResult.Result);
        }
示例#3
0
        public async Task TestGetAnimalOwnershipAppropriateId()
        {
            var controller  = new AnimalOwnershipsController(context);
            var ownedAnimal = await controller.GetAnimalOwnership(ID_TO_FIND);

            var actionResult = Assert.IsType <ActionResult <AnimalOwnership> >(ownedAnimal);

            Assert.NotNull(actionResult);
            Assert.Equal(ID_TO_FIND, actionResult.Value.Id);
        }
示例#4
0
        public async Task TestPutAnimalOwnershipInappropriateId()
        {
            var             controller  = new AnimalOwnershipsController(context);
            AnimalOwnership ownedAnimal = context.AnimalOwnership.Find(ID_TO_FIND);

            var modifiedOwnedAnimal = await controller.PutAnimalOwnership(INAPPROPRIATE_ID_TO_FIND, ownedAnimal);

            // Assert
            var actionResult = Assert.IsType <ActionResult <AnimalOwnership> >(modifiedOwnedAnimal);

            Assert.IsType <BadRequestResult>(actionResult.Result);
        }
示例#5
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);
        }
示例#6
0
        public async Task TestPutAnimalOwnershipAppropriateId()
        {
            var             controller  = new AnimalOwnershipsController(context);
            AnimalOwnership ownedAnimal = context.AnimalOwnership.Find(ID_TO_FIND);

            ownedAnimal.Name = CHANGED_TEXT;

            var modifiedOwnedAnimal = await controller.PutAnimalOwnership(ownedAnimal.Id, ownedAnimal);

            var actionResult = Assert.IsType <ActionResult <AnimalOwnership> >(modifiedOwnedAnimal);

            Assert.NotNull(actionResult);
            Assert.Equal(CHANGED_TEXT, actionResult.Value.Name);
            ownedAnimal = context.AnimalOwnership.Find(ID_TO_FIND);
            Assert.Equal(CHANGED_TEXT, ownedAnimal.Name);
        }
示例#7
0
        public async Task TestDeleteAnimalOwnershipAppropriateId()
        {
            var             controller  = new AnimalOwnershipsController(context);
            AnimalOwnership ownedAnimal = context.AnimalOwnership.Find(ID_TO_FIND);

            Assert.False(ownedAnimal.IsDeleted);

            var deletedOwnedAnimal = await controller.DeleteAnimalOwnership(ID_TO_FIND);

            // Assert
            var actionResult = Assert.IsType <ActionResult <AnimalOwnership> >(deletedOwnedAnimal);

            Assert.True(deletedOwnedAnimal.Value.IsDeleted);
            ownedAnimal = context.AnimalOwnership.Find(ID_TO_FIND);
            Assert.True(ownedAnimal.IsDeleted);
        }
示例#8
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);
        }
示例#9
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);
        }