コード例 #1
0
        public void ToWeightType_shouldUpdateSpecificLocalizedValue()
        {
            //arrange
            WeightType weight = new WeightType()
            {
                Amount = 1,
                Desc = "100 גרם",
                GmWgt = 100,
                LocalizedDescription = new Localized("he", "100 גרם")
            };
            weight.LocalizedDescription.AddDescription("en-US", "100 gramm");

            Dish dish = new Dish();
            dish.DefaultWeight = weight;

            //act
            WeightTypeModel weightModelDefault = weight.ToWeightTypeModel(null);
            WeightTypeModel weightModelHe = weight.ToWeightTypeModel("he");
            WeightTypeModel weightModelEn = weight.ToWeightTypeModel("en-US");
            weightModelDefault.Desc = "111 גרם";
            weightModelHe.Desc = "222 גרם";
            weightModelEn.Desc = "333 gramm";

            WeightType convertedWeightDefault = weightModelDefault.ToWeightType(dish, null);
            WeightType convertedweightHe = weightModelHe.ToWeightType(dish, "he");
            WeightType convertedweightEn = weightModelEn.ToWeightType(dish, "en-US");

            //Assert
            Assert.IsNotNull(convertedWeightDefault);
            Assert.IsNotNull(convertedweightHe);
            Assert.IsNotNull(convertedweightEn);
            Assert.IsNotNull(convertedWeightDefault.LocalizedDescription);
            Assert.IsNotNull(convertedweightHe.LocalizedDescription);
            Assert.IsNotNull(convertedweightEn.LocalizedDescription);

            Assert.AreEqual(convertedWeightDefault.Desc, "111 גרם");
            Assert.AreEqual(convertedweightHe.Desc, "222 גרם");
            Assert.AreEqual(convertedweightEn.Desc, "100 גרם");

            Assert.AreEqual(convertedweightHe.LocalizedDescription.GetDescription("he"), "222 גרם");
            Assert.AreEqual(convertedweightEn.LocalizedDescription.GetDescription("en-US"), "333 gramm");
        }
コード例 #2
0
        public static WeightType ToWeightType(this WeightTypeModel weight, Dish dish, string lang = DefaultLang)
        {
            WeightType returnValue = new WeightType()
            {
                Amount = weight.Amount,
                //Desc = weight.Desc,
                GmWgt = weight.GmWgt
            };
            //If already has Localized Description
            if (dish.DefaultWeight != null && dish.DefaultWeight.LocalizedDescription != null)
            {
                returnValue.Desc = dish.DefaultWeight.Desc;
                returnValue.LocalizedDescription = dish.DefaultWeight.LocalizedDescription;
            }

            if (lang == null || lang == DefaultLang)
            {
                returnValue.Desc = weight.Desc;
            }
            if (lang != null)
            {
                returnValue.LocalizedDescription.UpdateDescription(lang, weight.Desc);
            }

            return returnValue;
        }
コード例 #3
0
        public void ToWeightTypeModel_shouldConvertToSpecificLanguage()
        {
            //arrange
            WeightType weight = new WeightType()
            {
                Desc = "100 גרם",
                LocalizedDescription = new Localized("he", "100 גרם")
            };
            weight.LocalizedDescription.AddDescription("en-US", "100 gramm");

            //act

            WeightTypeModel weightModelDefault = weight.ToWeightTypeModel(null);
            WeightTypeModel weightModelHe = weight.ToWeightTypeModel("he");
            WeightTypeModel weightModelEn = weight.ToWeightTypeModel("en-US");

            //Assert
            Assert.IsNotNull(weightModelDefault);
            Assert.IsNotNull(weightModelHe);
            Assert.IsNotNull(weightModelEn);
            Assert.AreEqual(weightModelDefault.Desc, "100 גרם");
            Assert.AreEqual(weightModelHe.Desc, "100 גרם");
            Assert.AreEqual(weightModelEn.Desc, "100 gramm");
        }