private object[] GetExecuteArguments(BindingMatch match) { if (match.Arguments.Length != match.StepBinding.ParameterTypes.Length) throw errorProvider.GetParameterCountError(match, match.Arguments.Length); var arguments = match.Arguments.Select( (arg, argIndex) => ConvertArg(arg, match.StepBinding.ParameterTypes[argIndex])) .ToArray(); return arguments; }
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; }
private TimeSpan ExecuteStepMatch(BindingMatch match, object[] arguments) { OnStepStart(); TimeSpan duration; match.StepBinding.InvokeAction(contextManager, arguments, testTracer, out duration); OnStepEnd(); return duration; }
public void TraceStepDone(BindingMatch match, object[] arguments, TimeSpan duration) { traceListener.WriteToolOutput("done: {0} ({1:F1}s)", stepFormatter.GetMatchText(match, arguments), duration.TotalSeconds); }
public void TraceStepPending(BindingMatch match, object[] arguments) { traceListener.WriteToolOutput("pending: {0}", stepFormatter.GetMatchText(match, arguments)); }
public string GetMatchText(BindingMatch match, object[] arguments) { var methodInfo = match.StepBinding.MethodInfo; return GetMatchText(methodInfo, arguments); }
public Exception GetParameterCountError(BindingMatch match, int expectedParameterCount) { return new BindingException( string.Format("Parameter count mismatch! The binding method '{0}' should have {1} parameters", GetMethodText(match.StepBinding.MethodInfo), expectedParameterCount)); }
public void TraceStepDone(TechTalk.SpecFlow.Bindings.BindingMatch match, object[] arguments, TimeSpan duration) { throw new NotImplementedException(); }
public void TraceStepPending(TechTalk.SpecFlow.Bindings.BindingMatch match, object[] arguments) { throw new NotImplementedException(); }
private TimeSpan ExecuteStepMatch(BindingMatch match, object[] arguments) { TimeSpan duration = TimeSpan.Zero; try { match.StepBinding.Invoke(contextManager, testTracer, arguments, out duration); } catch(Exception ex) { if (stepErrorHandlers != null) { StepFailureEventArgs stepFailureEventArgs = new StepFailureEventArgs(match.StepBinding, match.StepArgs.StepContext, ex); foreach (var stepErrorHandler in stepErrorHandlers) { stepErrorHandler.OnStepFailure(this, stepFailureEventArgs); } if (stepFailureEventArgs.IsHandled) return duration; } throw; } return duration; }
public string GetMatchText(BindingMatch match, object[] arguments) { return GetMatchText(match.StepBinding.Method, arguments); }
private object[] GetExecuteArguments(BindingMatch match) { var bindingParameters = match.StepBinding.Method.Parameters.ToArray(); object[] arguments; if (bindingParameters.Any(p => p.IsParamArray)) { arguments = new object[] { match.Arguments.ToArray<object>() }; } else { if (match.Arguments.Length != bindingParameters.Length) throw errorProvider.GetParameterCountError(match, match.Arguments.Length); arguments = match.Arguments.Select( (arg, argIndex) => ConvertArg(arg, bindingParameters[argIndex].Type)) .ToArray(); } return arguments; }