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 MealTemplateAddedToViewModelWhenAddedToRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.MealTemplates() );

             var viewModel = new AllMealTemplatesViewModel( dataRespositoryMock.Object );
             var mealTemplate = new MealTemplate( Guid.NewGuid(), data.MealTypes().Find( mt => mt.ID == MockData.dinnerID ), DateTime.Today.AddHours( 18 ), "Dine-in", "Eatme" );
             data.MealTemplates().Add( mealTemplate );
             dataRespositoryMock.Raise( e => e.ItemAdded += null, new RepositoryObjectEventArgs( mealTemplate ) );

             AssertViewModelContents( viewModel, data.MealTemplates() );
        }
        public void InitializeData()
        {
            FoodGroup fruit = new FoodGroup( Guid.NewGuid(), "Fruit", "" );
             FoodGroup meat = new FoodGroup( Guid.NewGuid(), "Meat", "" );
             FoodGroup vegitable = new FoodGroup( Guid.NewGuid(), "Vegetable", "" );
             FoodGroup dairy = new FoodGroup( Guid.NewGuid(), "Dairy", "" );
             FoodGroup grain = new FoodGroup( Guid.NewGuid(), "Grain", "" );
             MealType lunch = new MealType( Guid.NewGuid(), "Lunch", "", DateTime.Now, false );
             MealType snack = new MealType( Guid.NewGuid(), "Snack", "", DateTime.Now, false );
             DateTime currentDateTime = DateTime.Now;

             FoodItem hamburger = new FoodItem( Guid.NewGuid(), "Hamburger", "", 300 );
             hamburger.FoodGroupsPerServing.Add( new Serving<FoodGroup>( grain, 2 ) );
             hamburger.FoodGroupsPerServing.Add( new Serving<FoodGroup>( meat, 1 ) );

             FoodItem glassOfMilk = new FoodItem( Guid.NewGuid(), "Glass of Milk", "", 90 );
             glassOfMilk.FoodGroupsPerServing.Add( new Serving<FoodGroup>( dairy, 1 ) );

             FoodItem babyCarrots = new FoodItem( Guid.NewGuid(), "Baby Carrots", "", 40 );
             babyCarrots.FoodGroupsPerServing.Add( new Serving<FoodGroup>( vegitable, 1 ) );

             MealTemplate sourceMealTemplate = new MealTemplate( Guid.NewGuid(), lunch, currentDateTime, "Test Meal", "This is a test" );
             sourceMealTemplate.FoodItemServings.Add( new Serving<FoodItem>( hamburger, 1 ) );
             sourceMealTemplate.FoodItemServings.Add( new Serving<FoodItem>( glassOfMilk, 2 ) );
             sourceMealTemplate.FoodItemServings.Add( new Serving<FoodItem>( babyCarrots, 1.5M ) );

             MealTemplate mealTemplate = new MealTemplate();
             Assert.AreNotEqual( sourceMealTemplate.ID, mealTemplate.ID );

             mealTemplate.InitializeData( sourceMealTemplate );
             Assert.AreEqual( sourceMealTemplate.ID, mealTemplate.ID );
             Assert.AreEqual( sourceMealTemplate.Name, mealTemplate.Name );
             Assert.AreEqual( sourceMealTemplate.Description, mealTemplate.Description );
             Assert.AreEqual( sourceMealTemplate.Calories, mealTemplate.Calories );
             Assert.AreEqual( sourceMealTemplate.FoodGroupServings.Count, mealTemplate.FoodGroupServings.Count );
             Assert.AreEqual( sourceMealTemplate.FoodItemServings.Count, mealTemplate.FoodItemServings.Count );

             mealTemplate.FoodItemServings[0].Quantity += 1;
             Assert.AreNotEqual( sourceMealTemplate.Calories, mealTemplate.Calories );

             // Create a new mealTemplate template that is just baby carrots (kind of a snack)
             sourceMealTemplate = new MealTemplate( Guid.NewGuid(), snack, DateTime.Now, "Snack", "This is a snack" );
             sourceMealTemplate.FoodItemServings.Add( new Serving<FoodItem>( babyCarrots, 2.5M ) );

             mealTemplate.InitializeData( sourceMealTemplate );
             Assert.AreEqual( sourceMealTemplate.ID, mealTemplate.ID );
             Assert.AreEqual( sourceMealTemplate.Name, mealTemplate.Name );
             Assert.AreEqual( sourceMealTemplate.Description, mealTemplate.Description );
             Assert.AreEqual( sourceMealTemplate.Calories, mealTemplate.Calories );
             Assert.AreEqual( sourceMealTemplate.FoodGroupServings.Count, mealTemplate.FoodGroupServings.Count );
             Assert.AreEqual( sourceMealTemplate.FoodItemServings.Count, mealTemplate.FoodItemServings.Count );
        }
Example #4
0
 public MealTemplate( MealTemplate mealTemplate )
     : base(mealTemplate)
 {
 }
        public void DeleteMealTemplate()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             HealthTracker.DataRepository.Services.DataRepository dataRepository = new HealthTracker.DataRepository.Services.DataRepository( configurationMock.Object );

             // Make a deep copy of a currentMealTemplate template
             MealTemplate chzBurger = new MealTemplate();
             chzBurger.InitializeData( dataRepository.FindMealTemplate( mt => mt.Name == "Cheeseburger Lunch" ) );
             Assert.IsNotNull( chzBurger );

             // Delete the currentMealTemplate template.  Show that the currentMealTemplate template has been deleted, but none of the
             // other data repository items have not been effected.
             Int32 origFoodGroupCount = dataRepository.GetAllFoodGroups().Count;
             Int32 origFoodItemCount = dataRepository.GetAllFoodItems().Count;
             Int32 origMealTypeCount = dataRepository.GetAllMealTypes().Count;
             Int32 origMealTemplateCount = dataRepository.GetAllMealTemplates().Count;
             Int32 origMealCount = dataRepository.GetAllMeals().Count;
             dataRepository.Remove( chzBurger );
             Assert.AreEqual( origFoodGroupCount, dataRepository.GetAllFoodGroups().Count );
             Assert.AreEqual( origFoodItemCount, dataRepository.GetAllFoodItems().Count );
             Assert.AreEqual( origMealTypeCount, dataRepository.GetAllMealTypes().Count );
             Assert.AreEqual( origMealTemplateCount - 1, dataRepository.GetAllMealTemplates().Count );
             Assert.AreEqual( origMealCount, dataRepository.GetAllMeals().Count );
             Assert.IsNotNull( chzBurger.ID );
             Assert.IsNull( dataRepository.FindMealTemplate( mt => mt.ID == chzBurger.ID ) );
        }
        public void SaveMealTemplate()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             HealthTracker.DataRepository.Services.DataRepository dataRepository = new HealthTracker.DataRepository.Services.DataRepository( configurationMock.Object );

             // Get some food items that we can use for the new Meal Template.
             FoodItem fruitSalad = dataRepository.FindFoodItem( f => f.ID == FullTestData.FruitSaladID );
             FoodItem glassOfMilk = dataRepository.FindFoodItem( f => f.ID == FullTestData.GlassOfMilkID );
             FoodItem glassOfWater = dataRepository.FindFoodItem( f => f.ID == FullTestData.GlassOfWaterID );

             MealType breakfast = dataRepository.FindMealType( f => f.ID == FullTestData.BreakfastID );

             // Create one new Meal Template, and get a deep copy of one out of the repository.
             // When the new one is saved, a meal template should be added to the repository.
             // When the deep copy of the existing one is modified, the modifications should not be applied to the repository
             // until the copy is saved, at which a new meal template should not be created, but the meal template object with
             // the same ID should have the modifications applied to it.
             MealTemplate fruitBreakfast = new MealTemplate( new Guid( "63a29a24-d2cb-40b1-9826-b355943817ab" ),
            breakfast, DateTime.Now, "Fruit Breakfast", "Fruit Salad and some milk" );
             fruitBreakfast.FoodItemServings.Add( new Serving<FoodItem>( fruitSalad, 1 ) );
             fruitBreakfast.FoodItemServings.Add( new Serving<FoodItem>( glassOfMilk, 1 ) );
             Assert.IsTrue( fruitBreakfast.IsValid );

             MealTemplate repositoryChzBurgerLunch = dataRepository.FindMealTemplate( m => m.ID == FullTestData.CheeseBurgerLunchID );
             Assert.IsNotNull( repositoryChzBurgerLunch );
             MealTemplate chzBurgerLunch = new MealTemplate();
             chzBurgerLunch.InitializeData( repositoryChzBurgerLunch );
             Int32 origMealTemplateCount = dataRepository.GetAllMealTemplates().Count;

             // Verifiy the copies are the same
             Assert.AreEqual( repositoryChzBurgerLunch.ID, chzBurgerLunch.ID );
             Assert.AreEqual( repositoryChzBurgerLunch.Name, chzBurgerLunch.Name );
             Assert.AreEqual( repositoryChzBurgerLunch.Description, chzBurgerLunch.Description );
             Assert.AreEqual( repositoryChzBurgerLunch.Calories, chzBurgerLunch.Calories );
             Assert.AreEqual( repositoryChzBurgerLunch.FoodItemServings.Count, chzBurgerLunch.FoodItemServings.Count );

             // Replace the glasses of milk with a glass of water, and only have one burger
             chzBurgerLunch.FoodItemServings.Remove( chzBurgerLunch.FoodItemServings.Find( f => f.Entity.ID == FullTestData.GlassOfMilkID ) );
             chzBurgerLunch.FoodItemServings.Add( new Serving<FoodItem>( glassOfWater, 1.5M ) );
             chzBurgerLunch.FoodItemServings.Find( f => f.Entity.ID == FullTestData.CheeseBurgerID ).Quantity = 1;
             chzBurgerLunch.Description = "A typical cheese burger lunch, made a bit healthier";

             repositoryChzBurgerLunch = dataRepository.FindMealTemplate( m => m.ID == FullTestData.CheeseBurgerLunchID );
             Assert.AreEqual( repositoryChzBurgerLunch.ID, chzBurgerLunch.ID );
             Assert.AreEqual( repositoryChzBurgerLunch.Name, chzBurgerLunch.Name );
             Assert.AreNotEqual( repositoryChzBurgerLunch.Description, chzBurgerLunch.Description );
             Assert.AreNotEqual( repositoryChzBurgerLunch.Calories, chzBurgerLunch.Calories );

             // Save the changes and verify the changes were saved
             dataRepository.SaveItem( chzBurgerLunch );
             repositoryChzBurgerLunch = dataRepository.FindMealTemplate( m => m.ID == FullTestData.CheeseBurgerLunchID );
             Assert.AreEqual( chzBurgerLunch.Name, repositoryChzBurgerLunch.Name );
             Assert.AreEqual( chzBurgerLunch.Description, repositoryChzBurgerLunch.Description );
             Assert.AreEqual( chzBurgerLunch.FoodItemServings.Count, repositoryChzBurgerLunch.FoodItemServings.Count );
             Assert.AreEqual( chzBurgerLunch.Calories, repositoryChzBurgerLunch.Calories );
             Assert.AreEqual( origMealTemplateCount, dataRepository.GetAllMealTemplates().Count );

             // Save the breakfast
             dataRepository.SaveItem( fruitBreakfast );
             Assert.AreEqual( origMealTemplateCount + 1, dataRepository.GetAllMealTemplates().Count );
             MealTemplate repositoryFruitBreakfast = dataRepository.FindMealTemplate( f => f.ID == new Guid( "63a29a24-d2cb-40b1-9826-b355943817ab" ) );
             Assert.IsNotNull( repositoryFruitBreakfast );
             Assert.AreEqual( fruitBreakfast.ID, repositoryFruitBreakfast.ID );
             Assert.AreEqual( fruitBreakfast.Name, repositoryFruitBreakfast.Name );
             Assert.AreEqual( fruitBreakfast.Description, repositoryFruitBreakfast.Description );
             Assert.AreEqual( fruitBreakfast.FoodItemServings.Count, repositoryFruitBreakfast.FoodItemServings.Count );
             Assert.AreEqual( fruitBreakfast.Calories, repositoryFruitBreakfast.Calories );
        }
        public void SaveNotCalledForNonChangedMealTemplate()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var regionManagerMock = new Mock<IRegionManager>();
             var regionNavigationServiceMock = new Mock<IRegionNavigationService>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var interactionServiceMock = new Mock<IInteractionService>();

             var mealTemplate = new MealTemplate( Guid.NewGuid(), new MealType( Guid.NewGuid(), "Meal Type", "", DateTime.Now, false ), DateTime.Now, "Template", "" );
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( new FoodItem( Guid.NewGuid(), "Test Item", "", 420 ), 1 ) );

             dataRepositoryMock.Setup( x => x.GetAllFoodItems() )
            .Returns( new ReadOnlyCollection<FoodItem>( new List<FoodItem>() ) );
             dataRepositoryMock.Setup( x => x.GetAllMealTypes() )
            .Returns( new ReadOnlyCollection<MealType>( new List<MealType>() ) );
             dataRepositoryMock.Setup( x => x.Contains( It.IsAny<MealTemplate>() ) ).Returns( true );
             dataRepositoryMock.Setup( x => x.GetMealTemplate( mealTemplate.ID ) ).Returns( mealTemplate );

             var mealTemplateViewModel =
            new MealTemplateViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             var navigationContext = new NavigationContext( regionNavigationServiceMock.Object,
            new Uri( "MealTemplateView?ID=" + mealTemplate.ID.ToString(), UriKind.Relative ) );
             mealTemplateViewModel.OnNavigatedTo( navigationContext );

             Assert.IsTrue( mealTemplateViewModel.IsValid );
             Assert.IsFalse( mealTemplateViewModel.IsDirty );
             Assert.IsFalse( mealTemplateViewModel.IsNew );

             mealTemplateViewModel.SaveCommand.Execute( null );

             dataRepositoryMock.Verify( x => x.SaveItem( It.IsAny<MealTemplate>() ), Times.Never() );
        }
        public void MealTemplateName()
        {
            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 );

             MealTemplate mealTemplate = new MealTemplate( Guid.NewGuid(), dataRepository.FindMealType( mt => mt.Name == "Dinner" ),
            DateTime.Now, "Just a test mealTemplate", "" );

             Assert.IsNull( mealTemplate["Name"] );

             // Use String w/ just whitespace
             mealTemplate.Name = "      ";
             Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );
             Assert.IsNull( mealTemplate.Name );

             // Whitespace on front
             mealTemplate.Name = "   The Name";
             Assert.IsNull( mealTemplate["Name"] );
             Assert.AreEqual( "The Name", mealTemplate.Name );

             // Whitespace on end
             mealTemplate.Name = "The Name    ";
             Assert.IsNull( mealTemplate["Name"] );
             Assert.AreEqual( "The Name", mealTemplate.Name );

             // Whitespace on front and end
             mealTemplate.Name = "   The Name     ";
             Assert.IsNull( mealTemplate["Name"] );
             Assert.AreEqual( "The Name", mealTemplate.Name );

             // Only whitespace in middle
             mealTemplate.Name = "The Name";
             Assert.IsNull( mealTemplate["Name"] );
             Assert.AreEqual( "The Name", mealTemplate.Name );
        }
        /// <summary>
        /// Remove a mealTemplate template from the repository.
        /// </summary>
        /// <param name="mealTemplate">The mealTemplate template to remove.</param>
        public void Remove( MealTemplate mealTemplate )
        {
            Debug.Assert( mealTemplate != null );

             if (Contains( mealTemplate ))
             {
            _mealTemplates.Remove( _mealTemplates.Find( mt => mt.ID == mealTemplate.ID ) );
            if (ItemDeleted != null)
            {
               ItemDeleted( this, new RepositoryObjectEventArgs( mealTemplate ) );
            }

            SaveRepository();
             }
        }
Example #10
0
 /// <summary>
 /// Determine if a mealTemplate template's name is already being used by another mealTemplate template.
 /// </summary>
 /// <param name="mealTemplate">The mealTemplate template</param>
 /// <returns>True if some other mealTemplate template is using this same name, false otherwise</returns>
 public Boolean NameIsDuplicate( MealTemplate mealTemplate )
 {
     return (_mealTemplates.Find(
     template => template.Name == mealTemplate.Name && template.ID != mealTemplate.ID ) != null);
 }
Example #11
0
 /// <summary>
 /// Determine if a mealTemplate template is referenced elsewhere in the repository
 /// </summary>
 /// <param name="mealTemplate">The mealTemplate template</param>
 /// <returns>Always returns false</returns>
 public Boolean ItemIsUsed( MealTemplate mealTemplate )
 {
     return false;
 }
Example #12
0
 /// <summary>
 /// Determine if the repository contains the given mealTemplate template
 /// </summary>
 /// <param name="mealTemplate">The mealTemplate template to look for</param>
 /// <returns>True of the mealTemplate template is in the repository, false otherwise</returns>
 public Boolean Contains( MealTemplate mealTemplate )
 {
     return (_mealTemplates.Find( item => item.ID == mealTemplate.ID ) != null);
 }
        public override void OnNavigatedTo( NavigationContext navigationContext )
        {
            if (Model == null)
             {
            String idParameter = navigationContext.Parameters["ID"];
            Guid myID;
            MealTemplate mealTemplate = null;

            if (idParameter != null && Guid.TryParse( idParameter, out myID ))
            {
               mealTemplate = this.DataRepository.GetMealTemplate( myID );
            }
            else
            {
               mealTemplate = new MealTemplate();
               mealTemplate.DateAndTimeOfMeal = DateTime.Now.Date;
            }
            Model = mealTemplate;

            base.OnNavigatedTo( navigationContext );
             }
        }
        public void MealTemplateIsDeletedIfAnswerIsYes()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var interactionServiceMock = new Mock<IInteractionService>();
             var regionNavigationServiceMock = new Mock<IRegionNavigationService>();
             var regionManagerMock = new Mock<IRegionManager>();

             var mealTemplate = new MealTemplate( Guid.NewGuid(), new MealType( Guid.NewGuid(), "test", "test", DateTime.Now, false ), DateTime.Now, "test", "This is a test" );
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( new FoodItem( Guid.NewGuid(), "test", "test", 100.0M ), 1.5M ) );

             dataRepositoryMock.Setup( x => x.Contains( mealTemplate ) ).Returns( true );
             dataRepositoryMock.Setup( x => x.ItemIsUsed( mealTemplate ) ).Returns( false );
             dataRepositoryMock.Setup( x => x.GetMealTemplate( mealTemplate.ID ) ).Returns( mealTemplate );
             dataRepositoryMock
            .Setup( x => x.GetAllMealTypes() )
            .Returns( new ReadOnlyCollection<MealType>( new List<MealType>() ) );
             dataRepositoryMock
            .Setup( x => x.GetAllFoodItems() )
            .Returns( new ReadOnlyCollection<FoodItem>( new List<FoodItem>() ) );

             var viewModel = new MealTemplateViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             var navigationContext =
                     new NavigationContext(
                        regionNavigationServiceMock.Object, new Uri( "MealTempalate?ID=" + mealTemplate.ID.ToString(), UriKind.Relative ) );
             viewModel.OnNavigatedTo( navigationContext );

             // Setup the regions so we can determine if the view has been removed or not
             var view = new UserControl();
             view.DataContext = viewModel;

             var views = new List<UserControl>();
             views.Add( new UserControl() );
             views.Add( view );
             views.Add( new UserControl() );
             views.Add( new UserControl() );

             var regionMock = new Mock<IRegion>();
             var regions = new List<IRegion>();
             regions.Add( regionMock.Object );

             regionManagerMock.Setup( x => x.Regions.GetEnumerator() ).Returns( regions.GetEnumerator() );
             regionMock.Setup( x => x.Views.GetEnumerator() ).Returns( views.GetEnumerator() );

             interactionServiceMock
            .Setup( x => x.ShowMessageBox(
               Messages.Question_MealTemplate_Delete, DisplayStrings.DeleteCaption, MessageBoxButton.YesNo, MessageBoxImage.Question ) )
            .Returns( MessageBoxResult.Yes );

             Assert.IsTrue( viewModel.DeleteCommand.CanExecute( null ) );
             viewModel.DeleteCommand.Execute( null );

             interactionServiceMock.VerifyAll();
             dataRepositoryMock.VerifyAll();
             dataRepositoryMock.Verify( x => x.Remove( mealTemplate ), Times.Exactly( 1 ) );
             regionMock.Verify( x => x.Remove( view ), Times.Exactly( 1 ) );
             regionMock.Verify( x => x.Remove( It.IsAny<Object>() ), Times.Exactly( 1 ) );
        }
        /// <summary>
        /// Close test template.  All of the close tests follow this based pattern, so they all call this rather than repeating everything
        /// </summary>
        private void RunCloseTest( Boolean makeDirty, Boolean makeInvalid, MessageBoxResult messageResponse, Boolean expectRemove, Boolean expectSave )
        {
            var loggerMock = new Mock<ILoggerFacade>();
             Mock<IDataRepository> dataRepositoryMock = new Mock<IDataRepository>();
             Mock<IRegionNavigationService> regionNavigationServiceMock = new Mock<IRegionNavigationService>();
             Mock<IRegionManager> regionManagerMock = new Mock<IRegionManager>();
             Mock<IRegion> regionWithoutViewMock = new Mock<IRegion>();
             Mock<IRegion> regionMock = new Mock<IRegion>();
             Mock<IInteractionService> interactionServiceMock = new Mock<IInteractionService>();

             // TODO: Will need to build a food group list (done) and a food mealType list, then build the mealTemplate template to test.

             // Set up the food group list in the data repository mock.
             FoodGroup testFoodGroup = new FoodGroup( Guid.NewGuid(), "test", "The only food group in the mock data repository" );
             List<FoodGroup> foodGroups = new List<FoodGroup>();
             foodGroups.Add( testFoodGroup );
             dataRepositoryMock.Setup( x => x.GetAllFoodGroups() ).Returns( new ReadOnlyCollection<FoodGroup>( foodGroups ) );
             FoodItem testFoodItem = new FoodItem( Guid.NewGuid(), "Test Food Item", "Test Food Item Description", 42.0M );
             testFoodItem.FoodGroupsPerServing.Add( new Serving<FoodGroup>( testFoodGroup, 5.0M ) );
             Assert.IsTrue( testFoodItem.IsValid );
             List<FoodItem> foodItems = new List<FoodItem>();
             foodItems.Add( testFoodItem );
             dataRepositoryMock.Setup( x => x.GetAllFoodItems() ).Returns( new ReadOnlyCollection<FoodItem>( foodItems ) );
             MealType testMealType = new MealType( Guid.NewGuid(), "Lunch", "A lunch for testing", DateTime.Now, false );
             Assert.IsTrue( testMealType.IsValid );
             List<MealType> mealTypes = new List<MealType>();
             mealTypes.Add( testMealType );
             dataRepositoryMock.Setup( x => x.GetAllMealTypes() ).Returns( new ReadOnlyCollection<MealType>( mealTypes ) );

             MealTemplate mealTemplate = new MealTemplate( Guid.NewGuid(), testMealType, DateTime.Now, "test mealTemplate", "This is a test" );
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( testFoodItem, 1.5M ) );

             dataRepositoryMock.Setup( x => x.GetMealTemplate( mealTemplate.ID ) ).Returns( mealTemplate );
             dataRepositoryMock.Setup( x => x.Contains( mealTemplate ) ).Returns( true );

             // Create the view model under test and associate it with a view
             MealTemplateViewModel viewModel =
            new MealTemplateViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             UserControl view = new UserControl();
             view.DataContext = viewModel;

             // Set up two regions each with their own set of views.
             List<UserControl> views = new List<UserControl>();
             views.Add( new UserControl() );
             views.Add( view );
             views.Add( new UserControl() );
             views.Add( new UserControl() );

             List<UserControl> viewsWithoutView = new List<UserControl>();
             viewsWithoutView.Add( new UserControl() );
             viewsWithoutView.Add( new UserControl() );

             List<IRegion> regions = new List<IRegion>();
             regions.Add( regionMock.Object );

             regionManagerMock.Setup( x => x.Regions.GetEnumerator() ).Returns( regions.GetEnumerator() );
             regionWithoutViewMock.Setup( x => x.Views.GetEnumerator() ).Returns( viewsWithoutView.GetEnumerator() );
             regionMock.Setup( x => x.Views.GetEnumerator() ).Returns( views.GetEnumerator() );

             // Navigate to the view that "displays" our food mealType.  This loads the view model
             NavigationContext navigationContext =
            new NavigationContext( regionNavigationServiceMock.Object, new Uri( "MealTemplateView?ID=" + mealTemplate.ID.ToString(), UriKind.Relative ) );
             viewModel.OnNavigatedTo( navigationContext );

             if (makeDirty)
             {
            if (makeInvalid)
            {
               interactionServiceMock
                  .Setup( x => x.ShowMessageBox( Messages.Question_MealTemplate_Close, DisplayStrings.CloseCaption, MessageBoxButton.YesNo, MessageBoxImage.Question ) )
                  .Returns( messageResponse );
               viewModel.Name = "";
               Assert.IsTrue( viewModel.IsDirty );
               Assert.IsFalse( viewModel.IsValid );
            }
            else
            {
               interactionServiceMock
                  .Setup( x => x.ShowMessageBox( Messages.Question_MealTemplate_Save, DisplayStrings.SaveChangesCaption, MessageBoxButton.YesNoCancel, MessageBoxImage.Question ) )
                  .Returns( messageResponse );
               viewModel.Name = "Something Else";
               Assert.IsTrue( viewModel.IsDirty );
               Assert.IsTrue( viewModel.IsValid );
            }
             }
             else
             {
            // This will fail if we have passed in the non-sensical makeDirty == false, makeInvalid == true
            Assert.AreEqual( makeDirty, viewModel.IsDirty );
             }

             // Attempt a close.
             viewModel.CloseCommand.Execute( null );

             // If we were dirty, then we need to verify that the correct interaction was done, otherwise, that no interaction was done
             if (makeDirty)
             {
            interactionServiceMock.VerifyAll();
             }
             else
             {
            interactionServiceMock.Verify(
               x => x.ShowMessageBox( It.IsAny<String>(), It.IsAny<String>(), It.IsAny<MessageBoxButton>(), It.IsAny<MessageBoxImage>() ), Times.Never() );
             }

             if (expectRemove)
             {
            regionMock.Verify( x => x.Remove( view ), Times.Exactly( 1 ) );
            regionMock.Verify( x => x.Remove( It.IsAny<UserControl>() ), Times.Exactly( 1 ) );
             }
             else
             {
            regionMock.Verify( x => x.Remove( It.IsAny<UserControl>() ), Times.Never() );
             }

             if (expectSave)
             {
            dataRepositoryMock.Verify( x => x.SaveItem( mealTemplate ), Times.Exactly( 1 ) );
            dataRepositoryMock.Verify( x => x.SaveItem( It.IsAny<MealTemplate>() ), Times.Exactly( 1 ) );
             }
             else
             {
            dataRepositoryMock.Verify( x => x.SaveItem( It.IsAny<MealTemplate>() ), Times.Never() );
             }
        }
        public void MealTemplateIDTypeTimeNameDescription()
        {
            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 );

             DateTime theTime = DateTime.Now;
             MealTemplate mealTemplate = new MealTemplate( new Guid( "1c456eca-17c6-4395-a14f-85800a5c9d35" ),
            dataRepository.FindMealType( mt => mt.Name == "Dinner" ),
            theTime, "Just a test mealTemplate", "And this is the description" );

             // Should be invalid when instantiated since there is a lot of missing data
             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, mealTemplate["FoodItemServings"] );
             Assert.IsNull( mealTemplate["Name"] );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.AreEqual( new Guid( "1c456eca-17c6-4395-a14f-85800a5c9d35" ), mealTemplate.ID );
             Assert.AreEqual( "Dinner", mealTemplate.TypeOfMeal.Name );
             Assert.ReferenceEquals( dataRepository.FindMealType( mt => mt.Name == "Dinner" ), mealTemplate.TypeOfMeal );
             Assert.AreEqual( theTime, mealTemplate.DateAndTimeOfMeal );
             Assert.AreEqual( "Just a test mealTemplate", mealTemplate.Name );
             Assert.AreEqual( "And this is the description", mealTemplate.Description );
             Assert.AreEqual( 0, mealTemplate.FoodItemServings.Count );
             Assert.AreEqual( 0, mealTemplate.Calories );
             Assert.AreEqual( 0, mealTemplate.FoodGroupServings.Count );

             // Add missing data, show that it is now valid
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Baby Carrots" ), 2.5M ) );
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Deluxe Bacon Cheese Burger" ), 1 ) );
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Glass of Skim Milk" ), 2 ) );
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Fruit Salad" ), 1.5M ) );

             Assert.IsTrue( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.IsNull( mealTemplate["FoodItemServings"] );
             Assert.IsNull( mealTemplate["Name"] );
             Assert.AreEqual( (2.5M * 40) + 650 + (2 * 90) + (1.5M * 150), mealTemplate.Calories );
             Assert.AreEqual( 5, mealTemplate.FoodGroupServings.Count );
             Assert.AreEqual( 3, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Vegetable" ).Quantity );
             Assert.AreEqual( 1, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Grain" ).Quantity );
             Assert.AreEqual( 1.5M, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Meat" ).Quantity );
             Assert.AreEqual( 5, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Dairy" ).Quantity );
             Assert.AreEqual( 3, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Fruit" ).Quantity );
        }
        public void MealTemplateMeal()
        {
            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 );

             DateTime theTime = DateTime.Now;
             Meal meal = new Meal( Guid.NewGuid(), dataRepository.FindMealType( mt => mt.Name == "Lunch" ), theTime, "Lunch", null );
             meal.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Baby Carrots" ), 2.5M ) );
             meal.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Deluxe Bacon Cheese Burger" ), 1 ) );
             Assert.IsTrue( meal.IsValid );
             Assert.AreEqual( 750, meal.Calories );

             MealTemplate mealTemplate = new MealTemplate( meal );
             Assert.AreEqual( meal.ID, mealTemplate.ID );
             Assert.AreEqual( meal.TypeOfMeal, mealTemplate.TypeOfMeal );
             Assert.AreEqual( meal.DateAndTimeOfMeal, mealTemplate.DateAndTimeOfMeal );
             Assert.AreEqual( 2, mealTemplate.FoodItemServings.Count );
             Assert.IsNotNull( mealTemplate.FoodItemServings.Find( s => s.Entity.Name == "Baby Carrots" ) );
             Assert.IsNotNull( mealTemplate.FoodItemServings.Find( s => s.Entity.Name == "Deluxe Bacon Cheese Burger" ) );
             Assert.IsTrue( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["Name"] );
        }
Example #18
0
        public void SaveItem( MealTemplate mealTemplate )
        {
            if (mealTemplate == null)
             {
            throw new ArgumentNullException( "mealTemplate" );
             }

             if (!Contains( mealTemplate ))
             {
            _mealTemplates.Add( new MealTemplate( mealTemplate ) );
            if (ItemAdded != null)
            {
               ItemAdded( this, new RepositoryObjectEventArgs( mealTemplate ) );
            }
             }
             else
             {
            MealTemplate repositoryMealTemplate = _mealTemplates.Find( m => m.ID == mealTemplate.ID );
            Debug.Assert( repositoryMealTemplate != null );
            repositoryMealTemplate.InitializeData( mealTemplate );
            if (ItemModified != null)
            {
               ItemModified( this, new RepositoryObjectEventArgs( mealTemplate ) );
            }
             }

             this.SaveRepository();
        }
        public void MealTemplateValidationTests()
        {
            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 );

             DateTime theTime = DateTime.Now;
             MealTemplate mealTemplate = new MealTemplate( Guid.NewGuid(), default( MealType ), default( DateTime ), null, null );

             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.AreEqual( Messages.Error_No_MealType, mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, mealTemplate["FoodItemServings"] );
             Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );

             // Add a valid mealTemplate type
             mealTemplate.TypeOfMeal = dataRepository.FindMealType( mt => mt.Name == "Lunch" );
             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, mealTemplate["FoodItemServings"] );
             Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );

             // Add a valid time for the mealTemplate
             mealTemplate.DateAndTimeOfMeal = theTime;
             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.AreEqual( Messages.Error_No_FoodItems, mealTemplate["FoodItemServings"] );
             Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );

             // Add a food item serving
             mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( dataRepository.FindFoodItem( food => food.Name == "Baby Carrots" ), 2.5M ) );
             Assert.IsFalse( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.IsNull( mealTemplate["FoodItemServings"] );
             Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );

             // Assign a valid name
             mealTemplate.Name = "A test mealTemplate template";
             Assert.IsTrue( mealTemplate.IsValid );
             Assert.IsNull( mealTemplate["ID"] );
             Assert.IsNull( mealTemplate["TypeOfMeal"] );
             Assert.IsNull( mealTemplate["TimeOfMeal"] );
             Assert.IsNull( mealTemplate["FoodItemServings"] );
             Assert.IsNull( mealTemplate["Name"] );
        }
Example #20
0
        // This is really, really ugly.  It works, but it is not pretty.  Look into changing this.
        private void LoadRepository( String dataFileName )
        {
            XDocument xmlDoc;

             using (FileStream stream = new FileStream( dataFileName, FileMode.Open ))
             {
            using (XmlReader xmlRdr = new XmlTextReader( stream ))
            {
               xmlDoc = XDocument.Load( xmlRdr );

               // If we don't have the root element
               if (xmlDoc.Element( rootNodeTag ) == null)
               {
                  _foodGroups = new List<FoodGroup>();
                  _foodItems = new List<FoodItem>();
                  _mealTypes = new List<MealType>();
                  _mealTemplates = new List<MealTemplate>();
                  _meals = new List<Meal>();
               }
               else
               {
                  if (xmlDoc.Element( rootNodeTag ).Element( foodGroupsNodeTag ) != null)
                  {
                     _foodGroups =
                        (from foodGroupElement in xmlDoc.Element( rootNodeTag ).Element( foodGroupsNodeTag ).Elements( foodGroupNodeTag )
                         select new FoodGroup(
                            (Guid)foodGroupElement.Attribute( idAttribute ),
                            (String)foodGroupElement.Attribute( nameAttribute ),
                            foodGroupElement.Element( descriptionNodeTag ) == null ? null :
                            (String)foodGroupElement.Element( descriptionNodeTag ).Value )).ToList();
                  }
                  else
                  {
                     _foodGroups = new List<FoodGroup>();
                  }

                  // FoodItems
                  _foodItems = new List<FoodItem>();
                  if (xmlDoc.Element( rootNodeTag ).Element( foodItemsNodeTag ) != null)
                  {
                     foreach (XElement foodItemElement in xmlDoc.Element( rootNodeTag ).Element( foodItemsNodeTag ).Elements( foodItemNodeTag ))
                     {
                        // Construct a food item and add it to the collection
                        FoodItem foodItem = new FoodItem( (Guid)foodItemElement.Attribute( idAttribute ),
                           (String)foodItemElement.Attribute( nameAttribute ),
                           foodItemElement.Element( descriptionNodeTag ) == null ? null :
                           (String)foodItemElement.Element( descriptionNodeTag ).Value,
                           (Decimal)foodItemElement.Attribute( caloriesAttribute ) ); // TODO: Should probably do a tryparse on that...
                        _foodItems.Add( foodItem );

                        // Loop through the FoodGroupServings to build that list
                        if (foodItemElement.Element( foodGroupServingsNodeTag ) != null)
                        {
                           foreach (XElement servingElement in foodItemElement.Element( foodGroupServingsNodeTag ).Elements( servingNodeTag ))
                           {
                              Serving<FoodGroup> foodGroupServing = new Serving<FoodGroup>(
                                 _foodGroups.Find( fg => fg.ID == (Guid)servingElement.Attribute( foodGroupIdAttribute ) ),
                                 (Decimal)servingElement.Attribute( quantityAttribute ) );
                              foodItem.FoodGroupsPerServing.Add( foodGroupServing );
                           }
                        }
                     }
                  }

                  if (xmlDoc.Element( rootNodeTag ).Element( mealTypesNodeTag ) != null)
                  {
                     _mealTypes =
                        (from mealTypeElement in xmlDoc.Element( rootNodeTag ).Element( mealTypesNodeTag ).Elements( mealTypeNodeTag )
                         select new MealType(
                            (Guid)mealTypeElement.Attribute( idAttribute ),
                            (String)mealTypeElement.Attribute( nameAttribute ),
                            mealTypeElement.Element( descriptionNodeTag ) == null ? null :
                            (String)mealTypeElement.Element( descriptionNodeTag ).Value,
                            (DateTime)mealTypeElement.Attribute( dateTimeAttribute ),
                            (Boolean)mealTypeElement.Attribute( useDefaultDateTimeAttribute ) )).ToList();
                  }
                  else
                  {
                     _mealTypes = new List<MealType>();
                  }

                  // Meal Templates
                  _mealTemplates = new List<MealTemplate>();
                  if (xmlDoc.Element( rootNodeTag ).Element( mealTemplatesNodeTag ) != null)
                  {
                     foreach (XElement mealTemplateElement in xmlDoc.Element( rootNodeTag ).Element( mealTemplatesNodeTag ).Elements( mealNodeTag ))
                     {
                        // Construct a food item and add it to the collection
                        MealTemplate mealTemplate = new MealTemplate(
                           (Guid)mealTemplateElement.Attribute( idAttribute ),
                           _mealTypes.Find( mt => mt.ID == (Guid)mealTemplateElement.Attribute( mealTypeIdAttribute ) ),
                           (DateTime)mealTemplateElement.Attribute( dateTimeAttribute ),
                           (String)mealTemplateElement.Attribute( nameAttribute ),
                            mealTemplateElement.Element( descriptionNodeTag ) == null ? null :
                            (String)mealTemplateElement.Element( descriptionNodeTag ).Value );
                        _mealTemplates.Add( mealTemplate );

                        // Loop through the FoodItemServings to build that list
                        if (mealTemplateElement.Element( foodItemServingsNodeTag ) != null)
                        {
                           foreach (XElement servingElement in mealTemplateElement.Element( foodItemServingsNodeTag ).Elements( servingNodeTag ))
                           {
                              Serving<FoodItem> foodItem = new Serving<FoodItem>(
                                 _foodItems.Find( fi => fi.ID == (Guid)servingElement.Attribute( foodItemIdAttribute ) ),
                                 (Decimal)servingElement.Attribute( quantityAttribute ) );
                              mealTemplate.FoodItemServings.Add( foodItem );
                           }
                        }
                     }
                  }

                  // Meals
                  _meals = new List<Meal>();
                  if (xmlDoc.Element( rootNodeTag ).Element( mealsNodeTag ) != null)
                  {
                     foreach (XElement mealElement in xmlDoc.Element( rootNodeTag ).Element( mealsNodeTag ).Elements( mealNodeTag ))
                     {
                        // Construct a food item and add it to the collection
                        var meal = new Meal(
                           (Guid)mealElement.Attribute( idAttribute ),
                           _mealTypes.Find( mt => mt.ID == (Guid)mealElement.Attribute( mealTypeIdAttribute ) ),
                           (DateTime)mealElement.Attribute( dateTimeAttribute ),
                           (String)mealElement.Attribute( nameAttribute ),
                            mealElement.Element( descriptionNodeTag ) == null ? null :
                            (String)mealElement.Element( descriptionNodeTag ).Value );
                        _meals.Add( meal );

                        // Loop through the FoodItemServings to build that list
                        if (mealElement.Element( foodItemServingsNodeTag ) != null)
                        {
                           foreach (XElement servingElement in mealElement.Element( foodItemServingsNodeTag ).Elements( servingNodeTag ))
                           {
                              Serving<FoodItem> foodItem = new Serving<FoodItem>(
                                 _foodItems.Find( fi => fi.ID == (Guid)servingElement.Attribute( foodItemIdAttribute ) ),
                                 (Decimal)servingElement.Attribute( quantityAttribute ) );
                              meal.FoodItemServings.Add( foodItem );
                           }
                        }
                     }
                  }
               }
            }
             }
        }
 public void MealTempalateDefault()
 {
     // Create a mealTemplate template.  It should be invalid and empty with the exception of an ID.
      // Other tests handle making a valid object, so ignore that with this one.
      MealTemplate mealTemplate = new MealTemplate();
      Assert.IsFalse( mealTemplate.IsValid );
      Assert.IsNotNull( mealTemplate.ID );
      Assert.IsNull( mealTemplate.TypeOfMeal );
      Assert.IsNull( mealTemplate.Name );
      Assert.IsNull( mealTemplate.Description );
      Assert.AreEqual( mealTemplate.DateAndTimeOfMeal, default( DateTime ) );
      Assert.AreEqual( 0, mealTemplate.FoodItemServings.Count );
      Assert.AreEqual( 0, mealTemplate.FoodGroupServings.Count );
      Assert.AreEqual( 0, mealTemplate.Calories );
      Assert.AreEqual( Messages.Error_No_MealType, mealTemplate["TypeOfMeal"] );
      Assert.IsNull( mealTemplate["TimeOfMeal"] );
      Assert.AreEqual( Messages.Error_No_FoodItems, mealTemplate["FoodItemServings"] );
      Assert.AreEqual( Messages.Error_No_Name, mealTemplate["Name"] );
      Assert.IsNull( mealTemplate["Description"] );
 }
Example #22
0
        public List<MealTemplate> MealTemplates()
        {
            var fruit = FoodGroups().Find( fg => fg.ID == fruitID );
             var dairy = FoodGroups().Find( fg => fg.ID == dairyID );
             var meat = FoodGroups().Find( fg => fg.ID == meatID );
             var vegetable = FoodGroups().Find( fg => fg.ID == vegetableID );
             var starch = FoodGroups().Find( fg => fg.ID == starchID );

             var breakfast = MealTypes().Find( mt => mt.ID == breakfastID );
             var lunch = MealTypes().Find( mt => mt.ID == lunchID );
             var dinner = MealTypes().Find( mt => mt.ID == dinnerID );

             // drinks
             var milk = Foods().Find( f => f.ID == milkID );
             var oj = Foods().Find( f => f.ID == ojID );
             var friedEgg = Foods().Find( f => f.ID == friedEggID );
             var hashBrowns = Foods().Find( f => f.ID == hashBrownsID );
             var bacon = Foods().Find( f => f.ID == baconID );
             var cereal = Foods().Find( f => f.ID == cerealID );
             var hamSandwich = Foods().Find( f => f.ID == hamSandwichID );
             var baconCheeseBurger = Foods().Find( f => f.ID == baconCheeseBurgerID );
             var frenchFries = Foods().Find( f => f.ID == frenchFriesID );
             var carrotSticks = Foods().Find( f => f.ID == carrotSticksID );
             var chickenDinner = Foods().Find( f => f.ID == chickenDinnerID );
             var steakDinner = Foods().Find( f => f.ID == steakDinnerID );

             if (_mealTemplates == null)
             {
            _mealTemplates = new List<MealTemplate>();

            // Big Breakfast                          Calories
            //    three eggs                             180.0
            //    6 strips of bacon (2 servings)         200.0
            //    hashbrowns                             125.5
            //    OJ                                     100.0
            //                                        --------
            //                                           605.5
            // Food Groups
            //    Meat         5.0
            //    Fruit        1.0
            //    Starch       1.0
            var mealTemplate = new MealTemplate( BigBreakfastID, breakfast, DateTime.Today.AddHours( 6 ), "Big Breakfast", "A Rather Large Breakfast" );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( friedEgg, 3.0M ) );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( hashBrowns, 1.0M ) );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( bacon, 2.0M ) );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( oj, 1.0M ) );
            _mealTemplates.Add( mealTemplate );

            // Small Breakfast                        Calories
            //    Cereal                                 125.0
            //    Milk (half serving)                     45.0
            //    OJ                                     100.0
            //                                        --------
            //                                           270.0
            // Food Groups
            //    Dairy        0.5
            //    Fruit        1.0
            //    Starch       1.0
            mealTemplate = new MealTemplate( SmallBreakfastID, breakfast, DateTime.Today.AddHours( 6 ), "Small Breakfast", "A Rather Normal Breakfast" );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( cereal, 1.0M ) );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( milk, 0.5M ) );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( oj, 1.0M ) );
            _mealTemplates.Add( mealTemplate );

            // Cheeseburger Lunch                     Calories
            //    Bacon Cheese Burger                    600.0
            //    French Fries                           200.0
            //    Milk                                    90.0
            //                                        --------
            //                                           890.0
            // Food Groups
            //    Dairy        1.5
            //    Meat         2.0
            //    Starch       2.5
            //    Vegetable    0.25
            mealTemplate = new MealTemplate( CheeseburgerLunchID, lunch, DateTime.Today.AddHours( 12 ), "Greasy Lunch", "A Rather unhealthy lunch" );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( baconCheeseBurger, 1.0M ) );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( frenchFries, 0.5M ) );
            mealTemplate.FoodItemServings.Add( new Serving<FoodItem>( milk, 1.0M ) );
            _mealTemplates.Add( mealTemplate );
             }

             return _mealTemplates;
        }