コード例 #1
0
        internal static void AssertEqual(this ChileProductIngredient ingredient, ISetChileProductIngredientParameters parameters)
        {
            if (ingredient == null)
            {
                throw new ArgumentNullException("ingredient");
            }
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            Assert.AreEqual(ingredient.ToAdditiveTypeKey().KeyValue, parameters.AdditiveTypeKey);
            Assert.AreEqual(ingredient.Percentage, parameters.Percentage);
        }
        internal static IResult <SetChileProductIngredientCommandParameters> ToParsedParameters(this ISetChileProductIngredientParameters parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            var additiveTypeKeyResult = KeyParserHelper.ParseResult <IAdditiveTypeKey>(parameters.AdditiveTypeKey);

            if (!additiveTypeKeyResult.Success)
            {
                return(additiveTypeKeyResult.ConvertTo <SetChileProductIngredientCommandParameters>());
            }

            if (parameters.Percentage < 0.0 || parameters.Percentage > 100.0)
            {
                return(new InvalidResult <SetChileProductIngredientCommandParameters>(null, UserMessages.IngredientPercentageCanIngredientPercentageOutOfRange));
            }

            return(new SuccessResult <SetChileProductIngredientCommandParameters>(new SetChileProductIngredientCommandParameters
            {
                Parameters = parameters,
                AdditiveTypeKey = additiveTypeKeyResult.ResultingObject.ToAdditiveTypeKey()
            }));
        }