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

             FoodItemViewModel testFoodItemViewModel =
            new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext( regionNavigationServiceMock.Object, new Uri( "FoodItemView", UriKind.Relative ) );
             testFoodItemViewModel.OnNavigatedTo( navigationContext );
             Assert.IsFalse( testFoodItemViewModel.IsValid );
             Assert.AreEqual( Messages.Error_No_Name, testFoodItemViewModel["Name"] );
             Assert.AreEqual( Messages.Error_No_FoodGroups, testFoodItemViewModel["FoodGroupsPerServing"] );
             Assert.IsTrue( String.IsNullOrEmpty( testFoodItemViewModel["Description"] ) );

             testFoodItemViewModel.Name = "Fruit Salad";
             testFoodItemViewModel.FoodGroupsPerServing.Add(
            new ServingViewModel<FoodGroup>(
               dataRepository.FindFoodGroup( fg => fg.Name == "Fruit" ), 1 ) );
             Assert.IsFalse( testFoodItemViewModel.IsValid );
             Assert.AreEqual( Messages.Error_FoodItem_Exists, testFoodItemViewModel["Name"] );
             Assert.IsTrue( String.IsNullOrEmpty( testFoodItemViewModel["FoodGroupsPerServing"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testFoodItemViewModel["Description"] ) );

             testFoodItemViewModel.Name = "Some Unique Name";
             Assert.IsTrue( testFoodItemViewModel.IsValid );
             Assert.IsTrue( String.IsNullOrEmpty( testFoodItemViewModel.Error ) );
             Assert.IsTrue( String.IsNullOrEmpty( testFoodItemViewModel["Name"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testFoodItemViewModel["FoodGroupsPerServing"] ) );
             Assert.IsTrue( String.IsNullOrEmpty( testFoodItemViewModel["Description"] ) );
        }
        public void FoodItemViewModelIsDirty()
        {
            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 Food Item
             //   Starts clean
             //   Change Name - dirty
             //   Undo - clean
             //   Change Description - dirty
             //   Undo - clean
             //   Change Calories - dirty
             //   Undo - clean
             //   Change Food Group Serving - dirty
             //   Undo - clean
             //   Add food group - dirty
             //   undo - clean
             //
             FoodItem cheeseBurger = dataRepository.GetFoodItem( FullTestData.CheeseBurgerID );
             Assert.IsNotNull( cheeseBurger );
             String originalName = cheeseBurger.Name;
             String originalDescription = cheeseBurger.Description;

             FoodItemViewModel cheeseBurgerViewModel =
            new FoodItemViewModel( dataRepository, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             NavigationContext navigationContext = new NavigationContext(
            regionNavigationServiceMock.Object, new Uri( "FoodItemView?ID=" + cheeseBurger.ID.ToString(), UriKind.Relative ) );
             cheeseBurgerViewModel.OnNavigatedTo( navigationContext );
             Assert.IsFalse( cheeseBurgerViewModel.IsDirty );

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

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

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

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

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

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

             cheeseBurgerViewModel.CaloriesPerServing += 90;
             Assert.IsTrue( cheeseBurgerViewModel.IsDirty );

             cheeseBurgerViewModel.CaloriesPerServing -= 90;
             Assert.IsFalse( cheeseBurgerViewModel.IsDirty );

             cheeseBurgerViewModel.FoodGroupsPerServing[0].Quantity += 1;
             Assert.IsTrue( cheeseBurgerViewModel.IsDirty );

             cheeseBurgerViewModel.FoodGroupsPerServing[0].Quantity -= 1;
             Assert.IsFalse( cheeseBurgerViewModel.IsDirty );

             ServingViewModel<FoodGroup> serving = cheeseBurgerViewModel.FoodGroupsPerServing[0];
             cheeseBurgerViewModel.FoodGroupsPerServing.Remove( serving );
             Assert.IsTrue( cheeseBurgerViewModel.IsDirty );

             // Create an exact duplicate of the servings.
             ServingViewModel<FoodGroup> copyOfServing = new ServingViewModel<FoodGroup>( serving.Entity, serving.Quantity );

             cheeseBurgerViewModel.FoodGroupsPerServing.Add( copyOfServing );
             Assert.IsFalse( cheeseBurgerViewModel.IsDirty );

             serving = new ServingViewModel<FoodGroup>(
            dataRepository.FindFoodGroup( fg => fg.Name == "Water" ), 1 );
             cheeseBurgerViewModel.FoodGroupsPerServing.Add( serving );
             Assert.IsTrue( cheeseBurgerViewModel.IsDirty );

             cheeseBurgerViewModel.FoodGroupsPerServing.Remove( serving );
             Assert.IsFalse( cheeseBurgerViewModel.IsDirty );
        }