public string CalculateRegexFromMethod(StepDefinitionType stepDefinitionType, IBindingMethod bindingMethod)
        {
            // if method name seems to contain regex, we use it as-is
            if (nonIdentifierRe.Match(bindingMethod.Name).Success)
            {
                return bindingMethod.Name;
            }

            string stepText = bindingMethod.Name;
            stepText = RemoveStepPrefix(stepDefinitionType, stepText);

            var parameters = bindingMethod.Parameters.ToArray();

            int processedPosition = 0;
            var reBuilder = new StringBuilder("(?i)");
            foreach (var paramPosition in parameters.Select((p, i) => CalculateParamPosition(stepText, p, i)).Where(pp => pp.Position >= 0).OrderBy(pp => pp.Position))
            {
                if (paramPosition.Position < processedPosition)
                    continue; //this is an error case -> overlapping parameters

                reBuilder.Append(CalculateRegex(stepText.Substring(processedPosition, paramPosition.Position - processedPosition)));
                reBuilder.Append(CalculateParamRegex(parameters[paramPosition.ParamIndex]));
                processedPosition = paramPosition.Position + paramPosition.Length;
            }

            reBuilder.Append(CalculateRegex(stepText.Substring(processedPosition, stepText.Length - processedPosition)));
            reBuilder.Append(@"\W*");

            return reBuilder.ToString();
        }
        public CodeFunction FindCodeFunction(VsProjectScope projectScope, IBindingMethod bindingMethod)
        {
            var project = projectScope.Project;

            var function = FindCodeFunction(project, bindingMethod);
            if (function != null)
                return function;

            var specFlowProject = projectScope.SpecFlowProjectConfiguration;
            if (specFlowProject != null)
            {
                foreach (var assemblyName in specFlowProject.RuntimeConfiguration.AdditionalStepAssemblies)
                {
                    string simpleName = assemblyName.Split(new[] { ',' }, 2)[0];

                    var stepProject = VsxHelper.FindProjectByAssemblyName(project.DTE, simpleName);
                    if (stepProject != null)
                    {
                        function = FindCodeFunction(stepProject, bindingMethod);
                        if (function != null)
                            return function;
                    }
                }
            }

            return null;
        }
Example #3
0
 public StepBinding(IBindingMethod method, BindingType bindingType, Regex regex, BindingScope bindingScope)
 {
     Method = method;
     BindingType = bindingType;
     Regex = regex;
     BindingScope = bindingScope;
 }
Example #4
0
 public IStepDefinitionBinding CreateStepBinding(StepDefinitionType type, string regexString,
     IBindingMethod bindingMethod, BindingScope bindingScope)
 {
     if (regexString == null)
         regexString = stepDefinitionRegexCalculator.CalculateRegexFromMethod(type, bindingMethod);
     return new StepDefinitionBinding(type, regexString, bindingMethod, bindingScope);
 }
 public StepDefinitionBinding(StepDefinitionType stepDefinitionType, Regex regex, IBindingMethod bindingMethod, BindingScope bindingScope)
     : base(bindingMethod)
 {
     StepDefinitionType = stepDefinitionType;
     Regex = regex;
     BindingScope = bindingScope;
 }
Example #6
0
 public HookBinding(IBindingMethod bindingMethod, HookType hookType, BindingScope bindingScope, int hookOrder)
     : base(bindingMethod)
 {
     HookOrder = hookOrder;
     HookType = hookType;
     BindingScope = bindingScope;
 }
 private CodeFunction FindCodeFunction(Project project, IBindingMethod bindingMethod)
 {
     return GetClassesIncludingPartialClasses(project)
         .Where(c => c.FullName == bindingMethod.Type.FullName)
         .SelectMany(c => c.GetFunctions()).FirstOrDefault(
             f => f.Name == bindingMethod.Name && bindingMethod.MethodEquals(bindingReflectionFactory.CreateBindingMethod(f)));
 }
        public static bool MethodEquals(this IBindingMethod method1, IBindingMethod method2)
        {
            if (ReferenceEquals(method1, method2))
                return true;

            if (method1 == null || method2 == null)
                return false;

            return method1.Name == method2.Name &&
                   method1.Type.TypeEquals(method2.Type) &&
                   method1.Parameters.ParamsEquals(method2.Parameters);
        }
        public static bool MethodEquals(this IBindingMethod method1, IBindingMethod method2)
        {
            if (ReferenceEquals(method1, method2))
                return true;

            if (method1 == null || method2 == null)
                return false;

            if (method1 is RuntimeBindingMethod && method2 is RuntimeBindingMethod)
                return ((RuntimeBindingMethod)method1).MethodInfo.Equals(((RuntimeBindingMethod)method2).MethodInfo);

            return method1.Name == method2.Name &&
                   method1.Type.TypeEquals(method2.Type) &&
                   method1.Parameters.ParamsEquals(method2.Parameters);
        }
Example #10
0
 public Exception GetNonStaticEventError(IBindingMethod method)
 {
     throw new BindingException(
         string.Format("The binding methods for before/after feature and before/after test run events must be static! {0}",
         GetMethodText(method)));
 }
Example #11
0
 public Exception GetCallError(IBindingMethod method, Exception ex)
 {
     return new BindingException(
         string.Format("Error calling binding method '{0}': {1}",
             GetMethodText(method), ex.Message));
 }
Example #12
0
 public void TraceDuration(TimeSpan elapsed, IBindingMethod method, object[] arguments)
 {
     traceListener.WriteToolOutput("duration: {0}: {1:F1}s",
                                   stepFormatter.GetMatchText(method, arguments), elapsed.TotalSeconds);
 }
Example #13
0
 public IStepArgumentTransformationBinding CreateStepArgumentTransformation(string regexString, IBindingMethod bindingMethod)
 {
     return new StepArgumentTransformationBinding(regexString, bindingMethod);
 }
Example #14
0
 public HookBinding(IBindingMethod bindingMethod, HookType hookType, BindingScope bindingScope) : base(bindingMethod)
 {
     HookType = hookType;
     BindingScope = bindingScope;
 }
Example #15
0
 public void TraceDuration(TimeSpan elapsed, IBindingMethod method, object[] arguments)
 {
     traceListener.WriteToolOutput("duration: {0}: {1:F1}s", 
         stepFormatter.GetMatchText(method, arguments), elapsed.TotalSeconds);
 }
Example #16
0
        private IEnumerable <StepInstanceWithProjectScope> FindAllStepMatchingStepInstances(Document document, IBindingMethod bindingMethod)
        {
            var projectScopes = GetProjectScopes(document).ToArray();

            if (projectScopes.Any(ps => !ps.StepSuggestionProvider.Populated))
            {
                MessageBox.Show("Step bindings are still being analyzed. Please wait.", "Go to steps");
                return(new StepInstanceWithProjectScope[0]);
            }
            return(projectScopes.SelectMany(ps => GetMatchingSteps(bindingMethod, ps)).ToArray());
        }
 public Exception GetCallError(IBindingMethod method, Exception ex)
 {
     return(new BindingException(
                string.Format("Error calling binding method '{0}': {1}",
                              GetMethodText(method), ex.Message)));
 }
 public StepDefinitionBindingWithSourceAndError(StepDefinitionType stepDefinitionType, string regexString, IBindingMethod bindingMethod, BindingScope bindingScope) : base(stepDefinitionType, regexString, bindingMethod, bindingScope)
 {
 }
Example #19
0
 public HookBinding(IBindingMethod bindingMethod, HookType hookType, BindingScope bindingScope, int hookOrder) : base(bindingMethod)
 {
     HookOrder    = hookOrder;
     HookType     = hookType;
     BindingScope = bindingScope;
 }
Example #20
0
 public IStepArgumentTransformationBinding CreateStepArgumentTransformation(string regexString, IBindingMethod bindingMethod)
 {
     return(new StepArgumentTransformationBinding(regexString, bindingMethod));
 }
Example #21
0
 public IStepDefinitionBinding CreateStepBinding(StepDefinitionType type, string regexString, IBindingMethod bindingMethod, BindingScope bindingScope)
 {
     if (regexString == null)
     {
         regexString = stepDefinitionRegexCalculator.CalculateRegexFromMethod(type, bindingMethod);
     }
     return(new StepDefinitionBinding(type, regexString, bindingMethod, bindingScope));
 }
Example #22
0
 public IHookBinding CreateHookBinding(IBindingMethod bindingMethod, HookType hookType, BindingScope bindingScope)
 {
     return(new HookBinding(bindingMethod, hookType, bindingScope));
 }
Example #23
0
        public string CalculateRegexFromMethod(StepDefinitionType stepDefinitionType, IBindingMethod bindingMethod)
        {
            // if method name seems to contain regex, we use it as-is
            if (nonIdentifierRe.Match(bindingMethod.Name).Success)
            {
                return(bindingMethod.Name);
            }

            string stepText = bindingMethod.Name;

            stepText = RemoveStepPrefix(stepDefinitionType, stepText);

            var parameters = bindingMethod.Parameters.ToArray();

            int processedPosition = 0;
            var reBuilder         = new StringBuilder("(?i)");

            foreach (var paramPosition in parameters.Select((p, i) => CalculateParamPosition(stepText, p, i)).Where(pp => pp.Position >= 0).OrderBy(pp => pp.Position))
            {
                if (paramPosition.Position < processedPosition)
                {
                    continue; //this is an error case -> overlapping parameters
                }
                reBuilder.Append(CalculateRegex(stepText.Substring(processedPosition, paramPosition.Position - processedPosition)));
                reBuilder.Append(CalculateParamRegex(parameters[paramPosition.ParamIndex]));
                processedPosition = paramPosition.Position + paramPosition.Length;
            }

            reBuilder.Append(CalculateRegex(stepText.Substring(processedPosition, stepText.Length - processedPosition)));
            reBuilder.Append(@"\W*");

            return(reBuilder.ToString());
        }
Example #24
0
 public void TraceDuration(TimeSpan elapsed, IBindingMethod method, object[] arguments)
 {
     //nop
 }
 private IStepArgumentTransformationBinding CreateStepTransformationBinding(string regexString, IBindingMethod transformMethod)
 {
     return new StepArgumentTransformationBinding(regexString, transformMethod);
 }
Example #26
0
 protected MethodBinding(IBindingMethod bindingMethod)
 {
     Method = bindingMethod;
 }
Example #27
0
 public Exception GetNonStaticEventError(IBindingMethod method)
 {
     throw new BindingException(
               string.Format("The binding methods for before/after feature and before/after test run events must be static! {0}",
                             GetMethodText(method)));
 }
Example #28
0
 private void AddStepBinding(IBindingMethod bindingMethod, StepDefinitionBaseAttribute stepDefinitionBaseAttr, BindingScope stepScope)
 {
     foreach (var bindingType in stepDefinitionBaseAttr.Types)
     {
         var stepBinding = bindingFactory.CreateStepBinding(bindingType, stepDefinitionBaseAttr.Regex, bindingMethod, stepScope);
         stepDefinitions.Add(stepBinding);
     }
 }
Example #29
0
 protected MethodBinding(IBindingMethod bindingMethod)
 {
     Method = bindingMethod;
 }
        public IStepDefinitionMatchExpression CreateExpression(string expressionString, StepDefinitionType type, IBindingMethod bindingMethod)
        {
            if (expressionString == null || !IsCucumberExpression(expressionString))
            {
                if (expressionString == null)
                {
                    expressionString = _stepDefinitionRegexCalculator.CalculateRegexFromMethod(type, bindingMethod);
                }

                return(new RegexExpression(expressionString));
            }

            return(new CucumberExpression(expressionString, _cucumberExpressionParameterTypeRegistry));
        }
Example #31
0
 public IHookBinding CreateEventBinding(IBindingMethod bindingMethod, BindingScope bindingScope)
 {
     return new HookBinding(bindingMethod, bindingScope);
 }
 public LateBoundStepDefinitionBindingWithSource(StepDefinitionType stepDefinitionType, IBindingMethod bindingMethod, BindingScope bindingScope, string sourceExpression, Func <Tuple <Regex, string> > regexFactory)
     : this(stepDefinitionType, bindingMethod, bindingScope, sourceExpression, new Lazy <Tuple <Regex, string> >(regexFactory, true))
 {
 }
Example #33
0
 public IHookBinding CreateHookBinding(IBindingMethod bindingMethod, HookType hookType, BindingScope bindingScope)
 {
     return new HookBinding(bindingMethod, hookType, bindingScope);
 }
 protected LateBoundStepDefinitionBindingWithSource(StepDefinitionType stepDefinitionType, IBindingMethod bindingMethod, BindingScope bindingScope, string sourceExpression, Lazy <Tuple <Regex, string> > regexProvider)
     : base(bindingMethod)
 {
     _regexProvider     = regexProvider;
     StepDefinitionType = stepDefinitionType;
     BindingScope       = bindingScope;
     SourceExpression   = sourceExpression;
 }
Example #35
0
 public string GetMatchText(IBindingMethod method, object[] arguments)
 {
     string argText = arguments == null ? "" : string.Join(", ", 
                                                   arguments.Select(a => GetParamString(a)).ToArray());
     return string.Format("{0}.{1}({2})", method.Type.Name, method.Name, argText);
 }
 public StepArgumentTransformationBinding(string regexString, IBindingMethod bindingMethod)
     : this(RegexFactory.Create(regexString), bindingMethod)
 {
 }
Example #37
0
 public string GetMethodText(IBindingMethod method)
 {
     return string.Format("{0}.{1}({2})", method.Type.Name, method.Name,
         string.Join(", ", method.Parameters.Select(p => p.Type.Name).ToArray()));
 }
 private CodeFunction FindCodeFunction(Project project, IBindingMethod bindingMethod)
 {
     return(VsxHelper.GetClasses(project).Where(IsBindingClass).Where(c => c.FullName == bindingMethod.Type.FullName)
            .SelectMany(c => c.GetFunctions()).FirstOrDefault(
                f => f.Name == bindingMethod.Name && BindingReflectionExtensions.MethodEquals(bindingMethod, new VsBindingMethod(f))));
 }
 private CodeFunction FindCodeFunction(Project project, IBindingMethod bindingMethod)
 {
     return VsxHelper.GetClasses(project).Where(IsBindingClass).Where(c => c.FullName == bindingMethod.Type.FullName)
         .SelectMany(c => c.GetFunctions()).FirstOrDefault(
             f => f.Name == bindingMethod.Name && BindingReflectionExtensions.MethodEquals(bindingMethod, new VsBindingMethod(f)));
 }
Example #40
0
        private string GetParamTypes(IBindingMethod bindingMethod)
        {
            var paramTypes = string.Join("|", bindingMethod.Parameters.Select(GetParamType));

            return(paramTypes.Length == 0 ? null : paramTypes);
        }
 public StepDefinitionBinding(StepDefinitionType stepDefinitionType, string regexString, IBindingMethod bindingMethod, BindingScope bindingScope)
     : this(stepDefinitionType, RegexFactory.Create(regexString), bindingMethod, bindingScope)
 {
 }
 private IStepArgumentTransformationBinding CreateStepTransformationBinding(string regexString, IBindingMethod transformMethod)
 {
     return(new StepArgumentTransformationBinding(regexString, transformMethod));
 }
 public StepArgumentTransformationBinding(Regex regex, IBindingMethod bindingMethod)
     : base(bindingMethod)
 {
     Regex = regex;
 }
        public string GetMethodText(IBindingMethod method)
        {
            string parametersDisplayed = string.Join(", ", method.Parameters.Select(p => p.Type.Name).ToArray());

            return($"{method.Type.AssemblyName}:{method.Type.FullName}.{method.Name}({parametersDisplayed})");
        }
        private Regex CallCalculateRegexFromMethodAndAssertRegex(StepDefinitionRegexCalculator sut, StepDefinitionType stepDefinitionType, IBindingMethod bindingMethod)
        {
            var result = sut.CalculateRegexFromMethod(stepDefinitionType, bindingMethod);

            return(AssertRegex(result));
        }
Example #46
0
 public HookBinding(IBindingMethod bindingMethod, BindingScope bindingScope) : base(bindingMethod)
 {
     BindingScope = bindingScope;
 }