Example #1
0
        public FoodDetailsModels(string jsonString)
        {
            JObject detailObject = JObject.Parse(jsonString);
            string  userID       = System.Web.HttpContext.Current.User.Identity.GetUserId();

            Description = detailObject.SelectToken("description")?.ToString() ?? "";
            BrandOwner  = detailObject.SelectToken("brandOwner")?.ToString() ?? "";
            var ingredientString = detailObject.SelectToken("ingredients")?.ToString() ?? "";

            if (!string.IsNullOrEmpty(ingredientString))
            {
                var primary   = new List <Ingredient>();
                var secondary = new List <Ingredient>();
                IngredientParser.Parse(ingredientString, out primary, out secondary);
                PrimaryIngredients   = primary;
                SecondaryIngredients = secondary;
            }
            double servingSize;

            ServingSize         = double.TryParse(detailObject.SelectToken("servingSize")?.ToString() ?? "", out servingSize) ? servingSize : 0.0;
            ServingSizeUnit     = detailObject.SelectToken("servingSizeUnit")?.ToString() ?? "";
            ServingSizeFullText = ServingSizeCleaner.Clean(detailObject.SelectToken("householdServingFullText")?.ToString() ?? "");
            LabelNutrients      = detailObject.SelectToken("labelNutrients")?.ToString() ?? "";
            int fdcId;

            FdcId = int.TryParse(detailObject.SelectToken("fdcId")?.ToString() ?? "", out fdcId) ? fdcId : -1;
            UPC   = detailObject.SelectToken("gtinUpc")?.ToString() ?? "";
            MaxFodmapPercentage = Math.Round(Algorithm.GetMaxFodmapPercentage(PrimaryIngredients, SecondaryIngredients), 2);
            FodmapScore         = MaxFodmapPercentage > 5 ? $"{Score.High}" : MaxFodmapPercentage > 0 ? $"{Score.Medium}" : $"{Score.Low}";
        }
Example #2
0
        public void CleanStringWithParentheses_ReturnsOnlyFirstPart()
        {
            string result = ServingSizeCleaner.Clean("1 can(355ml)");

            Assert.AreEqual("1 can", result);
        }
Example #3
0
        public void CleanOZA_Returns_fl_OZ()
        {
            string result = ServingSizeCleaner.Clean("22 OZA");

            Assert.AreEqual("22 fl oz", result);
        }
Example #4
0
        public void CleanONZ_ReturnsOZ()
        {
            string result = ServingSizeCleaner.Clean("12 ONZ");

            Assert.AreEqual("12 oz", result);
        }
Example #5
0
        public void CleanGenericString_ReturnsLowerCase()
        {
            string result = ServingSizeCleaner.Clean("THIs is 1 teST!");

            Assert.AreEqual("this is 1 test!", result);
        }
Example #6
0
        public void CleanEmptyString_ReturnsEmpty()
        {
            string result = ServingSizeCleaner.Clean("");

            Assert.AreEqual("", result);
        }