private StepDefinitionBinding CreateStepDefinitionBinding(string regex) { var bindingType = new BindingType("StepNameReplacerTests", "UnitTests.StepNameReplacerTests"); var bindingScope = new BindingScope(null, null, null); var bindingMethod = new BindingMethod(bindingType, "", Enumerable.Empty <IBindingParameter>(), bindingType); var binding = new StepDefinitionBinding(StepDefinitionType.Given, regex, bindingMethod, bindingScope); return(binding); }
public void GetStepDefinitions_should_return_all_step_definitions() { var sut = new BindingRegistry(); var stepDefinitionBinding1 = new StepDefinitionBinding(StepDefinitionType.Given, @"foo.*", new Mock <IBindingMethod>().Object, null); var stepDefinitionBinding2 = new StepDefinitionBinding(StepDefinitionType.When, @"bar.*", new Mock <IBindingMethod>().Object, null); sut.RegisterStepDefinitionBinding(stepDefinitionBinding1); sut.RegisterStepDefinitionBinding(stepDefinitionBinding2); var result = sut.GetStepDefinitions(); result.Should().BeEquivalentTo(stepDefinitionBinding1, stepDefinitionBinding2); }
private static Type TryGetBindingType(IBinding binding) { StepDefinitionBinding stepDefinitionBinding = binding as StepDefinitionBinding; if (stepDefinitionBinding == null) { return(null); } var type = stepDefinitionBinding.Method.Type; RuntimeBindingType runtimeBindingType = type as RuntimeBindingType; if (runtimeBindingType == null) { return(null); } return(runtimeBindingType.Type); }
private BindingMatch Match(StepDefinitionBinding stepDefinitionBinding, StepArgs stepArgs, bool useParamMatching, bool useScopeMatching) { Match match = stepDefinitionBinding.Regex.Match(stepArgs.Text); // Check if regexp is a match if (!match.Success) { return(null); } int scopeMatches = 0; if (useScopeMatching && stepDefinitionBinding.IsScoped) { if (!stepDefinitionBinding.BindingScope.Match(stepArgs.StepContext, out scopeMatches)) { return(null); } } var bindingMatch = new BindingMatch(stepDefinitionBinding, match, CalculateExtraArgs(stepArgs), stepArgs, scopeMatches); if (useParamMatching) { // check if the regex + extra arguments match to the binding method parameters if (bindingMatch.Arguments.Length != stepDefinitionBinding.ParameterTypes.Length) { return(null); } // Check if regex & extra arguments can be converted to the method parameters if (bindingMatch.Arguments.Where( (arg, argIndex) => !CanConvertArg(arg, stepDefinitionBinding.ParameterTypes[argIndex])).Any()) { return(null); } } return(bindingMatch); }