Пример #1
0
        public void GetAllFoodsNoneReturnTest()
        {
            IList<Food> foods = null;
            foodRepositoryMock.Setup(t => t.RetrieveFoods()).Returns(foods);

            FoodController controller = new FoodController(foodRepositoryMock.Object, mealRepositoryMock.Object);
            var results = controller.Get() as IEnumerable<FoodViewModel>;

            Assert.IsNotNull(results);
            Assert.AreEqual(0, results.Count());
        }
Пример #2
0
        public void GetAllFoodsTest()
        {
            foodRepositoryMock.Setup(t => t.RetrieveFoods()).Returns(new List<Food>(){
                new Food(){ Name = "test", Id = "1"},
                new Food() { Name = "test2", Id = "2"},
                new Food() { Name = "test3", Id = "3"}
            });

            FoodController controller = new FoodController(foodRepositoryMock.Object, mealRepositoryMock.Object);
            var results = controller.Get() as IEnumerable<FoodViewModel>;

            Assert.IsNotNull(results);
            Assert.AreEqual(3, results.Count());
            Assert.AreEqual("test", results.First(t => t.Name.Equals("test")).Name);
        }
Пример #3
0
        public void GetFoodByIdNoServingsTest()
        {
            foodRepositoryMock.Setup(t => t.RetrieveCompleteFood(It.IsAny<int>())).Returns(new Food()
            {
                Name = "test",
                Id = "1",
                AvailableNutrients = new List<Nutrient>(){
                    new Nutrient(){ Description = "Protein"},
                    new Nutrient(){ Description = "Carbs"},
                    new Nutrient(){ Description = "Fat"}
                }
            });

            FoodController controller = new FoodController(foodRepositoryMock.Object, mealRepositoryMock.Object);
            var results = controller.Get(0) as FoodViewModel;

            Assert.IsNotNull(results);
            Assert.AreEqual("test", results.Name);
            Assert.AreEqual(3, results.Nutrients.Count);
            Assert.IsNull(results.Servings);
        }
Пример #4
0
        public void UnsuccessfullySaveFoodsTest()
        {
            IList<SaveFoodViewModel> saveFoodViewModels = new List<SaveFoodViewModel>()
            {
                new SaveFoodViewModel(){
                    Date = DateTime.Now,
                    FoodId = 1,
                    Name = "food",
                    ServingSize = 1,
                    ServingTypeId = 1
                },
                new SaveFoodViewModel(){
                    Date = DateTime.Now,
                    FoodId = 2,
                    Name = "food2",
                    ServingSize = 1,
                    ServingTypeId = 2
                }
            };
            mealRepositoryMock.Setup(t => t.SaveMeals(It.IsAny<IList<Meal>>())).Returns(false);

            FoodController controller = new FoodController(foodRepositoryMock.Object, mealRepositoryMock.Object);
            var results = controller.Post(saveFoodViewModels) as HttpResponseMessage;

            Assert.IsNotNull(results);
            Assert.AreEqual(HttpStatusCode.InternalServerError, results.StatusCode);
            Assert.AreEqual("unable to save food", results.ReasonPhrase);
        }
Пример #5
0
        public void SaveFoodNullTest()
        {
            IList<SaveFoodViewModel> saveFoodViewModels = null;

            FoodController controller = new FoodController(foodRepositoryMock.Object, mealRepositoryMock.Object);
            var results = controller.Post(saveFoodViewModels) as HttpResponseMessage;

            Assert.IsNotNull(results);
            Assert.AreEqual(HttpStatusCode.BadRequest, results.StatusCode);
            Assert.AreEqual("no valid request content present", results.ReasonPhrase);
        }
Пример #6
0
        public void SaveFoodNoFoodsTest()
        {
            IList<SaveFoodViewModel> saveFoodViewModels = new List<SaveFoodViewModel>()
            {
                new SaveFoodViewModel(){
                    Date = DateTime.Now
                },
                new SaveFoodViewModel(){
                    Date = DateTime.Now
                }
            };

            FoodController controller = new FoodController(foodRepositoryMock.Object, mealRepositoryMock.Object);
            var results = controller.Post(saveFoodViewModels) as HttpResponseMessage;

            Assert.IsNotNull(results);
            Assert.AreEqual(HttpStatusCode.BadRequest, results.StatusCode);
            Assert.AreEqual("no foods present", results.ReasonPhrase);
        }
Пример #7
0
        public void SaveFoodNoEntryDateTest()
        {
            IList<SaveFoodViewModel> saveFoodViewModels = new List<SaveFoodViewModel>()
            {
                new SaveFoodViewModel(){
                    FoodId = 1,
                    Name = "food",
                    ServingSize = 1,
                    ServingTypeId = 1
                },
                new SaveFoodViewModel(){
                    Date = DateTime.Now,
                    FoodId = 2,
                    Name = "food2",
                    ServingSize = 1,
                    ServingTypeId = 2
                }
            };

            FoodController controller = new FoodController(foodRepositoryMock.Object, mealRepositoryMock.Object);
            var results = controller.Post(saveFoodViewModels) as HttpResponseMessage;

            Assert.IsNotNull(results);
            Assert.AreEqual(HttpStatusCode.BadRequest, results.StatusCode);
            Assert.AreEqual("no valid date present", results.ReasonPhrase);
        }
Пример #8
0
        public void GetFoodByIdNotExistsTest()
        {
            Food food = null;
            foodRepositoryMock.Setup(t => t.RetrieveCompleteFood(It.IsAny<int>())).Returns(food);

            FoodController controller = new FoodController(foodRepositoryMock.Object, mealRepositoryMock.Object);
            var results = controller.Get(0) as FoodViewModel;

            Assert.IsNotNull(results);
            Assert.IsNullOrEmpty(results.Name);
            Assert.IsNull(results.Nutrients);
            Assert.IsNull(results.Servings);
        }