public void AllFoodItemsViewModelContainsAllFoods()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.Foods() );

             var viewModel = new AllFoodItemsViewModel( dataRespositoryMock.Object );

             AssertViewModelContents( viewModel, data.Foods() );
             dataRespositoryMock.VerifyAll();
        }
        private void AssertViewModelContents( AllFoodItemsViewModel viewModel, List<FoodItem> foods )
        {
            Assert.AreEqual( foods.Count, viewModel.Items.Count );

             foreach (var food in viewModel.Items)
             {
            var foodItemFromRepository = foods.Find( f => f.ID == food.ID );

            Assert.IsNotNull( food );
            Assert.AreEqual( foodItemFromRepository.Name, food.Name );
             }
        }
        public void FoodItemRemovedFromViewModelWhenRemovedFromRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.Foods() );

             var viewModel = new AllFoodItemsViewModel( dataRespositoryMock.Object );
             var food = data.Foods().Find( mt => mt.ID == MockData.baconCheeseBurgerID );
             data.Foods().Remove( food );
             dataRespositoryMock.Raise( e => e.ItemDeleted += null, new RepositoryObjectEventArgs( food ) );

             AssertViewModelContents( viewModel, data.Foods() );
        }
        public void FoodItemModifiedInViewModelWhenChangedInRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.Foods() );
             var viewModel = new AllFoodItemsViewModel( dataRespositoryMock.Object );

             var food = data.Foods().Find( f => f.ID == MockData.baconCheeseBurgerID );
             food.Name += " Unit Test";
             dataRespositoryMock.Raise( e => e.ItemModified += null, new RepositoryObjectEventArgs( food ) );

             AssertViewModelContents( viewModel, data.Foods() );
        }
        public void FoodItemAddedToViewModelWhenAddedToRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.Foods() );

             var viewModel = new AllFoodItemsViewModel( dataRespositoryMock.Object );
             var food = new FoodItem( Guid.NewGuid(), "New Type", "For a unit test", 42.0M );
             data.Foods().Add( food );
             dataRespositoryMock.Raise( e => e.ItemAdded += null, new RepositoryObjectEventArgs( food ) );

             AssertViewModelContents( viewModel, data.Foods() );
        }
        public MealViewModelBase( IDataRepository dataRepository, IRegionManager regionManager, IInteractionService interactionService, ILoggerFacade logger )
            : base(dataRepository, regionManager, interactionService, logger)
        {
            _foodGroupServings = new ObservableCollection<ServingViewModel<FoodGroup>>();
             FoodGroupServings = new ReadOnlyObservableCollection<ServingViewModel<FoodGroup>>( _foodGroupServings );

             FoodItemServings = new ObservableCollection<ServingViewModel<FoodItem>>();

             ValidFoodItems = new AllFoodItemsViewModel( dataRepository );
             ValidMealTypes = new AllMealTypesViewModel( dataRepository );

             _timeSetManually = false;
        }