Beispiel #1
0
        public void StrokeAnimalHappyTest()
        {
            List <Animal> animalList = new List <Animal>
            {
                new Sheep(0, "Dory", 0),
                new Sheep(1, "Clone", 0)
            };

            var mockGet = new Mock <IGetDataServices>();

            mockGet.Setup(repo => repo.GetAnimals()).Returns(animalList);
            mockGet.Setup(repo => repo.GetAnimalById(0)).Returns(animalList[0]);

            var mockSet = new Mock <ISetDataServices>();

            mockSet.Setup(m => m.ActionAnimal(animalList[0], animalList, It.IsAny <Func <Animal, bool> >())).Returns(false);

            // arrange
            var controller = new AnimalsController(mockGet.Object, mockSet.Object);

            // act
            var result   = controller.FeedAnimal(0);
            var okResult = result as OkObjectResult;

            // assert
            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
            Assert.ReferenceEquals($"{animalList[0]} is completely happy and it do not want more strokes", okResult.Value);
        }
Beispiel #2
0
        public void FeedAnimalTest()
        {
            List <Animal> animalList = new List <Animal>
            {
                new Sheep(0, "Dory", 0),
                new Sheep(1, "Clone", 0)
            };


            var mockGet = new Mock <IGetDataServices>();

            mockGet.Setup(repo => repo.GetAnimals()).Returns(animalList);
            mockGet.Setup(repo => repo.GetAnimalById(0)).Returns(animalList[0]);

            var mockSet = new Mock <ISetDataServices>();

            mockSet.Setup(m => m.ActionAnimal(animalList[0], animalList, It.IsAny <Func <Animal, bool> >())).Returns(true);

            // arrange
            var controller = new AnimalsController(mockGet.Object, mockSet.Object);

            // act
            var result   = controller.FeedAnimal(0);
            var okResult = result as OkObjectResult;

            // assert
            Assert.IsNotNull(okResult);
            Assert.AreEqual(200, okResult.StatusCode);
        }