public void AllMealTemplatesViewModelContainsAllTemplates()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.MealTemplates() );

             var viewModel = new AllMealTemplatesViewModel( dataRespositoryMock.Object );

             AssertViewModelContents( viewModel, data.MealTemplates() );
             dataRespositoryMock.VerifyAll();
        }
        public void MealTemplateRemovedFromViewModelWhenRemovedFromRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.MealTemplates() );

             var viewModel = new AllMealTemplatesViewModel( dataRespositoryMock.Object );
             var mealTemplate = data.MealTemplates().Find( mt => mt.ID == MockData.CheeseburgerLunchID );
             data.MealTemplates().Remove( mealTemplate );
             dataRespositoryMock.Raise( e => e.ItemDeleted += null, new RepositoryObjectEventArgs( mealTemplate ) );

             AssertViewModelContents( viewModel, data.MealTemplates() );
        }
        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() );
        }
        private void AssertViewModelContents( AllMealTemplatesViewModel viewModel, List<MealTemplate> mealTemplates )
        {
            Assert.AreEqual( mealTemplates.Count, viewModel.Items.Count );

             foreach (var template in viewModel.Items)
             {
            var templateFromRepository = mealTemplates.Find( mt => mt.ID == template.ID );

            Assert.IsNotNull( template );
            Assert.AreEqual( templateFromRepository.Name, template.Name );
            Assert.AreEqual( templateFromRepository.Calories, template.Calories );
             }
        }
        public void MealTemplateModifiedInViewModelWhenChangedInRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.MealTemplates() );
             var viewModel = new AllMealTemplatesViewModel( dataRespositoryMock.Object );

             var mealTemplate = data.MealTemplates().Find( mt => mt.ID == MockData.CheeseburgerLunchID );
             mealTemplate.Name += " Unit Test";
             mealTemplate.FoodItemServings[0].Quantity += 1;
             dataRespositoryMock.Raise( e => e.ItemModified += null, new RepositoryObjectEventArgs( mealTemplate ) );

             AssertViewModelContents( viewModel, data.MealTemplates() );
        }