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 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 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 GetAllMeals() { 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 ); var allMeals = dataRepository.GetAllMeals(); Assert.AreEqual( 7, allMeals.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 SaveMeal() { 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. 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, and get a deep copy of one out of the repository. // When the new one is saved, a meal 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 time a new meal should not be created, but the meal object with the same // ID should have the modifications applied to it. Guid breakfastMealID = new Guid( "12ed06f0-2251-44c3-bced-b656e6fbe558" ); Guid lunchMealID = new Guid( "53edb94e-3b15-497e-9907-34de41c9bc8d" ); Meal fruitBreakfast = new Meal( breakfastMealID, 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 ); Meal repositoryChzBurgerLunch = dataRepository.FindMeal( m => m.ID == lunchMealID ); Assert.IsNotNull( repositoryChzBurgerLunch ); Meal chzBurgerLunch = new Meal(); chzBurgerLunch.InitializeData( repositoryChzBurgerLunch ); Int32 origMealCount = dataRepository.GetAllMeals().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.FindMeal( m => m.ID == lunchMealID ); 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.FindMeal( m => m.ID == lunchMealID ); 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( origMealCount, dataRepository.GetAllMeals().Count ); // Save the breakfast dataRepository.SaveItem( fruitBreakfast ); Assert.AreEqual( origMealCount + 1, dataRepository.GetAllMeals().Count ); var repositoryFruitBreakfast = dataRepository.FindMeal( f => f.ID == breakfastMealID ); 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 ); }