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 FoodGroupNodeVewModelModifyFoodGroup()
        {
            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();

             FoodGroupNodeViewModel foodGroupNodeViewModel = new FoodGroupNodeViewModel( dataRepository, null );
             Int32 originalChildCount = foodGroupNodeViewModel.Children.Count;

             FoodGroup foodGroup = dataRepository.GetAllFoodGroups().ElementAt( 0 );
             String originalName = foodGroup.Name;

             ClickableTreeNodeViewModel foodGroupInTree = null;
             foreach (ClickableTreeNodeViewModel child in foodGroupNodeViewModel.Children)
             {
            child.PropertyChanged += propertyChangedHandler.OnPropertyChanged;
            if ((Guid)child.Parameter == foodGroup.ID)
            {
               foodGroupInTree = child;
            }
             }

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

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

             Assert.AreEqual( originalName + "Modified", foodGroupInTree.Name );
             Assert.AreEqual( 1, propertyChangedHandler.PropertiesChanged.Count );
             Assert.AreEqual( foodGroupInTree, propertyChangedHandler.Sender );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Name" ) );
        }
        public void FoodItemViewModelTitle()
        {
            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 );

             FoodItemViewModel foodItemViewModel =
            new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             Assert.AreEqual( DisplayStrings.NewFoodItemTitle, foodItemViewModel.Title );

             // Need to navigate to a new food group in order to makes changes and save them.
             NavigationContext navigationContext = new NavigationContext(
            regionNavigationServiceMock.Object, new Uri( "FoodItemView", UriKind.Relative ) );
             foodItemViewModel.OnNavigatedTo( navigationContext );

             Assert.AreEqual( DisplayStrings.NewFoodItemTitle, foodItemViewModel.Title );
             foodItemViewModel.Name = "Test the Title";
             foodItemViewModel.Description = "This is just to test the title";
             foodItemViewModel.CaloriesPerServing = 90;
             foodItemViewModel.FoodGroupsPerServing.Add( new ServingViewModel<FoodGroup>( dataRepository.GetAllFoodGroups()[0], 1 ) );
             Assert.AreEqual( DisplayStrings.NewFoodItemTitle, foodItemViewModel.Title );
             Assert.IsTrue( foodItemViewModel.SaveCommand.CanExecute( null ) );
             foodItemViewModel.SaveCommand.Execute( null );
             Assert.AreEqual( "Test the Title", foodItemViewModel.Title );
        }
        public void FoodItemViewModelValidFoodGroups()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             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 );

             FoodItemViewModel foodItemViewModel =
            new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );

             Assert.IsNotNull( foodItemViewModel.ValidFoodGroups );
             Assert.AreEqual( dataRepository.GetAllFoodGroups().Count, foodItemViewModel.ValidFoodGroups.Items.Count );
        }
        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 );
             }
        }