예제 #1
0
        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;
        }
예제 #2
0
        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;
        }
예제 #3
0
        private TimeSpan ExecuteStepMatch(BindingMatch match, object[] arguments)
        {
            OnStepStart();
            TimeSpan duration;
            match.StepBinding.InvokeAction(contextManager, arguments, testTracer, out duration);
            OnStepEnd();

            return duration;
        }
예제 #4
0
 public void TraceStepDone(BindingMatch match, object[] arguments, TimeSpan duration)
 {
     traceListener.WriteToolOutput("done: {0} ({1:F1}s)", 
         stepFormatter.GetMatchText(match, arguments), duration.TotalSeconds);
 }
예제 #5
0
 public void TraceStepPending(BindingMatch match, object[] arguments)
 {
     traceListener.WriteToolOutput("pending: {0}",
         stepFormatter.GetMatchText(match, arguments));
 }
예제 #6
0
 public string GetMatchText(BindingMatch match, object[] arguments)
 {
     var methodInfo = match.StepBinding.MethodInfo;
     return GetMatchText(methodInfo, arguments);
 }
예제 #7
0
 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));
 }
예제 #8
0
 public void TraceStepDone(TechTalk.SpecFlow.Bindings.BindingMatch match, object[] arguments, TimeSpan duration)
 {
     throw new NotImplementedException();
 }
예제 #9
0
 public void TraceStepPending(TechTalk.SpecFlow.Bindings.BindingMatch match, object[] arguments)
 {
     throw new NotImplementedException();
 }
예제 #10
0
        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;
        }
예제 #11
0
 public string GetMatchText(BindingMatch match, object[] arguments)
 {
     return GetMatchText(match.StepBinding.Method, arguments);
 }
예제 #12
0
        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;
        }