public void MealForTodayAddedToChildrenWhenAddedToRepository()
        {
            var dataRepositoryMock = new Mock<IDataRepository>();
             var data = new MockData();
             var allMeals = data.Meals();

             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Now.Date ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in allMeals
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Now.Date
                                           select meal).ToList() ) );
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Now.Date.AddDays( MockData.DaysToAddForFutureMeals ) ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in allMeals
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Now.Date.AddDays( MockData.DaysToAddForFutureMeals )
                                           select meal).ToList() ) );

             var mealNodeViewModel = new MealNodeViewModel( dataRepositoryMock.Object, null );
             Assert.AreEqual( 3, mealNodeViewModel.Children.Count );

             var newMeal = new Meal(
            Guid.NewGuid(), new MealType( Guid.NewGuid(), "Doesn't Matter", "", DateTime.Now, false ), DateTime.Now, "Test Meal", "Just a test" );
             newMeal.FoodItemServings.Add( new Serving<FoodItem>( new FoodItem( Guid.NewGuid(), "test", "", 42 ), 1 ) );
             allMeals.Add( newMeal );
             dataRepositoryMock.Raise( e => e.ItemAdded += null, new RepositoryObjectEventArgs( newMeal ) );
             Assert.AreEqual( 4, mealNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in mealNodeViewModel.Children)
             {
            Meal meal = allMeals.Find( m => m.ID == (Guid)node.Parameter );
            Assert.IsNotNull( meal );
            Assert.AreEqual( meal.Name, node.Name );
             }
        }
        public void MealForOtherDayNotRemovedFromChildrenWhenRemovedFromRepository()
        {
            var dataRepositoryMock = new Mock<IDataRepository>();
             var data = new MockData();
             var allMeals = data.Meals();

             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Now.Date ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in allMeals
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Now.Date
                                           select meal).ToList() ) );
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Now.Date.AddDays( MockData.DaysToAddForFutureMeals ) ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in allMeals
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Now.Date.AddDays( MockData.DaysToAddForFutureMeals )
                                           select meal).ToList() ) );

             var mealNodeViewModel = new MealNodeViewModel( dataRepositoryMock.Object, null );
             Assert.AreEqual( 3, mealNodeViewModel.Children.Count );

             var removedMeal = allMeals.Find( m => m.DateAndTimeOfMeal.Date == DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals ) && m.TypeOfMeal.Name == "Dinner" );
             Assert.IsNotNull( removedMeal );
             allMeals.Remove( removedMeal );
             dataRepositoryMock.Raise( e => e.ItemDeleted += null, new RepositoryObjectEventArgs( removedMeal ) );
             Assert.AreEqual( 3, mealNodeViewModel.Children.Count );

             foreach (ClickableTreeNodeViewModel node in mealNodeViewModel.Children)
             {
            var meal = allMeals.Find( m => m.ID == (Guid)node.Parameter );
            Assert.IsNotNull( meal );
            Assert.AreEqual( meal.Name, node.Name );
             }
        }
        public void CaloriesLoadCorrectlyForExistingMeal()
        {
            var data = new MockData();
             var meal = data.Meals().Find( x => x.ID == MockData.DayTwoBreakfastID );

             var viewModel = CreateViewModelForMeal( new Meal( meal ) );

             Assert.AreEqual( meal.Calories, viewModel.Calories );
        }
        public void AllMealTypesViewModelContainsAllTypes()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.MealTypes() );

             var viewModel = new AllMealTypesViewModel( dataRespositoryMock.Object );

             AssertViewModelContents( viewModel, data.MealTypes() );
             dataRespositoryMock.VerifyAll();
        }
        public void CaloriesAdjustedAsFoodItemsAdded()
        {
            var data = new MockData();
             var meal = data.Meals().Find( x => x.ID == MockData.DayTwoBreakfastID );

             var viewModel = CreateViewModelForMeal( new Meal( meal ) );

             Assert.AreEqual( meal.Calories, viewModel.Calories );
             viewModel.FoodItemServings.Add( new ServingViewModel<FoodItem>( new FoodItem( Guid.NewGuid(), "Test", "", 42.5M ), 3 ) );
             Assert.AreEqual( meal.Calories + 127.5M, viewModel.Calories );
        }
        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 MealTypeRemovedFromViewModelWhenRemovedFromRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.MealTypes() );

             var viewModel = new AllMealTypesViewModel( dataRespositoryMock.Object );
             var mealType = data.MealTypes().Find( mt => mt.ID == MockData.lunchID );
             data.MealTypes().Remove( mealType );
             dataRespositoryMock.Raise( e => e.ItemDeleted += null, new RepositoryObjectEventArgs( mealType ) );

             AssertViewModelContents( viewModel, data.MealTypes() );
        }
        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 MealTypeAddedToViewModelWhenAddedToRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.MealTypes() );

             var viewModel = new AllMealTypesViewModel( dataRespositoryMock.Object );
             var mealType = new MealType( Guid.NewGuid(), "New Type", "For a unit test", DateTime.Now, false );
             data.MealTypes().Add( mealType );
             dataRespositoryMock.Raise( e => e.ItemAdded += null, new RepositoryObjectEventArgs( mealType ) );

             AssertViewModelContents( viewModel, data.MealTypes() );
        }
        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 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 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() );
        }
        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 MealTypeModifiedInViewModelWhenChangedInRepository()
        {
            var data = new MockData();
             var dataRespositoryMock = CreateMockDataRepository( data.MealTypes() );
             var viewModel = new AllMealTypesViewModel( dataRespositoryMock.Object );

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

             AssertViewModelContents( viewModel, data.MealTypes() );
        }
Esempio n. 15
0
        public void CaloriesAdjustedAsFoodItemsRemoved()
        {
            var data = new MockData();
             var meal = data.Meals().Find( x => x.ID == MockData.DayTwoBreakfastID );

             var viewModel = CreateViewModelForMeal( new Meal( meal ) );

             Assert.AreEqual( meal.Calories, viewModel.Calories );
             var foodItem = viewModel.FoodItemServings[0];
             var foodItemCalories = foodItem.Entity.CaloriesPerServing * foodItem.Quantity;
             viewModel.FoodItemServings.RemoveAt( 0 );
             Assert.AreEqual( meal.Calories - foodItemCalories, viewModel.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() );
        }
        public void ModifyingMealOnDateUpdatesCaloriesAndFoodGroups()
        {
            PropertyChangedHandler propertyChangedHandler = new PropertyChangedHandler();

             var loggerMock = new Mock<ILoggerFacade>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();
             var navigationServiceMock = new Mock<IRegionNavigationService>();

             var data = new MockData();
             var fullMealList = data.Meals();
             var todaysMeals = (from meal in fullMealList
                            where meal.DateAndTimeOfMeal.Date == DateTime.Today
                            select meal).ToList();
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today ) )
            .Returns( new ReadOnlyCollection<Meal>( todaysMeals ) );

             var viewModel = new DailyLogViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             viewModel.CurrentDate = DateTime.Today;
             viewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged;

             Decimal originalFoodGroupServings = (from foodGroupServing in viewModel.FoodGroupServings
                                              select foodGroupServing.Quantity).Sum();
             Decimal originalCalories = viewModel.Calories;

             var foodGroupServings = viewModel.FoodGroupServings;
             Assert.AreEqual( 5, foodGroupServings.Count );
             var serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Fruit" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Starch" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 5.0M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Dairy" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 4.75M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Meat" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Vegetable" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 3.5M, serving.Quantity );

             var mealToModify = todaysMeals.Find( x => x.TypeOfMeal.Name == "Breakfast" );
             Assert.IsNotNull( mealToModify );
             mealToModify.FoodItemServings.Remove( mealToModify.FoodItemServings.Find( x => x.Entity.Name == "Orange Juice" ) );
             dataRepositoryMock.Raise( x => x.ItemModified += null, new RepositoryObjectEventArgs( mealToModify ) );

             Assert.AreEqual( originalFoodGroupServings - 2.5M,
                          (from foodGroupServing in viewModel.FoodGroupServings
                           select foodGroupServing.Quantity).Sum() );
             Assert.AreEqual( originalCalories - 250, viewModel.Calories );

             foodGroupServings = viewModel.FoodGroupServings;
             Assert.AreEqual( 4, foodGroupServings.Count );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Fruit" );
             Assert.IsNull( serving );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Starch" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 5.0M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Dairy" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 4.75M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Meat" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Vegetable" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 3.5M, serving.Quantity );

             Assert.AreEqual( 2, propertyChangedHandler.PropertiesChanged.Count );
             Assert.AreEqual( viewModel, propertyChangedHandler.Sender );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Calories" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupServings" ) );
        }
        public void ModifyingMealNotOnDateDoesNotUpdateCaloriesAndFoodGroups()
        {
            PropertyChangedHandler propertyChangedHandler = new PropertyChangedHandler();

             var loggerMock = new Mock<ILoggerFacade>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();
             var navigationServiceMock = new Mock<IRegionNavigationService>();

             var data = new MockData();
             var fullMealList = data.Meals();
             var todaysMeals = (from meal in fullMealList
                            where meal.DateAndTimeOfMeal.Date == DateTime.Today
                            select meal).ToList();
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today ) )
            .Returns( new ReadOnlyCollection<Meal>( todaysMeals ) );

             var viewModel = new DailyLogViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             viewModel.CurrentDate = DateTime.Today;
             viewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged;

             Decimal originalFoodGroupServings = (from foodGroupServing in viewModel.FoodGroupServings
                                              select foodGroupServing.Quantity).Sum();
             Decimal originalCalories = viewModel.Calories;

             var mealToModify = new Meal( fullMealList.Find( x => x.TypeOfMeal.Name == "Breakfast" && x.DateAndTimeOfMeal.Date != DateTime.Today ) );
             Assert.IsNotNull( mealToModify );
             mealToModify.FoodItemServings.Remove( mealToModify.FoodItemServings.Find( x => x.Entity.Name == "Orange Juice" ) );
             dataRepositoryMock.Raise( x => x.ItemModified += null, new RepositoryObjectEventArgs( mealToModify ) );

             Assert.AreEqual( originalFoodGroupServings,
                          (from foodGroupServing in viewModel.FoodGroupServings
                           select foodGroupServing.Quantity).Sum() );
             Assert.AreEqual( originalCalories, viewModel.Calories );

             Assert.AreEqual( 0, propertyChangedHandler.PropertiesChanged.Count );
        }
        public void FoodGroupsAreCalculatedBasedOnSelectedDay()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();
             var navigationServiceMock = new Mock<IRegionNavigationService>();

             var data = new MockData();
             var fullMealList = data.Meals();
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in fullMealList
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Today
                                           select meal).ToList() ) );
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals ) ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in fullMealList
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals )
                                           select meal).ToList() ) );

             var viewModel = new DailyLogViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             viewModel.CurrentDate = DateTime.Today;

             var foodGroupServings = viewModel.FoodGroupServings;
             Assert.AreEqual( 5, foodGroupServings.Count );
             var serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Fruit" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Starch" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 5.0M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Dairy" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 4.75M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Meat" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Vegetable" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 3.5M, serving.Quantity );

             viewModel.CurrentDate = DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals );
             foodGroupServings = viewModel.FoodGroupServings;
             Assert.AreEqual( 5, foodGroupServings.Count );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Starch" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.0M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Dairy" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.0M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Meat" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 4.0M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Vegetable" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 1.0M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Fruit" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.0M, serving.Quantity );

             dataRepositoryMock.VerifyAll();
        }
        public void AddingMealForDateToRepositoryUpdatesCaloriesAndFoodGroups()
        {
            PropertyChangedHandler propertyChangedHandler = new PropertyChangedHandler();

             var loggerMock = new Mock<ILoggerFacade>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();
             var navigationServiceMock = new Mock<IRegionNavigationService>();

             var data = new MockData();
             var fullMealList = data.Meals();
             var todaysMeals = (from meal in fullMealList
                            where meal.DateAndTimeOfMeal.Date == DateTime.Today
                            select meal).ToList();
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today ) ).Returns(
            new ReadOnlyCollection<Meal>( todaysMeals ) );

             var viewModel = new DailyLogViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             viewModel.CurrentDate = DateTime.Today;
             viewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged;

             Int32 originalFoodGroupCount = viewModel.FoodGroupServings.Count;
             Decimal originalFoodGroupServings = (from foodGroupServing in viewModel.FoodGroupServings
                                              select foodGroupServing.Quantity).Sum();
             Decimal originalCalories = viewModel.Calories;

             var foodGroupServings = viewModel.FoodGroupServings;
             Assert.AreEqual( 5, foodGroupServings.Count );
             var serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Fruit" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Starch" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 5.0M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Dairy" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 4.75M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Meat" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Vegetable" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 3.5M, serving.Quantity );

             var foodItem = new FoodItem( Guid.NewGuid(), "test", "", 42 );
             foodItem.FoodGroupsPerServing.Add( new Serving<FoodGroup>( new FoodGroup( Guid.NewGuid(), "Test1", "" ), 2 ) );
             foodItem.FoodGroupsPerServing.Add( new Serving<FoodGroup>( new FoodGroup( Guid.NewGuid(), "Test2", "" ), 1 ) );
             var newMeal = new Meal(
            Guid.NewGuid(), new MealType( Guid.NewGuid(), "Doesn't Matter", "", DateTime.Now, false ), DateTime.Now, "Test Meal", "Just a test" );
             newMeal.FoodItemServings.Add( new Serving<FoodItem>( foodItem, 1 ) );
             todaysMeals.Add( newMeal );
             dataRepositoryMock.Raise( e => e.ItemAdded += null, new RepositoryObjectEventArgs( newMeal ) );
             Assert.AreEqual( originalCalories + 42, viewModel.Calories );
             Assert.AreEqual( originalFoodGroupCount + 2, viewModel.FoodGroupServings.Count );
             Assert.AreEqual( originalFoodGroupServings + 3, (from foodGroupServing in viewModel.FoodGroupServings
                                                          select foodGroupServing.Quantity).Sum() );

             foodGroupServings = viewModel.FoodGroupServings;
             Assert.AreEqual( 7, foodGroupServings.Count );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Fruit" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Starch" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 5.0M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Dairy" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 4.75M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Meat" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Vegetable" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 3.5M, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Test1" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 2, serving.Quantity );
             serving = foodGroupServings.ToList().Find( x => x.Entity.Name == "Test2" );
             Assert.IsNotNull( serving );
             Assert.AreEqual( 1, serving.Quantity );

             Assert.AreEqual( 2, propertyChangedHandler.PropertiesChanged.Count );
             Assert.AreEqual( viewModel, propertyChangedHandler.Sender );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "Calories" ) );
             Assert.IsTrue( propertyChangedHandler.PropertiesChanged.Contains( "FoodGroupServings" ) );
        }
Esempio n. 21
0
        public void NameLoadsCorrectlyForExistingMeal()
        {
            var data = new MockData();
             var meal = data.Meals().Find( x => x.ID == MockData.DayTwoBreakfastID );
             var viewModel = CreateViewModelForMeal( meal );

             Assert.AreEqual( meal.Name, viewModel.Name );
        }
Esempio n. 22
0
        public void ExistingMealIsNotDirty()
        {
            var data = new MockData();
             var viewModel = CreateViewModelForMeal( data.Meals().Find( x => x.ID == MockData.DayTwoBreakfastID ) );

             Assert.IsFalse( viewModel.IsDirty );
        }
Esempio n. 23
0
        public void TimeAndDateOfMealLoadsCorrectlyForExistingMeal()
        {
            var data = new MockData();
             var meal = data.Meals().Find( x => x.ID == MockData.DayTwoBreakfastID );

             var viewModel = CreateViewModelForMeal( new Meal( meal ) );

             Assert.AreEqual( meal.DateAndTimeOfMeal, viewModel.TimeOfMeal );
             Assert.AreEqual( meal.DateAndTimeOfMeal.Date, viewModel.DateOfMeal );
        }
Esempio n. 24
0
        public void FoodGroupServingsAdjustedAsFoodItemsAdded()
        {
            var data = new MockData();
             var meal = data.Meals().Find( x => x.ID == MockData.DayTwoBreakfastID );

             var viewModel = CreateViewModelForMeal( new Meal( meal ) );

             var foodItem = new FoodItem( Guid.NewGuid(), "Test Food Item", "", 1 );
             foodItem.FoodGroupsPerServing.Add( new Serving<FoodGroup>( new FoodGroup( Guid.NewGuid(), "Test Food Group", "" ), 1 ) );
             viewModel.FoodItemServings.Add( new ServingViewModel<FoodItem>( foodItem, 2 ) );

             Assert.AreEqual( meal.FoodGroupServings.Count + 1, viewModel.FoodGroupServings.Count );
        }
        public void CaloriesAreCalculatedBasedOnSelectedDay()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();
             var navigationServiceMock = new Mock<IRegionNavigationService>();

             var data = new MockData();
             var fullMealList = data.Meals();
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in fullMealList
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Today
                                           select meal).ToList() ) );
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals ) ) ).Returns(
            new ReadOnlyCollection<Meal>( (from meal in fullMealList
                                           where meal.DateAndTimeOfMeal.Date == DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals )
                                           select meal).ToList() ) );

             var viewModel = new DailyLogViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             viewModel.CurrentDate = DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals );

             Assert.AreEqual( 1425.5M, viewModel.Calories );

             viewModel.CurrentDate = DateTime.Today;
             Assert.AreEqual( 2357.5M, viewModel.Calories );

             dataRepositoryMock.VerifyAll();
        }
Esempio n. 26
0
        public void LoadedMealIsNotUsed()
        {
            var mockData = new MockData();
             var viewModel = CreateViewModelForMeal( mockData.Meals().Find( x => x.ID == MockData.DayOneLunchID ) );

             Assert.IsFalse( viewModel.IsUsed );
        }
        public void DailyLogNodesReflectCurrentDate()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();

             var data = new MockData();
             var fullMealList = data.Meals();
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today ) )
            .Returns( new ReadOnlyCollection<Meal>( (from meal in fullMealList
                                                     where meal.DateAndTimeOfMeal.Date == DateTime.Today
                                                     select meal).ToList() ) );
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals ) ) )
            .Returns( new ReadOnlyCollection<Meal>( (from meal in fullMealList
                                                     where meal.DateAndTimeOfMeal.Date == DateTime.Today.AddDays( MockData.DaysToAddForFutureMeals )
                                                     select meal).ToList() ) );

             var viewModel = new DailyLogViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );

             Assert.AreEqual( 3, viewModel.DailyLogNodes[0].Children.Count );

             viewModel.CurrentDate = viewModel.CurrentDate.AddDays( MockData.DaysToAddForFutureMeals );
             Assert.AreEqual( 2, viewModel.DailyLogNodes[0].Children.Count );
        }
        public void DateDefaultsToToday()
        {
            var loggerMock = new Mock<ILoggerFacade>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();

             var data = new MockData();
             var fullMealList = data.Meals();
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today ) )
            .Returns( new ReadOnlyCollection<Meal>( (from meal in fullMealList
                                                     where meal.DateAndTimeOfMeal.Date == DateTime.Today
                                                     select meal).ToList() ) );

             var viewModel = new DailyLogViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );

             Assert.AreEqual( DateTime.Now.Date, viewModel.CurrentDate );
        }
        public void AddingMealForOtherDateToRepositoryDoesNotUpdateCaloriesAndFoodGroups()
        {
            PropertyChangedHandler propertyChangedHandler = new PropertyChangedHandler();

             var loggerMock = new Mock<ILoggerFacade>();
             var dataRepositoryMock = new Mock<IDataRepository>();
             var regionManagerMock = new Mock<IRegionManager>();
             var interactionServiceMock = new Mock<IInteractionService>();
             var navigationServiceMock = new Mock<IRegionNavigationService>();

             var data = new MockData();
             var fullMealList = data.Meals();
             var todaysMeals = (from meal in fullMealList
                            where meal.DateAndTimeOfMeal.Date == DateTime.Today
                            select meal).ToList();
             dataRepositoryMock.Setup( x => x.GetAllMealsForDate( DateTime.Today ) ).Returns(
            new ReadOnlyCollection<Meal>( todaysMeals ) );

             var viewModel = new DailyLogViewModel( dataRepositoryMock.Object, regionManagerMock.Object, interactionServiceMock.Object, loggerMock.Object );
             viewModel.CurrentDate = DateTime.Today;
             viewModel.PropertyChanged += propertyChangedHandler.OnPropertyChanged;

             Int32 originalFoodGroupCount = viewModel.FoodGroupServings.Count;
             Decimal originalFoodGroupServings = (from foodGroupServing in viewModel.FoodGroupServings
                                              select foodGroupServing.Quantity).Sum();
             Decimal originalCalories = viewModel.Calories;

             var foodItem = new FoodItem( Guid.NewGuid(), "test", "", 42 );
             foodItem.FoodGroupsPerServing.Add( new Serving<FoodGroup>( new FoodGroup( Guid.NewGuid(), "Test1", "" ), 2 ) );
             foodItem.FoodGroupsPerServing.Add( new Serving<FoodGroup>( new FoodGroup( Guid.NewGuid(), "Test2", "" ), 1 ) );
             var newMeal = new Meal(
            Guid.NewGuid(), new MealType( Guid.NewGuid(), "Doesn't Matter", "", DateTime.Now, false ), DateTime.Now.AddDays( 1 ), "Test Meal", "Just a test" );
             newMeal.FoodItemServings.Add( new Serving<FoodItem>( foodItem, 1 ) );
             dataRepositoryMock.Raise( e => e.ItemAdded += null, new RepositoryObjectEventArgs( newMeal ) );
             Assert.AreEqual( originalCalories, viewModel.Calories );
             Assert.AreEqual( originalFoodGroupCount, viewModel.FoodGroupServings.Count );
             Assert.AreEqual( originalFoodGroupServings, (from foodGroupServing in viewModel.FoodGroupServings
                                                      select foodGroupServing.Quantity).Sum() );

             Assert.AreEqual( 0, propertyChangedHandler.PropertiesChanged.Count );
        }
Esempio n. 30
0
        public void FoodItemServingsLoadsCorrectForExistingMeal()
        {
            var data = new MockData();
             var meal = data.Meals().Find( x => x.ID == MockData.DayTwoBreakfastID );

             var viewModel = CreateViewModelForMeal( new Meal( meal ) );

             Assert.AreEqual( meal.FoodItemServings.Count, viewModel.FoodItemServings.Count );
             foreach (var foodItem in viewModel.FoodItemServings)
             {
            var mealFoodItem = meal.FoodItemServings.Find( x => x.Entity.ID == foodItem.Entity.ID );
            Assert.IsNotNull( mealFoodItem );
            Assert.AreEqual( mealFoodItem.Quantity, foodItem.Quantity );
             }
        }