public void TestMenuClone_shouldCloneFullMenuFromOtheRestaurantAndInsteadOldMenu_OldMenuDeletted() { //arrange RestaurantBasicData restaurant1 = new RestaurantBasicData() { //arrange Id = ObjectId.Parse("50ae8b2a3720e80d085376db"), ItemLocation = new Location() { Latitude = 32.279296, Longitude = 34.860367 }, Menu = new Menu() }; RestaurantBasicData restaurant2 = new RestaurantBasicData() { //arrange Id = ObjectId.Parse("507d8f943720e807c045c442"), ItemLocation = new Location() { Latitude = 32, Longitude = 31 }, Menu = new Menu() }; 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>() }; MenuPart menuPart1 = new MenuPart() { Name = "עיקריות" }; MenuPart menuPart2 = new MenuPart() { Name = "עיקריות" }; menuPart1.Dishes.Add(dish1); menuPart1.Dishes.Add(dish2); menuPart1.Dishes.Add(dish3); menuPart2.Dishes.Add(dish4); restaurant1.Menu.MenuParts.Add(menuPart1); restaurant2.Menu.MenuParts.Add(menuPart2); //act restaurant2.MenuClone(restaurant1); //assert Assert.IsNull(restaurant2.Menu.MenuParts[0].Dishes.FirstOrDefault(d => d.Name=="חזה עוף")); foreach (var dish in restaurant1.Menu.MenuParts[0].Dishes) { Assert.IsNotNull(restaurant2.Menu.MenuParts[0].Dishes.FirstOrDefault(d => d.Name == dish.Name)); } foreach (var dish in restaurant2.Menu.MenuParts[0].Dishes) { Assert.AreEqual(dish.ItemLocation, restaurant2.ItemLocation); } }
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); } }
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 bool findMenuPart(Menu menu, MenuPart menuPart) { return false; }
public void GetDishModelTest_ShouldReturnRestaurantModelWithDishModelBackOfficeIfCalledWithRestaurantModelBackOfficeParameter() { Dish dish1 = new Dish() { Name = "TempDish1", Description = "description", Id = 1, NutritionFacts = new NutritionFacts(), BaseLineNutritionFacts = new NutritionFacts() }; Dish dish2 = new Dish() { Name = "TempDish2", Description = "description", Id = 2, NutritionFacts = new NutritionFacts(), BaseLineNutritionFacts = new NutritionFacts() }; Dish dish3 = new Dish() { Name = "TempDish3", Description = "description", Id = 3, NutritionFacts = new NutritionFacts(), BaseLineNutritionFacts = new NutritionFacts() }; Dish dish4 = new Dish() { Name = "TempDish4", Description = "description", Id = 4, NutritionFacts = new NutritionFacts(), BaseLineNutritionFacts = new NutritionFacts() }; var dishList1 = new List<Dish>(); dishList1.Add(dish1); dishList1.Add(dish2); var dishList2 = new List<Dish>(); dishList2.Add(dish3); dishList2.Add(dish4); MenuPart menuPart1 = new MenuPart() { Name = "TestMenuPart", Id = 1, OrderBy = 1, Dishes = dishList1 }; MenuPart menuPart2 = new MenuPart() { Name = "TestMenuPart", Id = 2, OrderBy = 2, Dishes = dishList1 }; List<MenuPart> menuPartsList = new List<MenuPart>(); menuPartsList.Add(menuPart1); menuPartsList.Add(menuPart2); Menu menu = new Menu(); menu.MenuParts.Add(menuPart1); menu.MenuParts.Add(menuPart2); RestaurantBasicData restBasic = new RestaurantBasicData() { Name = "TestRest", Id = new ObjectId(), Menu = menu }; RestaurantModelBackOffice restBO = new RestaurantModelBackOffice(); var restModel = restBasic.ToRestaurantModel(true, "he", restBO); foreach (var menuPart in restModel.Menu.MenuParts) { foreach (DishModel dishModel in menuPart.Dishes) { Assert.IsTrue(dishModel.GetType() == typeof(DishModelBackOffice)); } } }
public void ToMenuModel_ShouldConvertMenuToMenuModel_AllDishesAndMenusNamesToSpecificLanguage() { //arrange Dish dish1 = new Dish() { Id = 111, Name = "אורז לבן", Description = "אורז לבן מבושל", LocalizedName = new Localized("he", "אורז לבן"), LocalizedDescription = new Localized("he", "אורז לבן מבושל"), DefaultWeight = new WeightType() { Desc = "100 גרם", LocalizedDescription = new Localized("he", "100 גרם") } }; dish1.LocalizedName.AddDescription("en-US", "white rice"); dish1.LocalizedDescription.AddDescription("en-US", "cooked white rice"); dish1.DefaultWeight.LocalizedDescription.AddDescription("en-US", "100 gramm"); Dish dish2 = new Dish() { Id = 222, Name = "תפוח אדמה", Description = "תפוח אדמה אפוי", LocalizedName = new Localized("he", "תפוח אדמה"), LocalizedDescription = new Localized("he", "תפוח אדמה אפוי"), DefaultWeight = new WeightType() { Desc = "100 גרם", LocalizedDescription = new Localized("he", "200 גרם") } }; dish2.LocalizedName.AddDescription("en-US", "Potato"); dish2.LocalizedDescription.AddDescription("en-US", "Baked Potato"); dish2.DefaultWeight.LocalizedDescription.AddDescription("en-US", "200 gramm"); Menu menu = new Menu() { Id = 1, MenuParts = new List<MenuPart>() }; MenuPart menuPart = new MenuPart(){ Id = 1, Name = "תוספות", LocalizedName = new Localized("he", "תוספות"), Dishes = new List<Dish>() }; menuPart.LocalizedName.AddDescription("en-US", "garnish"); menuPart.Dishes.Add(dish1); menuPart.Dishes.Add(dish2); menu.MenuParts.Add(menuPart); //act MenuModel menuModelDefault = menu.ToMenuModel("2", "he"); MenuModel menuModelEn = menu.ToMenuModel("2", "en-US"); MenuModel menuModelHe = menu.ToMenuModel("2", "he"); //Assert Assert.AreEqual(menuModelDefault.MenuParts[0].Language, "he"); Assert.AreEqual(menuModelDefault.MenuParts[0].Name, "תוספות"); Assert.AreEqual(menuModelEn.MenuParts[0].Language, "en-US"); Assert.AreEqual(menuModelEn.MenuParts[0].Name, "garnish"); Assert.AreEqual(menuModelHe.MenuParts[0].Language, "he"); Assert.AreEqual(menuModelHe.MenuParts[0].Name, "תוספות"); Assert.AreEqual(menuModelDefault.MenuParts[0].Dishes[0].Name, "אורז לבן"); Assert.AreEqual(menuModelDefault.MenuParts[0].Dishes[0].DefaultWeight.Desc, "100 גרם"); Assert.AreEqual(menuModelDefault.MenuParts[0].Dishes[1].Name, "תפוח אדמה"); Assert.AreEqual(menuModelDefault.MenuParts[0].Dishes[1].DefaultWeight.Desc, "200 גרם"); Assert.AreEqual(menuModelHe.MenuParts[0].Dishes[0].Name, "אורז לבן"); Assert.AreEqual(menuModelHe.MenuParts[0].Dishes[0].DefaultWeight.Desc, "100 גרם"); Assert.AreEqual(menuModelHe.MenuParts[0].Dishes[1].Name, "תפוח אדמה"); Assert.AreEqual(menuModelHe.MenuParts[0].Dishes[1].DefaultWeight.Desc, "200 גרם"); Assert.AreEqual(menuModelEn.MenuParts[0].Dishes[0].Name, "white rice"); Assert.AreEqual(menuModelEn.MenuParts[0].Dishes[0].DefaultWeight.Desc, "100 gramm"); Assert.AreEqual(menuModelEn.MenuParts[0].Dishes[1].Name, "Potato"); Assert.AreEqual(menuModelEn.MenuParts[0].Dishes[1].DefaultWeight.Desc, "200 gramm"); }
public static bool Compare(MenuPart existMenuPart, MenuPart menuPart) { if (existMenuPart.Name != null && menuPart.Name != null && existMenuPart.Name == menuPart.Name) return true; return false; }
public static MenuPart ToMenuPartBasic(this MenuPartModel menuPartModel) { MenuPart menuPart = new MenuPart() { Id = menuPartModel.Id, OrderBy = menuPartModel.OrderBy, //Name = menuPartModel.Name, AvailableFrom = menuPartModel.AvailableFrom.ToUniversalTime(), AvailableTill = menuPartModel.AvailableTill.ToUniversalTime(), Dishes = ToDishBasicModel(menuPartModel.Dishes) }; //If already has Localized Description try { IServicesLayer m_serviceLayer = new ServiceLayerImpl(); MenuPart dbMenuPart = m_serviceLayer.GetMenuPartBasic(menuPartModel.Id, menuPartModel.RestaurantId); if (dbMenuPart != null) { if (menuPartModel.Language == null || menuPartModel.Language == DefaultLang) { menuPart.Name = menuPartModel.Name; } else { menuPart.Name = dbMenuPart.Name; } if (dbMenuPart.LocalizedName != null) { menuPart.LocalizedName = dbMenuPart.LocalizedName; } } if (menuPartModel.Language != null) { if (menuPart.LocalizedName == null) { menuPart.LocalizedName = new Localized(menuPartModel.Language, menuPartModel.Name); } else menuPart.LocalizedName.UpdateDescription(menuPartModel.Language, menuPartModel.Name); } else { menuPart.Name = menuPartModel.Name != null ? menuPartModel.Name : ""; } } catch (Exception ex) { log.ErrorFormat("[ExtensionMethods: ToMenuPartBasic] Exception={0}", ex.ToString()); } return menuPart; }
public void CopyAllMenuPart(MenuPart copyFrom) { this.Name = copyFrom.Name; if (copyFrom.LocalizedName != null) this.LocalizedName = copyFrom.LocalizedName; this.AvailableFrom = copyFrom.AvailableFrom; this.AvailableTill = copyFrom.AvailableTill; this.OrderBy = copyFrom.OrderBy; foreach (var Dish in copyFrom.Dishes) { Dish tempDish = new Dish(); tempDish.CopyFrom(Dish); tempDish.Id = Dish.Id; tempDish.OrderBy = Dish.OrderBy; this.Dishes.Add(tempDish); } }
public void CopySelectedMemuParts(CopyList copyList) { log.DebugFormat("[CopySellectedMemuParts] menuCopy={0}.", copyList.ToString()); foreach (var item in copyList.MenuPartsSelectedListCopyFrom) { MenuPart temp = new MenuPart(); temp.CopyAllMenuPart(GetMenuPartBasic(item, copyList.CopyFromId)); AddNewMenuPartBasic(copyList.CopyToRestId, temp); } }
public MenuPart TranslateMenuPart(MenuPart menuPart, string fromLang, string targetlang, bool withMenu) { log.InfoFormat("[TranslateMenuPart] menuPart.Name={0}, menuPart.Id={1}, fromLang={2}, targetlang={3}.", menuPart.Name, menuPart.Id, fromLang, targetlang); if (menuPart != null && fromLang != null && targetlang != null) { bool translatedFlag = false; if (menuPart.LocalizedName != null) { string nameFrom; if (fromLang == "Default") nameFrom = menuPart.Name; else nameFrom = menuPart.LocalizedName.GetDescription(fromLang); if (nameFrom != null) { string translatedName = GoogleTranslate(nameFrom, targetlang); if (translatedName != null && translatedName != nameFrom) { menuPart.LocalizedName.UpdateDescription(targetlang, translatedName); translatedFlag = true; } } } else //menuPart.LocalizedName == null { string nameFrom; if (fromLang == "Default") { nameFrom = menuPart.Name; if (nameFrom != null) { string translatedName = GoogleTranslate(nameFrom, targetlang); if (translatedName != null && translatedName != nameFrom) { menuPart.LocalizedName = new Localized(targetlang, translatedName); translatedFlag = true; } } } else { log.WarnFormat("[TranslateMenuPart] menuPart.LocalizedName == null && fromLang != Default"); } } //translate dishes if (withMenu && menuPart.Dishes != null && menuPart.Dishes.Count > 0) { foreach (var dish in menuPart.Dishes) { var translatedDish = TranslateDish(dish, fromLang, targetlang); if (translatedDish != null) { translatedFlag = true; } } } if (translatedFlag) return menuPart; else return null; } else { log.ErrorFormat("[TranslateMenuPart] menuPart == null or some parameter invalide."); return null; } }
public int AddNewMenuPartBasic(string restaurantId, MenuPart menuPart) { log.InfoFormat("[AddNewMenuPartBasic] restaurantId={0}", restaurantId); RestaurantBasicData tempRest = GetRestaurantBasicById(restaurantId); if(tempRest.Menu == null) tempRest.Menu = new Menu(); if (tempRest.Menu.MenuParts.Count > 0) menuPart.Id = tempRest.Menu.MenuParts.Max(c => c.Id) + 1; tempRest.Menu.MenuParts.Add(menuPart); tempRest.UpdateDishesLocation(); UpdateRestaurant(tempRest); return menuPart.Id; }
public MenuPart TranslateMenuPart(MenuPart menuPart, string fromLang, string targetlang, bool withMenu) { throw new NotImplementedException(); }
public void ToRestaurantModel_ShouldConvertMenuToMenuModel_AllDishesAndMenusNamesToSpecificLanguage() { //arrange RestaurantBasicData rest = new RestaurantBasicData() { Name = "מסעדה", Description = "מסעדת נסיון", LocalizedName = new Localized("he", "מסעדה"), LocalizedDescription = new Localized("he", "מסעדת נסיון") }; rest.LocalizedName.AddDescription("en-US", "restaurant"); rest.LocalizedDescription.AddDescription("en-US", "test restaurant"); Dish dish1 = new Dish() { Id = 111, Name = "אורז לבן", Description = "אורז לבן מבושל", LocalizedName = new Localized("he", "אורז לבן"), LocalizedDescription = new Localized("he", "אורז לבן מבושל"), DefaultWeight = new WeightType() { Desc = "100 גרם", LocalizedDescription = new Localized("he", "100 גרם") } }; dish1.LocalizedName.AddDescription("en-US", "white rice"); dish1.LocalizedDescription.AddDescription("en-US", "cooked white rice"); dish1.DefaultWeight.LocalizedDescription.AddDescription("en-US", "100 gramm"); Dish dish2 = new Dish() { Id = 222, Name = "תפוח אדמה", Description = "תפוח אדמה אפוי", LocalizedName = new Localized("he", "תפוח אדמה"), LocalizedDescription = new Localized("he", "תפוח אדמה אפוי"), DefaultWeight = new WeightType() { Desc = "100 גרם", LocalizedDescription = new Localized("he", "200 גרם") } }; dish2.LocalizedName.AddDescription("en-US", "Potato"); dish2.LocalizedDescription.AddDescription("en-US", "Baked Potato"); dish2.DefaultWeight.LocalizedDescription.AddDescription("en-US", "200 gramm"); Menu menu = new Menu() { Id = 1, MenuParts = new List<MenuPart>() }; MenuPart menuPart = new MenuPart(){ Id = 1, Name = "תוספות", LocalizedName = new Localized("he", "תוספות"), Dishes = new List<Dish>() }; menuPart.LocalizedName.AddDescription("en-US", "garnish"); menuPart.Dishes.Add(dish1); menuPart.Dishes.Add(dish2); menu.MenuParts.Add(menuPart); rest.Menu = menu; //act RestaurantModel restModelDefault = rest.ToRestaurantModel(); RestaurantModel restModelHe = rest.ToRestaurantModel(true, "he"); RestaurantModel restModelEn = rest.ToRestaurantModel(true, "en-US"); RestaurantModel restModelUknown = rest.ToRestaurantModel(true, "123"); //Assert Assert.AreEqual(restModelDefault.Language, "he"); Assert.AreEqual(restModelDefault.Name, "מסעדה"); Assert.AreEqual(restModelDefault.Description, "מסעדת נסיון"); Assert.AreEqual(restModelHe.Language, "he"); Assert.AreEqual(restModelHe.Name, "מסעדה"); Assert.AreEqual(restModelHe.Description, "מסעדת נסיון"); Assert.AreEqual(restModelEn.Language, "en-US"); Assert.AreEqual(restModelEn.Name, "restaurant"); Assert.AreEqual(restModelEn.Description, "test restaurant"); Assert.AreEqual(restModelUknown.Language, "123"); Assert.AreEqual(restModelUknown.Name, "מסעדה"); Assert.AreEqual(restModelUknown.Description, "מסעדת נסיון"); Assert.AreEqual(restModelDefault.Menu.MenuParts[0].Language, "he"); Assert.AreEqual(restModelDefault.Menu.MenuParts[0].Name, "תוספות"); Assert.AreEqual(restModelEn.Menu.MenuParts[0].Language, "en-US"); Assert.AreEqual(restModelEn.Menu.MenuParts[0].Name, "garnish"); Assert.AreEqual(restModelHe.Menu.MenuParts[0].Language, "he"); Assert.AreEqual(restModelHe.Menu.MenuParts[0].Name, "תוספות"); Assert.AreEqual(restModelDefault.Menu.MenuParts[0].Dishes[0].Name, "אורז לבן"); Assert.AreEqual(restModelDefault.Menu.MenuParts[0].Dishes[0].DefaultWeight.Desc, "100 גרם"); Assert.AreEqual(restModelDefault.Menu.MenuParts[0].Dishes[1].Name, "תפוח אדמה"); Assert.AreEqual(restModelDefault.Menu.MenuParts[0].Dishes[1].DefaultWeight.Desc, "200 גרם"); Assert.AreEqual(restModelHe.Menu.MenuParts[0].Dishes[0].Name, "אורז לבן"); Assert.AreEqual(restModelHe.Menu.MenuParts[0].Dishes[0].DefaultWeight.Desc, "100 גרם"); Assert.AreEqual(restModelHe.Menu.MenuParts[0].Dishes[1].Name, "תפוח אדמה"); Assert.AreEqual(restModelHe.Menu.MenuParts[0].Dishes[1].DefaultWeight.Desc, "200 גרם"); Assert.AreEqual(restModelEn.Menu.MenuParts[0].Dishes[0].Name, "white rice"); Assert.AreEqual(restModelEn.Menu.MenuParts[0].Dishes[0].DefaultWeight.Desc, "100 gramm"); Assert.AreEqual(restModelEn.Menu.MenuParts[0].Dishes[1].Name, "Potato"); Assert.AreEqual(restModelEn.Menu.MenuParts[0].Dishes[1].DefaultWeight.Desc, "200 gramm"); }
public void TestCopyAllDishesInMenuPart_shouldCopyToOtherMenuPart_andSaveAllProptertiesIncludeDishId() { //arrange MenuPart copyFrom = new MenuPart(); MenuPart copyTo = new MenuPart(); Dish dish1 = new Dish() { 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() { 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() { 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); //Create copy from data //act copyTo.CopyAllMenuPart(copyFrom); //assert Assert.AreEqual(copyTo.Name, copyFrom.Name); Assert.AreEqual(copyTo.AvailableFrom, copyFrom.AvailableFrom); Assert.AreEqual(copyTo.AvailableTill, copyFrom.AvailableTill); Assert.AreEqual(copyTo.OrderBy, copyFrom.OrderBy); foreach (var item in copyFrom.Dishes) { Assert.IsNotNull(copyTo.Dishes.FirstOrDefault(c => c.Name == item.Name)); Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Name == item.Name).Id, item.Id); Assert.AreEqual(copyTo.Dishes.FirstOrDefault(c => c.Name == item.Name).OrderBy, item.OrderBy); //check all other properties } }
/// <summary> /// Function copy partial MenuPart (dishes which Ids in CopyList) /// </summary> /// <param name="copyList"></param> /// <param name="copyFrom"></param> public void CopyPartialMenuPart(CopyList copyList, MenuPart copyFrom) { int tempDishId; //count of dishes to copy int copyCount = copyList.MenuPartsCopyList[0].DishesIdsList.Count; for (int i = 0; i < copyCount; i++) { tempDishId = copyList.MenuPartsCopyList[0].DishesIdsList[i]; Dish tempDish = new Dish(); tempDish.CopyFrom(copyFrom.Dishes.FirstOrDefault(c => c.Id == tempDishId)); tempDish.Id = this.MaxDishId() + 1; tempDish.OrderBy = tempDish.Id; this.Dishes.Add(tempDish); } }
public void TestUpdateDishesLocation_shouldChangeLocationOfAllDishesToRestaurantLocation() { RestaurantBasicData restaurant = new RestaurantBasicData() { //arrange Id = ObjectId.Parse("50ae8b2a3720e80d085376db"), ItemLocation = new Location() { Latitude = 32.279296, Longitude = 34.860367 }, Menu = new Menu() }; 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>() }; MenuPart menuPart1 = new MenuPart(){Name = "עיקריות"}; menuPart1.Dishes.Add(dish1); menuPart1.Dishes.Add(dish2); menuPart1.Dishes.Add(dish3); MenuPart menuPart2 = new MenuPart(){Name = "מנה ראשונה"}; menuPart2.Dishes.Add(dish1); menuPart2.Dishes.Add(dish2); menuPart2.Dishes.Add(dish3); restaurant.Menu.MenuParts.Add(menuPart1); restaurant.Menu.MenuParts.Add(menuPart2); //act restaurant.UpdateDishesLocation(); //assert int dishCount = 0; foreach (var part in restaurant.Menu.MenuParts) { foreach (var dish in part.Dishes) { dishCount++; Assert.AreEqual(restaurant.ItemLocation, dish.ItemLocation); } } //Chech if all dishes saved Assert.AreEqual(dishCount, 6); }
public static MenuPart ToMenuPartBasic(MenuPartModel menuPartModel) { MenuPart menuPart = new MenuPart() { Id = menuPartModel.Id, OrderBy = menuPartModel.OrderBy, Name = menuPartModel.Name, AvailableFrom = menuPartModel.AvailableFrom.ToUniversalTime(), AvailableTill = menuPartModel.AvailableTill.ToUniversalTime(), Dishes = ToDishBasicModel(menuPartModel.Dishes) }; return menuPart; }