예제 #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);
        }
예제 #2
0
        public void ReturnRightEnumForType()
        {
            var webSource = new RecipeUrlSource();
            var output    = webSource.GetSourceType();

            Assert.Equal(SourceType.WebSource, output);

            var cookbook = new RecipeCookbookSource();

            output = cookbook.GetSourceType();
            Assert.Equal(SourceType.Cookbook, output);

            var invalidSource = new InvalidSource();

            Assert.Throws(typeof(ArgumentException), () => invalidSource.GetSourceType());
        }
예제 #3
0
        public void Convert_RecipeUrlSource_To_WebSourceViewModel()
        {
            Initalize();

            var input = new RecipeUrlSource()
            {
                Id   = 1,
                Name = "TestDomain",
                Url  = "http://www.test.de/source"
            };

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

            Assert.IsType <WebSourceViewModel>(output);
            Assert.Equal(input.Name, output.Name);
            Assert.Equal(input.Url, output.SourceUrl);
            Assert.Equal(input.Id, output.Id);

            Assert.Null(output.Url);
        }
예제 #4
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);
        }
예제 #5
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
                };
            }
예제 #6
0
        private void InitLocalTestData()
        {
            //-------------------- Recipes ---------------------------------------

            var recipe1 = new Recipe()
            {
                Id               = 0,
                Name             = "Recipe 1",
                Calories         = 1,
                CookedCounter    = 0,
                Creator          = "Tester",
                LastTimeCooked   = new DateTime(),
                NumberOfServings = 1
            };

            var recipe2 = new Recipe()
            {
                Id               = 0,
                Name             = "Recipe 2",
                Calories         = 1,
                CookedCounter    = 0,
                Creator          = "Tester",
                LastTimeCooked   = new DateTime(),
                NumberOfServings = 1
            };

            this.Recipes.Add(recipe1);
            this.Recipes.Add(recipe2);

            //-------------------- Sources ---------------------------------------

            var cookbookSource = new RecipeCookbookSource()
            {
                Id   = 0,
                ISBN = "ISBN 978-3-86680-192-9",
                Name = "Cookbook 1",
                PublishingCompany = "ABC Corp"
            };

            var webSource = new RecipeUrlSource()
            {
                Id   = 0,
                Name = "Chefkoch.de",
                Url  = "http://www.chefkoch.de/recipe/1"
            };

            this.Sources.Add(cookbookSource);
            this.Sources.Add(webSource);

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

            var recipe1Step1 = new RecipeStep()
            {
                Id = 0, Recipe = recipe1, RecipeId = recipe1.Id, Order = 0, Description = "Desc 1"
            };
            var recipe1Step2 = new RecipeStep()
            {
                Id = 0, Recipe = recipe1, RecipeId = recipe1.Id, Order = 1, Description = "Desc 2"
            };
            var recipe2Step1 = new RecipeStep()
            {
                Id = 0, Recipe = recipe2, RecipeId = recipe2.Id, Order = 0, Description = "Desc 1"
            };
            var recipe2Step2 = new RecipeStep()
            {
                Id = 0, Recipe = recipe2, RecipeId = recipe2.Id, Order = 1, Description = "Desc 2"
            };
            var recipe2Step3 = new RecipeStep()
            {
                Id = 0, Recipe = recipe2, RecipeId = recipe2.Id, Order = 2, Description = "Desc 3"
            };

            this.Steps.Add(recipe1Step1);
            this.Steps.Add(recipe1Step2);
            this.Steps.Add(recipe2Step1);
            this.Steps.Add(recipe2Step2);
            this.Steps.Add(recipe2Step3);

            recipe1.Steps.Add(recipe1Step1);
            recipe1.Steps.Add(recipe1Step2);

            recipe2.Steps.Add(recipe2Step1);
            recipe2.Steps.Add(recipe2Step2);
            recipe2.Steps.Add(recipe2Step3);

            var ingrediant1 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 1"
            };
            var ingrediant2 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 2"
            };
            var ingrediant3 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 3"
            };
            var ingrediant4 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 4"
            };
            var ingrediant5 = new Ingrediant()
            {
                Id = 0, Name = "Ingrediant 5"
            };

            this.Ingrediants.Add(ingrediant1);
            this.Ingrediants.Add(ingrediant2);
            this.Ingrediants.Add(ingrediant3);
            this.Ingrediants.Add(ingrediant4);
            this.Ingrediants.Add(ingrediant5);

            //-------------------- Images ---------------------------------------

            var image1 = new RecipeImage()
            {
                Id = 0, Recipe = recipe1, RecipeId = recipe1.Id, Filename = "File1.jpg", Url = "http://www.service.de/images/1"
            };
            var image2 = new RecipeImage()
            {
                Id = 0, Recipe = recipe1, RecipeId = recipe1.Id, Filename = "File2.jpg", Url = "http://www.service.de/images/2"
            };
            var image3 = new RecipeImage()
            {
                Id = 0, Recipe = recipe2, RecipeId = recipe2.Id, Filename = "File3.jpg", Url = "http://www.service.de/images/3"
            };

            this.Images.Add(image1);
            this.Images.Add(image2);
            this.Images.Add(image3);

            recipe1.Images.Add(image1);
            recipe1.Images.Add(image2);
            recipe2.Images.Add(image3);

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

            var tag1 = new RecipeTag()
            {
                Id = 0, Name = "Tag 1"
            };
            var tag2 = new RecipeTag()
            {
                Id = 0, Name = "Tag 2"
            };
            var tag3 = new RecipeTag()
            {
                Id = 0, Name = "Tag 3"
            };
            var tag4 = new RecipeTag()
            {
                Id = 0, Name = "Tag 4"
            };

            this.Tags.Add(tag1);
            this.Tags.Add(tag2);
            this.Tags.Add(tag3);
            this.Tags.Add(tag4);
        }