Esempio n. 1
0
        public void RecipeTagsToString_ShouldReturnCorrectValue()
        {
            // Test ToString
            var tags = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);

            Assert.AreEqual("GlutenFree, NoAnimals, NoMeat, NoPork", tags.ToString());
        }
Esempio n. 2
0
        public MockModelerDBLoader(string filename)
        {
            var doc = XDocument.Load(filename);

            _dsRecipes = (from r in doc.Descendants("Recipe")
                          select new RecipeBinding()
            {
                Id = new Guid(r.Attribute("Id").Value),
                Rating = Convert.ToByte(r.Attribute("Rating").Value),
                Tags = RecipeTags.Parse(r.Attribute("Tags").Value)
            }).ToArray();

            _dsIngredients = (from u in doc.Descendants("Usage")
                              select new IngredientBinding()
            {
                RecipeId = new Guid(u.Attribute("RecipeId").Value),
                IngredientId = new Guid(u.Attribute("IngredientId").Value),
                Qty = Convert.ToSingle(u.Attribute("Qty").Value),
                Unit = Unit.Parse <Units>(u.Attribute("Unit").Value)
            }).ToArray();

            _dsRatings = (from r in doc.Descendants("Rating")
                          select new RatingBinding()
            {
                UserId = new Guid(r.Attribute("UserId").Value),
                RecipeId = new Guid(r.Attribute("RecipeId").Value),
                Rating = Convert.ToByte(r.Attribute("Rating").Value)
            }).ToArray();
        }
Esempio n. 3
0
        public async Task <IActionResult> Create(Recipe recipe)
        {
            if (ModelState.IsValid)
            {
                var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

                var loggedInCook = await _repo.Cook.FindByCondition(e => e.IdentityUserId == userId).SingleOrDefaultAsync();

                var loggedInCookID = loggedInCook.CookId;
                recipe.CookID   = loggedInCookID;
                recipe.CookName = loggedInCook.UserName;
                _repo.Recipe.Create(recipe);
                _repo.Save();

                //This is where the tags are bound to the recipe by the cook.
                var selectedRecipe = await _repo.Recipe.FindByCondition(r => r.RecipeId == recipe.RecipeId).SingleOrDefaultAsync();

                var selectedRecipeId = selectedRecipe.RecipeId;

                foreach (string tags in recipe.SelectedTags)
                {
                    var selectedTags = await _repo.Tags.FindByCondition(r => r.Name == tags).SingleOrDefaultAsync();

                    RecipeTags recipeTags = new RecipeTags();
                    recipeTags.RecipeId = selectedRecipeId;
                    recipeTags.TagsId   = selectedTags.TagsId;
                    _repo.RecipeTags.Create(recipeTags);
                    _repo.Save();
                }

                return(RedirectToAction(nameof(Index)));
            }
            return(View(recipe));
        }
Esempio n. 4
0
        public void TestParsing()
        {
            var tags = RecipeTags.Parse("No Red Meat, Dinner, Lunch");

            Assert.AreEqual(3, tags.Length);
            Assert.AreEqual("NoRedMeat, Dinner, Lunch", tags.ToString());
        }
Esempio n. 5
0
        public void RecipeTags_WithCorrectIndex_ShouldReturnCorrectElement()
        {
            var tags1 = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);

            // Test indexing
            Assert.IsTrue(tags1[0] == RecipeTag.GlutenFree);
            Assert.IsTrue(tags1[2] == RecipeTag.NoMeat);
        }
Esempio n. 6
0
        public Recipe(Guid id, RecipeTags tags, IngredientUsage[] ingredients)
        {
            this.ingredients = new IngredientUsageCollection();

            this.Id = id;
            this.Tags = tags;
            this.Ingredients = ingredients;
        }
Esempio n. 7
0
        public void TestRecipeTags()
        {
            var        tags1 = RecipeTag.GlutenFree | RecipeTag.NoAnimals | RecipeTag.NoMeat | RecipeTag.NoPork;
            var        tags2 = RecipeTag.LowCalorie | RecipeTag.LowFat;
            var        tags3 = RecipeTag.Lunch | RecipeTag.GlutenFree | RecipeTag.Dinner;
            RecipeTags tags4 = 15; //Same as tags1
            RecipeTags tags5 = null;
            RecipeTags tags6 = null;

            //TODO TI SI GOLQM GEI BE
            //Test counts
            Assert.AreEqual(4, tags1.Length);
            Assert.AreEqual(2, tags2.Length);
            Assert.AreEqual(4, tags4.Length);

            //Test Bitwise operators
            Assert.IsTrue((tags1 & RecipeTag.GlutenFree) > 0); //Has GlutenFree tag
            Assert.IsTrue((tags1 & RecipeTag.NoAnimals) > 0);  //Has NoAnimals tag
            Assert.IsTrue((tags1 & RecipeTag.NoMeat) > 0);     //Has NoMeat tag
            Assert.IsTrue((tags1 & RecipeTag.NoPork) > 0);     //Has NoPork tag

            Assert.IsTrue((tags1 & RecipeTag.LowSugar) == 0);  //Does NOT have LowSugar tag
            Assert.IsTrue((tags1 & RecipeTag.LowCarb) == 0);   //Does NOT have LowCarb tag

            Assert.IsFalse((tags1 & tags2) > 0);               //No overlap
            Assert.IsTrue((tags1 & tags3) > 0);                //Both share GlutenFree tag

            //Test comparison operators
            Assert.IsFalse(tags1 == tags2);
            Assert.IsTrue(tags1 == tags4);

            Assert.IsFalse(tags1 == null);
            Assert.IsFalse(tags1 == tags5);
            Assert.IsTrue(tags1 != null);
            Assert.IsTrue(tags5 == null);
            Assert.IsTrue(tags5 == tags6);

            //Test indexing
            Assert.IsTrue(tags1[0] == RecipeTag.GlutenFree);
            Assert.IsTrue(tags1[1] != RecipeTag.GlutenFree);

            //Test Iteration
            var tags = new List <RecipeTag>(2);

            tags.AddRange(tags2);

            Assert.AreEqual(2, tags.Count);
            Assert.AreEqual(tags[0], RecipeTag.LowCalorie);
            Assert.AreEqual(tags[1], RecipeTag.LowFat);

            //Test ToString
            Assert.AreEqual("Gluten Free, No Animals, No Meat, No Pork", tags1.ToString());
            Assert.AreEqual("Gluten Free No Animals No Meat No Pork", tags1.ToString(" "));

            //Test From
            Assert.AreEqual("No Pork", RecipeTags.From(RecipeTag.NoPork).ToString());
            Assert.AreEqual("No Pork, Lunch", RecipeTags.From(RecipeTag.NoPork, RecipeTag.Lunch).ToString());
        }
Esempio n. 8
0
        public void RecipeTagsHasTag_ShouldReturnCorrectResult()
        {
            var tags1 = new RecipeTags(RecipeTag.EasyToMake, RecipeTag.CommonIngredients);

            Assert.IsTrue(tags1.Contains(RecipeTag.EasyToMake));
            Assert.IsTrue(tags1.Contains(RecipeTag.CommonIngredients));
            Assert.IsFalse(tags1.Contains(RecipeTag.Breakfast));
            Assert.IsFalse(tags1.Contains(RecipeTag.LowCalorie));
        }
Esempio n. 9
0
        public void RecipeTagsLength_ShouldReturnCorrectLengthOfTheCollection()
        {
            var tags1 = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);
            var tags2 = new RecipeTags(RecipeTag.Lunch, RecipeTag.GlutenFree);

            // Test counts
            Assert.AreEqual(4, tags1.Length);
            Assert.AreEqual(2, tags2.Length);
        }
Esempio n. 10
0
        public void RecipeCreatorSetTags_ShouldSetRecipeTags()
        {
            var recipeCreator = new RecipeCreator(this.Context);
            var tags          = new RecipeTags(RecipeTag.CommonIngredients);

            recipeCreator.SetTags(tags);

            CollectionAssert.AreEqual(tags, recipeCreator.Recipe.Tags);
        }
Esempio n. 11
0
        public void RecipeTagsHasTag_ShouldReturnCorrectResult()
        {
            var tags1 = new RecipeTags(RecipeTag.EasyToMake, RecipeTag.CommonIngredients);

            Assert.IsTrue(tags1.Contains(RecipeTag.EasyToMake));
            Assert.IsTrue(tags1.Contains(RecipeTag.CommonIngredients));
            Assert.IsFalse(tags1.Contains(RecipeTag.Breakfast));
            Assert.IsFalse(tags1.Contains(RecipeTag.LowCalorie));
        }
Esempio n. 12
0
        public void RecipeTagsLength_ShouldReturnCorrectLengthOfTheCollection()
        {
            var tags1 = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);
            var tags2 = new RecipeTags(RecipeTag.Lunch, RecipeTag.GlutenFree);

            // Test counts
            Assert.AreEqual(4, tags1.Length);
            Assert.AreEqual(2, tags2.Length);
        }
Esempio n. 13
0
        public void RecipeTagsAddMethod_ShouldIncreseLengthPropertyCorrectly()
        {
            var tags1 = new RecipeTags();
            Assert.AreEqual(tags1.Length, 0);

            tags1.Add(RecipeTag.Breakfast);
            tags1.Add(RecipeTag.Dessert);

            Assert.AreEqual(2, tags1.Length);
        }
Esempio n. 14
0
        public void RecipeTagsAddMethod_ShouldAddACorrectElementToTheCollection()
        {
            var tags1 = new RecipeTags();

            tags1.Add(RecipeTag.Breakfast);
            tags1.Add(RecipeTag.Dessert);

            Assert.AreEqual(tags1[0], RecipeTag.Breakfast);
            Assert.AreEqual(tags1[1], RecipeTag.Dessert);
        }
Esempio n. 15
0
        public void RecipeTagsAddMethod_ShouldAddACorrectElementToTheCollection()
        {
            var tags1 = new RecipeTags();

            tags1.Add(RecipeTag.Breakfast);
            tags1.Add(RecipeTag.Dessert);

            Assert.AreEqual(tags1[0], RecipeTag.Breakfast);
            Assert.AreEqual(tags1[1], RecipeTag.Dessert);
        }
Esempio n. 16
0
        public void RecipeTagsAddMethod_ShouldIncreseLengthPropertyCorrectly()
        {
            var tags1 = new RecipeTags();

            Assert.AreEqual(tags1.Length, 0);

            tags1.Add(RecipeTag.Breakfast);
            tags1.Add(RecipeTag.Dessert);

            Assert.AreEqual(2, tags1.Length);
        }
Esempio n. 17
0
        public void RecipeTagsIterator_ShouldIterateTheCollectionCorrectly()
        {
            // Test Iteration
            var tags = new List<RecipeTag>();
            var tags2 = new RecipeTags(RecipeTag.Breakfast, RecipeTag.Dessert, RecipeTag.LowCalorie);
            tags.AddRange(tags2);

            Assert.AreEqual(3, tags.Count);
            Assert.AreEqual(tags[0], RecipeTag.Breakfast);
            Assert.AreEqual(tags[1], RecipeTag.Dessert);
            Assert.AreEqual(tags[2], RecipeTag.LowCalorie);
        }
Esempio n. 18
0
        public static Recipe MockRecipe(string title, string desc, RecipeTags tags = null)
        {
            var ret = new Recipe(Guid.NewGuid(), title, desc, null);

            ret.Method      = "This is a mock recipe.";
            ret.OwnerAlias  = "Fake Owner";
            ret.OwnerId     = Guid.NewGuid();
            ret.Permalink   = "http://www.kitchenpc.com/123";
            ret.ServingSize = 5;
            ret.Tags        = tags;

            return(ret);
        }
        public static Recipe MockRecipe(string title, string desc, RecipeTags tags = null)
        {
            var ret = new Recipe(Guid.NewGuid(), title, desc, null);

            ret.Method = "This is a mock recipe.";
            ret.OwnerAlias = "Fake Owner";
            ret.OwnerId = Guid.NewGuid();
            ret.PermanentLink = "http://www.kitchenpc.com/123";
            ret.ServingSize = 5;
            ret.Tags = tags;

            return ret;
        }
Esempio n. 20
0
        public void RecipeTagsIterator_ShouldIterateTheCollectionCorrectly()
        {
            // Test Iteration
            var tags  = new List <RecipeTag>();
            var tags2 = new RecipeTags(RecipeTag.Breakfast, RecipeTag.Dessert, RecipeTag.LowCalorie);

            tags.AddRange(tags2);

            Assert.AreEqual(3, tags.Count);
            Assert.AreEqual(tags[0], RecipeTag.Breakfast);
            Assert.AreEqual(tags[1], RecipeTag.Dessert);
            Assert.AreEqual(tags[2], RecipeTag.LowCalorie);
        }
Esempio n. 21
0
        public void RecipeTags_ComparisonOperatorsShouldReturnCorrectResult()
        {
            var tags1 = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);
            var tags2 = new RecipeTags(RecipeTag.Lunch, RecipeTag.GlutenFree);
            var tags3 = tags1;
            var tags4 = new RecipeTags(RecipeTag.Lunch, RecipeTag.GlutenFree);

            //Test comparison operators
            Assert.IsTrue(tags1 == tags3);

            Assert.IsFalse(tags1 == tags2);
            Assert.IsFalse(tags2 == tags4);

            Assert.IsFalse(tags1 != tags3);

            Assert.IsTrue(tags1 != tags2);
            Assert.IsTrue(tags2 != tags4);
        }
Esempio n. 22
0
        public void TestParsing()
        {
            RecipeTag dinner = "Dinner";
            RecipeTag lunch  = "Lunch";

            Assert.AreEqual(RecipeTag.Dinner, dinner);
            Assert.AreEqual(RecipeTag.Lunch, lunch);

            string strDinner = RecipeTag.Dinner;
            string strLunch  = RecipeTag.Lunch;

            Assert.AreEqual("Dinner", strDinner);
            Assert.AreEqual("Lunch", strLunch);

            var tags = RecipeTags.Parse("No Red Meat, Dinner, Lunch");

            Assert.AreEqual(3, tags.Length);
            Assert.AreEqual("No Red Meat, Dinner, Lunch", tags.ToString());
        }
Esempio n. 23
0
            public void Dispose()
            {
                var timer = new Stopwatch();

                timer.Start();

                ratingGraph = null;

                //Free up memory/increase index accessing speed by converting List<> objects to arrays
                foreach (var r in snapshot.recipeMap.Values)
                {
                    r.Ingredients = r.Ingredients.ToArray();
                }

                foreach (var i in snapshot.ingredientMap.Values)
                {
                    var temp     = new List <RecipeNode[]>();
                    var usedTags = new RecipeTags();

                    for (var c = 0; c < Enum.GetNames(typeof(RecipeTag)).Length; c++)
                    {
                        RecipeNode[] nodes = null;
                        if (i.RecipesByTag[c] != null)
                        {
                            nodes = i.RecipesByTag[c].ToArray();
                            usedTags.Add((RecipeTag)c);
                        }

                        temp.Add(nodes);
                    }

                    i.RecipesByTag  = temp.ToArray();
                    i.AvailableTags = usedTags;
                }

                GC.Collect(); //Force garbage collection now, since there might be several hundred megs of unreachable allocations

                timer.Stop();
                ModelingSession.Log.InfoFormat("Cleaning up Indexer took {0}ms.", timer.ElapsedMilliseconds);
            }
Esempio n. 24
0
            public void Dispose()
            {
                var timer = new Stopwatch();
                timer.Start();

                ratingGraph = null;

                //Free up memory/increase index accessing speed by converting List<> objects to arrays
                foreach (var r in snapshot.recipeMap.Values)
                {
                    r.Ingredients = r.Ingredients.ToArray();
                }

                foreach (var i in snapshot.ingredientMap.Values)
                {
                    var temp = new List<RecipeNode[]>();
                    var usedTags = new RecipeTags();

                    for (var c = 0; c < Enum.GetNames(typeof(RecipeTag)).Length; c++)
                    {
                        RecipeNode[] nodes = null;
                        if (i.RecipesByTag[c] != null)
                        {
                            nodes = i.RecipesByTag[c].ToArray();
                            usedTags.Add((RecipeTag)c);
                        }

                        temp.Add(nodes);
                    }

                    i.RecipesByTag = temp.ToArray();
                    i.AvailableTags = usedTags;
                }

                GC.Collect(); //Force garbage collection now, since there might be several hundred megs of unreachable allocations

                timer.Stop();
                ModelingSession.Log.InfoFormat("Cleaning up Indexer took {0}ms.", timer.ElapsedMilliseconds);
            }
Esempio n. 25
0
        public void RecipeTagsToString_ShouldReturnCorrectValue()
        {
            // Test ToString
            var tags = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);

            Assert.AreEqual("GlutenFree, NoAnimals, NoMeat, NoPork", tags.ToString());
        }
Esempio n. 26
0
 public RecipeCreator WithTags(RecipeTags tags)
 {
     recipe.Tags = tags;
     return(this);
 }
Esempio n. 27
0
        public void RecipeTagsConstructor_WithMultipleParameters_ShouldConstructACorrectRecipeTagsObject()
        {
            var tags = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);

            CollectionAssert.AreEqual(tags, new RecipeTag[] { RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork });
        }
Esempio n. 28
0
        public IEnumerable<RecipeBinding> LoadRecipeGraph()
        {
            using (var session = this.GetStatelessSession())
            {
                RecipeMetadata metadata = null;
                var recipes = session.QueryOver<Models.Recipes>()
                   .JoinAlias(r => r.RecipeMetadata, () => metadata)
                   .Select(
                      p => p.RecipeId,
                      p => p.Rating,
                      p => metadata.DietGlutenFree,
                      p => metadata.DietNoAnimals,
                      p => metadata.DietNomeat,
                      p => metadata.DietNoPork,
                      p => metadata.DietNoRedMeat,
                      p => metadata.MealBreakfast,
                      p => metadata.MealDessert,
                      p => metadata.MealDinner,
                      p => metadata.MealLunch,
                      p => metadata.NutritionLowCalorie,
                      p => metadata.NutritionLowCarb,
                      p => metadata.NutritionLowFat,
                      p => metadata.NutritionLowSodium,
                      p => metadata.NutritionLowSugar,
                      p => metadata.SkillCommon,
                      p => metadata.SkillEasy,
                      p => metadata.SkillQuick)
                   .List<object[]>();

                List<RecipeBinding> recipeBindings = new List<RecipeBinding>();
                foreach (var recipe in recipes)
                {
                    RecipeTags tags = new RecipeTags();

                    if ((bool)recipe[2])
                    {
                        tags.Add(RecipeTag.GlutenFree);
                    }

                    if ((bool)recipe[3])
                    {
                        tags.Add(RecipeTag.NoAnimals);
                    }

                    if ((bool)recipe[4])
                    {
                        tags.Add(RecipeTag.NoMeat);
                    }

                    if ((bool)recipe[5])
                    {
                        tags.Add(RecipeTag.NoPork);
                    }

                    if ((bool)recipe[6])
                    {
                        tags.Add(RecipeTag.NoRedMeat);
                    }

                    if ((bool)recipe[7])
                    {
                        tags.Add(RecipeTag.Breakfast);
                    }

                    if ((bool)recipe[8])
                    {
                        tags.Add(RecipeTag.Dessert);
                    }

                    if ((bool)recipe[9])
                    {
                        tags.Add(RecipeTag.Dinner);
                    }

                    if ((bool)recipe[10])
                    {
                        tags.Add(RecipeTag.Lunch);
                    }

                    if ((bool)recipe[11])
                    {
                        tags.Add(RecipeTag.LowCalorie);
                    }

                    if ((bool)recipe[12])
                    {
                        tags.Add(RecipeTag.LowCarb);
                    }

                    if ((bool)recipe[13])
                    {
                        tags.Add(RecipeTag.LowFat);
                    }

                    if ((bool)recipe[14])
                    {
                        tags.Add(RecipeTag.LowSodium);
                    }

                    if ((bool)recipe[15])
                    {
                        tags.Add(RecipeTag.LowSugar);
                    }

                    if ((bool)recipe[16])
                    {
                        tags.Add(RecipeTag.CommonIngredients);
                    }

                    if ((bool)recipe[17])
                    {
                        tags.Add(RecipeTag.EasyToMake);
                    }

                    if ((bool)recipe[18])
                    {
                        tags.Add(RecipeTag.Quick);
                    }

                    RecipeBinding recipeBinding = new RecipeBinding()
                                                 {
                                                     Id = (Guid)recipe[0],
                                                     Rating = Convert.ToByte(recipe[1]),
                                                     Tags = tags
                                                 };
                    recipeBindings.Add(recipeBinding);
                }

                return recipeBindings;
            }
        }
Esempio n. 29
0
 public RecipeCreator WithTags(RecipeTags tags)
 {
     this.recipe.Tags = tags;
     return this;
 }
        Dictionary<IngredientNode, IngredientUsage> totals; //Hold totals for each scoring round so we don't have to reallocate map every time

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Create a ModelingSession instance.
        /// </summary>
        /// <param name="context">KitchenPC context used for this modeling session.</param>
        /// <param name="db">Object containing all available recipes, ratings, and trend information.</param>
        /// <param name="profile">Object containing user specific information, such as pantry and user ratings.</param>
        public ModelingSession(IKPCContext context, DBSnapshot db, IUserProfile profile)
        {
            this.db = db;
             this.context = context;
             this.profile = profile;
             this.favTags = new bool[RecipeTag.NUM_TAGS];
             this.favIngs = new int[profile.FavoriteIngredients.Length];

             if (profile.Pantry != null && profile.Pantry.Length == 0) //Empty pantries must be null, not zero items
             {
            throw new EmptyPantryException();
             }

             if (profile.AllowedTags != null)
             {
            AllowedTags = profile.AllowedTags;
             }

             if (profile.Pantry != null)
             {
            pantryAmounts = new Dictionary<IngredientNode, float?>();
            foreach (var item in profile.Pantry)
            {
               var node = this.db.FindIngredient(item.IngredientId);

               //If an ingredient isn't used by any recipe, there's no reason for it to be in the pantry.
               if (node == null)
               {
                  continue;
               }

               //If an ingredient exists, but doesn't have any link to any allowed tags, there's no reason for it to be in the pantry.
               if (AllowedTags != null && (node.AvailableTags & AllowedTags) == 0)
               {
                  continue;
               }

               if (pantryAmounts.ContainsKey(node))
               {
                  throw new DuplicatePantryItemException();
               }

               pantryAmounts.Add(node, item.Amt);
            }

            if (pantryAmounts.Keys.Count == 0)
            {
               throw new ImpossibleQueryException();
            }

            pantryIngredients = pantryAmounts.Keys.ToArray();
             }

             if (profile.FavoriteIngredients != null)
             {
            var i = 0;
            foreach (var ing in profile.FavoriteIngredients)
            {
               var node = this.db.FindIngredient(ing);
               favIngs[i] = node.Key;
            }
             }

             if (profile.FavoriteTags != null)
             {
            foreach (var tag in profile.FavoriteTags)
            {
               this.favTags[tag.Value] = true;
            }
             }

             if (profile.BlacklistedIngredients != null)
             {
            ingBlacklist = new List<IngredientNode>();
            foreach (var ing in profile.BlacklistedIngredients)
            {
               var node = this.db.FindIngredient(ing);
               ingBlacklist.Add(node);
            }
             }

             if (profile.Ratings != null)
             {
            ratings = new Dictionary<RecipeNode, byte>(profile.Ratings.Length);
            foreach (var r in profile.Ratings)
            {
               var n = this.db.FindRecipe(r.RecipeId);
               ratings.Add(n, r.Rating);
            }
             }
             else
             {
            ratings = new Dictionary<RecipeNode, byte>(0);
             }
        }
 public ProfileCreator AllowedTags(RecipeTags tags)
 {
     allowedTags = tags;
      return this;
 }
Esempio n. 32
0
        public void RecipeTags_WithIncorrectIndex_ShouldThrowAnIndexOutOfRangeException()
        {
            var tags1 = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);

            var tag = tags1[-1];
        }
Esempio n. 33
0
        /// <summary>
        /// Create a ModelingSession instance.
        /// </summary>
        /// <param name="context">KitchenPC context used for this modeling session.</param>
        /// <param name="db">Object containing all available recipes, ratings, and trend information.</param>
        /// <param name="profile">Object containing user specific information, such as pantry and user ratings.</param>
        public ModelingSession(IKPCContext context, DBSnapshot db, IUserProfile profile)
        {
            this.db      = db;
            this.context = context;
            this.profile = profile;
            this.favTags = new bool[RecipeTag.NUM_TAGS];
            this.favIngs = new int[profile.FavoriteIngredients.Length];

            if (profile.Pantry != null && profile.Pantry.Length == 0) //Empty pantries must be null, not zero items
            {
                throw new EmptyPantryException();
            }

            if (profile.AllowedTags != null)
            {
                AllowedTags = profile.AllowedTags;
            }

            if (profile.Pantry != null)
            {
                pantryAmounts = new Dictionary <IngredientNode, float?>();
                foreach (var item in profile.Pantry)
                {
                    var node = this.db.FindIngredient(item.IngredientId);

                    //If an ingredient isn't used by any recipe, there's no reason for it to be in the pantry.
                    if (node == null)
                    {
                        continue;
                    }

                    //If an ingredient exists, but doesn't have any link to any allowed tags, there's no reason for it to be in the pantry.
                    if (AllowedTags != null && (node.AvailableTags & AllowedTags) == 0)
                    {
                        continue;
                    }

                    if (pantryAmounts.ContainsKey(node))
                    {
                        throw new DuplicatePantryItemException();
                    }

                    pantryAmounts.Add(node, item.Amt);
                }

                if (pantryAmounts.Keys.Count == 0)
                {
                    throw new ImpossibleQueryException();
                }

                pantryIngredients = pantryAmounts.Keys.ToArray();
            }

            if (profile.FavoriteIngredients != null)
            {
                var i = 0;
                foreach (var ing in profile.FavoriteIngredients)
                {
                    var node = this.db.FindIngredient(ing);
                    favIngs[i] = node.Key;
                }
            }

            if (profile.FavoriteTags != null)
            {
                foreach (var tag in profile.FavoriteTags)
                {
                    this.favTags[tag.Value] = true;
                }
            }

            if (profile.BlacklistedIngredients != null)
            {
                ingBlacklist = new List <IngredientNode>();
                foreach (var ing in profile.BlacklistedIngredients)
                {
                    var node = this.db.FindIngredient(ing);
                    ingBlacklist.Add(node);
                }
            }

            if (profile.Ratings != null)
            {
                ratings = new Dictionary <RecipeNode, byte>(profile.Ratings.Length);
                foreach (var r in profile.Ratings)
                {
                    var n = this.db.FindRecipe(r.RecipeId);
                    ratings.Add(n, r.Rating);
                }
            }
            else
            {
                ratings = new Dictionary <RecipeNode, byte>(0);
            }
        }
Esempio n. 34
0
 public ProfileCreator FavoriteTags(RecipeTags tags)
 {
     this.favTags = tags;
     return(this);
 }
Esempio n. 35
0
        public static RecipeTags ToRecipeTags(RecipeMetadata metadata)
        {
            var tags = new RecipeTags();

            if (metadata.DietGlutenFree)
            {
                tags.Add(RecipeTag.GlutenFree);
            }

            if (metadata.DietNoAnimals)
            {
                tags.Add(RecipeTag.NoAnimals);
            }

            if (metadata.DietNomeat)
            {
                tags.Add(RecipeTag.NoMeat);
            }

            if (metadata.DietNoPork)
            {
                tags.Add(RecipeTag.NoPork);
            }

            if (metadata.DietNoRedMeat)
            {
                tags.Add(RecipeTag.NoRedMeat);
            }

            if (metadata.MealBreakfast)
            {
                tags.Add(RecipeTag.Breakfast);
            }

            if (metadata.MealDessert)
            {
                tags.Add(RecipeTag.Dessert);
            }

            if (metadata.MealDinner)
            {
                tags.Add(RecipeTag.Dinner);
            }

            if (metadata.MealLunch)
            {
                tags.Add(RecipeTag.Lunch);
            }

            if (metadata.NutritionLowCalorie)
            {
                tags.Add(RecipeTag.LowCalorie);
            }

            if (metadata.NutritionLowCarb)
            {
                tags.Add(RecipeTag.LowCarb);
            }

            if (metadata.NutritionLowFat)
            {
                tags.Add(RecipeTag.LowFat);
            }

            if (metadata.NutritionLowSodium)
            {
                tags.Add(RecipeTag.LowSodium);
            }

            if (metadata.NutritionLowSugar)
            {
                tags.Add(RecipeTag.LowSugar);
            }

            if (metadata.SkillCommon)
            {
                tags.Add(RecipeTag.CommonIngredients);
            }

            if (metadata.SkillEasy)
            {
                tags.Add(RecipeTag.EasyToMake);
            }

            if (metadata.SkillQuick)
            {
                tags.Add(RecipeTag.Quick);
            }

            return(tags);
        }
        public void RecipeCreatorSetTags_ShouldSetRecipeTags()
        {
            var recipeCreator = new RecipeCreator(this.Context);
            var tags = new RecipeTags(RecipeTag.CommonIngredients);
            recipeCreator.SetTags(tags);

            CollectionAssert.AreEqual(tags, recipeCreator.Recipe.Tags);
        }
Esempio n. 37
0
        public void RecipeTags_WithCorrectIndex_ShouldReturnCorrectElement()
        {
            var tags1 = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);

            // Test indexing
            Assert.IsTrue(tags1[0] == RecipeTag.GlutenFree);
            Assert.IsTrue(tags1[2] == RecipeTag.NoMeat);
        }
Esempio n. 38
0
        public void RecipeTags_WithIncorrectIndex_ShouldThrowAnIndexOutOfRangeException()
        {
            var tags1 = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);

            var tag = tags1[-1];
        }
Esempio n. 39
0
        public void RecipeTagsConstructor_WithASingleParameter_ShouldConstructACorrectRecipeTagsObject()
        {
            var tags = new RecipeTags(RecipeTag.LowCalorie);

            CollectionAssert.AreEqual(tags, new RecipeTag[] { RecipeTag.LowCalorie });
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ModelingSession"/> class.
        /// </summary>
        /// <param name="context">KitchenPC context used for this modeling session.</param>
        /// <param name="db">Object containing all available recipes, ratings, and trend information.</param>
        /// <param name="profile">Object containing user specific information, such as pantry and user ratings.</param>
        public ModelingSession(IKPCContext context, DBSnapshot db, IUserProfile profile)
        {
            Log = LogManager.GetLogger(typeof(ModelingSession));
            this.dataBase = db;
            this.context = context;
            this.profile = profile;
            this.favoriteTags = new bool[RecipeTag.NumberOfTags];
            this.favoriteIngredients = new int[profile.FavoriteIngredients.Length];

            // Empty pantries must be null, not zero items
            if (this.profile.Pantry != null && this.profile.Pantry.Length == 0)
            {
                throw new EmptyPantryException();
            }

            if (this.profile.AllowedTags != null)
            {
                this.allowedTags = this.profile.AllowedTags;
            }

            if (this.profile.Pantry != null)
            {
                this.pantryAmounts = new Dictionary<IngredientNode, float?>();
                foreach (var item in this.profile.Pantry)
                {
                    var node = this.dataBase.FindIngredient(item.IngredientId);

                    // If an ingredient isn't used by any recipe, there's no reason for it to be in the pantry.
                    if (node == null)
                    {
                        continue;
                    }

                    // If an ingredient exists, but doesn't have any link to any allowed tags, there's no reason for it to be in the pantry.
                    if (this.allowedTags != null && (node.AvailableTags & this.allowedTags) == 0)
                    {
                        continue;
                    }

                    if (this.pantryAmounts.ContainsKey(node))
                    {
                        throw new DuplicatePantryItemException();
                    }

                    this.pantryAmounts.Add(node, item.Amount);
                }

                if (this.pantryAmounts.Keys.Count == 0)
                {
                    throw new ImpossibleQueryException();
                }

                this.pantryIngredients = this.pantryAmounts.Keys.ToArray();
            }

            if (this.profile.FavoriteIngredients != null)
            {
                var i = 0;
                foreach (var ingredient in this.profile.FavoriteIngredients)
                {
                    var node = this.dataBase.FindIngredient(ingredient);
                    this.favoriteIngredients[i] = node.Key;
                }
            }

            if (this.profile.FavoriteTags != null)
            {
                foreach (var tag in this.profile.FavoriteTags)
                {
                    this.favoriteTags[tag.Value] = true;
                }
            }

            if (this.profile.BlacklistedIngredients != null)
            {
                this.ingredientBlacklist = new List<IngredientNode>();
                foreach (var ingredient in this.profile.BlacklistedIngredients)
                {
                    var node = this.dataBase.FindIngredient(ingredient);
                    this.ingredientBlacklist.Add(node);
                }
            }

            if (this.profile.Ratings != null)
            {
                this.ratings = new Dictionary<RecipeNode, byte>(profile.Ratings.Length);
                foreach (var recipe in this.profile.Ratings)
                {
                    var node = this.dataBase.FindRecipe(recipe.RecipeId);
                    this.ratings.Add(node, recipe.Rating);
                }
            }
            else
            {
                this.ratings = new Dictionary<RecipeNode, byte>(0);
            }
        }
Esempio n. 41
0
        public static RecipeTags ToRecipeTags(RecipeMetadata metadata)
        {
            var tags = new RecipeTags();

              if (metadata.DietGlutenFree)
              {
              tags.Add(RecipeTag.GlutenFree);
              }

              if (metadata.DietNoAnimals)
              {
              tags.Add(RecipeTag.NoAnimals);
              }

              if (metadata.DietNomeat)
              {
              tags.Add(RecipeTag.NoMeat);
              }

              if (metadata.DietNoPork)
              {
              tags.Add(RecipeTag.NoPork);
              }

              if (metadata.DietNoRedMeat)
              {
              tags.Add(RecipeTag.NoRedMeat);
              }

              if (metadata.MealBreakfast)
              {
              tags.Add(RecipeTag.Breakfast);
              }

              if (metadata.MealDessert)
              {
              tags.Add(RecipeTag.Dessert);
              }

              if (metadata.MealDinner)
              {
              tags.Add(RecipeTag.Dinner);
              }

              if (metadata.MealLunch)
              {
              tags.Add(RecipeTag.Lunch);
              }

              if (metadata.NutritionLowCalorie)
              {
              tags.Add(RecipeTag.LowCalorie);
              }

              if (metadata.NutritionLowCarb)
              {
              tags.Add(RecipeTag.LowCarb);
              }

              if (metadata.NutritionLowFat)
              {
              tags.Add(RecipeTag.LowFat);
              }

              if (metadata.NutritionLowSodium)
              {
              tags.Add(RecipeTag.LowSodium);
              }

              if (metadata.NutritionLowSugar)
              {
              tags.Add(RecipeTag.LowSugar);
              }

              if (metadata.SkillCommon)
              {
              tags.Add(RecipeTag.CommonIngredients);
              }

              if (metadata.SkillEasy)
              {
              tags.Add(RecipeTag.EasyToMake);
              }

              if (metadata.SkillQuick)
              {
              tags.Add(RecipeTag.Quick);
              }

              return tags;
        }
Esempio n. 42
0
        public void RecipeTags_ComparisonOperatorsShouldReturnCorrectResult()
        {
            var tags1 = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);
            var tags2 = new RecipeTags(RecipeTag.Lunch, RecipeTag.GlutenFree);
            var tags3 = tags1;
            var tags4 = new RecipeTags(RecipeTag.Lunch, RecipeTag.GlutenFree);

            //Test comparison operators
            Assert.IsTrue(tags1 == tags3);

            Assert.IsFalse(tags1 == tags2);
            Assert.IsFalse(tags2 == tags4);

            Assert.IsFalse(tags1 != tags3);

            Assert.IsTrue(tags1 != tags2);
            Assert.IsTrue(tags2 != tags4);
        }
Esempio n. 43
0
 public RecipeCreator SetTags(RecipeTags tags)
 {
     this.recipe.Tags = tags;
     return(this);
 }
Esempio n. 44
0
 public ProfileCreator AllowedTags(RecipeTags tags)
 {
     this.allowedTags = tags;
     return(this);
 }
Esempio n. 45
0
        public void RecipeTagsConstructor_WithASingleParameter_ShouldConstructACorrectRecipeTagsObject()
        {
            var tags = new RecipeTags(RecipeTag.LowCalorie);

            CollectionAssert.AreEqual(tags, new RecipeTag[] { RecipeTag.LowCalorie });
        }
 public ProfileCreator FavoriteTags(RecipeTags tags)
 {
     favTags = tags;
      return this;
 }
Esempio n. 47
0
        public void RecipeTagsConstructor_WithMultipleParameters_ShouldConstructACorrectRecipeTagsObject()
        {
            var tags = new RecipeTags(RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork);

            CollectionAssert.AreEqual(tags, new RecipeTag[] { RecipeTag.GlutenFree, RecipeTag.NoAnimals, RecipeTag.NoMeat, RecipeTag.NoPork });
        }