Esempio n. 1
0
        public void CreateFoodSuccessTest()
        {
            //// Arranage
            var food = new Food
            {
                Name      = "First Test",
                Category  = "Success diet food",
                Nutrition = "Test nutrition"
            };

            var addedFood = new DAL.Models.Foods
            {
                Name      = "First Test",
                Category  = "success diet plan",
                Nutrition = "Test nutrition",
                Id        = 1
            };

            _genericAccess.Setup(access => access.Add(It.IsAny <DAL.Models.Foods>())).Returns(addedFood);

            //// Act
            var returned = _service.create(food);

            //// Assert
            _genericAccess.Verify(access => access.Add(It.IsAny <DAL.Models.Foods>()), Times.Once);
            Assert.Equal(addedFood.Id, returned.Id);
        }
Esempio n. 2
0
        public void getFoodByNameSuccessTest()
        {
            ////Arrange
            var foodEntity1 = new DAL.Models.Foods
            {
                Id        = 1,
                Name      = "Food One",
                Category  = "Test",
                Nutrition = "Test Nutrition",
            };

            var foodEntity2 = new DAL.Models.Foods
            {
                Id        = 2,
                Name      = "Food Two",
                Category  = "Test",
                Nutrition = "Test Nutrition",
            };

            var foodEntity3 = new DAL.Models.Foods
            {
                Id        = 3,
                Name      = "Fud Three",
                Category  = "Test",
                Nutrition = "Test Nutrition",
            };

            var foodEntity_List = new List <DAL.Models.Foods> {
                foodEntity1, foodEntity2
            };

            var food1 = FoodService.EntityObjToPOCO(foodEntity1);
            var food2 = FoodService.EntityObjToPOCO(foodEntity2);
            var food3 = FoodService.EntityObjToPOCO(foodEntity3);

            _foodAccess.Setup(access => access.GetFoodsByName(It.IsAny <string>())).Returns(foodEntity_List);

            //// Act
            var returned = _service.getFoodsByName("Food");

            //// Assert
            _foodAccess.Verify(access => access.GetFoodsByName(It.IsAny <string>()), Times.Once);
            Assert.Equal(2, returned.Count);
            Assert.Equal(food1.Id, returned[0].Id);
            Assert.Equal(food1.Name, returned[0].Name);
            Assert.Equal(food1.Category, returned[0].Category);
            Assert.Equal(food1.Nutrition, returned[0].Nutrition);
            Assert.Equal(food2.Id, returned[1].Id);
            Assert.Equal(food2.Name, returned[1].Name);
            Assert.Equal(food2.Category, returned[1].Category);
            Assert.Equal(food2.Nutrition, returned[1].Nutrition);
        }