Exemple #1
0
        public BindingMatch(StepBinding stepBinding, Match match, object[] extraArguments, StepArgs stepArgs, int scopeMatches)
        {
            if (stepBinding == null)
            {
                throw new ArgumentNullException("stepBinding");
            }
            if (match == null)
            {
                throw new ArgumentNullException("match");
            }
            if (extraArguments == null)
            {
                throw new ArgumentNullException("extraArguments");
            }
            if (stepArgs == null)
            {
                throw new ArgumentNullException("stepArgs");
            }

            StepBinding    = stepBinding;
            Match          = match;
            ExtraArguments = extraArguments;
            StepArgs       = stepArgs;
            ScopeMatches   = scopeMatches;

            RegexArguments = Match.Groups.Cast <Group>().Skip(1).Select(g => g.Value).ToArray();
            Arguments      = RegexArguments.Concat(ExtraArguments).ToArray();
        }
Exemple #2
0
 public BindingMatch(StepBinding stepBinding, Match match, object[] extraArguments, StepArgs stepArgs)
 {
     StepBinding = stepBinding;
     Match = match;
     ExtraArguments = extraArguments;
     StepArgs = stepArgs;
 }
        public BindingMatch Match(StepBinding 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 BindingMatch.NonMatching;

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

            int scopeMatches = 0;
            if (useScopeMatching && stepBinding.IsScoped && stepInstance.StepScope != null && !stepBinding.BindingScope.Match(stepInstance.StepScope, out scopeMatches))
                return BindingMatch.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 BindingMatch.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 BindingMatch.NonMatching;
            }

            return new BindingMatch(stepBinding, scopeMatches);
        }
Exemple #4
0
 public BindingMatch(StepBinding stepBinding, Match match, object[] extraArguments, StepArgs stepArgs, bool isScoped)
 {
     StepBinding = stepBinding;
     Match = match;
     ExtraArguments = extraArguments;
     StepArgs = stepArgs;
     IsScoped = isScoped;
 }
Exemple #5
0
        public BindingMatch(StepBinding stepBinding, Match match, object[] extraArguments, StepArgs stepArgs, int scopeMatches)
        {
            if (stepBinding == null) throw new ArgumentNullException("stepBinding");
            if (match == null) throw new ArgumentNullException("match");
            if (extraArguments == null) throw new ArgumentNullException("extraArguments");
            if (stepArgs == null) throw new ArgumentNullException("stepArgs");

            StepBinding = stepBinding;
            Match = match;
            ExtraArguments = extraArguments;
            StepArgs = stepArgs;
            ScopeMatches = scopeMatches;

            RegexArguments = Match.Groups.Cast<Group>().Skip(1).Select(g => g.Value).ToArray();
            Arguments = RegexArguments.Concat(ExtraArguments).ToArray();
        }
        public BindingMatch Match(StepBinding 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(BindingMatch.NonMatching);
            }

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

            int scopeMatches = 0;

            if (useScopeMatching && stepBinding.IsScoped && stepInstance.StepScope != null && !stepBinding.BindingScope.Match(stepInstance.StepScope, out scopeMatches))
            {
                return(BindingMatch.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(BindingMatch.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(BindingMatch.NonMatching);
                }
            }

            return(new BindingMatch(stepBinding, scopeMatches));
        }
        private BindingMatch Match(StepBinding stepBinding, StepArgs stepArgs, bool useParamMatching, bool useScopeMatching)
        {
            Match match = stepBinding.Regex.Match(stepArgs.Text);

            // Check if regexp is a match
            if (!match.Success)
                return null;

            int scopeMatches = 0;
            if (useScopeMatching && stepBinding.IsScoped)
            {
                if (!stepBinding.BindingScope.Match(stepArgs.StepContext, out scopeMatches))
                    return null;
            }

            var bindingMatch = new BindingMatch(stepBinding, match, CalculateExtraArgs(stepArgs), stepArgs, scopeMatches);

            if (useParamMatching)
            {
                // check if the regex + extra arguments match to the binding method parameters
                if (bindingMatch.Arguments.Length != stepBinding.ParameterTypes.Length)
                    return null;

                // Check if regex & extra arguments can be converted to the method parameters
                if (bindingMatch.Arguments.Where(
                    (arg, argIndex) => !CanConvertArg(arg, stepBinding.ParameterTypes[argIndex])).Any())
                    return null;
            }
            return bindingMatch;
        }