Esempio n. 1
0
        public StepBinding GetBestMatchingBinding(StepInstance stepInstance, out IEnumerable <StepBinding> candidatingBindings)
        {
            candidatingBindings = Enumerable.Empty <StepBinding>();
            var matches = GetCandidatingBindings(stepInstance, useParamMatching: true).ToList();

            if (matches.Count == 0)
            {
                //HACK: since out param matching does not support agrument converters yet, we rather show more results than "no match"
                matches = GetCandidatingBindings(stepInstance, useParamMatching: false).ToList();
            }

            if (matches.Count > 1)
            {
                // if there are both scoped and non-scoped matches, we take the ones with the higher degree of scope matches
                int maxScopeMatches = matches.Max(m => m.ScopeMatches);
                matches.RemoveAll(m => m.ScopeMatches < maxScopeMatches);
            }
            if (matches.Count == 0)
            {
                return(null);
            }
            if (matches.Count > 1)
            {
                candidatingBindings = matches.Select(m => m.StepBinding);
                return(null);
            }
            return(matches[0].StepBinding);
        }
        public GenerateStepDefinitionSkeletonForm(string featureTitle, StepInstance[] steps, Project specFlowProject, StepDefinitionSkeletonStyle stepDefinitionSkeletonStyle, ProgrammingLanguage defaultLanguage, DTE dte)
        {
            this.dte = dte;
            InitializeComponent();

            stepsList.BeginUpdate();
            stepsList.Items.Clear();
            foreach (var step in steps)
            {
                stepsList.Items.Add(new ListItem(step), true);
            }
            stepsList.EndUpdate();

            classNameTextBox.Text = string.Format("{0} Steps", featureTitle).ToIdentifier();

            styleComboBox.BeginUpdate();
            var styles = Enum.GetValues(typeof (StepDefinitionSkeletonStyle)).Cast<StepDefinitionSkeletonStyle>()
                .Where(value => value != StepDefinitionSkeletonStyle.MethodNameRegex || defaultLanguage == ProgrammingLanguage.FSharp)
                .ToArray();
            styleComboBox.Items.Clear();
            styleComboBox.Items.AddRange(styles.Select(s => new StyleItem(s)).ToArray<object>());

            int selectedIndex = Array.IndexOf(styles, stepDefinitionSkeletonStyle);
            styleComboBox.SelectedIndex = selectedIndex < 0 ? 0 : selectedIndex;
            styleComboBox.EndUpdate();

            defaultFolder = Path.Combine(VsxHelper.GetProjectFolder(specFlowProject), "StepDefinitions");
            if (!Directory.Exists(defaultFolder))
                defaultFolder = VsxHelper.GetProjectFolder(specFlowProject);
        }
        public override string GetStepDefinitionSkeleton(StepInstance stepInstance)
        {
            List<string> extraArgs = new List<string>();
            if (stepInstance.MultilineTextArgument != null)
                extraArgs.Add("ByVal multilineText As String");
            if (stepInstance.TableArgument != null)
                extraArgs.Add("ByVal table As Table");

            StringBuilder result = new StringBuilder();

            // in VB "When" and "Then" are language keywords - use the fully qualified namespace
            string namespaceAddition = "TechTalk.SpecFlow.";
            if (stepInstance.StepDefinitionType == StepDefinitionType.Given)
            {
                namespaceAddition = "";
            }

            result.AppendFormat(@"<{4}{0}(""{1}"")> _
Public Sub {2}({3})
    ScenarioContext.Current.Pending()
End Sub",
                stepInstance.StepDefinitionType,
                EscapeRegex(stepInstance.Text),
                GetStepText(stepInstance).ToIdentifier(),
                string.Join(", ", extraArgs.ToArray()),
                namespaceAddition
                );
            result.AppendLine();

            return result.ToString();
        }
Esempio n. 4
0
 private IEnumerable<BindingMatchNew> GetCandidatingBindings(StepInstance stepInstance, bool useParamMatching = true)
 {
     var matches = bindingRegistry.GetConsideredBindings(stepInstance.Text).Select(b => Match(b, stepInstance, useParamMatching: useParamMatching)).Where(b => b.Success);
     // we remove duplicate maches for the same method (take the highest scope matches from each)
     matches = matches.GroupBy(m => m.StepBinding.Method, (methodInfo, methodMatches) => methodMatches.OrderByDescending(m => m.ScopeMatches).First(), BindingMethodComparer.Instance);
     return matches;
 }
Esempio n. 5
0
        public StepBindingNew GetBestMatchingBinding(StepInstance stepInstance, out IEnumerable<StepBindingNew> candidatingBindings)
        {
            candidatingBindings = Enumerable.Empty<StepBindingNew>();
            var matches = GetCandidatingBindings(stepInstance, useParamMatching: true).ToList();
            if (matches.Count == 0)
            {
                //HACK: since out param matching does not support agrument converters yet, we rather show more results than "no match"
                matches = GetCandidatingBindings(stepInstance, useParamMatching: false).ToList();
            }

            if (matches.Count > 1)
            {
                // if there are both scoped and non-scoped matches, we take the ones with the higher degree of scope matches
                int maxScopeMatches = matches.Max(m => m.ScopeMatches);
                matches.RemoveAll(m => m.ScopeMatches < maxScopeMatches);
            }
            if (matches.Count == 0)
            {
                return null;
            }
            if (matches.Count > 1)
            {
                candidatingBindings = matches.Select(m => m.StepBinding);
                return null;
            }
            return matches[0].StepBinding;
        }
Esempio n. 6
0
        public BindingMatchNew Match(StepBindingNew stepBinding, StepInstance stepInstance, bool useRegexMatching = true, bool useParamMatching = true, bool useScopeMatching = true)
        {
            if (useParamMatching)
                useRegexMatching = true;

            Match match = null;
            if (useRegexMatching && stepBinding.Regex != null && !(match = stepBinding.Regex.Match(stepInstance.Text)).Success)
                return BindingMatchNew.NonMatching;

            if (stepBinding.BindingType != stepInstance.BindingType)
                return BindingMatchNew.NonMatching;

            int scopeMatches = 0;
            if (useScopeMatching && stepBinding.IsScoped && stepInstance.StepScope != null && !stepBinding.BindingScope.Match(stepInstance.StepScope, out scopeMatches))
                return BindingMatchNew.NonMatching;

            if (useParamMatching)
            {
                Debug.Assert(match != null);
                var regexArgs = match.Groups.Cast<Group>().Skip(1).Select(g => g.Value);
                var arguments = regexArgs.Cast<object>().AppendIfNotNull(stepInstance.MultilineTextArgument).AppendIfNotNull(stepInstance.TableArgument).ToArray();
                // check if the regex + extra arguments match to the binding method parameters
                if (arguments.Count() != stepBinding.Method.Parameters.Count())
                    return BindingMatchNew.NonMatching;

                // Check if regex & extra arguments can be converted to the method parameters
                if (arguments.Zip(stepBinding.Method.Parameters, (arg, parameter) => CanConvertArg(arg, parameter.Type)).Any(canConvert => !canConvert))
                    return BindingMatchNew.NonMatching;
            }

            return new BindingMatchNew(stepBinding, scopeMatches);
        }
Esempio n. 7
0
        public void TraceNoMatchingStepDefinition(StepInstance stepInstance, ProgrammingLanguage targetLanguage, List<BindingMatch> matchesWithoutScopeCheck)
        {
//            string stepDescription = stepFormatter.GetStepDescription(stepArgs);
//            return new BindingException(
//                string.Format("Multiple step definitions found, but none of them have matching scope for step '{0}': {1}",
//                    stepDescription,
//                    string.Join(", ", matches.Select(m => GetMethodText(m.StepBinding.MethodInfo)).ToArray())));


            IStepDefinitionSkeletonProvider stepDefinitionSkeletonProvider = stepDefinitionSkeletonProviders[targetLanguage];

            StringBuilder message = new StringBuilder();
            if (matchesWithoutScopeCheck == null || matchesWithoutScopeCheck.Count == 0)
                message.AppendLine("No matching step definition found for the step. Use the following code to create one:");
            else
            {
                string preMessage = string.Format("No matching step definition found for the step. There are matching step definitions, but none of them have matching scope for this step: {0}.", 
                    string.Join(", ", matchesWithoutScopeCheck.Select(m => stepFormatter.GetMatchText(m, null)).ToArray()));
                traceListener.WriteToolOutput(preMessage);
                message.AppendLine("Change the scope or use the following code to create a new step definition:");
            }
            message.Append(
                stepDefinitionSkeletonProvider.GetBindingClassSkeleton(
                    stepDefinitionSkeletonProvider.GetStepDefinitionSkeleton(stepInstance))
                        .Indent(StepDefinitionSkeletonProviderBase.CODEINDENT));

            traceListener.WriteToolOutput(message.ToString());
        }
Esempio n. 8
0
        public string GetStepText(StepInstance stepInstance)
        {
            StringBuilder result = new StringBuilder();
            if (stepInstance.Keyword != null)
                result.Append(stepInstance.Keyword);
            else
            {
                result.Append(LanguageHelper.GetDefaultKeyword(stepInstance.StepContext.Language, stepInstance.StepDefinitionKeyword));
                result.Append(" ");
            }
            result.AppendLine(stepInstance.Text);

            if (stepInstance.MultilineTextArgument != null)
            {
                result.AppendLine("--- multiline step argument ---".Indent(INDENT));
                result.AppendLine(stepInstance.MultilineTextArgument.Indent(INDENT));
            }

            if (stepInstance.TableArgument != null)
            {
                result.AppendLine("--- table step argument ---".Indent(INDENT));
                result.AppendLine(stepInstance.TableArgument.ToString().Indent(INDENT));
            }

            return result.ToString();
        }
        public BindingMatch Match(IStepDefinitionBinding stepDefinitionBinding, StepInstance stepInstance, CultureInfo bindingCulture, bool useRegexMatching = true, bool useParamMatching = true, bool useScopeMatching = true)
        {
            if (useParamMatching)
                useRegexMatching = true;

            if (stepDefinitionBinding.StepDefinitionType != stepInstance.StepDefinitionType)
                return BindingMatch.NonMatching;

            Match match = null;
            if (useRegexMatching && stepDefinitionBinding.Regex != null && !(match = stepDefinitionBinding.Regex.Match(stepInstance.Text)).Success)
                return BindingMatch.NonMatching;

            int scopeMatches = 0;
            if (useScopeMatching && stepDefinitionBinding.IsScoped && stepInstance.StepContext != null && !stepDefinitionBinding.BindingScope.Match(stepInstance.StepContext, out scopeMatches))
                return BindingMatch.NonMatching;

            var arguments = match == null ? new object[0] : CalculateArguments(match, stepInstance);

            if (useParamMatching)
            {
                Debug.Assert(match != null); // useParamMatching -> useRegexMatching
                var bindingParameters = stepDefinitionBinding.Method.Parameters.ToArray();

                // check if the regex + extra arguments match to the binding method parameters
                if (arguments.Length != bindingParameters.Length)
                    return BindingMatch.NonMatching;

                // Check if regex & extra arguments can be converted to the method parameters
                //if (arguments.Zip(bindingParameters, (arg, parameter) => CanConvertArg(arg, parameter.Type)).Any(canConvert => !canConvert))
                if (arguments.Where((arg, argIndex) => !CanConvertArg(arg, bindingParameters[argIndex].Type, bindingCulture)).Any())
                    return BindingMatch.NonMatching;
            }

            return new BindingMatch(stepDefinitionBinding, scopeMatches, arguments, stepInstance.StepContext);
        }
        public override string GetStepDefinitionSkeleton(StepInstance stepArgs)
        {
            List<string> extraArgs = new List<string>();

            if (stepArgs.MultilineTextArgument != null)
                extraArgs.Add("string multilineText");
            if (stepArgs.TableArgument != null)
                extraArgs.Add("Table table");

            string stepText = EscapeRegexOutsideQuotes(stepArgs.Text);
            string methodName = Regex.Replace(EscapeRegex(stepArgs.Text), QuotesRegex, "").ToIdentifier();

            extraArgs.AddRange(ParseArgsFromQuotes(ref stepText)); //Adds values passed in via quotes to the args for the method

            StringBuilder result = new StringBuilder();
            result.AppendFormat(
@"[{0}(@""{1}"")]
public void {0}{2}({3})
{{
    ScenarioContext.Current.Pending();
}}",
                stepArgs.BindingType,
                stepText,
                methodName,
                string.Join(", ", extraArgs.ToArray()));
            result.AppendLine();

            return result.ToString();
        }
 private static IEnumerable<StepInstance> GetOrderedSteps(StepInstance[] stepInstances)
 {
     return stepInstances
         .Select((si, index) => new { Step = si, Index = index})
         .OrderBy(item => item.Step.StepDefinitionType)
         .ThenBy(item => item.Index)
         .Select(item => item.Step);
 }
Esempio n. 12
0
 public Exception GetAmbiguousBecauseParamCheckMatchError(List<BindingMatch> matches, StepInstance stepInstance)
 {
     string stepDescription = stepFormatter.GetStepDescription(stepInstance);
     return new BindingException(
         string.Format("Multiple step definitions found, but none of them have matching parameter count and type for step '{0}': {1}",
             stepDescription,
             string.Join(", ", matches.Select(m => GetMethodText(m.StepBinding.Method)).ToArray())));
 }
Esempio n. 13
0
 public Exception GetAmbiguousMatchError(List<BindingMatch> matches, StepInstance stepInstance)
 {
     string stepDescription = stepFormatter.GetStepDescription(stepInstance);
     return new BindingException(
         string.Format("Ambiguous step definitions found for step '{0}': {1}",
             stepDescription,
             string.Join(", ", matches.Select(m => GetMethodText(m.StepBinding.Method)).ToArray())));
 }
Esempio n. 14
0
        private IEnumerable <BindingMatch> GetCandidatingBindings(StepInstance stepInstance, bool useParamMatching = true)
        {
            var matches = bindingRegistry.GetConsideredBindings(stepInstance.Text).Select(b => Match(b, stepInstance, useParamMatching: useParamMatching)).Where(b => b.Success);

            // we remove duplicate maches for the same method (take the highest scope matches from each)
            matches = matches.GroupBy(m => m.StepBinding.Method, (methodInfo, methodMatches) => methodMatches.OrderByDescending(m => m.ScopeMatches).First(), BindingMethodComparer.Instance);
            return(matches);
        }
Esempio n. 15
0
 public Exception GetNoMatchBecauseOfScopeFilterError(List<BindingMatch> matches, StepInstance stepInstance)
 {
     string stepDescription = stepFormatter.GetStepDescription(stepInstance);
     return new BindingException(
         string.Format("Multiple step definitions found, but none of them have matching scope for step '{0}': {1}",
             stepDescription,
             string.Join(", ", matches.Select(m => GetMethodText(m.StepBinding.Method)).ToArray())));
 }
 public AnalyzedStepText Analyze(StepInstance stepInstance, CultureInfo bindingCulture)
 {
     var result = stepTextAnalyzer.Analyze(stepInstance.Text, bindingCulture);
     if (stepInstance.MultilineTextArgument != null)
         result.Parameters.Add(new AnalyzedStepParameter("String", "multilineText"));
     if (stepInstance.TableArgument != null)
         result.Parameters.Add(new AnalyzedStepParameter("Table", "table"));
     return result;
 }
        private object[] CalculateArguments(Match match, StepInstance stepInstance)
        {
            var regexArgs = match.Groups.Cast<Group>().Skip(1).Select(g => g.Value);
            var arguments = regexArgs.Cast<object>().ToList();
            if (stepInstance.MultilineTextArgument != null)
                arguments.Add(stepInstance.MultilineTextArgument);
            if (stepInstance.TableArgument != null)
                arguments.Add(stepInstance.TableArgument);

            return arguments.ToArray();
        }
            public override string GetStepDefinitionSkeleton(ProgrammingLanguage language, StepInstance stepInstance, StepDefinitionSkeletonStyle style, CultureInfo bindingCulture)
            {
                if (getSkeleton != null)
                    return getSkeleton(stepInstance);

                if (usageIndex < stepDefinitionSkeletons.Length)
                {
                    return stepDefinitionSkeletons[usageIndex++];
                }

                return stepDefinitionSkeletons[stepDefinitionSkeletons.Length - 1];
            }
        public string GetBindingClassSkeleton(ProgrammingLanguage language, StepInstance[] stepInstances, string namespaceName, string className, StepDefinitionSkeletonStyle style, CultureInfo bindingCulture)
        {
            var template = templateProvider.GetStepDefinitionClassTemplate(language);

            var bindings = string.Join(Environment.NewLine, GetOrderedSteps(stepInstances)
                .Select(si => GetStepDefinitionSkeleton(language, si, style, bindingCulture)).Distinct().ToArray()).TrimEnd();
            if (bindings.Length > 0)
                bindings = bindings.Indent(METHOD_INDENT);

            //{namespace}/{className}/{bindings}
            return ApplyTemplate(template, new { @namespace = namespaceName, className, bindings});
        }
        protected string GetStepText(StepInstance stepInstance)
        {
            string keyword;

            if (stepInstance.StepDefinitionKeyword == StepDefinitionKeyword.Given ||
                stepInstance.StepDefinitionKeyword == StepDefinitionKeyword.When ||
                stepInstance.StepDefinitionKeyword == StepDefinitionKeyword.Then)
                keyword = stepInstance.Keyword;
            else
                keyword = gherkinDialect.GetStepKeywords((StepKeyword) stepInstance.BindingType).FirstOrDefault(k => !k.StartsWith("*")) ?? "";

            return keyword + stepInstance.Text;
        }
 public virtual string GetStepDefinitionSkeleton(ProgrammingLanguage language, StepInstance stepInstance, StepDefinitionSkeletonStyle style, CultureInfo bindingCulture)
 {
     var withRegex = style == StepDefinitionSkeletonStyle.RegexAttribute;
     var template = templateProvider.GetStepDefinitionTemplate(language, withRegex);
     var analyzedStepText = Analyze(stepInstance, bindingCulture);
     //{attribute}/{regex}/{methodName}/{parameters}
     return ApplyTemplate(template, new
                                        {
                                            attribute = stepInstance.StepDefinitionType, 
                                            regex = withRegex ? GetRegex(analyzedStepText) : "", 
                                            methodName = GetMethodName(stepInstance, analyzedStepText, style, language), 
                                            parameters = string.Join(", ", analyzedStepText.Parameters.Select(p => ToDeclaration(language, p)).ToArray())
                                        });
 }
        private object[] CalculateRecursiveArguments(Match match, StepInstance stepInstance)
        {
            var regexArgs = match.Groups.Cast<Group>().Skip<Group>(1)
                        .SelectMany<Group, string>(g =>
                            g.Captures.Cast<Capture>()
                            .Select<Capture, string>(c => c.Value)
                            .ToArray<string>())
                            .ToArray<string>();
            var arguments = regexArgs.Cast<object>().ToList();
            if (stepInstance.MultilineTextArgument != null)
                arguments.Add(stepInstance.MultilineTextArgument);
            if (stepInstance.TableArgument != null)
                arguments.Add(stepInstance.TableArgument);

            return arguments.ToArray();
        }
        public void Produces_CSharp_Method_Skeleton_With_Parsed_Doubles()
        {
            var expected = new StringBuilder();
            expected.Append(
@"[Then(@""I can parse a double """"(.*)"""" and another double """"(.*)"""""")]
public void ThenICanParseADoubleAndAnotherDouble(double double1, double double2)
{
    ScenarioContext.Current.Pending();
}
");
            var stepScope = new StepScopeNew("TestFeature", "TestScenario", null);
            var stepInstance = new StepInstance(BindingType.Then, StepDefinitionKeyword.Then, "Then",
                                                         "I can parse a double \"3.4\" and another double \"902.302\"", stepScope);
            string result = skeletonProviderCS.GetStepDefinitionSkeleton(stepInstance);
            Assert.AreEqual(expected.ToString(), result);
        }
Esempio n. 24
0
        public BindingMatch Match(StepBinding stepBinding, StepInstance stepInstance, bool useRegexMatching = true, bool useParamMatching = true, bool useScopeMatching = true)
        {
            if (useParamMatching)
            {
                useRegexMatching = true;
            }

            Match match = null;

            if (useRegexMatching && stepBinding.Regex != null && !(match = stepBinding.Regex.Match(stepInstance.Text)).Success)
            {
                return(BindingMatch.NonMatching);
            }

            if (stepBinding.BindingType != stepInstance.BindingType)
            {
                return(BindingMatch.NonMatching);
            }

            int scopeMatches = 0;

            if (useScopeMatching && stepBinding.IsScoped && stepInstance.StepScope != null && !stepBinding.BindingScope.Match(stepInstance.StepScope, out scopeMatches))
            {
                return(BindingMatch.NonMatching);
            }

            if (useParamMatching)
            {
                Debug.Assert(match != null);
                var regexArgs = match.Groups.Cast <Group>().Skip(1).Select(g => g.Value);
                var arguments = regexArgs.Cast <object>().AppendIfNotNull(stepInstance.MultilineTextArgument).AppendIfNotNull(stepInstance.TableArgument).ToArray();
                // check if the regex + extra arguments match to the binding method parameters
                if (arguments.Count() != stepBinding.Method.Parameters.Count())
                {
                    return(BindingMatch.NonMatching);
                }

                // Check if regex & extra arguments can be converted to the method parameters
                if (arguments.Zip(stepBinding.Method.Parameters, (arg, parameter) => CanConvertArg(arg, parameter.Type)).Any(canConvert => !canConvert))
                {
                    return(BindingMatch.NonMatching);
                }
            }

            return(new BindingMatch(stepBinding, scopeMatches));
        }
        public void Produces_CSharp_Method_Skeleton()
        {
            StringBuilder expected = new StringBuilder();
            expected.Append(
@"[Given(@""I have a new step"")]
public void GivenIHaveANewStep()
{
    ScenarioContext.Current.Pending();
}
");
            var stepScope = new StepScopeNew("TestFeature", "TestScenario", null);
            StepInstance stepInstance = new StepInstance(BindingType.Given, StepDefinitionKeyword.Given, "Given",
                                                         "I have a new step", stepScope);

            string result = skeletonProviderCS.GetStepDefinitionSkeleton(stepInstance);
            Assert.AreEqual(expected.ToString(), result);
        }
        public void Produces_CSharp_Method_Skeleton_With_Parsed_Dates()
        {
            var expected = new StringBuilder();
            expected.Append(
@"[When(@""I can parse dates such as """"(.*)"""", """"(.*)"""" and """"(.*)"""""")]
public void WhenICanParseDatesSuchAsAnd(DateTime dateTime1, DateTime dateTime2, DateTime dateTime3)
{
    ScenarioContext.Current.Pending();
}
");
            var stepScope = new StepScopeNew("TestFeature", "TestScenario", null);
            var stepInstance = new StepInstance(BindingType.When, StepDefinitionKeyword.When, "When",
                                                         "I can parse dates such as \"20/10/02\", \"12:00\" and \"20.12.09\"", stepScope);

            string result = skeletonProviderCS.GetStepDefinitionSkeleton(stepInstance);
            Assert.AreEqual(expected.ToString(), result);
        }
Esempio n. 27
0
        public void TraceNoMatchingStepDefinition(StepInstance stepInstance, ProgrammingLanguage targetLanguage, CultureInfo bindingCulture, List<BindingMatch> matchesWithoutScopeCheck)
        {
            StringBuilder message = new StringBuilder();
            if (matchesWithoutScopeCheck == null || matchesWithoutScopeCheck.Count == 0)
                message.AppendLine("No matching step definition found for the step. Use the following code to create one:");
            else
            {
                string preMessage = string.Format("No matching step definition found for the step. There are matching step definitions, but none of them have matching scope for this step: {0}.", 
                    string.Join(", ", matchesWithoutScopeCheck.Select(m => stepFormatter.GetMatchText(m, null)).ToArray()));
                traceListener.WriteToolOutput(preMessage);
                message.AppendLine("Change the scope or use the following code to create a new step definition:");
            }
            message.Append(
               stepDefinitionSkeletonProvider.GetStepDefinitionSkeleton(targetLanguage, stepInstance, runtimeConfiguration.StepDefinitionSkeletonStyle, bindingCulture)
                    .Indent(StepDefinitionSkeletonProvider.METHOD_INDENT));

            traceListener.WriteToolOutput(message.ToString());
        }
 private string GetMethodName(StepInstance stepInstance, AnalyzedStepText analyzedStepText, StepDefinitionSkeletonStyle style, ProgrammingLanguage language)
 {
     var keyword = LanguageHelper.GetDefaultKeyword(stepInstance.StepContext.Language, stepInstance.StepDefinitionType);
     switch (style)
     {
         case StepDefinitionSkeletonStyle.RegexAttribute:
             return keyword.ToIdentifier() + string.Concat(analyzedStepText.TextParts.ToArray()).ToIdentifier();
         case StepDefinitionSkeletonStyle.MethodNameUnderscores:
             return GetMatchingMethodName(keyword, analyzedStepText, stepInstance.StepContext.Language, AppendWordsUnderscored, "_{0}");
         case StepDefinitionSkeletonStyle.MethodNamePascalCase:
             return GetMatchingMethodName(keyword, analyzedStepText, stepInstance.StepContext.Language, AppendWordsPascalCase, "_{0}_");
         case StepDefinitionSkeletonStyle.MethodNameRegex:
             if (language != ProgrammingLanguage.FSharp)
                 goto case StepDefinitionSkeletonStyle.MethodNameUnderscores;
             return "``" + GetRegex(analyzedStepText) + "``";
         default:
             throw new NotSupportedException();
     }
 }
        public override string GetStepDefinitionSkeleton(StepInstance stepInfo)
        {
            List<string> extraArgs = new List<string>();

            if (stepInfo.MultilineTextArgument != null)
                extraArgs.Add("ByVal multilineText As String");
            if (stepInfo.TableArgument != null)
                extraArgs.Add("ByVal table As Table");

            string stepText = EscapeRegexOutsideQuotes(stepInfo.Text);
            extraArgs.AddRange(ParseArgsFromQuotes(ref stepText));
            //Adds parameters passed in via quotes to the args for the method
            string methodName = Regex.Replace(EscapeRegex(stepInfo.Text), QuotesRegex, "").ToIdentifier();
            StringBuilder result = new StringBuilder();

            // in VB "When" and "Then" are language keywords - use the fully qualified namespace
            string namespaceAddition = "TechTalk.SpecFlow.";
            if (stepInfo.BindingType == BindingType.Given)
            {
                namespaceAddition = "";
            }

            result.AppendFormat(
@"<{4}{0}(""{1}"")> _
Public Sub {0}{2}({3})
{5}ScenarioContext.Current.Pending()
End Sub",
                stepInfo.BindingType,
                stepText,
                methodName,
                string.Join(", ", extraArgs.ToArray()),
                namespaceAddition,
                CODEINDENT
                );
            result.AppendLine();

            return result.ToString();
        }
        public override string GetStepDefinitionSkeleton(StepInstance stepInstance)
        {
            List<string> extraArgs = new List<string>();
            if (stepInstance.MultilineTextArgument != null)
                extraArgs.Add("string multilineText");
            if (stepInstance.TableArgument != null)
                extraArgs.Add("Table table");

            StringBuilder result = new StringBuilder();
            result.AppendFormat(@"[{0}(@""{1}"")]
public void {2}({3})
{{
    ScenarioContext.Current.Pending();
}}",
                                stepInstance.BindingType,
                                EscapeRegex(stepInstance.Text),
                                GetStepText(stepInstance).ToIdentifier(),
                                string.Join(", ", extraArgs.ToArray())
                );
            result.AppendLine();

            return result.ToString();
        }
 public abstract string GetStepDefinitionSkeleton(StepInstance steps);
Esempio n. 32
0
            protected override IEnumerable<BindingMatch> GetCandidatingBindingsForBestMatch(StepInstance stepInstance, CultureInfo bindingCulture)
            {
                var normalResult = base.GetCandidatingBindingsForBestMatch(stepInstance, bindingCulture).ToList();
                if (normalResult.Count > 0)
                    return normalResult;

                return GetCandidatingBindings(stepInstance, bindingCulture, useParamMatching: false); // we disable param checking
            }
Esempio n. 33
0
 public string GetStepDescription(StepInstance stepInstance)
 {
     return string.Format("{0} {1}", stepInstance.StepDefinitionType, stepInstance.Text);
 }