00001 00002 using System; 00003 using NUnit.Framework; 00004 using Foodolini.BusinessLogic; 00005 using System.Collections.Generic; 00006 00007 namespace Foodolini.BusinessLogic.Test 00008 { 00009 00013 [TestFixture] 00014 public class RecipeTest: LogicTest 00015 { 00019 [Test] 00020 public void CreateRecipeTest () 00021 { 00022 Recipe recipe = new Recipe("Sloppy Joe"); 00023 recipe.Save(); 00024 } 00025 00026 00030 [Test] 00031 public void SaveRecipeTest() 00032 { 00033 Recipe recipe = new Recipe("Sloppy Joe"); 00034 recipe.Ingredients.Add(new Ingredient("ingTitle"), 23); 00035 recipe.Ingredients.Add(new Ingredient("ingName"), 34); 00036 recipe.Categories.Add("Breakfast"); 00037 recipe.Difficulty = Difficulty.Easy; 00038 recipe.Directions.Add("Do the first ting"); 00039 recipe.Directions.Add("Do the next thing"); 00040 recipe.PreparationTime = new TimeSpan(34); 00041 recipe.Save(); 00042 } 00043 00051 [Test] 00052 00053 public void SaveAndLoadRecipeTest() 00054 { 00055 Recipe recipe = new Recipe("Sloppy Joe"); 00056 recipe.Ingredients.Add(new Ingredient("ingTitle"), 23); 00057 recipe.Ingredients.Add(new Ingredient("ingName"), 34); 00058 recipe.Categories.Add("Breakfast"); 00059 recipe.Difficulty = Difficulty.Easy; 00060 recipe.Directions.Add("Do the first ting"); 00061 recipe.Directions.Add("Do the next thing"); 00062 recipe.PreparationTime = new TimeSpan(34); 00063 recipe.Save(); 00064 00065 Recipe loadedrecipe = Recipe.GetByTitle("Sloppy Joe"); 00066 00067 Assert.AreEqual("Sloppy Joe",loadedrecipe.Title); 00068 Assert.AreEqual(2,loadedrecipe.Ingredients.Count); 00069 Assert.AreEqual(2,loadedrecipe.Directions.Count); 00070 00071 00072 } 00079 [Test] 00080 public void CookRecipeTest() 00081 { 00082 Ingredient ing1 = Ingredient.GetByLongDescription("Butter, salted"); 00083 Ingredient ing2 = Ingredient.GetByLongDescription("Cheese, brick"); 00084 00085 ing1.Save(); 00086 ing2.Save(); 00087 00088 FoodItem food1 = new FoodItem(80,ing1,new DateTime((int)2010,(int)1,(int)1),false); 00089 FoodItem food2 = new FoodItem(80,ing2,new DateTime((int)2010,(int)1,(int)1),false); 00090 food1.Save(); 00091 food2.Save(); 00092 00093 Recipe recipe = new Recipe("Sloppy Joe"); 00094 recipe.Ingredients.Add(ing1, 34); 00095 recipe.Ingredients.Add(ing2, 22); 00096 recipe.Categories.Add("Breakfast"); 00097 recipe.Difficulty = Difficulty.Easy; 00098 recipe.Directions.Add("Do the first ting"); 00099 recipe.Directions.Add("Do the next thing"); 00100 recipe.PreparationTime = new TimeSpan(34); 00101 recipe.Save(); 00102 00103 Recipe loadedrecipe = Recipe.GetByTitle("Sloppy Joe"); 00104 00105 Assert.AreNotEqual(null,loadedrecipe,"must not be null"); 00106 00107 List<FoodItem> count = new List<FoodItem>(FoodItem.ListFoodItems()); 00108 Assert.AreEqual(2, count.Count ,"there shoud only be 2 fooditems in the database"); 00109 00110 loadedrecipe.Cook(2,50).Save() ; 00111 00112 Assert.AreNotEqual(null, Ingredient.GetByLongDescription("Sloppy Joe"),"there is no ingredient Sloppy Joe"); 00113 00114 Assert.AreEqual( Math.Round((ing1.Carbohydrates * 34 + ing2.Carbohydrates*22)/200 ,4),Math.Round(Ingredient.GetByLongDescription("Sloppy Joe").Carbohydrates,4) ,"add the Carbohydrates wrong"); 00115 Assert.AreEqual( Math.Round((ing1.Protein * 34 + ing2.Protein*22)/200 ,4),Math.Round(Ingredient.GetByLongDescription("Sloppy Joe").Protein,4) ,"add the Protein wrong"); 00116 Assert.AreEqual( Math.Round((ing1.Fat * 34 + ing2.Fat*22)/200 ,4),Math.Round(Ingredient.GetByLongDescription("Sloppy Joe").Fat,4) ,"add the Fat wrong"); 00117 00118 count = new List<FoodItem>(FoodItem.ListFoodItems()); 00119 Assert.AreEqual(3, count.Count ,"there shoud be 3 fooditems in the database as we have cooked a new one"); 00120 00121 00122 List<FoodItem> fooditem = new List<FoodItem>(FoodItem.ListFoodItems()); 00123 foreach (var f in fooditem){ 00124 if (f.Id == food1.Id){ 00125 Assert.AreEqual(12, f.Quantity ,"foodremaining dont match"); 00126 }else if (f.Id == food2.Id){ 00127 Assert.AreEqual(36, f.Quantity ,"foodremaining dont match"); 00128 }else{ 00129 Assert.AreEqual(56, f.Quantity ,"new cooked fooditem dont match"); 00130 } 00131 } 00132 } 00133 } 00134 }