예제 #1
0
        public void DeleteMeal()
        {
            var configurationMock = new Mock<IConfiguration>();
             configurationMock.Setup( x => x.DataSource ).Returns( DataSourceType.XMLFile );
             configurationMock.Setup( x => x.FileName ).Returns( FullTestData.DataFileName );

             FullTestData.Reset();
             var dataRepository = new HealthTracker.DataRepository.Services.DataRepository( configurationMock.Object );

             // Make a deep copy of a meal
             var chzBurgerMealID = new Guid( "FEB4A1B2-796F-11E0-BB69-31B74724019B" );
             var chzBurgerMeal = new Meal();
             chzBurgerMeal.InitializeData( dataRepository.FindMeal( m => m.ID == chzBurgerMealID ) );
             Assert.IsNotNull( chzBurgerMeal );

             // Delete the meal.  Show that the meal 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( chzBurgerMeal );
             Assert.AreEqual( origFoodGroupCount, dataRepository.GetAllFoodGroups().Count );
             Assert.AreEqual( origFoodItemCount, dataRepository.GetAllFoodItems().Count );
             Assert.AreEqual( origMealTypeCount, dataRepository.GetAllMealTypes().Count );
             Assert.AreEqual( origMealTemplateCount, dataRepository.GetAllMealTemplates().Count );
             Assert.AreEqual( origMealCount - 1, dataRepository.GetAllMeals().Count );
             Assert.IsNotNull( chzBurgerMeal.ID );
             Assert.IsNull( dataRepository.FindMealTemplate( mt => mt.ID == chzBurgerMeal.ID ) );
        }
예제 #2
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 ) );
        }
예제 #3
0
        public void FindMealTemplate()
        {
            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
             MealTemplate item = dataRepository.FindMealTemplate( 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.FindMealTemplate( x => x.Name == "Cheeseburger Lunch" );
             Assert.AreEqual( "Cheeseburger Lunch", item.Name );
             MealTemplate sameItem = dataRepository.FindMealTemplate( x => x.Name == "Cheeseburger 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 = "My Guttbomb";
             Assert.AreEqual( "My Guttbomb", item.Name );
             Assert.AreEqual( "Cheeseburger Lunch", sameItem.Name );
        }
예제 #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 );
        }