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 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 FoodItemNodeViewModelRemoveFoodItem()
        {
            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 removedFoodItem = dataRepository.GetAllFoodItems().ElementAt( 0 );
             dataRepository.Remove( removedFoodItem );
             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 FoodItemNodeViewModelDefault()
        {
            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 );

             Assert.AreEqual( DisplayStrings.AdminFoodItemsTitle, foodItemNodeViewModel.Name );

             // If the counts are the same, and every child is in the repository, then the data should be fine.
             Assert.AreEqual( dataRepository.GetAllFoodItems().Count, 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 NavigateToNewFoodItem()
        {
            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 );

             var viewModel =
            new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             var navigationContext =
            new NavigationContext( regionNavigationServiceMock.Object, new Uri( "FoodItemViewModel", UriKind.Relative ) );
             viewModel.OnNavigatedTo( navigationContext );
             foreach (var foodItem in dataRepository.GetAllFoodItems())
             {
            Assert.AreNotEqual( foodItem.ID, viewModel.ID );
             }
             Assert.IsNull( viewModel.Name );
             Assert.IsNull( viewModel.Description );
             Assert.AreEqual( 0, viewModel.FoodGroupsPerServing.Count );
             Assert.IsFalse( viewModel.IsDirty );
        }
        public void MealTemplateViewModelTitle()
        {
            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 );

             // NOTE: The title being assigned properly out of construction is actually tested via the constructor tests.
             //       This test just ensure the title changes after a save, but not before.
             MealTemplateViewModel mealTemplateViewModel =
            new MealTemplateViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext( regionNavigationServiceMock.Object, new Uri( "MealTemplateView", UriKind.Relative ) );
             mealTemplateViewModel.OnNavigatedTo( navigationContext );

             Assert.AreEqual( DisplayStrings.NewMealTemplateTitle, mealTemplateViewModel.Title );
             mealTemplateViewModel.Name = "Test the Title";
             mealTemplateViewModel.Description = "This is just to test the title";
             mealTemplateViewModel.TimeOfMeal = DateTime.Now;
             mealTemplateViewModel.TypeOfMeal = dataRepository.GetAllMealTypes()[0];
             mealTemplateViewModel.FoodItemServings.Add( new ServingViewModel<FoodItem>( dataRepository.GetAllFoodItems()[0], 1 ) );
             Assert.AreEqual( DisplayStrings.NewMealTemplateTitle, mealTemplateViewModel.Title );
             Assert.IsTrue( mealTemplateViewModel.SaveCommand.CanExecute( null ) );
             mealTemplateViewModel.SaveCommand.Execute( null );
             Assert.AreEqual( "Test the Title", mealTemplateViewModel.Title );
        }