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 ) ); }
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 ); }
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 ) ); }
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 ); }
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 ); }
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 ); }
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 ); }
public void GetAllFoodItems() { 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<FoodItem> allFoodItems = dataRepository.GetAllFoodItems(); Assert.AreEqual( 5, allFoodItems.Count ); }
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 ) ); }
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 ); }