Beispiel #1
0
        public void Convert_RecipeBaseSource_To_SourceListEntryViewModel()
        {
            Initalize();

            var source = new RecipeUrlSource()
            {
                Name = "WebSource", Id = 1, Url = "http://www.websource.de"
            };
            var recipe = new Recipe()
            {
                Name = "recipe 1", Id = 1
            };

            var input = new RecipeSourceRecipe()
            {
                Recipe   = recipe,
                RecipeId = recipe.Id,
                Source   = source,
                SourceId = source.Id,
                Page     = 0
            };

            source.RecipeSourceRecipes.Add(input);
            recipe.SourceId = source.Id;
            recipe.Source   = input;

            var output = Mapper.Map <SourceListEntryViewModel>(source);

            Assert.IsType <SourceListEntryViewModel>(output);
            Assert.Equal(input.Source.Name, output.Name);
            Assert.Equal(source.RecipeSourceRecipes.Count, output.CountRecipes);
            Assert.Equal(input.Source.GetSourceType(), output.Type);
            Assert.Equal(input.SourceId, output.Id);
        }
Beispiel #2
0
        public void Convert_RecipeCookbookSource_To_CookbookSourceViewModel()
        {
            Initalize();

            var source = new RecipeCookbookSource()
            {
                Name = "WebSource", Id = 1, ISBN = "1234", PublishingCompany = "ABC Corp."
            };
            var recipe = new Recipe()
            {
                Name = "recipe 1", Id = 1
            };

            var input = new RecipeSourceRecipe()
            {
                Recipe   = recipe,
                RecipeId = recipe.Id,
                Source   = source,
                SourceId = source.Id,
                Page     = 0
            };

            source.RecipeSourceRecipes.Add(input);
            recipe.SourceId = source.Id;
            recipe.Source   = input;

            var output = Mapper.Map <CookbookSourceViewModel>(source);

            Assert.IsType <CookbookSourceViewModel>(output);
            Assert.Equal(source.Name, output.Name);
            Assert.Equal(source.Id, output.Id);

            var outputRecipe = output.Recipes.FirstOrDefault();

            Assert.NotNull(outputRecipe);
            Assert.Equal(input.Page, outputRecipe.Page);
            Assert.Equal(source.GetSourceType(), outputRecipe.Type);
            Assert.Equal(recipe.Name, outputRecipe.Name);
            Assert.Equal(recipe.Id, outputRecipe.Id);

            Assert.Null(outputRecipe.Url);
            Assert.Null(output.Url);
        }
Beispiel #3
0
        public void Convert_RecipeSourceRecipe_To_RecipeSourceShortInfoViewModel()
        {
            Initalize();

            var source = new RecipeUrlSource()
            {
                Name = "WebSource", Id = 1, Url = "http://www.websource.de"
            };
            var recipe = new Recipe()
            {
                Name = "recipe 1", Id = 1
            };

            var input = new RecipeSourceRecipe()
            {
                Recipe   = recipe,
                RecipeId = recipe.Id,
                Source   = source,
                SourceId = source.Id,
                Page     = 0
            };

            source.RecipeSourceRecipes.Add(input);
            recipe.SourceId = source.Id;
            recipe.Source   = input;

            var output = Mapper.Map <RecipeShortInfoViewModel>(input);

            Assert.IsType <RecipeShortInfoViewModel>(output);
            Assert.Equal(input.Recipe.Name, output.Name);
            Assert.Equal(input.Page, output.Page);
            Assert.Equal(input.Source.GetSourceType(), output.Type);
            Assert.Equal(input.RecipeId, output.Id);

            Assert.Null(output.Url);
        }
Beispiel #4
0
            public RecipeTestData()
            {
                #region Init Recipe

                // ------------------- Generel ----------------------
                Recipe = new Recipe()
                {
                    Name             = "My Recipe",
                    Id               = 1,
                    Calories         = 1,
                    CookedCounter    = 2,
                    Creator          = "Tester",
                    LastTimeCooked   = new DateTime(),
                    NumberOfServings = 3
                };

                // ------------------- Images ----------------------
                var image = new RecipeImage()
                {
                    Recipe   = this.Recipe,
                    Id       = 1,
                    RecipeId = Recipe.Id,
                    Url      = "http://imageUrl.de",
                    Filename = "MyImage.jpg"
                };
                Recipe.Images.Add(image);

                // ------------------- Steps ----------------------

                var steps = new List <RecipeStep>()
                {
                    new RecipeStep()
                    {
                        Recipe = Recipe, Id = 1, RecipeId = Recipe.Id, Order = 0, Description = "Step 1"
                    },
                    new RecipeStep()
                    {
                        Recipe = Recipe, Id = 2, RecipeId = Recipe.Id, Order = 1, Description = "Step 2"
                    }
                };
                Recipe.Steps.AddRange(steps);

                // ------------------- Tags ----------------------

                var tags = new List <RecipeTag>()
                {
                    new RecipeTag()
                    {
                        Id = 1, Name = "Tag 1"
                    },
                    new RecipeTag()
                    {
                        Id = 2, Name = "Tag 2"
                    },
                };

                var recipeTags = new List <RecipeRecipeTag>()
                {
                    new RecipeRecipeTag()
                    {
                        Recipe = Recipe, RecipeId = Recipe.Id, RecipeTag = tags.First(), RecipeTagId = tags.First().Id
                    },
                    new RecipeRecipeTag()
                    {
                        Recipe = Recipe, RecipeId = Recipe.Id, RecipeTag = tags.Last(), RecipeTagId = tags.Last().Id
                    },
                };

                tags.First().Recipes.Add(recipeTags.First());
                tags.Last().Recipes.Add(recipeTags.Last());
                Recipe.Tags.AddRange(recipeTags);

                // ------------------- Source ----------------------

                var source = new RecipeUrlSource()
                {
                    Id   = 1,
                    Name = "WebSource",
                    Url  = "http://www.websource.de"
                };
                var recipeSource = new RecipeSourceRecipe()
                {
                    Page     = 0,
                    Recipe   = Recipe,
                    RecipeId = Recipe.Id,
                    Source   = source,
                    SourceId = source.Id
                };
                source.RecipeSourceRecipes.Add(recipeSource);
                Recipe.Source   = recipeSource;
                Recipe.SourceId = source.Id;

                // ------------------- Ingrediant ----------------------

                var ingrediant = new Ingrediant()
                {
                    Id   = 1,
                    Name = "Ingrediant 1"
                };

                var recipeIngrediant = new RecipeIngrediant()
                {
                    Recipe       = Recipe,
                    RecipeId     = Recipe.Id,
                    Ingrediant   = ingrediant,
                    IngrediantId = ingrediant.Id,
                    Amount       = 1,
                    CookingUnit  = CookingUnit.Gramm
                };
                ingrediant.Recipes.Add(recipeIngrediant);
                Recipe.Ingrediants.Add(recipeIngrediant);

                #endregion
                UpdateModel = new RecipeUpdateViewModel()
                {
                    Id               = 1,
                    Name             = "Old Recipe",
                    Url              = "http://www.webservice.de/recipes/1",
                    Calories         = Recipe.Calories.GetValueOrDefault(),
                    NumberOfServings = Recipe.NumberOfServings
                };
                CreationModel = new RecipeCreationViewModel()
                {
                    Name             = UpdateModel.Name,
                    Calories         = UpdateModel.Calories,
                    NumberOfServings = UpdateModel.NumberOfServings,
                    Creator          = Recipe.Creator
                };
            }
Beispiel #5
0
        private async Task SetManyToManyRelationshipsAsync()
        {
            #region Recipes <-> Sources

            var recipe1 = this.Context.Recipes.First();

            var cookbookSource = this.Sources.First(x => x is RecipeCookbookSource);

            var cookbookRecipe1Connection = new RecipeSourceRecipe()
            {
                Page     = 4,
                Recipe   = recipe1,
                RecipeId = recipe1.Id,
                Source   = cookbookSource,
                SourceId = cookbookSource.Id
            };
            cookbookSource.RecipeSourceRecipes.Add(cookbookRecipe1Connection);
            recipe1.Source   = cookbookRecipe1Connection;
            recipe1.SourceId = cookbookSource.Id;

            var recipe2   = this.Context.Recipes.Last();
            var webSource = this.Sources.First(x => x is RecipeUrlSource);

            var webSourceRecipe2Connection = new RecipeSourceRecipe()
            {
                Recipe   = recipe2,
                RecipeId = recipe2.Id,
                Source   = webSource,
                SourceId = webSource.Id,
                Page     = 0
            };
            webSource.RecipeSourceRecipes.Add(webSourceRecipe2Connection);
            recipe2.Source   = webSourceRecipe2Connection;
            recipe2.SourceId = webSourceRecipe2Connection.SourceId;

            await this.Context.SaveChangesAsync();

            #endregion

            #region Recipes <-> Ingrediants

            var ingrediant1 = Ingrediants.ElementAt(0);
            var ingrediant2 = Ingrediants.ElementAt(1);
            var ingrediant3 = Ingrediants.ElementAt(2);
            var ingrediant4 = Ingrediants.ElementAt(3);
            var ingrediant5 = Ingrediants.ElementAt(4);

            recipe1.Ingrediants.Add(new RecipeIngrediant()
            {
                RecipeId = recipe1.Id, IngrediantId = ingrediant1.Id, Amount = 1, CookingUnit = CookingUnit.Gramm
            });
            recipe1.Ingrediants.Add(new RecipeIngrediant()
            {
                RecipeId = recipe1.Id, IngrediantId = ingrediant2.Id, Amount = 2, CookingUnit = CookingUnit.Kilogramm
            });

            recipe2.Ingrediants.Add(new RecipeIngrediant()
            {
                RecipeId = recipe2.Id, IngrediantId = ingrediant1.Id, Amount = 1, CookingUnit = CookingUnit.Bunch
            });
            recipe2.Ingrediants.Add(new RecipeIngrediant()
            {
                RecipeId = recipe2.Id, IngrediantId = ingrediant4.Id, Amount = 4, CookingUnit = CookingUnit.Liter
            });
            recipe2.Ingrediants.Add(new RecipeIngrediant()
            {
                RecipeId = recipe2.Id, IngrediantId = ingrediant5.Id, Amount = 5, CookingUnit = CookingUnit.Msp
            });
            await this.Context.SaveChangesAsync();

            #endregion

            #region Recipes <-> Tags

            var tag1 = this.Tags.ElementAt(0);
            var tag2 = this.Tags.ElementAt(1);
            var tag3 = this.Tags.ElementAt(2);

            recipe1.Tags.Add(new RecipeRecipeTag()
            {
                RecipeId = recipe1.Id, RecipeTagId = tag1.Id
            });
            recipe1.Tags.Add(new RecipeRecipeTag()
            {
                RecipeId = recipe1.Id, RecipeTagId = tag2.Id
            });
            recipe2.Tags.Add(new RecipeRecipeTag()
            {
                RecipeId = recipe2.Id, RecipeTagId = tag1.Id
            });
            recipe2.Tags.Add(new RecipeRecipeTag()
            {
                RecipeId = recipe2.Id, RecipeTagId = tag3.Id
            });
            await this.Context.SaveChangesAsync();


            #endregion
        }