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

             MealTemplate mealTemplate = dataRepository.GetMealTemplate( FullTestData.CheeseBurgerLunchID );
             MealTemplateViewModel testMealTemplateViewModel =
            new MealTemplateViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext(
            regionNavigationServiceMock.Object, new Uri( "MealTemplateView?ID=" + mealTemplate.ID.ToString(), UriKind.Relative ) );
             testMealTemplateViewModel.OnNavigatedTo( navigationContext );
             testMealTemplateViewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged;
             Assert.AreEqual( mealTemplate.Name, testMealTemplateViewModel.Name );
             Assert.IsFalse( testMealTemplateViewModel.IsDirty );
             Assert.IsTrue( testMealTemplateViewModel.IsValid );

             testMealTemplateViewModel.Name = "Some other name";
             Assert.AreEqual( "Some other name", testMealTemplateViewModel.Name );
             Assert.IsTrue( testMealTemplateViewModel.IsDirty );
             Assert.IsTrue( testMealTemplateViewModel.IsValid );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Name" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) );
             Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count );

             testMealTemplateViewModel.Name = mealTemplate.Name;
             Assert.IsFalse( testMealTemplateViewModel.IsDirty );
             propertyChangedHandler.Reset();

             // Make the name invalid, show that the error is set properly
             testMealTemplateViewModel.Name = "";
             Assert.IsTrue( String.IsNullOrEmpty( testMealTemplateViewModel.Name ) );
             Assert.IsTrue( testMealTemplateViewModel.IsDirty );
             Assert.IsFalse( testMealTemplateViewModel.IsValid );
             Assert.AreEqual( Messages.Error_No_Name, testMealTemplateViewModel.Error );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Name" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsValid" ) );
             Assert.AreEqual( 3, propertyChangedHandler.PropertiesChanged.Count );
        }
        public void MealTemplateViewModelIsDirty()
        {
            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 );

             // Existing Meal Template
             //   Starts clean
             //   Change Name - dirty
             //   Undo - clean
             //   Change Description - dirty
             //   Undo - clean
             MealTemplate cheeseBurgerMealTemplate = dataRepository.GetMealTemplate( FullTestData.CheeseBurgerLunchID );
             Assert.IsNotNull( cheeseBurgerMealTemplate );
             String originalName = cheeseBurgerMealTemplate.Name;
             String originalDescription = cheeseBurgerMealTemplate.Description;

             MealTemplateViewModel cheeseBurgerMealTemplateViewModel =
            new MealTemplateViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext(
            regionNavigationServiceMock.Object, new Uri( "MealTemplateView?ID=" + cheeseBurgerMealTemplate.ID.ToString(), UriKind.Relative ) );
             cheeseBurgerMealTemplateViewModel.OnNavigatedTo( navigationContext );
             Assert.IsFalse( cheeseBurgerMealTemplateViewModel.IsDirty );

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

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

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

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

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

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

             // Test a couple of the easier to test items from the base class to ensure the base
             // class' IsDirty is being called.
             DateTime originalTimeOfMeal = cheeseBurgerMealTemplateViewModel.TimeOfMeal;
             cheeseBurgerMealTemplateViewModel.TimeOfMeal = DateTime.Now;
             Assert.IsTrue( cheeseBurgerMealTemplateViewModel.IsDirty );
             cheeseBurgerMealTemplateViewModel.TimeOfMeal = originalTimeOfMeal;
             Assert.IsFalse( cheeseBurgerMealTemplateViewModel.IsDirty );

             MealType originalMealType = cheeseBurgerMealTemplateViewModel.TypeOfMeal;
             cheeseBurgerMealTemplateViewModel.TypeOfMeal = null;
             Assert.IsTrue( cheeseBurgerMealTemplateViewModel.IsDirty );
             cheeseBurgerMealTemplateViewModel.TypeOfMeal = originalMealType;
             Assert.IsFalse( cheeseBurgerMealTemplateViewModel.IsDirty );
        }
        public void MealTemplateViewModelDescription()
        {
            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();

             MealTemplate testMealTemplate = dataRepository.GetMealTemplate( FullTestData.CheeseBurgerLunchID );
             MealTemplateViewModel testMealTemplateViewModel =
            new MealTemplateViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext(
            regionNavigationServiceMock.Object, new Uri( "MealTempalte?ID=" + testMealTemplate.ID.ToString(), UriKind.Relative ) );
             testMealTemplateViewModel.OnNavigatedTo( navigationContext );
             testMealTemplateViewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged;
             Assert.AreEqual( testMealTemplate.Description, testMealTemplateViewModel.Description );
             Assert.IsFalse( testMealTemplateViewModel.IsDirty );
             Assert.IsTrue( testMealTemplateViewModel.IsValid );

             testMealTemplateViewModel.Description = "Some other description";
             Assert.AreEqual( "Some other description", testMealTemplateViewModel.Description );
             Assert.IsTrue( testMealTemplateViewModel.IsDirty );
             Assert.IsTrue( testMealTemplateViewModel.IsValid );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Description" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "IsDirty" ) );
             Assert.AreEqual( 2, propertyChangedHandler.PropertiesChanged.Count );
        }