/// <summary>
 /// Sets up the RecipeInformationWindowDialog
 /// </summary>
 /// <param name="recipe">Recipe to show</param>
 /// <param name="window">Window to set as owner</param>
 /// <param name="title">Title to set on the window</param>
 public RecipeInformationWindowDialog(Recipe recipe, Window window, string title)
 {
     _window = new RecipeInformationWindow();
     _window.DataContext = recipe;
     if(window != null)
         _window.Owner = window;
     _window.Title = title;
 }
        public void SetupForTests()
        {
            _testCollector = new Collector(new DatabaseContext());

            _testItem = new Item() {ItemId = 100, Name = "TestItem", IsBought = true};
            _testIngredient = new Ingredient() { ItemId = 101, Name = "TestIngredient", Amount = 10 };
            _testRecipe = new Recipe() {RecipeId = 100,RecipeName = "TestOpskrift", Ingredients = new List<Ingredient>() {_testIngredient, new Ingredient()} };
            _testFoodplan = new Foodplan() { FoodPlanId = 100, CreatedDate = DateTime.Now, RecipeList = new List<Recipe>() {_testRecipe} };
            _testShoppinglist = new Shoppinglist() {ShoppingListId = 100, ShoppingItems = new List<Item>() {_testItem} };
            _tesUser = new User() {UserId = 100,UserName = "******",UserPassword = "******",UserFoodplan = _testFoodplan, UserShoppinglist = _testShoppinglist};

        }
        public void ShowRecipeCommand_UserClickCancel_FoodplanIsNotCalled()
        {
            //Setup
            ISubWindowFactory fac = Substitute.For<ISubWindowFactory>();
            _uut.SetWindowFactory(fac);
            IRecipeInformationWindowDialog dia = Substitute.For<IRecipeInformationWindowDialog>();
            fac.GetRecipeInformationWindow(Arg.Any<Recipe>(), Arg.Any<Window>(), Arg.Any<string>()).Returns(dia);
            dia.ShowDialog().Returns(false);

            Recipe r = new Recipe();
            _uut.ShowRecipeCommand.Execute(r);
            _foodplan.DidNotReceive().Add(r, Arg.Any<DateTime>());
        }
        /// <inheritdoc />
        public IRecipeInformationWindowDialog GetRecipeInformationWindow(Recipe recipe, Window window, string title)
        {
            var win = new RecipeInformationWindowDialog(recipe, window, title);

            return win;
        }
 private void AddRecipe(Window w)
 {
     Recipe recipe = new Recipe();
     recipe.Ingredients = Ingredients.ToList();
     recipe.Procedure = Procedure;
     recipe.RecipeName = RecipeName;
     _recipeListModel.AddRecipeToDb(recipe, FilePath);
     if (w != null)
         w.Close();
 }
        private void ShowRecipe(Recipe recipeToShow)
        {
            Window _win;
            if (Application.ResourceAssembly == null)
                _win = null;
            else
                _win = Application.Current.MainWindow;


            var SRC = _fac.GetRecipeInformationWindow(recipeToShow,
                _win, "");

            if (SRC.ShowDialog())
            {
                _foodplan.Add(recipeToShow, SRC.GetDate());
            }
        }
        /// <summary>
        /// Adds a recipe to foodplan
        /// </summary>
        /// <param name="recipeToAdd"></param>
        private void AddRecipe(Recipe recipeToAdd)
        {
            Window _win;
            if (Application.ResourceAssembly == null)
                _win = null;
            else
                _win = Application.Current.MainWindow;

            var CalenderDialog = _fac.GetCalenderDialog(_win);

            if (CalenderDialog.ShowDialog())
            {
                _foodplan.Add(recipeToAdd, CalenderDialog.GetDate());
            }
        }
        public void AddRecipe_UserClickOK_FoodplanIsCalled()
        {
            //Setup
            ISubWindowFactory fac = Substitute.For<ISubWindowFactory>();
            _uut.SetWindowFactory(fac);
            ICalenderDialog dia = Substitute.For<ICalenderDialog>();
            fac.GetCalenderDialog(Arg.Any<Window>()).Returns(dia);
            dia.ShowDialog().Returns(true);

            Recipe r = new Recipe();
            _uut.AddRecipeCommand.Execute(r);
            _foodplan.Received().Add(r, Arg.Any<DateTime>());
        }
        public void AddRecipe_UserClickCancel_ShoppingListIsNotCalled()
        {
            //Setup
            ISubWindowFactory fac = Substitute.For<ISubWindowFactory>();
            _uut.SetWindowFactory(fac);
            ICalenderDialog dia = Substitute.For<ICalenderDialog>();
            fac.GetCalenderDialog(Arg.Any<Window>()).Returns(dia);
            dia.ShowDialog().Returns(false);

            Recipe r = new Recipe();
            _uut.AddRecipeCommand.Execute(r);
            _shoppingList.DidNotReceive().AddItem(Arg.Any<Item>());
        }
        public void ShowRecipeCommand_IngredientsIsNull_ShoppingListIsNotCalled()
        {
            //Setup
            ISubWindowFactory fac = Substitute.For<ISubWindowFactory>();
            _uut.SetWindowFactory(fac);
            IRecipeInformationWindowDialog dia = Substitute.For<IRecipeInformationWindowDialog>();
            fac.GetRecipeInformationWindow(Arg.Any<Recipe>(), Arg.Any<Window>(), Arg.Any<string>()).Returns(dia);
            dia.ShowDialog().Returns(true);

            Recipe r = new Recipe();
            _uut.ShowRecipeCommand.Execute(r);
            _shoppingList.DidNotReceive().AddItem(Arg.Any<Item>());
        }