Exemplo n.º 1
0
        public void ShouldInitializeIngredientsProperty()
        {
            var wrapper = new RecipeWrapper(_recipeDetailModel);

            Assert.NotNull(wrapper.Ingredients);
            CheckIfModelCollectionIsInSync(wrapper);
        }
Exemplo n.º 2
0
        public void ShouldBeInSyncAfterAddingIngredient()
        {
            _recipeDetailModel.Ingredients.Remove(_ingredientAmountDetailModel);
            var wrapper = new RecipeWrapper(_recipeDetailModel);

            wrapper.Ingredients.Add(new IngredientAmountWrapper(_ingredientAmountDetailModel));
            CheckIfModelCollectionIsInSync(wrapper);
        }
Exemplo n.º 3
0
        public void ShouldBeInSyncAfterRemovingIngredient()
        {
            var wrapper            = new RecipeWrapper(_recipeDetailModel);
            var ingredientToRemove = wrapper.Ingredients.Single(ew => ew.Model == _ingredientAmountDetailModel);

            wrapper.Ingredients.Remove(ingredientToRemove);
            CheckIfModelCollectionIsInSync(wrapper);
        }
Exemplo n.º 4
0
        public void ShouldSetValueOfUnderlyingModelProperty()
        {
            var _ = new RecipeWrapper(_recipeDetailModel)
            {
                Name = "Recipe 1"
            };

            Assert.Equal("Recipe 1", _recipeDetailModel.Name);
        }
Exemplo n.º 5
0
        public void ShouldRaisePropertyChangedEventOnPropertyChange()
        {
            var fired   = false;
            var wrapper = new RecipeWrapper(_recipeDetailModel);

            wrapper.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(RecipeWrapper.Name))
                {
                    fired = true;
                }
            };
            wrapper.Name = "new name";
            Assert.True(fired);
        }
Exemplo n.º 6
0
        public void ShouldNotRaisePropertyChangedEventIfPropertyIsSetToSameValue()
        {
            var fired   = false;
            var wrapper = new RecipeWrapper(_recipeDetailModel);

            wrapper.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == nameof(RecipeWrapper.Name))
                {
                    fired = true;
                }
            };
            wrapper.Name = wrapper.Name;
            Assert.False(fired);
        }
Exemplo n.º 7
0
        public List <RecipeWrapper> getFew(string list)//[FromUri] List<String> ing = null,int page = 1, string mealType = "NO", int missingMax = 0
        {
            List <Ingredient> ingredients = new List <Ingredient>();

            List <Recipe> recipes = _recipeRepository.getAllRecipes();

            List <RecipeWrapper> suggestedRecipes = new List <RecipeWrapper>();

            if (list == null)
            {
                foreach (Recipe r in recipes)
                {
                    suggestedRecipes.Add(new RecipeWrapper(r, 0));
                }
                return(suggestedRecipes);
            }


            foreach (string name in list.Split(','))
            {
                ingredients.Add(_ingredientRepository.getIngredient(name));
            }


            foreach (Recipe recipe in recipes)
            {
                int ingredientCount        = _recipeIngredientRepository.RecipeIngredients.Count(p => p.RecipeId == recipe.Id);
                int matchedIngredientCount = 0;
                foreach (Ingredient ingredient in ingredients)
                {
                    bool found = _recipeIngredientRepository.RecipeIngredients.Any(p => p.RecipeId == recipe.Id && p.IngredientId == ingredient.Id);
                    if (found)
                    {
                        matchedIngredientCount++;
                    }
                }
                if (matchedIngredientCount > 0)
                {
                    RecipeWrapper recipeWrapper = new RecipeWrapper(recipe, ingredientCount - matchedIngredientCount);
                    suggestedRecipes.Add(recipeWrapper);
                }
            }

            return(suggestedRecipes);
        }
Exemplo n.º 8
0
 private void CheckIfModelCollectionIsInSync(RecipeWrapper wrapper)
 {
     Assert.Equal(_recipeDetailModel.Ingredients.Count, wrapper.Ingredients.Count);
     Assert.True(_recipeDetailModel.Ingredients.All(e =>
                                                    wrapper.Ingredients.Any(we => we.Model == e)));
 }
Exemplo n.º 9
0
        public void ShouldGetValueOfUnderlyingModelProperty()
        {
            var wrapper = new RecipeWrapper(_recipeDetailModel);

            Assert.Equal(_recipeDetailModel.Name, wrapper.Name);
        }
Exemplo n.º 10
0
        public void ShouldContainModelInModelProperty()
        {
            var wrapper = new RecipeWrapper(_recipeDetailModel);

            Assert.Equal(_recipeDetailModel, wrapper.Model);
        }