private string GetSimpleRegex(AnalyzedStepText stepText)
        {
            StringBuilder result = new StringBuilder();

            result.Append(stepText.TextParts[0]);
            for (int i = 1; i < stepText.TextParts.Count; i++)
            {
                result.AppendFormat("({0})", stepText.Parameters[i - 1].RegexPattern);
                result.Append(stepText.TextParts[i]);
            }

            return(result.ToString());
        }
        public void Setup()
        {
            templateProviderMock = new Mock <ISkeletonTemplateProvider>();
            templateProviderMock.Setup(tp => tp.GetStepDefinitionClassTemplate(It.IsAny <ProgrammingLanguage>()))
            .Returns("{namespace}/{className}/{bindings}");
            templateProviderMock.Setup(tp => tp.GetStepDefinitionTemplate(It.IsAny <ProgrammingLanguage>(), true))
            .Returns("{attribute}/{regex}/{methodName}/{parameters}");
            templateProviderMock.Setup(tp => tp.GetStepDefinitionTemplate(It.IsAny <ProgrammingLanguage>(), false))
            .Returns("{attribute}/{methodName}/{parameters}");

            analizeResult        = new AnalyzedStepText();
            stepTextAnalyzerMock = new Mock <IStepTextAnalyzer>();
            stepTextAnalyzerMock.Setup(a => a.Analyze(It.IsAny <string>(), It.IsAny <CultureInfo>()))
            .Returns(analizeResult);
        }
        private List <string> AddStatements(CodeMemberMethod testMethod, MethodInfo methodInfo, List <string> classesDeclared, ScenarioStep step, AnalyzedStepText stepText, string regex)
        {
            if (!HasClassBeenDeclared(classesDeclared, methodInfo.DeclaringType.ToString()))
            {
                var testRunnerField = new CodeVariableDeclarationStatement(
                    methodInfo.DeclaringType, methodInfo.DeclaringType.Name.ToLower(),
                    new CodeObjectCreateExpression(methodInfo.DeclaringType));
                testMethod.Statements.Add(testRunnerField);
                classesDeclared.Add(methodInfo.DeclaringType.ToString());
            }

            ParameterInfo[] parameters = methodInfo.GetParameters();

            if (parameters.Any())
            {
                //declare any variables needed here
                //string value = step.Text
                int i = 0;
                foreach (ParameterInfo parameterInfo in parameters) //these are the parameters needed
                {
                    string parameterValue = stepText.TextParts[i];


                    Match match = Regex.Match(step.Text, regex);
                    if (match.Success)
                    {
                        parameterValue = match.Groups[1].Value;
                    }

                    bool paramAlreadyDeclared = false;

                    //check not in test case
                    foreach (CodeParameterDeclarationExpression parameter in testMethod.Parameters) //these are the ones specified by the test case attributes
                    {
                        if (parameterInfo.Name == parameter.Name)
                        {
                            paramAlreadyDeclared = true;
                        }
                    }

                    //check not already declared in body of method
                    foreach (var preDecalredParam in m_parametersDeclaredInMethod)
                    {
                        if (preDecalredParam == parameterInfo.Name)
                        {
                            paramAlreadyDeclared = true;
                        }
                    }

                    if (!paramAlreadyDeclared)
                    {
                        m_parametersDeclaredInMethod.Add(parameterInfo.Name);//record that param declared
                        CodeVariableDeclarationStatement variable = new CodeVariableDeclarationStatement(typeof(string), parameterInfo.Name, new CodePrimitiveExpression(parameterValue));
                        testMethod.Statements.Add(variable);
                    }
                }



                testMethod.Statements.Add(new CodeMethodInvokeExpression(
                                              new CodeTypeReferenceExpression(
                                                  methodInfo.DeclaringType.Name.ToLower()),
                                              methodInfo.Name,
                                              GetParameters(testMethod, methodInfo)));
            }
            else
            {
                testMethod.Statements.Add(new CodeMethodInvokeExpression(
                                              new CodeTypeReferenceExpression(
                                                  methodInfo.DeclaringType.Name.ToLower()),
                                              methodInfo.Name));
            }
            return(classesDeclared);
        }