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; }
public StepBinding(IBindingMethod method, BindingType bindingType, Regex regex, BindingScope bindingScope) { Method = method; BindingType = bindingType; Regex = regex; BindingScope = bindingScope; }
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; }
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); }
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))); }
public Exception GetCallError(IBindingMethod method, Exception ex) { return new BindingException( string.Format("Error calling binding method '{0}': {1}", GetMethodText(method), ex.Message)); }
public void TraceDuration(TimeSpan elapsed, IBindingMethod method, object[] arguments) { traceListener.WriteToolOutput("duration: {0}: {1:F1}s", stepFormatter.GetMatchText(method, arguments), elapsed.TotalSeconds); }
public IStepArgumentTransformationBinding CreateStepArgumentTransformation(string regexString, IBindingMethod bindingMethod) { return new StepArgumentTransformationBinding(regexString, bindingMethod); }
public HookBinding(IBindingMethod bindingMethod, HookType hookType, BindingScope bindingScope) : base(bindingMethod) { HookType = hookType; BindingScope = bindingScope; }
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) { }
public IStepArgumentTransformationBinding CreateStepArgumentTransformation(string regexString, IBindingMethod bindingMethod) { return(new StepArgumentTransformationBinding(regexString, bindingMethod)); }
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 IHookBinding CreateHookBinding(IBindingMethod bindingMethod, HookType hookType, BindingScope bindingScope) { return(new HookBinding(bindingMethod, hookType, bindingScope)); }
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 void TraceDuration(TimeSpan elapsed, IBindingMethod method, object[] arguments) { //nop }
private IStepArgumentTransformationBinding CreateStepTransformationBinding(string regexString, IBindingMethod transformMethod) { return new StepArgumentTransformationBinding(regexString, transformMethod); }
protected MethodBinding(IBindingMethod bindingMethod) { Method = bindingMethod; }
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); } }
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)); }
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)) { }
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; }
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) { }
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))); }
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)); }
public HookBinding(IBindingMethod bindingMethod, BindingScope bindingScope) : base(bindingMethod) { BindingScope = bindingScope; }