示例#1
0
        public async void TestFeedAnimalInappropriate()
        {
            var controller  = new MediatonicTestController(context);
            var ownedAnimal = await controller.FeedAnimal(INAPPROPRIATE_ID_TO_FIND);

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

            Assert.IsType <BadRequestResult>(actionResult.Result);
        }
示例#2
0
        public async void TestGetAnimalAppropriately()
        {
            var controller  = new MediatonicTestController(context);
            var ownedAnimal = await controller.GetAnimal(ID_TO_FIND);

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

            Assert.NotNull(actionResult);
            Assert.Equal(ID_TO_FIND, actionResult.Value.Id);
        }
示例#3
0
        public async void TestFeedAnimalAppropriate()
        {
            var controller  = new MediatonicTestController(context);
            var ownedAnimal = await controller.GetAnimal(ID_TO_FIND);

            int initialHunger = ownedAnimal.Value.Hunger;

            ownedAnimal = await controller.FeedAnimal(ID_TO_FIND);

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

            Assert.Equal(initialHunger - 1, actionResult.Value.Hunger);
        }
示例#4
0
        public async void TestStrokeAnimalAppropriate()
        {
            var controller  = new MediatonicTestController(context);
            var ownedAnimal = await controller.GetAnimal(ID_TO_FIND);

            int initialHappiness = ownedAnimal.Value.Happiness;

            ownedAnimal = await controller.StrokeAnimal(ID_TO_FIND);

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

            Assert.Equal(initialHappiness + 1, actionResult.Value.Happiness);
        }
示例#5
0
        public void TestGetAnimalsForUser()
        {
            var controller = new MediatonicTestController(context);
            IEnumerable <OwnedAnimal> ownedAnimals = controller.GetAnimalsForUser(ID_TO_FIND);

            int i = 0;

            foreach (OwnedAnimal animal in ownedAnimals)
            {
                i++;
            }

            Assert.Equal(EXPECTED_SIZE_PER_USER, i);
        }
示例#6
0
        public void TestGetAllOwnedAnimals()
        {
            var controller = new MediatonicTestController(context);
            IEnumerable <OwnedAnimal> ownedAnimals = controller.Get();

            int i = 0;

            foreach (OwnedAnimal animal in ownedAnimals)
            {
                i++;
            }

            Assert.Equal(EXPECTED_SIZE_OF_ALL, i);
        }
示例#7
0
        public async void TestGetAnimalCreatedInThePast()
        {
            var controller      = new MediatonicTestController(context);
            var animalOwnership = context.AnimalOwnership.Find(ID_OF_ANIMAL_CREATED_IN_PAST);

            Assert.Equal(db.PAST_CREATION_DATE, animalOwnership.LastUpdated);
            var ownedAnimal = await controller.GetAnimal(ID_OF_ANIMAL_CREATED_IN_PAST);

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

            Assert.NotNull(actionResult);
            Assert.Equal(ID_OF_ANIMAL_CREATED_IN_PAST, actionResult.Value.Id);

            animalOwnership = context.AnimalOwnership.Find(ID_OF_ANIMAL_CREATED_IN_PAST);
            Assert.Equal(DateTime.Now.Year, animalOwnership.LastUpdated.Year);
        }
示例#8
0
        public async void TestFeedAnimalCreatedInPast()
        {
            var controller      = new MediatonicTestController(context);
            var animalOwnership = context.AnimalOwnership.Find(ID_OF_ANIMAL_CREATED_IN_PAST);

            Assert.Equal(db.PAST_CREATION_DATE, animalOwnership.LastUpdated);

            var ownedAnimal = await controller.GetAnimal(ID_OF_ANIMAL_CREATED_IN_PAST);

            int initialHunger = ownedAnimal.Value.Hunger;

            ownedAnimal = await controller.FeedAnimal(ID_TO_FIND);

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

            Assert.Equal(initialHunger - 1, actionResult.Value.Hunger);

            animalOwnership = context.AnimalOwnership.Find(ID_OF_ANIMAL_CREATED_IN_PAST);
            Assert.Equal(DateTime.Now.Year, animalOwnership.LastUpdated.Year);
        }
示例#9
0
        public async void TestGetAnimalDegradation()
        {
            var      controller      = new MediatonicTestController(context);
            var      animalOwnership = context.AnimalOwnership.Find(ID_OF_ANIMAL_CREATED_IN_PAST_BY_AN_HOUR);
            DateTime updatedTime     = animalOwnership.LastUpdated;

            Assert.Equal(DateTime.Now.Hour - 1, updatedTime.Hour);
            var animal = context.Animal.Find(animalOwnership.AnimalId);

            //Assert current state is equal to defaults
            Assert.Equal(MOCK_ANIMAL_DEFAULT_HAPPINESS, animalOwnership.Happiness);
            Assert.Equal(MOCK_ANIMAL_DEFAULT_HUNGER, animalOwnership.Hunger);

            var ownedAnimal = await controller.GetAnimal(ID_OF_ANIMAL_CREATED_IN_PAST_BY_AN_HOUR);

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

            Assert.NotNull(actionResult);
            Assert.Equal(ID_OF_ANIMAL_CREATED_IN_PAST_BY_AN_HOUR, actionResult.Value.Id);
            Assert.Equal(MOCK_ANIMAL_DEFAULT_HUNGER + animal.HungerIncrease, ownedAnimal.Value.Hunger);
            Assert.Equal(MOCK_ANIMAL_DEFAULT_HAPPINESS - animal.HappinessDecrease, ownedAnimal.Value.Happiness);
        }