예제 #1
0
        public static void AddTranslationForIngredient()
        {
            try
            {
                Console.WriteLine("Add translation for ingredients");
                Console.WriteLine("Enter strart NDB No:");
                string NDBNoStr = Console.ReadLine();
                int startNDBNo = 0, count = 0;
                if (NDBNoStr != null)
                {
                    startNDBNo = int.Parse(NDBNoStr);
                    if (startNDBNo < 1001 || startNDBNo > 93600)
                    {
                        log.WarnFormat("[AddTranslationForIngredient] Incorrect strart NDB No = {0}.", NDBNoStr);
                        return;
                    }

                }

                Console.WriteLine("Enter count of ingredients:");
                NDBNoStr = Console.ReadLine();
                if (NDBNoStr != null)
                {
                    count = int.Parse(NDBNoStr);
                    if (count < -1 || count > 8463)
                    {
                        log.WarnFormat("[AddTranslationForIngredient] Incorrect count = {0}.", NDBNoStr);
                        return;
                    }

                }
                log.InfoFormat("[AddTranslationForIngredient] strart NDB No = {0}, count = {1}.", startNDBNo, count);
                USDAImport usdaImport = new USDAImport();
                usdaImport.AddTranslationForSeveralIngredients(startNDBNo, count);
            }
            catch (Exception e)
            {
                log.ErrorFormat("[AddTranslationForIngredient] Exception={0}", e);
            }
        }
예제 #2
0
        public void NutDataToNutritionDataTest_ShouldConvertAllProperties()
        {
            //arrange
            NUT_DATA NutData1 = new NUT_DATA
            {
                NDB_No = "1",
                Nutr_No = "203",
                Nutr_Val = 101,
                Num_Data_Pts = 1,
                Std_Error = 1,
                Src_Cd = "Src_Cd",
                Deriv_Cd = "Deriv_Cd",
                Ref_NDB_No = "Ref_NDB_No",
                Add_Nutr_Mark = "Add_Nutr_Mark",
                Num_Studies = 1,
                Min = 101,
                Max = 201,
                DF = 1,
                Low_EB = 1,
                Up_EB = 1,
                Stat_Cmt = "Stat_Cmt",
                AddMod_Date = "12/2013",
            };
            NUT_DATA NutData2 = new NUT_DATA
            {
                NDB_No = "1",
                Nutr_No = "205",
                Nutr_Val = 102,
                Num_Data_Pts = 2,
                Std_Error = 2,
                Src_Cd = "Src_Cd",
                Deriv_Cd = "Deriv_Cd",
                Ref_NDB_No = "Ref_NDB_No",
                Add_Nutr_Mark = "Add_Nutr_Mark",
                Num_Studies = 2,
                Min = 102,
                Max = 202,
                DF = 2,
                Low_EB = 2,
                Up_EB = 2,
                Stat_Cmt = "Stat_Cmt",
                AddMod_Date = "12/2013",
            };
            NUT_DATA NutData3 = new NUT_DATA
            {
                NDB_No = "1",
                Nutr_No = "210",
                Nutr_Val = 103,
                Num_Data_Pts = 3,
                Std_Error = 3,
                Src_Cd = "Src_Cd",
                Deriv_Cd = "Deriv_Cd",
                Ref_NDB_No = "Ref_NDB_No",
                Add_Nutr_Mark = "Add_Nutr_Mark",
                Num_Studies = 3,
                Min = 103,
                Max = 203,
                DF = 3,
                Low_EB = 3,
                Up_EB = 3,
                Stat_Cmt = "Stat_Cmt",
                AddMod_Date = "12/2013",
            };

            //act

            //usda_nutritionEntities context = new usda_nutritionEntities();
            //var food_groups = context.FD_GROUP.ToList();
            //var weigts = context.WEIGHT.ToList();

            USDAImport usdaImport = new USDAImport();
            NutritionData nut1 = usdaImport.NutDataToNutritionData(NutData1);
            NutritionData nut2 = usdaImport.NutDataToNutritionData(NutData2);
            NutritionData nut3 = usdaImport.NutDataToNutritionData(NutData3);

            //assert
            Assert.IsNotNull(nut1);
            Assert.IsNotNull(nut2);
            Assert.IsNotNull(nut3);
            Assert.IsNotNull(nut1);
            Assert.AreEqual(nut1.Nutr_No, int.Parse(NutData1.Nutr_No));
            Assert.AreEqual(nut1.Std_Error, (double)NutData1.Std_Error);
            Assert.AreEqual(nut1.Min, (double)NutData1.Min);
            Assert.AreEqual(nut1.Max, (double)NutData1.Max);
            Assert.AreEqual(nut1.DF, (double)NutData1.DF);
            Assert.AreEqual(nut1.Low_EB, (double)NutData1.Low_EB);
            Assert.AreEqual(nut1.Up_EB, (double)NutData1.Up_EB);
            Assert.AreEqual(nut1.AddMod_Date, DateTime.Parse(NutData1.AddMod_Date));
        }
예제 #3
0
        public void NutDataListToNutritionFactsTest_ShouldReseiveListOfNut_DATA_AndConvertToNutritionFactsObject()
        {
            //arrange
            NUT_DATA NutData1 = new NUT_DATA
            {
                NDB_No = "1",
                Nutr_No = "203",
                Nutr_Val = 101,
                Num_Data_Pts = 1,
                Std_Error = 1,
                Src_Cd = "Src_Cd",
                Deriv_Cd = "Deriv_Cd",
                Ref_NDB_No = "Ref_NDB_No",
                Add_Nutr_Mark = "Add_Nutr_Mark",
                Num_Studies = 1,
                Min = 101,
                Max = 201,
                DF = 1,
                Low_EB = 1,
                Up_EB = 1,
                Stat_Cmt = "Stat_Cmt",
                AddMod_Date = "12/2013",
            };
            NUT_DATA NutData2 = new NUT_DATA
            {
                NDB_No = "1",
                Nutr_No = "205",
                Nutr_Val = 102,
                Num_Data_Pts = 2,
                Std_Error = 2,
                Src_Cd = "Src_Cd",
                Deriv_Cd = "Deriv_Cd",
                Ref_NDB_No = "Ref_NDB_No",
                Add_Nutr_Mark = "Add_Nutr_Mark",
                Num_Studies = 2,
                Min = 102,
                Max = 202,
                DF = 2,
                Low_EB = 2,
                Up_EB = 2,
                Stat_Cmt = "Stat_Cmt",
                AddMod_Date = "12/2013",
            };
            NUT_DATA NutData3 = new NUT_DATA
            {
                NDB_No = "1",
                Nutr_No = "210",
                Nutr_Val = 103,
                Num_Data_Pts = 3,
                Std_Error = 3,
                Src_Cd = "Src_Cd",
                Deriv_Cd = "Deriv_Cd",
                Ref_NDB_No = "Ref_NDB_No",
                Add_Nutr_Mark = "Add_Nutr_Mark",
                Num_Studies = 3,
                Min = 103,
                Max = 203,
                DF = 3,
                Low_EB = 3,
                Up_EB = 3,
                Stat_Cmt = "Stat_Cmt",
                AddMod_Date = "12/2013",
            };
            List<NUT_DATA> nutList = new List<NUT_DATA>() { NutData1, NutData2, NutData3 };

            //act
            USDAImport usdaImport = new USDAImport();
            NutritionFacts nutFacts =  usdaImport.NutDataListToNutritionFacts(nutList);

            //assert
            Assert.IsNotNull(nutFacts);
            Assert.AreEqual(nutFacts.FullNutrisionList.Count, 3);

            Assert.AreEqual(nutFacts.Protein, 101);
            Assert.AreEqual(nutFacts.TotalCarbohydrate, 102);
            Assert.IsNotNull(nutFacts.FullNutrisionList.Exists(c => c.Nutr_No == 210));
        }
예제 #4
0
        public void GetNutritionTypeByNo_ShouldReturnNutritionTypeObject()
        {
            //act
            USDAImport usdaImport = new USDAImport();
            NutritionType tempNut = usdaImport.GetNutritionTypeByNo(205);

            //assert
            Assert.IsNotNull(tempNut);
            Assert.IsNotNull(tempNut.NutrDesc, "Carbohydrate, by difference");
        }
예제 #5
0
        public void FoodDesToIngredientTest_ShouldConvertFOOD_DES_objectToIngreadientObjectWithAllParameters()
        {
            //arrange

            USDADataImport.FOOD_DES food1 = new USDADataImport.FOOD_DES
            {
                NDB_No = "1",
                FdGrp_Cd = "0100", //Dairy and Egg Products
                Long_Desc = "Long_Desc",
                Shrt_Desc = "Shrt_Desc",
                ComName = "ComName",
                ManufacName = "ManufacName",
                Ref_Desc = "Ref_Desc",
                Refuse = 0,
                SciName = "SciName",
                N_Factor = 0,
                Pro_Factor = 0,
                Fat_Factor = 0,
                CHO_Factor = 0,
                NUT_DATA = new List<NUT_DATA>(),
                WEIGHT = new List<WEIGHT>(),
                LANGDESC = new List<LANGDESC>()
            };

            NUT_DATA NutData1 = new NUT_DATA
            {
                NDB_No = "1",
                Nutr_No = "203",
                Nutr_Val = 101,
                Num_Data_Pts = 1,
                Std_Error = 1,
                Src_Cd = "Src_Cd",
                Deriv_Cd = "Deriv_Cd",
                Ref_NDB_No = "Ref_NDB_No",
                Add_Nutr_Mark = "Add_Nutr_Mark",
                Num_Studies = 1,
                Min = 101,
                Max = 201,
                DF = 1,
                Low_EB = 1,
                Up_EB = 1,
                Stat_Cmt = "Stat_Cmt",
                AddMod_Date = "12/2013",
            };
            NUT_DATA NutData2 = new NUT_DATA
            {
                NDB_No = "1",
                Nutr_No = "205",
                Nutr_Val = 102,
                Num_Data_Pts = 2,
                Std_Error = 2,
                Src_Cd = "Src_Cd",
                Deriv_Cd = "Deriv_Cd",
                Ref_NDB_No = "Ref_NDB_No",
                Add_Nutr_Mark = "Add_Nutr_Mark",
                Num_Studies = 2,
                Min = 102,
                Max = 202,
                DF = 2,
                Low_EB = 2,
                Up_EB = 2,
                Stat_Cmt = "Stat_Cmt",
                AddMod_Date = "12/2013",
            };
            NUT_DATA NutData3 = new NUT_DATA
            {
                NDB_No = "1",
                Nutr_No = "210",
                Nutr_Val = 103,
                Num_Data_Pts = 3,
                Std_Error = 3,
                Src_Cd = "Src_Cd",
                Deriv_Cd = "Deriv_Cd",
                Ref_NDB_No = "Ref_NDB_No",
                Add_Nutr_Mark = "Add_Nutr_Mark",
                Num_Studies = 3,
                Min = 103,
                Max = 203,
                DF = 3,
                Low_EB = 3,
                Up_EB = 3,
                Stat_Cmt = "Stat_Cmt",
                AddMod_Date = "12/2013",
            };
            food1.NUT_DATA.Add(NutData1);
            food1.NUT_DATA.Add(NutData2);
            food1.NUT_DATA.Add(NutData3);
            WEIGHT weight1 = new WEIGHT
            {
                NDB_No = "1",
                Seq = "1",
                Amount = 1,
                Msre_Desc = "stick",
                Gm_Wgt = 21
            };
            WEIGHT weight2 = new WEIGHT
            {
                NDB_No = "1",
                Seq = "2",
                Amount = 2,
                Msre_Desc = "serving 5 sticks",
                Gm_Wgt = 107
            };
            food1.WEIGHT.Add(weight1);
            food1.WEIGHT.Add(weight2);

            List<FD_GROUP> food_groups = new List<FD_GROUP>();
            food_groups.Add(new FD_GROUP { FdGrp_CD = "0100", FdGrp_Desc = "Dairy and Egg Products" });
            food_groups.Add(new FD_GROUP { FdGrp_CD = "0200", FdGrp_Desc = "Spices and Herbs" });
            food_groups.Add(new FD_GROUP { FdGrp_CD = "0300", FdGrp_Desc = "Baby Foods" });

            //act

            USDAImport usdaImport = new USDAImport();
            Ingredient ingredient = usdaImport.FoodDesToIngredient(food1, food_groups);

            //assert
            Assert.IsNotNull(ingredient);
            Assert.IsNotNull(ingredient.NutritionFacts);
            Assert.IsNotNull(ingredient.NutritionFacts.FullNutrisionList);
            Assert.AreEqual(ingredient.NutritionFacts.FullNutrisionList.Count, 3);
            Assert.IsNotNull(ingredient.Weigts);
            Assert.AreEqual(ingredient.Weigts.Count, 2);
            Assert.AreEqual((int)ingredient.FoodGrp, 0100);
        }