Beispiel #1
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());
        }
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);
        }