Ejemplo n.º 1
0
        public void SaveFoodGroup()
        {
            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 );

             // Create one new food group, and get a deep copy of one out of the repository.
             // When the new one is saved, a food group 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 food group should not be created, but the food group object with the same
             // ID should have the modifications applied to it.

             // TODO: This needs to change
             FoodGroup stuffing = new FoodGroup( new Guid( "5ff4f935-00b9-482b-a86a-3ffd53de9dda" ), "Stuffing", "The stuff that goes in a turkey" );
             FoodGroup repositoryMeat = dataRepository.FindFoodGroup( fg => fg.ID == FullTestData.MeatID );
             FoodGroup meat = new FoodGroup();
             meat.InitializeData( repositoryMeat );

             Assert.IsNotNull( meat );
             Assert.AreEqual( meat.ID, FullTestData.MeatID );
             Assert.AreEqual( meat.Name, "Meat" );
             Assert.AreEqual( meat.Description, "Lean meat is generally the best." );

             // Saving the one that already exists should result in the existing item being changed.
             Int32 origFoodGroupCount = dataRepository.GetAllFoodGroups().Count;
             meat.Name = "Meat and Poultry";
             meat.Description = "Eat more chicken.";
             repositoryMeat = dataRepository.FindFoodGroup( fg => fg.ID == FullTestData.MeatID );
             Assert.AreNotEqual( meat.Name, repositoryMeat.Name );
             Assert.AreNotEqual( meat.Description, repositoryMeat.Description );
             dataRepository.SaveItem( meat );
             repositoryMeat = dataRepository.FindFoodGroup( fg => fg.ID == FullTestData.MeatID );
             Assert.AreEqual( origFoodGroupCount, dataRepository.GetAllFoodGroups().Count );
             Assert.AreEqual( meat.Name, repositoryMeat.Name );
             Assert.AreEqual( meat.Description, repositoryMeat.Description );

             // Saving the one that does not exist, should result in the new item being added.
             dataRepository.SaveItem( stuffing );
             Assert.AreEqual( origFoodGroupCount + 1, dataRepository.GetAllFoodGroups().Count );
             FoodGroup repositoryStuffing = dataRepository.FindFoodGroup( fg => fg.ID == new Guid( "5ff4f935-00b9-482b-a86a-3ffd53de9dda" ) );
             Assert.AreEqual( stuffing.Name, repositoryStuffing.Name );
             Assert.AreEqual( stuffing.Description, repositoryStuffing.Description );
        }
Ejemplo n.º 2
0
        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 );
        }
Ejemplo n.º 3
0
        public void SaveMealType()
        {
            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 );

             MealType forthMeal = new MealType( new Guid( "18bbf0b4-9f2e-4477-97c9-d2b9419fe57f" ), "Forth Meal", "Going to Taco Bell", DateTime.Now, false );

             MealType repositoryBreakfast = dataRepository.FindMealType( m => m.ID == FullTestData.BreakfastID );
             MealType breakfast = new MealType();
             breakfast.InitializeData( repositoryBreakfast );

             Int32 origMealTypeCount = dataRepository.GetAllMealTypes().Count;

             // Verfiy the breakfasts are the same
             Assert.AreEqual( breakfast.ID, repositoryBreakfast.ID );
             Assert.AreEqual( breakfast.Name, repositoryBreakfast.Name );
             Assert.AreEqual( breakfast.Description, repositoryBreakfast.Description );
             Assert.AreEqual( breakfast.DefaultTimeOfMeal, repositoryBreakfast.DefaultTimeOfMeal );
             Assert.AreEqual( breakfast.UseDefaultMealTime, repositoryBreakfast.UseDefaultMealTime );

             // Change the breakfast, verify the repository has not changed
             breakfast.Name = "Big Breakfast";
             breakfast.Description = "Bacon, Eggs, Pancakes, stuff like that";
             breakfast.DefaultTimeOfMeal = DateTime.Now.AddHours( 2.5 );
             breakfast.UseDefaultMealTime = false;

             repositoryBreakfast = dataRepository.FindMealType( m => m.ID == FullTestData.BreakfastID );
             Assert.AreEqual( breakfast.ID, repositoryBreakfast.ID );
             Assert.AreNotEqual( breakfast.Name, repositoryBreakfast.Name );
             Assert.AreNotEqual( breakfast.Description, repositoryBreakfast.Description );
             Assert.AreNotEqual( breakfast.DefaultTimeOfMeal, repositoryBreakfast.DefaultTimeOfMeal );
             Assert.AreNotEqual( breakfast.UseDefaultMealTime, repositoryBreakfast.UseDefaultMealTime );

             Assert.AreEqual( origMealTypeCount, dataRepository.GetAllMealTypes().Count );

             // Save the change, verify the repository item has been changed, and no new currentMealTemplate types have been added
             dataRepository.SaveItem( breakfast );
             repositoryBreakfast = dataRepository.FindMealType( m => m.ID == FullTestData.BreakfastID );
             Assert.AreEqual( breakfast.ID, repositoryBreakfast.ID );
             Assert.AreEqual( breakfast.Name, repositoryBreakfast.Name );
             Assert.AreEqual( breakfast.Description, repositoryBreakfast.Description );
             Assert.AreEqual( breakfast.DefaultTimeOfMeal, repositoryBreakfast.DefaultTimeOfMeal );
             Assert.AreEqual( breakfast.UseDefaultMealTime, repositoryBreakfast.UseDefaultMealTime );

             Assert.AreEqual( origMealTypeCount, dataRepository.GetAllMealTypes().Count );

             // Save the new Meal type
             dataRepository.SaveItem( forthMeal );
             MealType repositoryForthMeal = dataRepository.FindMealType( m => m.ID == forthMeal.ID );
             Assert.IsNotNull( repositoryForthMeal );
             Assert.AreNotEqual( forthMeal, repositoryForthMeal );
             Assert.AreEqual( forthMeal.ID, repositoryForthMeal.ID );
             Assert.AreEqual( forthMeal.Name, repositoryForthMeal.Name );
             Assert.AreEqual( forthMeal.Description, repositoryForthMeal.Description );
             Assert.AreEqual( forthMeal.DefaultTimeOfMeal, repositoryForthMeal.DefaultTimeOfMeal );
             Assert.AreEqual( forthMeal.UseDefaultMealTime, repositoryForthMeal.UseDefaultMealTime );

             Assert.AreEqual( origMealTypeCount + 1, dataRepository.GetAllMealTypes().Count );
        }
Ejemplo n.º 4
0
        public void SaveFoodItem()
        {
            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 groups that we can use
             FoodGroup meat = dataRepository.FindFoodGroup( f => f.ID == FullTestData.MeatID );
             FoodGroup vegetables = dataRepository.FindFoodGroup( f => f.ID == FullTestData.VegetableID );

             // Create one new food item, and get a deep copy of one out of the repository.
             // When the new one is saved, a food item 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 food item should not be created, but the food item object with the same
             // ID should have the modifications applied to it.
             FoodItem dublinCoddle = new FoodItem( new Guid( "f6ffa83c-5f7a-4961-8571-801f436c0eb9" ), "Dublin Coddle", "Poormans food", 250 );
             dublinCoddle.FoodGroupsPerServing.Add( new Serving<FoodGroup>( meat, 1 ) );
             dublinCoddle.FoodGroupsPerServing.Add( new Serving<FoodGroup>( vegetables, 2 ) );

             FoodItem repositoryChzBurger = dataRepository.FindFoodItem( f => f.ID == FullTestData.CheeseBurgerID );
             Assert.IsNotNull( repositoryChzBurger );
             FoodItem chzBurger = new FoodItem();
             chzBurger.InitializeData( repositoryChzBurger );
             Int32 origFoodItemCount = dataRepository.GetAllFoodItems().Count;

             // Verify the food groups, etc.
             Assert.AreEqual( repositoryChzBurger.CaloriesPerServing, chzBurger.CaloriesPerServing );
             Assert.AreEqual( repositoryChzBurger.Name, chzBurger.Name );
             Assert.AreEqual( repositoryChzBurger.Description, chzBurger.Description );
             Assert.AreEqual( repositoryChzBurger.FoodGroupsPerServing.Count, chzBurger.FoodGroupsPerServing.Count );

             // Remove the vegetables and bacon, and verify the difference
             chzBurger.Description = "Ground up cow, topped with curdled milk.";
             chzBurger.Name = "Cheese Burger";
             chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ).Quantity = 1;
             chzBurger.FoodGroupsPerServing.Remove( chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.VegetableID ) );
             chzBurger.CaloriesPerServing -= 140;

             repositoryChzBurger = dataRepository.FindFoodItem( f => f.ID == FullTestData.CheeseBurgerID );
             Assert.AreNotEqual( repositoryChzBurger.CaloriesPerServing, chzBurger.CaloriesPerServing );
             Assert.AreNotEqual( repositoryChzBurger.Name, chzBurger.Name );
             Assert.AreNotEqual( repositoryChzBurger.Description, chzBurger.Description );
             Assert.AreNotEqual( repositoryChzBurger.FoodGroupsPerServing.Count, chzBurger.FoodGroupsPerServing.Count );
             Assert.AreNotEqual(
            repositoryChzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ),
            chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ) );
             Assert.IsNotNull( repositoryChzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.VegetableID ) );
             Assert.IsNull( chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.VegetableID ) );

             // Save the cheese burger, and verify the changes are saved
             dataRepository.SaveItem( chzBurger );
             repositoryChzBurger = dataRepository.FindFoodItem( f => f.ID == FullTestData.CheeseBurgerID );
             Assert.AreEqual( repositoryChzBurger.CaloriesPerServing, chzBurger.CaloriesPerServing );
             Assert.AreEqual( repositoryChzBurger.Name, chzBurger.Name );
             Assert.AreEqual( repositoryChzBurger.Description, chzBurger.Description );
             Assert.AreEqual( repositoryChzBurger.FoodGroupsPerServing.Count, chzBurger.FoodGroupsPerServing.Count );
             Assert.AreEqual(
            repositoryChzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ).Quantity,
            chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ).Quantity );
             Assert.IsNull( repositoryChzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.VegetableID ) );
             Assert.IsNull( chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.VegetableID ) );

             Assert.AreEqual( origFoodItemCount, dataRepository.GetAllFoodItems().Count );

             // Add some fruit and verify the difference
             chzBurger.Name = "Hawian Cheese Burger";
             chzBurger.Description = "Ground up cow, topped with curdled milk, smoked pig, and pineapple.";
             chzBurger.FoodGroupsPerServing.Add( new Serving<FoodGroup>(
            dataRepository.FindFoodGroup( fg => fg.ID == FullTestData.FruitID ), 0.5M ) );
             chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ).Quantity += 1;
             chzBurger.CaloriesPerServing += 200;

             repositoryChzBurger = dataRepository.FindFoodItem( f => f.ID == FullTestData.CheeseBurgerID );
             Assert.AreNotEqual( repositoryChzBurger.CaloriesPerServing, chzBurger.CaloriesPerServing );
             Assert.AreNotEqual( repositoryChzBurger.Name, chzBurger.Name );
             Assert.AreNotEqual( repositoryChzBurger.Description, chzBurger.Description );
             Assert.AreNotEqual( repositoryChzBurger.FoodGroupsPerServing.Count, chzBurger.FoodGroupsPerServing.Count );
             Assert.AreNotEqual(
            repositoryChzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ),
            chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ) );
             Assert.IsNull( repositoryChzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.FruitID ) );
             Assert.IsNotNull( chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.FruitID ) );

             // Save the cheese burger, and verify the changes are saved
             dataRepository.SaveItem( chzBurger );
             repositoryChzBurger = dataRepository.FindFoodItem( f => f.ID == FullTestData.CheeseBurgerID );
             Assert.AreEqual( repositoryChzBurger.CaloriesPerServing, chzBurger.CaloriesPerServing );
             Assert.AreEqual( repositoryChzBurger.Name, chzBurger.Name );
             Assert.AreEqual( repositoryChzBurger.Description, chzBurger.Description );
             Assert.AreEqual( repositoryChzBurger.FoodGroupsPerServing.Count, chzBurger.FoodGroupsPerServing.Count );
             Assert.AreEqual(
            repositoryChzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ).Quantity,
            chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.MeatID ).Quantity );
             Assert.IsNotNull( repositoryChzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.FruitID ) );
             Assert.IsNotNull( chzBurger.FoodGroupsPerServing.Find( f => f.Entity.ID == FullTestData.FruitID ) );

             Assert.AreEqual( origFoodItemCount, dataRepository.GetAllFoodItems().Count );

             // Save the new food item
             dataRepository.SaveItem( dublinCoddle );
             Assert.AreEqual( origFoodItemCount + 1, dataRepository.GetAllFoodItems().Count );
             FoodItem repositoryCoddle = dataRepository.FindFoodItem( f => f.ID == new Guid( "f6ffa83c-5f7a-4961-8571-801f436c0eb9" ) );
             Assert.IsNotNull( repositoryCoddle );
             Assert.AreEqual( "Dublin Coddle", repositoryCoddle.Name );
             Assert.AreEqual( "Poormans food", repositoryCoddle.Description );
             Assert.AreEqual( 250, repositoryCoddle.CaloriesPerServing );
             Assert.AreEqual( 2, repositoryCoddle.FoodGroupsPerServing.Count );
        }