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

             MealTemplateNodeViewModel mealTemplateNodeViewModel = new MealTemplateNodeViewModel( dataRepository, null );
             Int32 originalChildCount = mealTemplateNodeViewModel.Children.Count;

             MealTemplate mealTemplate = dataRepository.GetAllMealTemplates().ElementAt( 0 );
             String originalName = mealTemplate.Name;

             ClickableTreeNodeViewModel mealTemplateInTree = null;
             foreach (ClickableTreeNodeViewModel child in mealTemplateNodeViewModel.Children)
             {
            child.PropertyChanged += propertyChangedHandler.OnPropertyChanged;
            if ((Guid)child.Parameter == mealTemplate.ID)
            {
               mealTemplateInTree = child;
            }
             }

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

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

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

             MealTemplateNodeViewModel mealTemplateNodeViewModel = new MealTemplateNodeViewModel( dataRepository, null );

             Int32 originalChildCount = mealTemplateNodeViewModel.Children.Count;

             MealTemplate removedMealTemplate = dataRepository.GetAllMealTemplates().ElementAt( 0 );
             dataRepository.Remove( removedMealTemplate );
             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 NavigateToNewMealTemplate()
        {
            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 MealTemplateViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );

             var navigationContext =
            new NavigationContext( regionNavigationServiceMock.Object, new Uri( "MealTemplateView", UriKind.Relative ) );
             viewModel.OnNavigatedTo( navigationContext );
             foreach (var mealTemplate in dataRepository.GetAllMealTemplates())
             {
            Assert.AreNotEqual( mealTemplate.ID, viewModel.ID );
             }
             Assert.IsNull( viewModel.Name );
             Assert.IsNull( viewModel.Description );
             Assert.AreEqual( 0, viewModel.FoodItemServings.Count );
             Assert.IsFalse( viewModel.IsDirty );
             Assert.AreEqual( DateTime.Now.Date, viewModel.TimeOfMeal );
        }
        public void MealTemplateNodeViewModelDefault()
        {
            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 );

             MealTemplateNodeViewModel mealTemplateNodeViewModel = new MealTemplateNodeViewModel( dataRepository, null );

             Assert.AreEqual( DisplayStrings.AdminMealTemplatesTitle, mealTemplateNodeViewModel.Name );

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

             MealTemplateViewModel mealTemplateViewModel =
            new MealTemplateViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext;

             // Meal templates in the repository cannot be used.
             foreach (MealTemplate mealTemplate in dataRepository.GetAllMealTemplates())
             {
            navigationContext = new NavigationContext(
               regionNavigationServiceMock.Object, new Uri( "MealTemplateView?ID=" + mealTemplate.ID.ToString(), UriKind.Relative ) );
            Assert.IsFalse( mealTemplateViewModel.IsUsed );
             }

             navigationContext = new NavigationContext( regionNavigationServiceMock.Object, new Uri( "MealTemplateView", UriKind.Relative ) );
             mealTemplateViewModel.OnNavigatedTo( navigationContext );
             Assert.IsFalse( mealTemplateViewModel.IsUsed );
        }