Ejemplo n.º 1
0
        public BindingMatchNew Match(StepBindingNew stepBinding, StepInstance stepInstance, bool useRegexMatching = true, bool useParamMatching = true, bool useScopeMatching = true)
        {
            if (useParamMatching)
                useRegexMatching = true;

            Match match = null;
            if (useRegexMatching && stepBinding.Regex != null && !(match = stepBinding.Regex.Match(stepInstance.Text)).Success)
                return BindingMatchNew.NonMatching;

            if (stepBinding.BindingType != stepInstance.BindingType)
                return BindingMatchNew.NonMatching;

            int scopeMatches = 0;
            if (useScopeMatching && stepBinding.IsScoped && stepInstance.StepScope != null && !stepBinding.BindingScope.Match(stepInstance.StepScope, out scopeMatches))
                return BindingMatchNew.NonMatching;

            if (useParamMatching)
            {
                Debug.Assert(match != null);
                var regexArgs = match.Groups.Cast<Group>().Skip(1).Select(g => g.Value);
                var arguments = regexArgs.Cast<object>().AppendIfNotNull(stepInstance.MultilineTextArgument).AppendIfNotNull(stepInstance.TableArgument).ToArray();
                // check if the regex + extra arguments match to the binding method parameters
                if (arguments.Count() != stepBinding.Method.Parameters.Count())
                    return BindingMatchNew.NonMatching;

                // Check if regex & extra arguments can be converted to the method parameters
                if (arguments.Zip(stepBinding.Method.Parameters, (arg, parameter) => CanConvertArg(arg, parameter.Type)).Any(canConvert => !canConvert))
                    return BindingMatchNew.NonMatching;
            }

            return new BindingMatchNew(stepBinding, scopeMatches);
        }
Ejemplo n.º 2
0
        public BindingMatchNew Match(StepBindingNew stepBinding, StepInstance stepInstance, bool useRegexMatching = true, bool useParamMatching = true, bool useScopeMatching = true)
        {
            if (useParamMatching)
            {
                useRegexMatching = true;
            }

            Match match = null;

            if (useRegexMatching && stepBinding.Regex != null && !(match = stepBinding.Regex.Match(stepInstance.Text)).Success)
            {
                return(BindingMatchNew.NonMatching);
            }

            if (stepBinding.BindingType != stepInstance.BindingType)
            {
                return(BindingMatchNew.NonMatching);
            }

            int scopeMatches = 0;

            if (useScopeMatching && stepBinding.IsScoped && stepInstance.StepScope != null && !stepBinding.BindingScope.Match(stepInstance.StepScope, out scopeMatches))
            {
                return(BindingMatchNew.NonMatching);
            }

            if (useParamMatching)
            {
                Debug.Assert(match != null);
                var regexArgs = match.Groups.Cast <Group>().Skip(1).Select(g => g.Value);
                var arguments = regexArgs.Cast <object>().AppendIfNotNull(stepInstance.MultilineTextArgument).AppendIfNotNull(stepInstance.TableArgument).ToArray();
                // check if the regex + extra arguments match to the binding method parameters
                if (arguments.Count() != stepBinding.Method.Parameters.Count())
                {
                    return(BindingMatchNew.NonMatching);
                }

                // Check if regex & extra arguments can be converted to the method parameters
                if (arguments.Zip(stepBinding.Method.Parameters, (arg, parameter) => CanConvertArg(arg, parameter.Type)).Any(canConvert => !canConvert))
                {
                    return(BindingMatchNew.NonMatching);
                }
            }

            return(new BindingMatchNew(stepBinding, scopeMatches));
        }