public CopyPartialMenuPart ( |
||
copyList | ||
copyFrom | ||
return | void |
public void TestCopyPartialDishesListToNewMenuPart_shouldCopyOnlySpecificDishesToOtherMenuPart_andSaveAllProptertiesIncludeDishId() { //arrange MenuPart copyFrom = new MenuPart() { Id = 13, OrderBy = 2, Name = "מנות עיקריות" }; MenuPart copyTo = new MenuPart(); Dish dish1 = new Dish() { Id = 1, Description = "סלט ירקות עם חתיכות חזה עוף", DishState = DishStateEnum.Active, Name = "סלט קיסר", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 30, Longitude = 27 }, ImageUrl = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRqKcIkvCQDkCNQkXq0TWtiqRSF5ryYK7NYB79ZBVebpjKBVPcA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 7.77 }, RecipeId = 10, State = new SuspiciousState() { Index = 7.77 }, OverrideIngredients = new List<Ingredient>() }; Dish dish2 = new Dish() { Id = 3, Description = "שניצל מוגש עם צ'יפס", DishState = DishStateEnum.Active, Name = "שניצל", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 31, Longitude = 29 }, ImageUrl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQX5WBzP336hF8Q0FQpk5TdX8m7GI7ymVqJMtyrzSA3afEkqfU8CA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 8.88 }, RecipeId = 28, State = new SuspiciousState() { Index = 8.88 }, OverrideIngredients = new List<Ingredient>() }; Dish dish3 = new Dish() { Id = 15, Description = "המבורגר 220גר עם צ'יפס בצד", DishState = DishStateEnum.Active, Name = "המבורגר", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 32, Longitude = 30 }, ImageUrl = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTmEsDLKjW9dj_Vl8SMdESJkTBGncjY5QDt0sqK77txEUwSi2RzUA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 50 }, RecipeId = 169, State = new SuspiciousState() { Index = 50 }, OverrideIngredients = new List<Ingredient>() }; copyFrom.Dishes.Add(dish1); copyFrom.Dishes.Add(dish2); copyFrom.Dishes.Add(dish3); CopyList copyList = new CopyList() { CopyFromId = "11111", MenuPartsCopyList = new List<MenuPartCopy>() }; //CopyFromList menuCopyFrom = new CopyFromList() //{ // RestaurantId = "11111", // CopyMenuPartList = new List<MenuPartCopy>() //}; copyList.MenuPartsCopyList.Add(new MenuPartCopy() { MenuPartId = 1, DishesIdsList = new List<int> { 1, 15 }, PartialCopy = true }); //CopyList copyList = new CopyList() { CopyFrom = menuCopyFrom }; //Create copy from data //act copyTo.CopyPartialMenuPart(copyList, copyFrom); //assert int tempDishId; for(int i=0; i < 2 ; i++) { tempDishId = copyList.MenuPartsCopyList[0].DishesIdsList[i]; string tempDishName = copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).Name; int newDishId = copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName).Id; Assert.IsNull(copyTo.Dishes.FirstOrDefault(c => c.Id == 3)); Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName)); Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Id == newDishId).Description, copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).Description); Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Id == newDishId).RecipeId, copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).RecipeId); Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Id == newDishId).State, copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).State); //check all other properties } }
public void TestCopyPartialDishesListToMenuPart_shouldCopyOnlySpecificDishesToOtherMenuPart_LeaveExistingDishes_updateIdsForInsertedDishes() { //arrange MenuPart copyFrom = new MenuPart() { Id = 13, OrderBy = 2, Name = "מנות עיקריות" }; MenuPart copyTo = new MenuPart(); Dish dish1 = new Dish() { Id = 1, Description = "סלט ירקות עם חתיכות חזה עוף", DishState = DishStateEnum.Active, Name = "סלט קיסר", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 30, Longitude = 27 }, ImageUrl = "https://encrypted-tbn3.gstatic.com/images?q=tbn:ANd9GcRqKcIkvCQDkCNQkXq0TWtiqRSF5ryYK7NYB79ZBVebpjKBVPcA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 7.77 }, RecipeId = 10, State = new SuspiciousState() { Index = 7.77 }, OverrideIngredients = new List<Ingredient>() }; Dish dish2 = new Dish() { Id = 3, Description = "שניצל מוגש עם צ'יפס", DishState = DishStateEnum.Active, Name = "שניצל", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 31, Longitude = 29 }, ImageUrl = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQX5WBzP336hF8Q0FQpk5TdX8m7GI7ymVqJMtyrzSA3afEkqfU8CA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 8.88 }, RecipeId = 28, State = new SuspiciousState() { Index = 8.88 }, OverrideIngredients = new List<Ingredient>() }; Dish dish3 = new Dish() { Id = 15, Description = "המבורגר 220גר עם צ'יפס בצד", DishState = DishStateEnum.Active, Name = "המבורגר", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 32, Longitude = 30 }, ImageUrl = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcTmEsDLKjW9dj_Vl8SMdESJkTBGncjY5QDt0sqK77txEUwSi2RzUA", IsItPublic = true, MappedState = new SuspiciousState() { Index = 50 }, RecipeId = 169, State = new SuspiciousState() { Index = 50 }, OverrideIngredients = new List<Ingredient>() }; Dish dish4 = new Dish() { Id = 4, Description = "חזה עך עם תוספת", DishState = DishStateEnum.Active, Name = "חזה עוף", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 32.89654, Longitude = 31.321 }, IsItPublic = true, MappedState = new SuspiciousState() { Index = 45.5 }, RecipeId = 169, State = new SuspiciousState() { Index = 45.5 }, OverrideIngredients = new List<Ingredient>() }; Dish dish5 = new Dish() { Id = 7, Description = "סטייק פרגית עם תוספת", DishState = DishStateEnum.Active, Name = "סטייק פרגית", NutritionFacts = new NutritionFacts(), ItemLocation = new Location() { Latitude = 31.2222, Longitude = 30.3333 }, IsItPublic = true, MappedState = new SuspiciousState() { Index = 35}, RecipeId = 169, State = new SuspiciousState() { Index = 35 }, OverrideIngredients = new List<Ingredient>() }; copyFrom.Dishes.Add(dish1); copyFrom.Dishes.Add(dish2); copyFrom.Dishes.Add(dish3); copyTo.Dishes.Add(dish4); copyTo.Dishes.Add(dish5); CopyList copyList = new CopyList() { CopyFromId = "11111", MenuPartsCopyList = new List<MenuPartCopy>() }; copyList.MenuPartsCopyList.Add(new MenuPartCopy() { MenuPartId = 1, DishesIdsList = new List<int> { 1, 15 }, PartialCopy = true }); //Create copy from data //act copyTo.CopyPartialMenuPart(copyList, copyFrom); //assert Assert.AreEqual(4, copyTo.Dishes.Count); //Checks if copy function does not deleted existing dishes Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == "חזה עוף")); Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == "סטייק פרגית")); int tempDishId; for (int i = 0; i < copyList.MenuPartsCopyList[0].DishesIdsList.Count; i++) { tempDishId = copyList.MenuPartsCopyList[0].DishesIdsList[i]; string tempDishName = copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId).Name; int newDishId = copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName).Id; //There is no Dish with id=3, which is not in CopyList Assert.IsNull(copyTo.Dishes.FirstOrDefault(c => c.Name == "שניצל")); Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == tempDishName)); //check all other properties } foreach(var dish in copyTo.Dishes) { //There is no Dishes with same Id Assert.AreEqual(copyTo.Dishes.Where(c => c.Id == dish.Id).Count(), 1); Assert.AreEqual(copyTo.Dishes.FindAll(c => c.Name == dish.Name).Count, 1); } }