예제 #1
0
        public void DeleteFoodItem()
        {
            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 food item.
             FoodItem fruitSalad = new FoodItem();
             fruitSalad.InitializeData( dataRepository.FindFoodItem( f => f.Name == "Fruit Salad" ) );

             // Delete the food item.  Show that the food item 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( fruitSalad );
             Assert.AreEqual( origFoodGroupCount, dataRepository.GetAllFoodGroups().Count );
             Assert.AreEqual( origFoodItemCount - 1, dataRepository.GetAllFoodItems().Count );
             Assert.AreEqual( origMealTypeCount, dataRepository.GetAllMealTypes().Count );
             Assert.AreEqual( origMealTemplateCount, dataRepository.GetAllMealTemplates().Count );
             Assert.AreEqual( origMealCount, dataRepository.GetAllMeals().Count );
             Assert.IsNotNull( fruitSalad.ID );
             Assert.IsNull( dataRepository.FindFoodItem( f => f.ID == fruitSalad.ID ) );
        }
예제 #2
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 );
        }
예제 #3
0
        public void RepositoryConstructAndLoadNoRootNode()
        {
            IDataRepository repository = new HealthTracker.DataRepository.Services.DataRepository( "../../../UnitTests.Support/Test Data/NoRootNodeTestData.xml" );

             Assert.IsNotNull( repository );

             Assert.AreEqual( 0, repository.GetAllFoodGroups().Count );
             Assert.AreEqual( 0, repository.GetAllFoodItems().Count );
             Assert.AreEqual( 0, repository.GetAllMealTemplates().Count );
             Assert.AreEqual( 0, repository.GetAllMealTypes().Count );
        }
예제 #4
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 ) );
        }
예제 #5
0
        public void RepositoryConstructAndLoadNoMealTypesAndTemplates()
        {
            IDataRepository repository = new HealthTracker.DataRepository.Services.DataRepository( "../../../UnitTests.Support/Test Data/NoMealTestFile.xml" );

             Assert.IsNotNull( repository );

             // Verify that the Food Groups loaded properly.  Spot check some of the actual data.
             Assert.AreEqual( 6, repository.GetAllFoodGroups().Count );
             foreach (FoodGroup foodGroup in repository.GetAllFoodGroups())
             {
            Assert.IsTrue( foodGroup.IsValid );
             }

             FoodGroup testFoodGroup = repository.GetAllFoodGroups()[0];
             Assert.AreEqual( new Guid( "269203a1-c066-4bca-a1ca-b80dc0cb72f3" ), testFoodGroup.ID );
             Assert.AreEqual( "Vegetable", testFoodGroup.Name );
             Assert.AreEqual( "Vegetables are good for you.  You should eat lots of them.",
                          testFoodGroup.Description );

             testFoodGroup = repository.GetAllFoodGroups()[2];
             Assert.AreEqual( new Guid( "e024273b-a01e-4fb4-a535-e3dc632be5e4" ), testFoodGroup.ID );
             Assert.AreEqual( "Meat", testFoodGroup.Name );
             Assert.AreEqual( "Lean meat is generally the best.", testFoodGroup.Description );

             testFoodGroup = repository.GetAllFoodGroups()[5];
             Assert.AreEqual( new Guid( "57ee9b15-46e8-4be4-a22a-2cbd8e8f359b" ), testFoodGroup.ID );
             Assert.AreEqual( "Water", testFoodGroup.Name );
             Assert.IsNull( testFoodGroup.Description );

             // Verify the Food Items loaded properly.  Spot check some of the data.
             Assert.AreEqual( 5, repository.GetAllFoodItems().Count );
             foreach (FoodItem foodItem in repository.GetAllFoodItems())
             {
            Assert.IsTrue( foodItem.IsValid );
             }

             FoodItem testFoodItem = repository.GetAllFoodItems()[0];
             Assert.AreEqual( new Guid( "4082072e-d6fd-4522-9535-d2fd6528a6be" ), testFoodItem.ID );
             Assert.AreEqual( "Deluxe Bacon Cheese Burger", testFoodItem.Name );
             Assert.AreEqual( "Ground up cow, topped with curdled milk and salted pig fat.  Add lettuce, tomato, and onion for health.",
                          testFoodItem.Description );
             Assert.AreEqual( 650, testFoodItem.CaloriesPerServing );
             Assert.AreEqual( 4, testFoodItem.FoodGroupsPerServing.Count );
             Assert.AreEqual( "Meat", testFoodItem.FoodGroupsPerServing[0].Entity.Name );
             Assert.AreEqual( 1.5M, testFoodItem.FoodGroupsPerServing[0].Quantity );
             Assert.AreEqual( "Vegetable", testFoodItem.FoodGroupsPerServing[3].Entity.Name );
             Assert.AreEqual( 0.5M, testFoodItem.FoodGroupsPerServing[3].Quantity );

             testFoodItem = repository.GetAllFoodItems()[2];
             Assert.AreEqual( new Guid( "46d04859-f95d-4ed6-9697-3e8a15c0bc91" ), testFoodItem.ID );
             Assert.AreEqual( "Glass of Skim Milk", testFoodItem.Name );
             Assert.IsNull( testFoodItem.Description );
             Assert.AreEqual( 90, testFoodItem.CaloriesPerServing );
             Assert.AreEqual( 1, testFoodItem.FoodGroupsPerServing.Count );
             Assert.AreEqual( "Dairy", testFoodItem.FoodGroupsPerServing[0].Entity.Name );
             Assert.AreEqual( 2, testFoodItem.FoodGroupsPerServing[0].Quantity );

             testFoodItem = repository.GetAllFoodItems()[4];
             Assert.AreEqual( new Guid( "d29701af-a487-466d-b752-34a6ae7269cd" ), testFoodItem.ID );
             Assert.AreEqual( "Baby Carrots", testFoodItem.Name );
             Assert.IsNull( testFoodItem.Description );
             Assert.AreEqual( 40, testFoodItem.CaloriesPerServing );
             Assert.AreEqual( 1, testFoodItem.FoodGroupsPerServing.Count );
             Assert.AreEqual( "Vegetable", testFoodItem.FoodGroupsPerServing[0].Entity.Name );
             Assert.AreEqual( 1, testFoodItem.FoodGroupsPerServing[0].Quantity );

             // Verify the Meal Types list is allocated, but empty
             Assert.AreEqual( 0, repository.GetAllMealTypes().Count );

             // Verify that the Meal Templates is allocated but empty
             Assert.AreEqual( 0, repository.GetAllMealTemplates().Count );
        }
예제 #6
0
        public void RepositoryConstructAndLoadNoFoodItems()
        {
            IDataRepository repository = new HealthTracker.DataRepository.Services.DataRepository( "../../../UnitTests.Support/Test Data/NoFoodItemsTestData.xml" );

             Assert.IsNotNull( repository );

             // Verify that the Food Groups loaded properly.  Spot check some of the actual data.
             Assert.AreEqual( 6, repository.GetAllFoodGroups().Count );
             foreach (FoodGroup foodGroup in repository.GetAllFoodGroups())
             {
            Assert.IsTrue( foodGroup.IsValid );
             }

             FoodGroup testFoodGroup = repository.GetAllFoodGroups()[0];
             Assert.AreEqual( new Guid( "269203a1-c066-4bca-a1ca-b80dc0cb72f3" ), testFoodGroup.ID );
             Assert.AreEqual( "Vegetable", testFoodGroup.Name );
             Assert.AreEqual( "Vegetables are good for you.  You should eat lots of them.", testFoodGroup.Description );

             testFoodGroup = repository.GetAllFoodGroups()[2];
             Assert.AreEqual( new Guid( "e024273b-a01e-4fb4-a535-e3dc632be5e4" ), testFoodGroup.ID );
             Assert.AreEqual( "Meat", testFoodGroup.Name );
             Assert.AreEqual( "Lean meat is generally the best.", testFoodGroup.Description );

             testFoodGroup = repository.GetAllFoodGroups()[5];
             Assert.AreEqual( new Guid( "57ee9b15-46e8-4be4-a22a-2cbd8e8f359b" ), testFoodGroup.ID );
             Assert.AreEqual( "Water", testFoodGroup.Name );
             Assert.IsNull( testFoodGroup.Description );

             // Verify the Food Items list is allocated but empty
             Assert.AreEqual( 0, repository.GetAllFoodItems().Count );

             // Verify the Meal Types are loaded properly.  Limited data, so check it all.
             Assert.AreEqual( 4, repository.GetAllMealTypes().Count );
             foreach (MealType mealType in repository.GetAllMealTypes())
             {
            Assert.IsTrue( mealType.IsValid );
             }

             MealType testMealType = repository.GetAllMealTypes()[0];
             Assert.AreEqual( new Guid( "47ab9db8-83a3-41d8-bce7-81f42d45fbc9" ), testMealType.ID );
             Assert.AreEqual( "Breakfast", testMealType.Name );
             Assert.AreEqual( "The most important meal of the day.", testMealType.Description );

             testMealType = repository.GetAllMealTypes()[1];
             Assert.AreEqual( new Guid( "176b6819-8aae-4bf7-a3d9-83ad4d39ea2e" ), testMealType.ID );
             Assert.AreEqual( "Lunch", testMealType.Name );
             Assert.IsNull( testMealType.Description );

             testMealType = repository.GetAllMealTypes()[2];
             Assert.AreEqual( new Guid( "a832aa99-722a-4619-87f0-7214db172221" ), testMealType.ID );
             Assert.AreEqual( "Dinner", testMealType.Name );
             Assert.IsNull( testMealType.Description );

             testMealType = repository.GetAllMealTypes()[3];
             Assert.AreEqual( new Guid( "c466b59b-ccba-4929-97f9-b3bc274dea04" ), testMealType.ID );
             Assert.AreEqual( "Snack", testMealType.Name );
             Assert.AreEqual( "Limit these and make them healthy.", testMealType.Description );

             // Verify that the Meal Templates list is allocated but empty
             Assert.AreEqual( 0, repository.GetAllMealTemplates().Count );
        }
예제 #7
0
        public void RepositoryConstructAndLoadFullTest()
        {
            FoodGroup foodGroup;
             IDataRepository repository = new HealthTracker.DataRepository.Services.DataRepository( "../../../UnitTests.Support/Test Data/FullTestData.xml" );

             Assert.IsNotNull( repository );

             // Verify that the Food Groups loaded properly.  Spot check some of the actual data.
             Assert.AreEqual( 7, repository.GetAllFoodGroups().Count );
             foreach (FoodGroup group in repository.GetAllFoodGroups())
             {
            Assert.IsTrue( group.IsValid );
             }

             foodGroup = repository.GetAllFoodGroups()[0];
             Assert.AreEqual( new Guid( "269203a1-c066-4bca-a1ca-b80dc0cb72f3" ), foodGroup.ID );
             Assert.AreEqual( "Vegetable", foodGroup.Name );
             Assert.AreEqual( "Vegetables are good for you.  You should eat lots of them.", foodGroup.Description );

             foodGroup = repository.GetAllFoodGroups()[2];
             Assert.AreEqual( new Guid( "e024273b-a01e-4fb4-a535-e3dc632be5e4" ), foodGroup.ID );
             Assert.AreEqual( "Meat", foodGroup.Name );
             Assert.AreEqual( "Lean meat is generally the best.", foodGroup.Description );

             foodGroup = repository.GetAllFoodGroups()[5];
             Assert.AreEqual( new Guid( "57ee9b15-46e8-4be4-a22a-2cbd8e8f359b" ), foodGroup.ID );
             Assert.AreEqual( "Water", foodGroup.Name );
             Assert.IsNull( foodGroup.Description );

             // Verify the Food Items loaded properly.  Spot check some of the data.
             Assert.AreEqual( 5, repository.GetAllFoodItems().Count );
             foreach (FoodItem item in repository.GetAllFoodItems())
             {
            Assert.IsTrue( item.IsValid );
             }
             FoodItem foodItem = repository.GetAllFoodItems()[0];
             Assert.AreEqual( new Guid( "4082072e-d6fd-4522-9535-d2fd6528a6be" ), foodItem.ID );
             Assert.AreEqual( "Deluxe Bacon Cheese Burger", foodItem.Name );
             Assert.AreEqual( "Ground up cow, topped with curdled milk and salted pig fat.  Add lettuce, tomato, and onion for health.",
                          foodItem.Description );
             Assert.AreEqual( 650, foodItem.CaloriesPerServing );
             Assert.AreEqual( 4, foodItem.FoodGroupsPerServing.Count );
             Assert.AreEqual( "Meat", foodItem.FoodGroupsPerServing[0].Entity.Name );
             Assert.AreEqual( 1.5M, foodItem.FoodGroupsPerServing[0].Quantity );
             Assert.AreEqual( "Vegetable", foodItem.FoodGroupsPerServing[3].Entity.Name );
             Assert.AreEqual( 0.5M, foodItem.FoodGroupsPerServing[3].Quantity );

             foodItem = repository.GetAllFoodItems()[2];
             Assert.AreEqual( new Guid( "46d04859-f95d-4ed6-9697-3e8a15c0bc91" ), foodItem.ID );
             Assert.AreEqual( "Glass of Skim Milk", foodItem.Name );
             Assert.IsNull( foodItem.Description );
             Assert.AreEqual( 90, foodItem.CaloriesPerServing );
             Assert.AreEqual( 1, foodItem.FoodGroupsPerServing.Count );
             Assert.AreEqual( "Dairy", foodItem.FoodGroupsPerServing[0].Entity.Name );
             Assert.AreEqual( 2, foodItem.FoodGroupsPerServing[0].Quantity );

             foodItem = repository.GetAllFoodItems()[4];
             Assert.AreEqual( new Guid( "d29701af-a487-466d-b752-34a6ae7269cd" ), foodItem.ID );
             Assert.AreEqual( "Baby Carrots", foodItem.Name );
             Assert.IsNull( foodItem.Description );
             Assert.AreEqual( 40, foodItem.CaloriesPerServing );
             Assert.AreEqual( 1, foodItem.FoodGroupsPerServing.Count );
             Assert.AreEqual( "Vegetable", foodItem.FoodGroupsPerServing[0].Entity.Name );
             Assert.AreEqual( 1, foodItem.FoodGroupsPerServing[0].Quantity );

             // Verify the Meal Types are loaded properly.  Limited data, so check it all.
             Assert.AreEqual( 4, repository.GetAllMealTypes().Count );
             foreach (MealType mealType in repository.GetAllMealTypes())
             {
            Assert.IsTrue( mealType.IsValid );
             }

             MealType testMealType = repository.GetAllMealTypes()[0];
             Assert.AreEqual( new Guid( "47ab9db8-83a3-41d8-bce7-81f42d45fbc9" ), testMealType.ID );
             Assert.AreEqual( "Breakfast", testMealType.Name );
             Assert.AreEqual( "The most important meal of the day.", testMealType.Description );

             testMealType = repository.GetAllMealTypes()[1];
             Assert.AreEqual( new Guid( "176b6819-8aae-4bf7-a3d9-83ad4d39ea2e" ), testMealType.ID );
             Assert.AreEqual( "Lunch", testMealType.Name );
             Assert.IsNull( testMealType.Description );

             testMealType = repository.GetAllMealTypes()[2];
             Assert.AreEqual( new Guid( "a832aa99-722a-4619-87f0-7214db172221" ), testMealType.ID );
             Assert.AreEqual( "Dinner", testMealType.Name );
             Assert.IsNull( testMealType.Description );

             testMealType = repository.GetAllMealTypes()[3];
             Assert.AreEqual( new Guid( "c466b59b-ccba-4929-97f9-b3bc274dea04" ), testMealType.ID );
             Assert.AreEqual( "Snack", testMealType.Name );
             Assert.AreEqual( "Limit these and make them healthy.", testMealType.Description );

             // Verify that the Meal Templates have loaded properly
             Assert.AreEqual( 2, repository.GetAllMealTemplates().Count );
             foreach (MealTemplate currentMealTemplate in repository.GetAllMealTemplates())
             {
            Assert.IsTrue( currentMealTemplate.IsValid );
             }

             MealTemplate mealTemplate = repository.GetAllMealTemplates()[0];
             Assert.AreEqual( "Cheeseburger Lunch", mealTemplate.Name );
             Assert.AreEqual( "A typical cheese burger based lunch.", mealTemplate.Description );
             Assert.AreEqual( "Lunch", mealTemplate.TypeOfMeal.Name );
             Assert.AreEqual( 1240, mealTemplate.Calories );
             Assert.AreEqual( DateTime.Parse( "2010-07-16T19:20-06:00" ), mealTemplate.DateAndTimeOfMeal );
             Assert.AreEqual( 3, mealTemplate.FoodItemServings.Count );
             Assert.AreEqual( 4, mealTemplate.FoodGroupServings.Count );

             Assert.AreEqual( 2.25M, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Meat" ).Quantity );
             Assert.AreEqual( 1.5M, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Grain" ).Quantity );
             Assert.AreEqual( 6.5M, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Dairy" ).Quantity );
             Assert.AreEqual( 1.75M, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Vegetable" ).Quantity );

             mealTemplate = repository.GetAllMealTemplates()[1];
             Assert.AreEqual( "Fruity Breakfast", mealTemplate.Name );
             Assert.AreEqual( "Big fruit salad and a glass of milk", mealTemplate.Description );
             Assert.AreEqual( "Breakfast", mealTemplate.TypeOfMeal.Name );
             Assert.AreEqual( 315, mealTemplate.Calories );
             Assert.AreEqual( DateTime.Parse( "2010-07-16T19:20-06:00" ), mealTemplate.DateAndTimeOfMeal );
             Assert.AreEqual( 2, mealTemplate.FoodItemServings.Count );
             Assert.AreEqual( 2, mealTemplate.FoodGroupServings.Count );

             Assert.AreEqual( 3, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Fruit" ).Quantity );
             Assert.AreEqual( 2, mealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Dairy" ).Quantity );

             // Verify that the meals are loaded properly
             Assert.AreEqual( 7, repository.GetAllMeals().Count );
             foreach (Meal currentMeal in repository.GetAllMeals())
             {
            Assert.IsTrue( currentMeal.IsValid );
             }

             var meal = repository.GetAllMeals()[3];
             Assert.AreEqual( "Breakfast #2", meal.Name );
             Assert.AreEqual( "Some Notes", meal.Description );
             Assert.AreEqual( "Breakfast", meal.TypeOfMeal.Name );
             Assert.AreEqual( 442.5M, meal.Calories );
             Assert.AreEqual( DateTime.Parse( "2010-07-17T19:20-06:00" ), meal.DateAndTimeOfMeal );
             Assert.AreEqual( 2, meal.FoodItemServings.Count );
             Assert.AreEqual( 2, meal.FoodGroupServings.Count );

             Assert.AreEqual( 3.5M, meal.FoodGroupServings.Find( fg => fg.Entity.Name == "Fruit" ).Quantity );
             Assert.AreEqual( 4, meal.FoodGroupServings.Find( fg => fg.Entity.Name == "Dairy" ).Quantity );
        }
예제 #8
0
        public void RepositoryConstructAndLoadBadIDs()
        {
            IDataRepository repository = new HealthTracker.DataRepository.Services.DataRepository( "../../../UnitTests.Support/Test Data/MissingDataTestData.xml" );

             Assert.IsNotNull( repository );

             // Verify that the Food Groups loaded properly.  Actual data is checked elsewhere.
             Assert.AreEqual( 5, repository.GetAllFoodGroups().Count );
             foreach (FoodGroup foodGroup in repository.GetAllFoodGroups())
             {
            Assert.IsTrue( foodGroup.IsValid );
             }

             // Verify the Food Items loaded properly.  Spot check some of the data.
             Assert.AreEqual( 5, repository.GetAllFoodItems().Count );
             foreach (FoodItem foodItem in repository.GetAllFoodItems())
             {
            // Items that are associated with the missing food group (vegitables)
            // should be invalid.
            if (foodItem.Name == "Baby Carrots" || foodItem.Name == "Deluxe Bacon Cheese Burger")
            {
               Assert.IsFalse( foodItem.IsValid );
               Assert.AreEqual( Messages.Error_No_ServingItem, foodItem["FoodGroupsPerServing"] );
            }
            else
            {
               Assert.IsTrue( foodItem.IsValid );
            }
             }

             FoodItem testFoodItem = repository.GetAllFoodItems()[0];
             Assert.AreEqual( new Guid( "4082072e-d6fd-4522-9535-d2fd6528a6be" ), testFoodItem.ID );
             Assert.AreEqual( "Deluxe Bacon Cheese Burger", testFoodItem.Name );
             Assert.AreEqual( "Ground up cow, topped with curdled milk and salted pig fat.  Add lettuce, tomato, and onion for health.",
                          testFoodItem.Description );
             Assert.AreEqual( 650, testFoodItem.CaloriesPerServing );
             Assert.AreEqual( 4, testFoodItem.FoodGroupsPerServing.Count );
             Assert.AreEqual( "Meat", testFoodItem.FoodGroupsPerServing[0].Entity.Name );
             Assert.AreEqual( 1.5M, testFoodItem.FoodGroupsPerServing[0].Quantity );
             Assert.IsNull( testFoodItem.FoodGroupsPerServing[3].Entity );
             Assert.AreEqual( 0.5M, testFoodItem.FoodGroupsPerServing[3].Quantity );

             testFoodItem = repository.GetAllFoodItems()[2];
             Assert.AreEqual( new Guid( "46d04859-f95d-4ed6-9697-3e8a15c0bc91" ), testFoodItem.ID );
             Assert.AreEqual( "Glass of Skim Milk", testFoodItem.Name );
             Assert.IsNull( testFoodItem.Description );
             Assert.AreEqual( 90, testFoodItem.CaloriesPerServing );
             Assert.AreEqual( 1, testFoodItem.FoodGroupsPerServing.Count );
             Assert.AreEqual( "Dairy", testFoodItem.FoodGroupsPerServing[0].Entity.Name );
             Assert.AreEqual( 2, testFoodItem.FoodGroupsPerServing[0].Quantity );

             testFoodItem = repository.GetAllFoodItems()[4];
             Assert.AreEqual( new Guid( "d29701af-a487-466d-b752-34a6ae7269cd" ), testFoodItem.ID );
             Assert.AreEqual( "Baby Carrots", testFoodItem.Name );
             Assert.IsNull( testFoodItem.Description );
             Assert.AreEqual( 40, testFoodItem.CaloriesPerServing );
             Assert.AreEqual( 1, testFoodItem.FoodGroupsPerServing.Count );
             Assert.IsNull( testFoodItem.FoodGroupsPerServing[0].Entity );
             Assert.AreEqual( 1, testFoodItem.FoodGroupsPerServing[0].Quantity );

             // Verify that the Meal Templates have loaded properly
             Assert.AreEqual( 1, repository.GetAllMealTemplates().Count );
             foreach (MealTemplate meal in repository.GetAllMealTemplates())
             {
            // In this case, the one and only currentMealTemplate we have set up should
            // not be valid.  It should not have a type
            Assert.IsFalse( meal.IsValid );
            Assert.AreEqual( Messages.Error_No_MealType, meal["TypeOfMeal"] );
             }

             MealTemplate testMealTemplate = repository.GetAllMealTemplates()[0];
             Assert.AreEqual( "Cheeseburger Lunch", testMealTemplate.Name );
             Assert.IsNull( testMealTemplate.Description );
             Assert.IsNull( testMealTemplate.TypeOfMeal );
             Assert.AreEqual( 1240, testMealTemplate.Calories );
             Assert.AreEqual( DateTime.Parse( "2010-07-16T19:20-06:00" ), testMealTemplate.DateAndTimeOfMeal );
             Assert.AreEqual( 3, testMealTemplate.FoodItemServings.Count );
             Assert.AreEqual( 4, testMealTemplate.FoodGroupServings.Count );

             Assert.AreEqual( 2.25M, testMealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Meat" ).Quantity );
             Assert.AreEqual( 1.5M, testMealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Grain" ).Quantity );
             Assert.AreEqual( 6.5M, testMealTemplate.FoodGroupServings.Find( fg => fg.Entity.Name == "Dairy" ).Quantity );
             Assert.AreEqual( 1.75M, testMealTemplate.FoodGroupServings.Find( fg => fg.Entity == null ).Quantity );
        }
예제 #9
0
        public void GetAllFoodGroups()
        {
            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 );

             ReadOnlyCollection<FoodGroup> allFoodGroups = dataRepository.GetAllFoodGroups();

             Assert.AreEqual( 7, allFoodGroups.Count );
        }
예제 #10
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 ) );
        }