async Task Add()
        {
            var foodid = await App.Current.MainPage.DisplayPromptAsync("FoodID", "FoodID");

            var foodname = await App.Current.MainPage.DisplayPromptAsync("Name", "Name");

            //var alcohol = await App.Current.MainPage.DisplayPromptAsync("Alcohol", "Alcohol");
            //var carbohydrates = await App.Current.MainPage.DisplayPromptAsync("Carbohydrates", "Carbohydrates");
            //var calcium = await App.Current.MainPage.DisplayPromptAsync("Calcium", "Calcium");
            //var cholesterol = await App.Current.MainPage.DisplayPromptAsync("Cholesterol", "Cholesterol");
            var calories = await App.Current.MainPage.DisplayPromptAsync("Calories", "Calories");

            //var kilojule = await App.Current.MainPage.DisplayPromptAsync("KiloJule", "KiloJule");
            //var fat = await App.Current.MainPage.DisplayPromptAsync("Fat", "Fat");
            //var glucose = await App.Current.MainPage.DisplayPromptAsync("Glucose", "Glucose");
            //var iron = await App.Current.MainPage.DisplayPromptAsync("Iron", "Iron");
            //var lactose = await App.Current.MainPage.DisplayPromptAsync("Lactose", "Lactose");
            //var magnesium = await App.Current.MainPage.DisplayPromptAsync("Magnesium", "Magnesium");
            //var potassium = await App.Current.MainPage.DisplayPromptAsync("Potassium", "Potassium");
            //var selenium = await App.Current.MainPage.DisplayPromptAsync("Selenium", "Selenium");
            //var sodium = await App.Current.MainPage.DisplayPromptAsync("Sodium", "Sodium");
            //var starch = await App.Current.MainPage.DisplayPromptAsync("Starch", "Starch");
            //var sugars = await App.Current.MainPage.DisplayPromptAsync("Sugars", "Sugars");
            //var water = await App.Current.MainPage.DisplayPromptAsync("Water", "Water");
            //var zinc = await App.Current.MainPage.DisplayPromptAsync("Zinc", "Zinc");

            await FoodService.AddFood(foodid, foodname, calories);

            //calcium, cholesterol, calories, kilojule, fat, glucose, iron,
            //lactose, magnesium, potassium, selenium, sodium, starch, sugars,
            //water, zinc) ;
            await Refresh();
        }
Exemple #2
0
        public void AddFood_ItemCountIsValid()
        {
            FoodService foodService = new FoodService();
            int         foodCount   = foodService.GetFoods().Count;
            int         expectedFoodCountAfterAddOperation = foodCount + 1;

            FoodDto foodDto = new FoodDto()
            {
                Id = new Guid("0f8fad5b-d9cb-469f-a165-70867728950e")
            };

            foodService.AddFood(foodDto);
            int foodCountAfterAddOperation = foodService.GetFoods().Count;

            Assert.AreEqual(expectedFoodCountAfterAddOperation, foodCountAfterAddOperation, "AddFood operation end unsuccessfully");
        }
Exemple #3
0
        public void AddFood_Success_Test()
        {
            // Arrange
            FoodDTO dto = SampleFoodDTO(1);

            // create mock for repository
            var mock = new Mock <IFoodRepository>();

            mock.Setup(s => s.AddFood(Moq.It.IsAny <R_Food>())).Returns(1);

            // service
            FoodService foodService = new FoodService();

            FoodService.Repository = mock.Object;

            // Act
            int id = foodService.AddFood(dto);

            // Assert
            Assert.AreEqual(1, id);
            Assert.AreEqual(1, dto.FoodId);
        }
Exemple #4
0
 /// <summary>
 /// 添加新食品
 /// </summary>
 /// <param name="food"></param>
 /// <returns></returns>
 public bool AddFood(Food food)
 {
     return(foodservice.AddFood(food));
 }