Esempio n. 1
0
        private bool CheckOutputParameter(Match match, Step step, ParameterInfo pi, object parameter)
        {
            Type type = pi.ParameterType.GetElementType();

            if (InlineTypes.InlineTypeExistsFor(type))
            {
                object expectedValue = ValueParser.ParseValue(match.Groups[pi.Name].Value, type);
                object actualValue   = parameter;

                if (!object.Equals(actualValue, expectedValue))
                {
                    Match m     = GetMatch(step);
                    Group group = m.Groups[pi.Name];
                    step.Text = step.Text.Substring(0, group.Index)
                                + string.Format("{0} (was {1})", expectedValue, actualValue)
                                + step.Text.Substring(group.Index + group.Length);
                    return(false);
                }
            }
            else if (step.Block != null && BlockTypes.BlockTypeExistsFor(type))
            {
                return(step.Block.Check(parameter));
            }

            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the pattern for a parameter type.
        /// </summary>
        /// <param name="parameterInfo">The parameter info.</param>
        /// <returns>The pattern.</returns>
        private static string GetPatternForParameter(ParameterInfo parameterInfo)
        {
            Type type = parameterInfo.ParameterType;

            if (parameterInfo.IsOut)
            {
                type = parameterInfo.ParameterType.GetElementType();
            }

            InlineType inlineType = InlineTypes.GetInlineTypeFor(type);

            if (inlineType != null)
            {
                return(string.Format(inlineType.GetPattern(type), parameterInfo.Name));
            }

            return(null);
        }
Esempio n. 3
0
        private object GetParameterFromMatch(ParameterInfo pi, Match match, IBlock block)
        {
            if (InlineTypes.InlineTypeExistsFor(pi.ParameterType))
            {
                if (match.Groups[pi.Name].Success)
                {
                    string value = match.Groups[pi.Name].Value;
                    return(ValueParser.ParseValue(value, pi.ParameterType));
                }
            }
            else if (block != null && BlockTypes.BlockTypeExistsFor(pi.ParameterType))
            {
                BlockType blockType = BlockTypes.GetBlockTypeFor(pi.ParameterType);
                return(blockType.GetObject(pi.ParameterType, block));
            }

            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// Replaces the arg placeholders with patterns based on their type.
        /// </summary>
        /// <param name="methodInfo">The method info.</param>
        /// <param name="splits">The split parts of the step text.</param>
        private static void ReplaceArgPlaceholdersWithPatterns(MethodInfo methodInfo, List <string> splits)
        {
            int i = 1;

            foreach (var pi in methodInfo.GetParameters())
            {
                if (InlineTypes.InlineTypeExistsFor(pi.ParameterType))
                {
                    string argPlaceholder = "arg" + i;

                    int parameterIndex = splits.FindIndex(delegate(string s) { return(s.Equals(argPlaceholder, StringComparison.OrdinalIgnoreCase)); });

                    if (parameterIndex != -1)
                    {
                        splits[parameterIndex] = GetPatternForParameter(pi);
                    }
                }

                i++;
            }
        }