private BindingMatch GetStepMatch(StepArgs stepArgs) { List <BindingMatch> matches = bindingRegistry .Where(b => b.Type == stepArgs.Type) .Select(binding => Match(binding, stepArgs, true, true)) .Where(match => match != null) .ToList(); if (matches.Count > 1) { // if there are both scoped and non-scoped matches, we take the ones with the higher degree of scope matches int maxScopeMatches = matches.Max(m => m.ScopeMatches); matches.RemoveAll(m => m.ScopeMatches < maxScopeMatches); } if (matches.Count > 1) { // we remove duplicate maches for the same method (take the first from each) matches = matches.GroupBy(m => m.StepBinding.MethodInfo, (methodInfo, methodMatches) => methodMatches.First()).ToList(); } if (matches.Count == 0) { // there were either no regex match or it was filtered out by the param/scope matching // to provide better error message for the param matching error, we re-run // the matching without param check List <BindingMatch> matchesWithoutScopeCheck = GetMatchesWithoutScopeCheck(stepArgs); // if (matchesWithoutScopeCheck.Count > 0) // { // no match, because of scope filter // throw errorProvider.GetNoMatchBecauseOfScopeFilterError(matchesWithoutScopeCheck, stepArgs); // } if (matchesWithoutScopeCheck.Count == 0) { List <BindingMatch> matchesWithoutParamCheck = GetMatchesWithoutParamCheck(stepArgs); if (matchesWithoutParamCheck.Count == 1) { // no ambiguouity, but param error -> execute will find it out return(matchesWithoutParamCheck[0]); } if (matchesWithoutParamCheck.Count > 1) { // ambiguouity, because of param error throw errorProvider.GetAmbiguousBecauseParamCheckMatchError(matchesWithoutParamCheck, stepArgs); } } testTracer.TraceNoMatchingStepDefinition(stepArgs, ObjectContainer.FeatureContext.FeatureInfo.GenerationTargetLanguage, matchesWithoutScopeCheck); ObjectContainer.ScenarioContext.MissingSteps.Add( stepDefinitionSkeletonProvider.GetStepDefinitionSkeleton(stepArgs)); throw errorProvider.GetMissingStepDefinitionError(); } if (matches.Count > 1) { if (RuntimeConfiguration.Current.DetectAmbiguousMatches) { throw errorProvider.GetAmbiguousMatchError(matches, stepArgs); } } return(matches[0]); }