public void FoodItemAddedToChildrenWhenAddedToRepository()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             DataRepository dataRepository = new DataRepository( configurationMock.Object );

             FoodItemNodeViewModel foodItemNodeViewModel = new FoodItemNodeViewModel( dataRepository, null );

             Int32 originalChildCount = foodItemNodeViewModel.Children.Count;

             FoodItem newFoodItem = new FoodItem( Guid.NewGuid(), "New Food Item", "Some Description", 92 );
             newFoodItem.FoodGroupsPerServing.Add( new Serving<FoodGroup>( dataRepository.GetAllFoodGroups()[0], 1 ) );
             dataRepository.SaveItem( newFoodItem );
             Assert.AreEqual( originalChildCount + 1, foodItemNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in foodItemNodeViewModel.Children)
             {
            FoodItem foodItem = dataRepository.GetFoodItem( (Guid)node.Parameter );
            Assert.IsNotNull( foodItem );
            Assert.AreEqual( foodItem.Name, node.Name );
             }
        }
        public void MealTemplateAddedToChildrenWhenAddedToRepository()
        {
            var configurationMock = new Mock<IConfiguration>();

             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );

             FullTestData.Reset();
             DataRepository dataRepository = new DataRepository( configurationMock.Object );

             MealTemplateNodeViewModel mealTemplateNodeViewModel = new MealTemplateNodeViewModel( dataRepository, null );

             Int32 originalChildCount = mealTemplateNodeViewModel.Children.Count;

             MealTemplate newMealTemplate = new MealTemplate(
            Guid.NewGuid(), dataRepository.GetAllMealTypes()[0], DateTime.Now, "Test Meal Template", "Just a test" );
             newMealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.GetAllFoodItems()[0], 1 ) );
             dataRepository.SaveItem( newMealTemplate );
             Assert.AreEqual( originalChildCount + 1, mealTemplateNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in mealTemplateNodeViewModel.Children)
             {
            MealTemplate mealTemplate = dataRepository.GetMealTemplate( (Guid)node.Parameter );
            Assert.IsNotNull( mealTemplate );
            Assert.AreEqual( mealTemplate.Name, node.Name );
             }
        }
        public void MealTypeAddedToChildrenWhenAddedToRepository()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             DataRepository dataRepository = new DataRepository( configurationMock.Object );

             MealTypeNodeViewModel mealTypeNodeViewModel = new MealTypeNodeViewModel( dataRepository, null );

             Int32 originalChildCount = mealTypeNodeViewModel.Children.Count;

             MealType newMealType = new MealType( Guid.NewGuid(), "New Meal Type", "Some Description", DateTime.Now, false );
             dataRepository.SaveItem( newMealType );
             Assert.AreEqual( originalChildCount + 1, mealTypeNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in mealTypeNodeViewModel.Children)
             {
            MealType mealType = dataRepository.GetMealType( (Guid)node.Parameter );
            Assert.IsNotNull( mealType );
            Assert.AreEqual( mealType.Name, node.Name );
             }
        }
        public void FoodItemNodeVewModelModifyFoodItem()
        {
            PropertyChangedHandler propertyChangedHandler = new PropertyChangedHandler();

             var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             DataRepository dataRepository = new DataRepository( configurationMock.Object );

             FoodItemNodeViewModel foodItemNodeViewModel = new FoodItemNodeViewModel( dataRepository, null );
             Int32 originalChildCount = foodItemNodeViewModel.Children.Count;

             FoodItem foodItem = dataRepository.GetAllFoodItems().ElementAt( 0 );
             String originalName = foodItem.Name;

             ClickableTreeNodeViewModel foodItemInTree = null;
             foreach (ClickableTreeNodeViewModel child in foodItemNodeViewModel.Children)
             {
            child.PropertyChanged += propertyChangedHandler.OnPropertyChanged;
            if ((Guid)child.Parameter == foodItem.ID)
            {
               foodItemInTree = child;
            }
             }

             Assert.IsNotNull( foodItemInTree );
             Assert.AreEqual( originalName, foodItemInTree.Name );

             foodItem.Name += "Modified";
             dataRepository.SaveItem( foodItem );

             Assert.AreEqual( originalName + "Modified", foodItemInTree.Name );
             Assert.AreEqual( 1, propertyChangedHandler.PropertiesChanged.Count );
             Assert.AreEqual( foodItemInTree, propertyChangedHandler.Sender );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Name" ) );
        }
        public void NonMealTemplateNotAddedToChildrenWhenAddedToRepository()
        {
            var configurationMock = new Mock<IConfiguration>();

             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );

             FullTestData.Reset();
             DataRepository dataRepository = new DataRepository( configurationMock.Object );

             MealTemplateNodeViewModel mealTemplateNodeViewModel = new MealTemplateNodeViewModel( dataRepository, null );

             Int32 originalChildCount = mealTemplateNodeViewModel.Children.Count;

             var mealType = new MealType( Guid.NewGuid(), "A New Meal Type", "This should not already exist", DateTime.Now, false );
             Assert.IsTrue( mealType.IsValid );
             dataRepository.SaveItem( mealType );

             Assert.AreEqual( originalChildCount, mealTemplateNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in mealTemplateNodeViewModel.Children)
             {
            MealTemplate mealTemplate = dataRepository.GetMealTemplate( (Guid)node.Parameter );
            Assert.IsNotNull( mealTemplate );
            Assert.AreEqual( mealTemplate.Name, node.Name );
             }
        }