Ejemplo n.º 1
0
        public void InitializeData()
        {
            FoodGroup fruit = new FoodGroup( Guid.NewGuid(), "Fruit", "" );
             FoodGroup meat = new FoodGroup( Guid.NewGuid(), "Meat", "" );
             FoodGroup vegitable = new FoodGroup( Guid.NewGuid(), "Vegetable", "" );
             FoodGroup dairy = new FoodGroup( Guid.NewGuid(), "Dairy", "" );
             FoodGroup grain = new FoodGroup( Guid.NewGuid(), "Grain", "" );
             MealType lunch = new MealType( Guid.NewGuid(), "Lunch", "", DateTime.Now, false );
             MealType snack = new MealType( Guid.NewGuid(), "Snack", "", DateTime.Now, false );
             DateTime currentDateTime = DateTime.Now;

             FoodItem hamburger = new FoodItem( Guid.NewGuid(), "Hamburger", "", 300 );
             hamburger.FoodGroupsPerServing.Add( new Serving<FoodGroup>( grain, 2 ) );
             hamburger.FoodGroupsPerServing.Add( new Serving<FoodGroup>( meat, 1 ) );

             FoodItem glassOfMilk = new FoodItem( Guid.NewGuid(), "Glass of Milk", "", 90 );
             glassOfMilk.FoodGroupsPerServing.Add( new Serving<FoodGroup>( dairy, 1 ) );

             FoodItem babyCarrots = new FoodItem( Guid.NewGuid(), "Baby Carrots", "", 40 );
             babyCarrots.FoodGroupsPerServing.Add( new Serving<FoodGroup>( vegitable, 1 ) );

             MealTemplate sourceMealTemplate = new MealTemplate( Guid.NewGuid(), lunch, currentDateTime, "Test Meal", "This is a test" );
             sourceMealTemplate.FoodItemServings.Add( new Serving<FoodItem>( hamburger, 1 ) );
             sourceMealTemplate.FoodItemServings.Add( new Serving<FoodItem>( glassOfMilk, 2 ) );
             sourceMealTemplate.FoodItemServings.Add( new Serving<FoodItem>( babyCarrots, 1.5M ) );

             MealTemplate mealTemplate = new MealTemplate();
             Assert.AreNotEqual( sourceMealTemplate.ID, mealTemplate.ID );

             mealTemplate.InitializeData( sourceMealTemplate );
             Assert.AreEqual( sourceMealTemplate.ID, mealTemplate.ID );
             Assert.AreEqual( sourceMealTemplate.Name, mealTemplate.Name );
             Assert.AreEqual( sourceMealTemplate.Description, mealTemplate.Description );
             Assert.AreEqual( sourceMealTemplate.Calories, mealTemplate.Calories );
             Assert.AreEqual( sourceMealTemplate.FoodGroupServings.Count, mealTemplate.FoodGroupServings.Count );
             Assert.AreEqual( sourceMealTemplate.FoodItemServings.Count, mealTemplate.FoodItemServings.Count );

             mealTemplate.FoodItemServings[0].Quantity += 1;
             Assert.AreNotEqual( sourceMealTemplate.Calories, mealTemplate.Calories );

             // Create a new mealTemplate template that is just baby carrots (kind of a snack)
             sourceMealTemplate = new MealTemplate( Guid.NewGuid(), snack, DateTime.Now, "Snack", "This is a snack" );
             sourceMealTemplate.FoodItemServings.Add( new Serving<FoodItem>( babyCarrots, 2.5M ) );

             mealTemplate.InitializeData( sourceMealTemplate );
             Assert.AreEqual( sourceMealTemplate.ID, mealTemplate.ID );
             Assert.AreEqual( sourceMealTemplate.Name, mealTemplate.Name );
             Assert.AreEqual( sourceMealTemplate.Description, mealTemplate.Description );
             Assert.AreEqual( sourceMealTemplate.Calories, mealTemplate.Calories );
             Assert.AreEqual( sourceMealTemplate.FoodGroupServings.Count, mealTemplate.FoodGroupServings.Count );
             Assert.AreEqual( sourceMealTemplate.FoodItemServings.Count, mealTemplate.FoodItemServings.Count );
        }
Ejemplo n.º 2
0
        public void DeleteMealTemplate()
        {
            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 );

             // Make a deep copy of a currentMealTemplate template
             MealTemplate chzBurger = new MealTemplate();
             chzBurger.InitializeData( dataRepository.FindMealTemplate( mt => mt.Name == "Cheeseburger Lunch" ) );
             Assert.IsNotNull( chzBurger );

             // Delete the currentMealTemplate template.  Show that the currentMealTemplate template has been deleted, but none of the
             // other data repository items have not been effected.
             Int32 origFoodGroupCount = dataRepository.GetAllFoodGroups().Count;
             Int32 origFoodItemCount = dataRepository.GetAllFoodItems().Count;
             Int32 origMealTypeCount = dataRepository.GetAllMealTypes().Count;
             Int32 origMealTemplateCount = dataRepository.GetAllMealTemplates().Count;
             Int32 origMealCount = dataRepository.GetAllMeals().Count;
             dataRepository.Remove( chzBurger );
             Assert.AreEqual( origFoodGroupCount, dataRepository.GetAllFoodGroups().Count );
             Assert.AreEqual( origFoodItemCount, dataRepository.GetAllFoodItems().Count );
             Assert.AreEqual( origMealTypeCount, dataRepository.GetAllMealTypes().Count );
             Assert.AreEqual( origMealTemplateCount - 1, dataRepository.GetAllMealTemplates().Count );
             Assert.AreEqual( origMealCount, dataRepository.GetAllMeals().Count );
             Assert.IsNotNull( chzBurger.ID );
             Assert.IsNull( dataRepository.FindMealTemplate( mt => mt.ID == chzBurger.ID ) );
        }
Ejemplo n.º 3
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 );
        }