public FoodItemViewModel( IDataRepository dataRepository, IRegionManager regionManager, IInteractionService interactionService, ILoggerFacade logger )
     : base(dataRepository, regionManager, interactionService, logger)
 {
     FoodGroupsPerServing = new ObservableCollection<ServingViewModel<FoodGroup>>();
      ValidFoodGroups = new AllFoodGroupsViewModel( dataRepository );
      Title = DisplayStrings.NewFoodItemTitle;
 }
        public void AllFoodGroupsViewModelContainsAllTypes()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.FoodGroups() );

             var viewModel = new AllFoodGroupsViewModel( dataRespositoryMock.Object );

             AssertViewModelContents( viewModel, data.FoodGroups() );
             dataRespositoryMock.VerifyAll();
        }
        private void AssertViewModelContents( AllFoodGroupsViewModel viewModel, List<FoodGroup> foodGroups )
        {
            Assert.AreEqual( foodGroups.Count, viewModel.Items.Count );

             foreach (var foodGroup in viewModel.Items)
             {
            var foodGroupFromRepository = foodGroups.Find( fg => fg.ID == foodGroup.ID );

            Assert.IsNotNull( foodGroup );
            Assert.AreEqual( foodGroupFromRepository.Name, foodGroup.Name );
             }
        }
        public void FoodGroupRemovedFromViewModelWhenRemovedFromRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.FoodGroups() );

             var viewModel = new AllFoodGroupsViewModel( dataRespositoryMock.Object );
             var foodGroup = data.FoodGroups().Find( mt => mt.ID == MockData.dairyID );
             data.FoodGroups().Remove( foodGroup );
             dataRespositoryMock.Raise( e => e.ItemDeleted += null, new RepositoryObjectEventArgs( foodGroup ) );

             AssertViewModelContents( viewModel, data.FoodGroups() );
        }
        public void FoodGroupModifiedInViewModelWhenChangedInRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.FoodGroups() );
             var viewModel = new AllFoodGroupsViewModel( dataRespositoryMock.Object );

             var foodGroup = data.FoodGroups().Find( mt => mt.ID == MockData.meatID );
             foodGroup.Name += " Unit Test";
             dataRespositoryMock.Raise( e => e.ItemModified += null, new RepositoryObjectEventArgs( foodGroup ) );

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

             var viewModel = new AllFoodGroupsViewModel( dataRespositoryMock.Object );
             var foodGroup = new FoodGroup( Guid.NewGuid(), "New Group", "Some newly dreamed up food group" );
             data.FoodGroups().Add( foodGroup );
             dataRespositoryMock.Raise( e => e.ItemAdded += null, new RepositoryObjectEventArgs( foodGroup ) );

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