public void FoodGroupAddedToChildrenWhenAddedToRepository()
        {
            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 );

             FoodGroupNodeViewModel foodGroupNodeViewModel = new FoodGroupNodeViewModel( dataRepository, null );

             Int32 originalChildCount = foodGroupNodeViewModel.Children.Count;

             var newFoodGroup = new FoodGroup( Guid.NewGuid(), "New Food Group", "Some Description" );
             dataRepository.SaveItem( newFoodGroup );
             Assert.AreEqual( originalChildCount + 1, foodGroupNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in foodGroupNodeViewModel.Children)
             {
            FoodGroup foodGroup = dataRepository.GetFoodGroup( (Guid)node.Parameter );
            Assert.IsNotNull( foodGroup );
            Assert.AreEqual( foodGroup.Name, node.Name );
             }
        }
        public void FoodItemViewModelUndoRedo()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             Mock<IRegionNavigationService> regionNavigationServiceMock = new Mock<IRegionNavigationService>();
             Mock<IRegionManager> regionManagerMock = new Mock<IRegionManager>();
             Mock<IInteractionService> interactionServiceMock = new Mock<IInteractionService>();

             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 );

             // TODO: Update this test when the undo and redo is expanded.
             // TODO: Update this test to include Calories (can be done before expansion)
             // Should not be able to undo or redo on a new object.
             ServingViewModel<FoodGroup> waterServing =
            new ServingViewModel<FoodGroup>( dataRepository.GetFoodGroup( FullTestData.WaterID ), 1.0M );
             ServingViewModel<FoodGroup> meatServing =
            new ServingViewModel<FoodGroup>( dataRepository.GetFoodGroup( FullTestData.MeatID ), 1.5M );
             ServingViewModel<FoodGroup> fruitServing =
            new ServingViewModel<FoodGroup>( dataRepository.GetFoodGroup( FullTestData.FruitID ), 2.5M );
             FoodItemViewModel foodItemViewModel =
            new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext( regionNavigationServiceMock.Object, new Uri( "FoodItemView", UriKind.Relative ) );
             foodItemViewModel.OnNavigatedTo( navigationContext );
             Assert.IsFalse( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );

             // Assign values to properties, save, and the load into new view model to reset the undo/redo log
             foodItemViewModel.Name = "Bob";
             foodItemViewModel.Description = "Battery Operated Buddy";
             foodItemViewModel.CaloriesPerServing = 42.0M;
             foodItemViewModel.FoodGroupsPerServing.Add( waterServing );
             navigationContext = new NavigationContext(
            regionNavigationServiceMock.Object, new Uri( "FoodItemView?ID=" + foodItemViewModel.ID.ToString(), UriKind.Relative ) );
             foodItemViewModel.SaveCommand.Execute( null );
             foodItemViewModel = new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             foodItemViewModel.OnNavigatedTo( navigationContext );
             Assert.IsFalse( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );

             // Make changes as such:
             //   o name changed from Bob to Pete
             //   o name changed from Pete to Peter
             //   o Description changed from "Battery Operated Buddy" to "The Rock"
             //   o Add Meat food group serving (1.5)
             //   o Change Calroies to 69
             //   o Add Fruit food group serving (2.5)
             //   o Change Meat servings to 3
             //   o Remove the Fruit food serving
             //   o name changed from Peter to Simon
             //   o name changed from Simon to Saul
             //   o description changed from "The Rock" to "The Persecutor"
             //   o description changed from "The Persecutor" to "The Apostle"
             //   o name changed from Saul to Paul
             // Verify can undo, cannot redo at each step
             foodItemViewModel.Name = "Pete";
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.Name += "r";
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.Description = "The Rock";
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.FoodGroupsPerServing.Add( meatServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.CaloriesPerServing = 69;
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.FoodGroupsPerServing.Add( fruitServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             meatServing.Quantity = 3;
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.FoodGroupsPerServing.Remove( fruitServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.Name = "Simon";
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.Name = "Saul";
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.Description = "The Persecutor";
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.Description = "The Apostle";
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.Name = "Paul";
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );

             Assert.AreEqual( "Paul", foodItemViewModel.Name );
             Assert.AreEqual( "The Apostle", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );

             // Undo once.  Verify last thing done is undone, and we can redo.
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Saul", foodItemViewModel.Name );
             Assert.AreEqual( "The Apostle", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );

             // Redo.  Verify last thing undone is redone, can no longer redo, can still undo.
             foodItemViewModel.RedoCommand.Execute( null );
             Assert.AreEqual( "Paul", foodItemViewModel.Name );
             Assert.AreEqual( "The Apostle", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsFalse( foodItemViewModel.RedoCommand.CanExecute( null ) );

             // Undo 4 times, verify undo worked
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Saul", foodItemViewModel.Name );
             Assert.AreEqual( "The Apostle", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Saul", foodItemViewModel.Name );
             Assert.AreEqual( "The Persecutor", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Saul", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Simon", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );

             // Redo 2 times, verify
             foodItemViewModel.RedoCommand.Execute( null );
             Assert.AreEqual( "Saul", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.RedoCommand.Execute( null );
             Assert.AreEqual( "Saul", foodItemViewModel.Name );
             Assert.AreEqual( "The Persecutor", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );

             // Undo until back to original, cannot undo, can redo
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Saul", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 3, meatServing.Quantity );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Simon", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 3, meatServing.Quantity );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 3, meatServing.Quantity );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 3, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( fruitServing ) );
             Assert.AreEqual( 3, meatServing.Quantity );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 3, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( fruitServing ) );
             Assert.AreEqual( 1.5M, meatServing.Quantity );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 1.5M, meatServing.Quantity );
             Assert.AreEqual( 69, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 1.5M, meatServing.Quantity );
             Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.AreEqual( 1.5M, meatServing.Quantity );
             Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description );
             Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.AreEqual( 1.5M, meatServing.Quantity );
             Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Pete", foodItemViewModel.Name );
             Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description );
             Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.AreEqual( 1.5M, meatServing.Quantity );
             Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.UndoCommand.Execute( null );
             Assert.AreEqual( "Bob", foodItemViewModel.Name );
             Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description );
             Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.AreEqual( 1.5M, meatServing.Quantity );
             Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing );
             Assert.IsFalse( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );

             // Redo 4 times, verify
             foodItemViewModel.RedoCommand.Execute( null );
             Assert.AreEqual( "Pete", foodItemViewModel.Name );
             Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description );
             Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.RedoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "Battery Operated Buddy", foodItemViewModel.Description );
             Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.RedoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 1, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
             foodItemViewModel.RedoCommand.Execute( null );
             Assert.AreEqual( "Peter", foodItemViewModel.Name );
             Assert.AreEqual( "The Rock", foodItemViewModel.Description );
             Assert.AreEqual( 2, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.FoodGroupsPerServing.Contains( meatServing ) );
             Assert.AreEqual( 42, foodItemViewModel.CaloriesPerServing );
             Assert.IsTrue( foodItemViewModel.UndoCommand.CanExecute( null ) );
             Assert.IsTrue( foodItemViewModel.RedoCommand.CanExecute( null ) );
        }
        public void FoodItemViewModelFoodGroupServings()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var regionNavigationServiceMock = new Mock<IRegionNavigationService>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();

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

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

             PropertyChangedHandler propertyChangedHandler = new PropertyChangedHandler();

             // Navigate to a known food group mealType and make sure the food group servings makes sense.
             // NOTE: No need to get too fancy, the model tests makes sure the data loaded properly.
             FoodItem foodItem = dataRepository.GetFoodItem( FullTestData.CheeseBurgerID );
             FoodItemViewModel foodItemViewModel =
            new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext(
            regionNavigationServiceMock.Object, new Uri( "FoodItemView?ID=" + foodItem.ID.ToString(), UriKind.Relative ) );
             foodItemViewModel.OnNavigatedTo( navigationContext );
             foodItemViewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged;
             Assert.AreEqual( foodItem.FoodGroupsPerServing.Count, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsFalse( foodItemViewModel.IsDirty );
             Assert.IsTrue( foodItemViewModel.IsValid );

             // Add a food group
             ServingViewModel<FoodGroup> testFoodServings = new ServingViewModel<FoodGroup>(
            dataRepository.GetFoodGroup( FullTestData.JunkFoodID ), 1 );
             foodItemViewModel.FoodGroupsPerServing.Add( testFoodServings );

             Assert.IsTrue( foodItemViewModel.IsDirty );
             Assert.IsTrue( foodItemViewModel.IsValid );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) );
             Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count );

             foodItemViewModel.FoodGroupsPerServing.Remove( testFoodServings );
             Assert.IsTrue( foodItemViewModel.IsValid );
             Assert.IsFalse( foodItemViewModel.IsDirty );
             propertyChangedHandler.Reset();

             // Delete a food group
             testFoodServings = foodItemViewModel.FoodGroupsPerServing.ElementAt( 0 );
             foodItemViewModel.FoodGroupsPerServing.Remove( testFoodServings );
             Assert.IsTrue( foodItemViewModel.IsDirty );
             Assert.IsTrue( foodItemViewModel.IsValid );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) );
             Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count );

             foodItemViewModel.FoodGroupsPerServing.Add( testFoodServings );
             Assert.IsTrue( foodItemViewModel.IsValid );
             Assert.IsFalse( foodItemViewModel.IsDirty );
             propertyChangedHandler.Reset();

             // Modify a food group
             foodItemViewModel.FoodGroupsPerServing[0].Quantity += 1;
             Assert.AreEqual( foodItem.FoodGroupsPerServing.Count, foodItemViewModel.FoodGroupsPerServing.Count );
             Serving<FoodGroup> modelServing = foodItem.FoodGroupsPerServing.Find( f => f.Entity.ID == foodItemViewModel.FoodGroupsPerServing[0].Entity.ID );
             Assert.IsNotNull( modelServing );
             Assert.IsTrue( foodItemViewModel.IsDirty );
             Assert.IsTrue( foodItemViewModel.IsValid );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) );
             Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count );

             foodItemViewModel.FoodGroupsPerServing[0].Quantity -= 1;
             Assert.IsTrue( foodItemViewModel.IsValid );
             Assert.IsFalse( foodItemViewModel.IsDirty );
             propertyChangedHandler.Reset();

             // Make a serving invalid.
             foodItemViewModel.FoodGroupsPerServing[0].Quantity *= -1;
             Assert.AreEqual( foodItem.FoodGroupsPerServing.Count, foodItemViewModel.FoodGroupsPerServing.Count );
             Assert.IsTrue( foodItemViewModel.IsDirty );
             Assert.IsFalse( foodItemViewModel.IsValid );
             Assert.AreEqual( Messages.Error_No_Quantity, foodItemViewModel.Error );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) );
             Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count );

             foodItemViewModel.FoodGroupsPerServing[0].Quantity *= -1;
             Assert.IsTrue( foodItemViewModel.IsValid );
             Assert.IsFalse( foodItemViewModel.IsDirty );
             propertyChangedHandler.Reset();

             // Remove all food groups
             foodItemViewModel.FoodGroupsPerServing.Clear();
             Assert.IsTrue( foodItemViewModel.IsDirty );
             Assert.IsFalse( foodItemViewModel.IsValid );
             Assert.AreEqual( Messages.Error_No_FoodGroups, foodItemViewModel.Error );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupsPerServing" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) );
             Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count );
        }
        public void FoodGroupViewModelName()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var regionNavigationServiceMock = new Mock<IRegionNavigationService>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();

             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 );

             PropertyChangedHandler propertyChangedHandler = new PropertyChangedHandler();
             FoodGroup testFoodGroup = dataRepository.GetFoodGroup( FullTestData.MeatID );

             // Tests:
             //   o Name is the same as the object from the repository
             //   o Changing the name causes appropriate properties to be marked as changed
             FoodGroupViewModel testFoodGroupViewModel =
            new FoodGroupViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext(
            regionNavigationServiceMock.Object, new Uri( "FoodGroupView?ID=" + FullTestData.MeatID, UriKind.Relative ) );
             testFoodGroupViewModel.OnNavigatedTo( navigationContext );
             testFoodGroupViewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged;
             Assert.AreEqual( testFoodGroup.Name, testFoodGroupViewModel.Name );

             testFoodGroupViewModel.Name = "Some other name";
             Assert.AreEqual( "Some other name", testFoodGroupViewModel.Name );

             Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Name" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) );
        }
        public void FoodGroupViewModelIsDirty()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var regionNavigationServiceMock = new Mock<IRegionNavigationService>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();

             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 );

             // Existing Food group
             //   Starts clean
             //   Change Name - dirty
             //   Undo - clean
             //   Change Description - dirty
             //   Undo - clean
             FoodGroup vegetableFoodGroup = dataRepository.GetFoodGroup( FullTestData.VegetableID );
             Assert.IsNotNull( vegetableFoodGroup );
             String originalName = vegetableFoodGroup.Name;
             String originalDescription = vegetableFoodGroup.Description;

             FoodGroupViewModel vegetableFoodGroupViewModel =
            new FoodGroupViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext(
            regionNavigationServiceMock.Object, new Uri( "DoesItMatter?ID=" + vegetableFoodGroup.ID.ToString(), UriKind.Relative ) );
             vegetableFoodGroupViewModel.OnNavigatedTo( navigationContext );
             Assert.IsFalse( vegetableFoodGroupViewModel.IsDirty );

             vegetableFoodGroupViewModel.Name += "Modified";
             Assert.IsTrue( vegetableFoodGroupViewModel.IsDirty );

             vegetableFoodGroupViewModel.Name = originalName;
             Assert.IsFalse( vegetableFoodGroupViewModel.IsDirty );

             vegetableFoodGroupViewModel.Description += "Different";
             Assert.IsTrue( vegetableFoodGroupViewModel.IsDirty );

             vegetableFoodGroupViewModel.Description = originalDescription;
             Assert.IsFalse( vegetableFoodGroupViewModel.IsDirty );

             vegetableFoodGroupViewModel.Name = null;
             Assert.IsTrue( vegetableFoodGroupViewModel.IsDirty );

             vegetableFoodGroupViewModel.Name = originalName;
             Assert.IsFalse( vegetableFoodGroupViewModel.IsDirty );
        }
        public void FoodGroupNodeViewModelRemoveFoodGroup()
        {
            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 );

             FoodGroupNodeViewModel foodGroupNodeViewModel = new FoodGroupNodeViewModel( dataRepository, null );

             Int32 originalChildCount = foodGroupNodeViewModel.Children.Count;

             FoodGroup removedFoodGroup = dataRepository.GetAllFoodGroups().ElementAt( 0 );
             dataRepository.Remove( removedFoodGroup );
             Assert.AreEqual( originalChildCount - 1, foodGroupNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in foodGroupNodeViewModel.Children)
             {
            FoodGroup foodGroup = dataRepository.GetFoodGroup( (Guid)node.Parameter );
            Assert.IsNotNull( foodGroup );
            Assert.AreEqual( foodGroup.Name, node.Name );
             }
        }
        public void FoodGroupNodeViewModelDefault()
        {
            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 );

             FoodGroupNodeViewModel foodGroupNodeViewModel = new FoodGroupNodeViewModel( dataRepository, null );

             Assert.AreEqual( DisplayStrings.AdminFoodGroupsTitle, foodGroupNodeViewModel.Name );

             // If the counts are the same, and every child is in the repository, then the data should be fine.
             Assert.AreEqual( dataRepository.GetAllFoodGroups().Count, foodGroupNodeViewModel.Children.Count );
             foreach (ClickableTreeNodeViewModel node in foodGroupNodeViewModel.Children)
             {
            FoodGroup foodGroup = dataRepository.GetFoodGroup( (Guid)node.Parameter );
            Assert.IsNotNull( foodGroup );
            Assert.AreEqual( foodGroup.Name, node.Name );
             }
        }