public void DishCompareTest_ShouldFindSameDishes() { var dish1 = new Dish() { Name = "חציל בלעדי", Description = "חציל בלעדי בטחינה" }; var dish2 = new Dish() { Name = "חציל בלעדי", Description = "חציל בלעדי בטחינה" }; var dish3 = new Dish() { Name = "חציל", Description = "חציל בלעדי בטחינה" }; var dish4 = new Dish() { Name = "חציל בלעדי", Description = "חציל בלעדי" }; //Act //var result1 = dishCompare.Compare(dish1, dish2); //var result2 = dishCompare(dish1, dish2); //var result3 = dishCompare(dish1, dish2); //var result4 = dishCompare(dish1, dish2); }
public override DishModel ToDishModel(Dish dishData, string restId, int MenuPId, string lang = DefaultLang, RestaurantModel restaurantModel = null) { if (restaurantModel == null) { restaurantModel = new RestaurantModel(); } if(restaurantModel.GetType() == typeof(RestaurantModelBackOffice)) { return ((RestaurantModelBackOffice)restaurantModel).GetDishModel(dishData, restId, MenuPId, false, lang); } return restaurantModel.GetDishModel(dishData, restId, MenuPId, false, lang); //return dishData.ToDishModel(restId, MenuPId, false, lang, restaurantModel); }
public void ToBaseLineViewModelTest_IfBaseLineIsNullShouldReturnRegularCarbohydrateLevel() { Dish dish1 = new Dish() { Name = "dish1", Description = "description1", NutritionFacts = new NutritionFacts() { TotalCarbohydrate = 2 } }; ToViewModelConverter converter = new ToBaseLineViewModel(); DishModel dishModel1 = converter.ToDishModel(dish1, "111111"); Assert.IsTrue(dishModel1.NutritionFacts.TotalCarbohydrate == 2); }
public void ToBaseLineViewModelTest_IfBaseLineSuspiciousStateMustBeZero() { Dish dish1 = new Dish() { Name = "dish1", Description = "description1", NutritionFacts = new NutritionFacts() { TotalCarbohydrate = 2 } }; ToViewModelConverter converter = new ToBaseLineViewModel(); DishModel dishModel1 = converter.ToDishModel(dish1, "111111"); Assert.IsTrue(dishModel1.State.Index == 0); }
public void ToBaseLineViewModelTest_ShouldConverToViewModelWithBaseLineCarbohydrateLevel() { Dish dish1 = new Dish() { Name = "dish1", Description = "description1", NutritionFacts = new NutritionFacts() { TotalCarbohydrate = 2 }, BaseLineNutritionFacts = new NutritionFacts() { TotalCarbohydrate = 1 } }; ToViewModelConverter converter = new ToBaseLineViewModel(); DishModel dishModel1 = converter.ToDishModel(dish1, "111111"); Assert.IsTrue(dishModel1.NutritionFacts.TotalCarbohydrate == 1); }
public void ToBaseLineViewModelTest_ShouldConverWithMenuPartIdParameter() { Dish dish1 = new Dish() { Name = "dish1", Description = "description1", NutritionFacts = new NutritionFacts() { TotalCarbohydrate = 2 }, BaseLineNutritionFacts = new NutritionFacts() { TotalCarbohydrate = 1 } }; ToViewModelConverter converter = new ToBaseLineViewModel(); DishModel dishModel1 = converter.ToDishModel(dish1, "111111", 3); Assert.IsTrue(dishModel1.MenuPartId == 3); }
public void GetDishModelTest_ShouldReturnDishModelBackOfficeIfCalledFromRestaurantModelBackOffice() { RestaurantModelBackOffice restBO = new RestaurantModelBackOffice(); Dish dish = new Dish() { Name = "TempDish", Description = "description", Id = 1, NutritionFacts = new NutritionFacts(), BaseLineNutritionFacts = new NutritionFacts() }; dish.NutritionFacts.TotalCarbohydrate = 20; dish.BaseLineNutritionFacts.TotalCarbohydrate = 33; DishModel dishModel = restBO.GetDishModel(dish, "111", false, "he"); var type = dishModel.GetType(); Assert.IsTrue(type == typeof(DishModelBackOffice)); }
public void GetDishModelTest_ShouldReturnDishModelBackOfficeWithBaseLineNutritionFacts() { RestaurantModelBackOffice restBO = new RestaurantModelBackOffice(); Dish dish = new Dish() { Name = "TempDish", Description = "description", Id = 1, NutritionFacts = new NutritionFacts(), BaseLineNutritionFacts = new NutritionFacts() }; dish.NutritionFacts.TotalCarbohydrate = 20; dish.BaseLineNutritionFacts.TotalCarbohydrate = 33; var dishModel = (DishModelBackOffice)restBO.GetDishModel(dish, "111", false, "he"); Assert.IsNotNull(dishModel.BaseLineNutritionFacts); Assert.IsTrue(dishModel.BaseLineNutritionFacts.TotalCarbohydrate == 33); }
public DishModel GetDishModel(Dish dishData, string restId, bool baseLine, string lang) { DishModelBackOffice returnValue = new DishModelBackOffice() { Id = dishData.Id, OrderBy = dishData.OrderBy, Name = dishData.Name, Language = lang, Description = dishData.Description, ItemLocation = new LocationModel(dishData.ItemLocation), RestaurantId = restId, //MenuPartId = MenuPId, RecipeId = dishData.RecipeId, //Images = item.Images, //OverrideIngredients = item.OverrideIngredients, CreatedAt = dishData.CreatedAt.ToLocalTime(), UpdatedAt = dishData.UpdatedAt.ToLocalTime(), State = baseLine ? new SuspiciousState() : dishData.State, IsItPublic = dishData.IsItPublic, DishState = dishData.DishState, NutritionFacts = new NutritionFactsViewModel(dishData.NutritionFacts), BaseLineNutritionFacts = dishData.BaseLineNutritionFacts != null ? new NutritionFactsViewModel(dishData.BaseLineNutritionFacts) : new NutritionFactsViewModel(dishData.NutritionFacts), ImageUrl = dishData.ImageUrl }; if (dishData.Image != null) { returnValue.LocalUrl = "/Restaurant/GetImage/" + dishData.Image.Id.ToString(); } if (dishData.DefaultWeight != null) returnValue.DefaultWeight = dishData.DefaultWeight.ToWeightTypeModel(lang); if (dishData.LocalizedName != null) { string locName = dishData.LocalizedName.GetDescription(lang); if (locName != null) returnValue.Name = locName; } if (dishData.LocalizedDescription != null) { string locDesc = dishData.LocalizedDescription.GetDescription(lang); if (locDesc != null) returnValue.Description = locDesc; } return returnValue; }
public void DishTranslate_ShouldTranslateNameAndDescriptionToSpecificLanguage() { //arrange Dish dish = new Dish() { Id = 111, Name = "אורז לבן", Description = "אורז לבן מבושל", LocalizedName = new Localized("he", "אורז לבן"), LocalizedDescription = new Localized("he", "אורז לבן מבושל") }; //dish.LocalizedName.AddDescription("en-US", "white rice"); //dish.LocalizedDescription.AddDescription("en-US", "cooked white rice"); //act var translatedDish = serviceLayer.TranslateDish(dish, "he", "en-US"); //Assert Assert.IsNotNull(translatedDish); Assert.AreEqual(translatedDish.LocalizedName.GetDescription("en-US"), "White rice"); Assert.AreEqual(translatedDish.LocalizedDescription.GetDescription("en-US"), "Cooked white rice"); }
public void TestDownloadImage_dishImageDataShouldReturnImage() { //Arrange ImageData imageData = new ImageData(); Dish dishWithImages = new Dish(); MongoGridFSFileInfo uploadedFile; using (var fs = new FileStream(fileName, FileMode.Open)) { uploadedFile = dishWithImages.UploadImageToDish(m_Testdb.GridFS, fs, fileName); } //act //Example for controller - File(fileStream, ("image/jpg") Stream fileStream = GetImageStream(dishWithImages.Image, m_Testdb.GridFS); //assert Assert.IsTrue(fileStream.CanRead); Assert.IsTrue(fileStream.Length > 0); }
public int AddNewDishBasic(string restId, int menuPartId, Dish dish) { log.InfoFormat("[AddNewDishBasic] RestaurantId={0}, MenuPartId={1}, Dish={2}.", restId, menuPartId.ToString(), dish.ToString()); try { dish.CreatedAt = DateTime.Now; dish.UpdatedAt = DateTime.Now; RestaurantBasicData tempRest = GetRestaurantBasicById(restId); if (tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == menuPartId).Dishes.Count == 0) dish.Id = 0; if (tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == menuPartId).Dishes.Count > 0) dish.Id = tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == menuPartId).Dishes.Max(c => c.Id) + 1; dish.ItemLocation = tempRest.ItemLocation; tempRest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == menuPartId).Dishes.Add(dish); UpdateRestaurant(tempRest); return dish.Id; } catch (Exception ex) { log.InfoFormat("[AddNewDish] Exception={0}, RestaurantId={1}, MenuPartId={2}, Dish={3} ", ex.ToString(), restId, menuPartId, dish.ToString()); return -1; } }
public static GeneralDish IngredientToGeneralDish(this Ingredient ingredient, string language = "en-US") { log.InfoFormat("[IngredientToGeneralDish] Ingredient.USDA_NDB_No={0}, language={1}", ingredient.USDA_NDB_No, language); // return null if LongDesc is null or LongDesc has no translation to this language string ingrName; string ingrDescription; if (ingredient.LongDesc == null || ingredient.LongDesc.GetDescription(language) == null) { log.WarnFormat("[IngredientToGeneralDish] There is no translation, Ingredient.USDA_NDB_No={0}, language={0}, add default(en-US) value.", ingredient.USDA_NDB_No, language); ingrName = ingredient.LongDesc.GetDescription(); ingrDescription = "100gr " + ingredient.LongDesc.GetDescription(); } else { ingrName = ingredient.LongDesc.GetDescription(language); ingrDescription = "100גרם " + ingredient.LongDesc.GetDescription(language); } Dish dish = new Dish() { CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, State = new SuspiciousState() { Index = 100 }, IsItPublic = true, Name = ingrName, Description = ingrDescription, OverrideIngredients = new List<Ingredient>() { ingredient }, NutritionFacts = ingredient.NutritionFacts != null ? ingredient.NutritionFacts : new NutritionFacts(), ItemLocation = new Location(0, 0), DefaultWeight = new WeightType() { Desc = "100גרם", Amount = 1, GmWgt = 100 } }; GeneralDish generalDish = new GeneralDish() { Dish = dish }; return generalDish; }
public Dish TranslateDish(Dish dish, string fromLang, string targetlang) { log.InfoFormat("[TranslateDish] dish={0}, Id={1}, fromLang={2}, targetlang={3}.", dish.Name, dish.Id, fromLang, targetlang); //Dish dish = GetDishBasic(menuPartId, restaurantId, Id); if (dish != null && fromLang != null && targetlang != null) { bool translatedFlag = false; if (dish.LocalizedName != null) { string nameFrom; if (fromLang == "Default") nameFrom = dish.Name; else nameFrom = dish.LocalizedName.GetDescription(fromLang); if (nameFrom != null) { string translatedName = GoogleTranslate(nameFrom, targetlang); if (translatedName != null && translatedName != nameFrom) { dish.LocalizedName.UpdateDescription(targetlang, translatedName); translatedFlag = true; } } } else //dish.LocalizedName == null { string nameFrom; if (fromLang == "Default") { nameFrom = dish.Name; if (nameFrom != null) { string translatedName = GoogleTranslate(nameFrom, targetlang); if (translatedName != null && translatedName != nameFrom) { dish.LocalizedName = new Localized(targetlang, translatedName); translatedFlag = true; } } } else { log.WarnFormat("[TranslateDish] dish.LocalizedName == null && fromLang != Default"); } } if (dish.LocalizedDescription != null) { string descriptionFrom; if (fromLang == "Default") descriptionFrom = dish.Description; else descriptionFrom = dish.LocalizedDescription.GetDescription(fromLang); if (descriptionFrom != null) { string translateDesc = GoogleTranslate(descriptionFrom, targetlang); if (translateDesc != null && translateDesc != descriptionFrom) { dish.LocalizedDescription.UpdateDescription(targetlang, translateDesc); translatedFlag = true; } } } else //dish.LocalizedDescription == null { string descriptionFrom; if (fromLang == "Default") { descriptionFrom = dish.Description; if (descriptionFrom != null) { string translateDesc = GoogleTranslate(descriptionFrom, targetlang); if (translateDesc != null && translateDesc != descriptionFrom) { dish.LocalizedDescription = new Localized(targetlang, translateDesc); translatedFlag = true; } } } else { log.WarnFormat("[TranslateDish] dish.LocalizedDescription == null && fromLang != Default"); } } if (translatedFlag) return dish; else return null; } else { log.ErrorFormat("[TranslateDish] Dish does not exist or can't get dish from DB."); return null; } }
/// <summary> /// Only for update dish image functions and Localized translateions /// </summary> /// <param name="dish"></param> /// <param name="restaurantId"></param> /// <param name="menuPartId"></param> public void UpdateDish(Dish dish, string restaurantId, int menuPartId) { RestaurantBasicData rest = GetRestaurantBasicById(restaurantId); Dish dbDish = rest.Menu.MenuParts.FirstOrDefault(mp => mp.Id == menuPartId).Dishes.First(d => d.Id == dish.Id); if (dbDish != null && dish != null) { dbDish.UpdatedAt = DateTime.Now; dbDish.Image = dish.Image; if (dish.ImageUrl != null && dish.ImageUrl != "" && dish.ImageUrl != dbDish.ImageUrl) { dbDish.ImageUrl = dish.ImageUrl; } if (dish.LocalizedName != null) { dbDish.LocalizedName = dish.LocalizedName; } if (dish.LocalizedDescription != null) { dbDish.LocalizedDescription = dish.LocalizedDescription; } UpdateRestaurant(rest); } }
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 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 } }
public void CopyFrom(Dish copyFrom) { this.Description = copyFrom.Description; if (copyFrom.LocalizedDescription != null) this.LocalizedDescription = copyFrom.LocalizedDescription; this.DishState = copyFrom.DishState; this.CreatedAt = copyFrom.CreatedAt; this.UpdatedAt = copyFrom.UpdatedAt; this.Name = copyFrom.Name; if (copyFrom.LocalizedName != null) this.LocalizedName = copyFrom.LocalizedName; this.NutritionFacts = copyFrom.NutritionFacts; this.ItemLocation = copyFrom.ItemLocation; this.Image = copyFrom.Image; this.Images = copyFrom.Images; this.ImageUrl = copyFrom.ImageUrl; this.IsItPublic = copyFrom.IsItPublic; this.MappedState = copyFrom.MappedState; this.RecipeId = copyFrom.RecipeId; this.State = copyFrom.State; this.OverrideIngredients = copyFrom.OverrideIngredients; }
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); } }
public void TestCopyDish_shouldAllPropertiesToOtherDishBeEquale() { //arrange //string copyFromRestaurantId = "111"; //int copyFromMenuPartId = 1; //string copyToRestaurantId = "222"; //int copyToMenuPartId = 2; Dish copyFrom = 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 copyTo = new Dish(); //Create copy from data //act copyTo.CopyFrom(copyFrom); //assert Assert.AreEqual(copyFrom.Description, copyTo.Description); Assert.AreEqual(copyFrom.DishState, copyTo.DishState); Assert.AreEqual(copyFrom.CreatedAt, copyTo.CreatedAt); Assert.AreEqual(copyFrom.UpdatedAt, copyTo.UpdatedAt); Assert.AreEqual(copyFrom.Name, copyTo.Name); Assert.AreEqual(copyFrom.NutritionFacts, copyTo.NutritionFacts); Assert.AreEqual(copyFrom.ItemLocation, copyTo.ItemLocation); Assert.AreEqual(copyFrom.Image, copyTo.Image); Assert.AreEqual(copyFrom.Images, copyTo.Images); Assert.AreEqual(copyFrom.ImageUrl, copyTo.ImageUrl); Assert.AreEqual(copyFrom.IsItPublic, copyTo.IsItPublic); Assert.AreEqual(copyFrom.MappedState, copyTo.MappedState); Assert.AreEqual(copyFrom.RecipeId, copyTo.RecipeId); Assert.AreEqual(copyFrom.State, copyTo.State); Assert.AreEqual(copyFrom.OverrideIngredients, copyTo.OverrideIngredients); }
// If conversion for new created dishModel then creat new Dish Object // If conversion for existing dish then update changed attributes public static Dish ToDish(this DishModel item, Dish dish = null) { IServicesLayer m_serviceLayer = new ServiceLayerImpl(); if (dish == null) { dish = new Dish(); } dish.Id = item.Id; dish.OrderBy = item.OrderBy; if (item.Language == null || item.Language == DefaultLang) { dish.Name = item.Name; dish.Description = item.Description; } if (dish.LocalizedName == null && item.Language != null) dish.LocalizedName = new Localized(item.Language, item.Name); else { if (item.Language != null) dish.LocalizedName.UpdateDescription(item.Language, item.Name); } if (dish.LocalizedDescription == null && item.Language != null) dish.LocalizedDescription = new Localized(item.Language, item.Description); else { if (item.Language != null) dish.LocalizedDescription.UpdateDescription(item.Language, item.Description); } if (item.ItemLocation == null) { var restaurnat = m_serviceLayer.GetRestaurantBasicById(item.RestaurantId); dish.ItemLocation = restaurnat.ItemLocation; } else { dish.ItemLocation = item.ItemLocation.toLoaction(); } dish.RecipeId = item.RecipeId; //dish.Images = item.Images; //dish.OverrideIngredients = item.OverrideIngredients; dish.CreatedAt = item.CreatedAt.ToUniversalTime(); dish.UpdatedAt = item.UpdatedAt.ToUniversalTime(); dish.State = item.State; dish.IsItPublic = item.IsItPublic; dish.DishState = item.DishState; dish.NutritionFacts = item.NutritionFacts.ToNutritionFacts(); dish.ImageUrl = item.ImageUrl; if (item.GetType() == typeof(DishModelBackOffice) && ((DishModelBackOffice)item).BaseLineNutritionFacts != null) { dish.BaseLineNutritionFacts = ((DishModelBackOffice)item).BaseLineNutritionFacts.ToNutritionFacts(); } try { Dish dbDish = m_serviceLayer.GetDishBasic(item.MenuPartId, item.RestaurantId, item.Id); if (dbDish != null) { if (dbDish.Image != null) dish.Image = dbDish.Image; if (dbDish.Images != null) dish.Images = dbDish.Images; if (item.DefaultWeight != null) dish.DefaultWeight = item.DefaultWeight.ToWeightType(dbDish, item.Language); } } catch (Exception ex) { log.ErrorFormat("[ExtensionMethods: ToDish] Exception={0}", ex.ToString()); } return dish; }
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 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 TestSaveImage_dishImageDataShouldBeSavedInFile() { //Arrange var newFileName = @"C:\Users\Vadik\Dropbox\Work\Downloaded_AlGauchoIcon.jpg"; ImageData imageData = new ImageData(); Dish dishWithImages = new Dish(); MongoGridFSFileInfo uploadedFile; using (var fs = new FileStream(fileName, FileMode.Open)) { uploadedFile = dishWithImages.UploadImageToDish(m_Testdb.GridFS, fs, fileName); } //act //save image to file var file = m_Testdb.GridFS.FindOne(Query.EQ("_id", dishWithImages.Image.Id)); using (var stream = file.OpenRead()) { var bytes = new byte[stream.Length]; stream.Read(bytes, 0, (int)stream.Length); using (var newFs = new FileStream(newFileName, FileMode.Create)) { newFs.Write(bytes, 0, bytes.Length); } } //open source and saved files var source = new FileStream(fileName, FileMode.Open); var savedFile = new FileStream(newFileName, FileMode.Open); //Example for controller - File(fileStream, ("image/jpg") //assert Assert.AreEqual(source.Length, savedFile.Length); }
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 TestUploadImage_should_beSavedDishImageIdShouldHaveSameId() { //Arrange ImageData imageData = new ImageData(); Dish dishWithImages = new Dish(); MongoGridFSFileInfo uploadedFile; using (var fs = new FileStream(fileName, FileMode.Open)) { //act uploadedFile = dishWithImages.UploadImageToDish(m_Testdb.GridFS, fs, fileName); } //assert Assert.IsNotNull(dishWithImages.Image); Assert.AreEqual(uploadedFile.Id, dishWithImages.Image.Id); }
/// <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 TestDownloadImage_should_existInStorage() { //Arrange ImageData imageData = new ImageData(); Dish dishWithImages = new Dish(); MongoGridFSFileInfo uploadedFile; using (var fs = new FileStream(fileName, FileMode.Open)) { uploadedFile = dishWithImages.UploadImageToDish(m_Testdb.GridFS, fs, fileName); } //act var file = m_Testdb.GridFS.FindOne(Query.EQ("_id", dishWithImages.Image.Id)); //assert Assert.IsTrue(file.Exists); }
public void GetDishModelTest_ShouldReturnListOfDishModelBackOfficeIfCalledWithRestaurantModelBackOfficeParameter() { RestaurantModelBackOffice restBO = new RestaurantModelBackOffice(); 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() }; var dishList = new List<Dish>(); dishList.Add(dish1); dishList.Add(dish2); List<DishModel> dishListModel = dishList.ToDishModel("111", 1, "he", restBO); foreach (DishModel dishModel in dishListModel) { Assert.IsTrue(dishModel.GetType() == typeof(DishModelBackOffice)); } }