예제 #1
0
        public void FindMealType()
        {
            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 );

             // Try to find a food group that does not exist, should be null
             MealType item = dataRepository.FindMealType( x => x.Name == "Does Not Exist" );
             Assert.IsNull( item );

             // Find a food group that does exist, show that a deep copy is returned
             item = dataRepository.FindMealType( x => x.Name == "Lunch" );
             Assert.AreEqual( "Lunch", item.Name );
             MealType sameItem = dataRepository.FindMealType( x => x.Name == "Lunch" );
             Assert.AreEqual( item.ID, sameItem.ID );
             Assert.AreNotEqual( item, sameItem );  // Show deep copy

             // Verify that changes to the first found food group do not affect changes to what is logically
             // the same food group returned by the second find (IOW, show they are deep copies).
             item.Name = "Mid-Day Meal";
             Assert.AreEqual( "Mid-Day Meal", item.Name );
             Assert.AreEqual( "Lunch", sameItem.Name );
        }
예제 #2
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 );
        }
예제 #3
0
        public void DeleteMealType()
        {
            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 type
             MealType lunch = new MealType();
             lunch.InitializeData( dataRepository.FindMealType( mt => mt.Name == "Lunch" ) );
             Assert.IsNotNull( lunch );

             // Delete the meal type.  Show that the meal type 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( lunch );
             Assert.AreEqual( origFoodGroupCount, dataRepository.GetAllFoodGroups().Count );
             Assert.AreEqual( origFoodItemCount, dataRepository.GetAllFoodItems().Count );
             Assert.AreEqual( origMealTypeCount - 1, dataRepository.GetAllMealTypes().Count );
             Assert.AreEqual( origMealTemplateCount, dataRepository.GetAllMealTemplates().Count );
             Assert.AreEqual( origMealCount, dataRepository.GetAllMeals().Count );
             Assert.IsNotNull( lunch.ID );
             Assert.IsNull( dataRepository.FindMealTemplate( mt => mt.ID == lunch.ID ) );
        }
예제 #4
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 );
        }