Exemple #1
0
 public override DishModel ToDishModel(Dish dishData, string restId, string lang = DefaultLang, RestaurantModel restaurantModel = null)
 {
     return dishData.ToDishModel(restId, false, lang, restaurantModel);
 }
        public void ToDish_ShouldConvertDishModelToDish_WithSelectedLanguagaTransltaion_andLeaveOtherTranslations()
        {
            //arrange

            Dish dish = new Dish()
            {
                Id = 111,
                Name = "אורז לבן",
                Description = "אורז לבן מבושל",
                LocalizedName = new Localized("he", "אורז לבן"),
                LocalizedDescription = new Localized("he", "אורז לבן מבושל"),
                DefaultWeight = new WeightType()
                {
                    Desc = "100 גרם",
                    LocalizedDescription = new Localized("he", "100 גרם")
                }
            };
            dish.LocalizedName.AddDescription("en-US", "white rice");
            dish.LocalizedDescription.AddDescription("en-US", "cooked white rice");
            dish.DefaultWeight.LocalizedDescription.AddDescription("en-US", "100 gramm");

            //act

            DishModel dishModelEn = dish.ToDishModel("111", "en-US");
            dishModelEn.Name = "White Rice with Corn";
            dishModelEn.Description = "cooked White Rice with Corn";
            Dish convertedDishEn = dishModelEn.ToDish(dish);

            //Assert
            Assert.IsNotNull(convertedDishEn);
            Assert.AreEqual(convertedDishEn.Name, "אורז לבן");
            Assert.AreEqual(convertedDishEn.Description, "אורז לבן מבושל");
            Assert.AreEqual(convertedDishEn.LocalizedName.GetDescription("en-US"), "White Rice with Corn");
            Assert.AreEqual(convertedDishEn.LocalizedDescription.GetDescription("en-US"), "cooked White Rice with Corn");
            Assert.AreEqual(convertedDishEn.LocalizedName.GetDescription("he"), "אורז לבן");
            Assert.AreEqual(convertedDishEn.LocalizedDescription.GetDescription("he"), "אורז לבן מבושל");

            //Assert.AreEqual(convertedDishEn.DefaultWeight.Desc, "100 גרם");
        }
        public void ToDishModel_ShouldConvertDishToDishModel_AndConvertWeightToSpecificLanguage()
        {
            //arrange

            Dish dish = new Dish()
            {
                Id = 111,
                Name = "אורז לבן",
                Description = "אורז לבן מבושל",
                LocalizedName = new Localized("he", "אורז לבן"),
                LocalizedDescription = new Localized("he", "אורז לבן מבושל"),
                DefaultWeight = new WeightType()
                {
                    Desc = "100 גרם",
                    LocalizedDescription = new Localized("he", "100 גרם")
                }
            };
            dish.LocalizedName.AddDescription("en-US", "white rice");
            dish.LocalizedDescription.AddDescription("en-US", "cooked white rice");
            dish.DefaultWeight.LocalizedDescription.AddDescription("en-US", "100 gramm");

            //act

            DishModel dishModelDefault = dish.ToDishModel("111");
            DishModel dishModelEn = dish.ToDishModel("111", "en-US");
            DishModel dishModelHe = dish.ToDishModel("111", "he");

            //Assert
            Assert.AreEqual(dishModelDefault.DefaultWeight.Desc, "100 גרם");
            Assert.AreEqual(dishModelHe.DefaultWeight.Desc, "100 גרם");
            Assert.AreEqual(dishModelEn.DefaultWeight.Desc, "100 gramm");
        }
        public void ToDishModel_TryToGetUknownLanguageDescriptio_ShouldReturn_DefaulValuesOfDishAndWeights()
        {
            //arrange

            Dish dish = new Dish()
            {
                Id = 111,
                Name = "אורז לבן",
                Description = "אורז לבן מבושל",
                LocalizedName = new Localized("he", "אורז לבן"),
                LocalizedDescription = new Localized("he", "אורז לבן מבושל"),
                DefaultWeight = new WeightType()
                {
                    Desc = "100 גרם",
                    LocalizedDescription = new Localized("he", "100 גרם")
                }
            };
            dish.LocalizedName.AddDescription("en-US", "white rice");
            dish.LocalizedDescription.AddDescription("en-US", "cooked white rice");
            dish.DefaultWeight.LocalizedDescription.AddDescription("en-US", "100 gramm");

            //act

            DishModel dishModelUknown = dish.ToDishModel("111", "111");

            //Assert
            Assert.IsNotNull(dishModelUknown);
            Assert.AreEqual(dishModelUknown.Name, "אורז לבן");
            Assert.AreEqual(dishModelUknown.Language, "111");
            Assert.AreEqual(dishModelUknown.DefaultWeight.Desc, "100 גרם");
        }
        public void ToDishModel_ShouldConvertDishToDishModelWithTranslationToSpecificLanguage()
        {
            //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

            DishModel dishModelDefault = dish.ToDishModel("111");
            DishModel dishModelEn = dish.ToDishModel("111", "en-US");
            DishModel dishModelHe = dish.ToDishModel("111", "he");

            //Assert
            Assert.IsNotNull(dishModelDefault);
            Assert.IsNotNull(dishModelEn);
            Assert.IsNotNull(dishModelHe);
            Assert.AreEqual(dishModelDefault.Name, "אורז לבן");
            Assert.AreEqual(dishModelDefault.Description, "אורז לבן מבושל");
            Assert.AreEqual(dishModelHe.Name, "אורז לבן");
            Assert.AreEqual(dishModelHe.Description, "אורז לבן מבושל");
            Assert.AreEqual(dishModelEn.Name, "white rice");
            Assert.AreEqual(dishModelEn.Description, "cooked white rice");
            Assert.AreEqual(dishModelDefault.Language, "he");
            Assert.AreEqual(dishModelEn.Language, "en-US");
            Assert.AreEqual(dishModelHe.Language, "he");
        }