private void GenerateCodeFromFeature(Feature feature, TextWriter writer) { CodeDomHelper codeDomHelper = new CodeDomHelper(CodeDomProviderLanguage.CSharp); XUnitTestGeneratorProvider xUnitTestGeneratorProvider = new XUnitTestGeneratorProvider(); SpecFlowUnitTestConverter converter = FactoryMethods.CreateUnitTestConverter(xUnitTestGeneratorProvider); var codeNamespace = converter.GenerateUnitTestFixture(feature, "TestClassName", "Target.Namespace"); CSharpCodeProvider codeProvider = new CSharpCodeProvider(); CodeGeneratorOptions options = new CodeGeneratorOptions(); codeProvider.GenerateCodeFromNamespace(codeNamespace, writer, options); }
public static UnitTestFeatureGenerator CreateUnitTestConverter(IUnitTestGeneratorProvider testGeneratorProvider) { var codeDomHelper = new CodeDomHelper(CodeDomProviderLanguage.CSharp); return new UnitTestFeatureGenerator(testGeneratorProvider, codeDomHelper, new GeneratorConfiguration { AllowRowTests = true, AllowDebugGeneratedFiles = true }, new DecoratorRegistryStub()); }
private static UnitTestFeatureGeneratorProvider CreateUnitTestFeatureGeneratorProvider() { GeneratorConfiguration generatorConfiguration = new GeneratorConfiguration(); CodeDomHelper codeDomHelper = new CodeDomHelper(CodeDomProviderLanguage.CSharp); UnitTestFeatureGenerator unitTestFeatureGenerator = new UnitTestFeatureGenerator( new NUnitTestGeneratorProvider(codeDomHelper), codeDomHelper, generatorConfiguration, new DecoratorRegistryStub()); return new UnitTestFeatureGeneratorProvider(unitTestFeatureGenerator); }
private void GenerateCodeFromFeature(Feature feature, TextWriter writer) { var codeDomHelper = new CodeDomHelper(CodeDomProviderLanguage.CSharp); var mbUnitTestGeneratorProvider = new MbUnitTestGeneratorProvider(); var converter = new SpecFlowUnitTestConverter(mbUnitTestGeneratorProvider, codeDomHelper, true); CodeNamespace codeNamespace = converter.GenerateUnitTestFixture(feature, "TestClassName", "Target.Namespace"); var codeProvider = new CSharpCodeProvider(); var options = new CodeGeneratorOptions(); codeProvider.GenerateCodeFromNamespace(codeNamespace, writer, options); }
public TestGenerator(GeneratorConfiguration generatorConfiguration, ProjectSettings projectSettings, ITestHeaderWriter testHeaderWriter, ITestUpToDateChecker testUpToDateChecker, IFeatureGeneratorRegistry featureGeneratorRegistry, CodeDomHelper codeDomHelper) { if (generatorConfiguration == null) throw new ArgumentNullException("generatorConfiguration"); if (projectSettings == null) throw new ArgumentNullException("projectSettings"); if (testHeaderWriter == null) throw new ArgumentNullException("testHeaderWriter"); if (testUpToDateChecker == null) throw new ArgumentNullException("testUpToDateChecker"); if (featureGeneratorRegistry == null) throw new ArgumentNullException("featureGeneratorRegistry"); this.generatorConfiguration = generatorConfiguration; this.testUpToDateChecker = testUpToDateChecker; this.featureGeneratorRegistry = featureGeneratorRegistry; this.codeDomHelper = codeDomHelper; this.testHeaderWriter = testHeaderWriter; this.projectSettings = projectSettings; }
public CodeNamespace GenerateTestFileCode(FeatureFileInput featureFile, TextReader inputReader, CodeDomProvider codeProvider, CodeDomHelper codeDomHelper) { string targetNamespace = GetTargetNamespace(featureFile); SpecFlowLangParser parser = new SpecFlowLangParser(project.Configuration.GeneratorConfiguration.FeatureLanguage); Feature feature = parser.Parse(inputReader, featureFile.GetFullPath(project.ProjectSettings)); IUnitTestGeneratorProvider generatorProvider = ConfigurationServices.CreateInstance<IUnitTestGeneratorProvider>(project.Configuration.GeneratorConfiguration.GeneratorUnitTestProviderType); codeDomHelper.InjectIfRequired(generatorProvider); ISpecFlowUnitTestConverter testConverter = new SpecFlowUnitTestConverter(generatorProvider, codeDomHelper, project.Configuration.GeneratorConfiguration); var codeNamespace = testConverter.GenerateUnitTestFixture(feature, null, targetNamespace); return codeNamespace; }
public void GenerateTestFile(FeatureFileInput featureFile, CodeDomProvider codeProvider, TextReader inputReader, TextWriter outputWriter) { outputWriter = new IndentProcessingWriter(outputWriter); CodeDomHelper codeDomHelper = new CodeDomHelper(codeProvider); var codeNamespace = GenerateTestFileCode(featureFile, inputReader, codeProvider, codeDomHelper); var options = new CodeGeneratorOptions { BracingStyle = "C" }; AddSpecFlowHeader(codeProvider, outputWriter, codeDomHelper); codeProvider.GenerateCodeFromNamespace(codeNamespace, outputWriter, options); AddSpecFlowFooter(codeProvider, outputWriter, codeDomHelper); outputWriter.Flush(); }
private string Generate(string inputFilePath, string inputFileContent, GeneratorServices generatorServices, CodeDomHelper codeDomHelper, ProjectSettings projectSettings) { string outputFileContent; try { TestGeneratorResult generationResult = GenerateCode(inputFilePath, inputFileContent, generatorServices, projectSettings); if (generationResult.Success) outputFileContent = generationResult.GeneratedTestCode; else outputFileContent = GenerateError(generationResult, codeDomHelper); } catch (Exception ex) { outputFileContent = GenerateError(ex, codeDomHelper); } return outputFileContent; }
public void GenerateScenarioExampleTests() { SpecFlowLangParser parser = new SpecFlowLangParser(new CultureInfo("en-US")); foreach (var testFile in TestFileHelper.GetTestFiles()) { using (var reader = new StreamReader(testFile)) { Feature feature = parser.Parse(reader, null); Assert.IsNotNull(feature); Console.WriteLine("Testing {0}", Path.GetFileName(testFile)); var codeDomHelper = new CodeDomHelper(CodeDomProviderLanguage.CSharp); var sampleTestGeneratorProvider = new SimpleTestGeneratorProvider(); var converter = new SpecFlowUnitTestConverter(sampleTestGeneratorProvider, codeDomHelper, true, true); CodeNamespace code = converter.GenerateUnitTestFixture(feature, "TestClassName", "Target.Namespace"); Assert.IsNotNull(code); // make sure name space is changed Assert.AreEqual(code.Name, SimpleTestGeneratorProvider.DefaultNameSpace); // make sure all method titles are changed correctly List<string> methodTitles = new List<string>(); for (int i = 0; i < code.Types[0].Members.Count; i++) { methodTitles.Add(code.Types[0].Members[i].Name); } foreach (var title in sampleTestGeneratorProvider.newTitles) { Assert.IsTrue(methodTitles.Contains(title)); } } } }
private string GenerateError(TestGeneratorResult generationResult, CodeDomHelper codeDomHelper) { var errorsArray = generationResult.Errors.ToArray(); foreach (var testGenerationError in errorsArray) { OnGenerationError(testGenerationError); } return string.Join(Environment.NewLine, errorsArray.Select(e => codeDomHelper.GetErrorStatementString(e.Message)).ToArray()); }
public TestGeneratorProvider(CodeDomHelper codeDomHelper) { _codeDomHelper = codeDomHelper; }
/// <summary> /// Construct GetILBOEx method /// </summary> /// <returns>CodeMemberMethod</returns> private CodeMemberMethod GetILBOEx() { CodeMemberMethod GetILBOEx = null; CodeMethodInvokeExpression MethodInvokation = null; try { GetILBOEx = new CodeMemberMethod { Name = "GetILBOEx", Attributes = MemberAttributes.Public | MemberAttributes.Override, ReturnType = new CodeTypeReference("IILBO") }; //method Parameters GetILBOEx.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "sILBOCode")); GetILBOEx.Parameters.Add(new CodeParameterDeclarationExpression(typeof(long), "lILBOIndex")); //method summary AddMethodSummary(GetILBOEx, "Creates/Gets the Object Handle of the ILBO"); CodeTryCatchFinallyStatement TryBlock = AddTryBlock(GetILBOEx); TryBlock.TryStatements.Add(AddTrace(GetILBOEx, TraceSeverity.Info)); TryBlock.TryStatements.Add(SnippetStatement("switch(sILBOCode)")); TryBlock.TryStatements.Add(SnippetStatement("{")); //GlobalVar.codeGeneration.activities[sName].ILBOList; foreach (ILBO ilbo in this._activity.ILBOs) { string mILBOName = string.Format("m_o{0}", ilbo.Code); TryBlock.TryStatements.Add(SnippetStatement(string.Format("case \"{0}\":", ilbo.Code))); CodeConditionStatement ifCondition = new CodeConditionStatement(); //if condition MethodInvokation = MethodInvocationExp(TypeReferenceExp(string.Format("{0}_Cyclic", mILBOName)), "ContainsKey"); AddParameters(MethodInvokation, new Object[] { new CodeBinaryOperatorExpression(VariableReferenceExp("lILBOIndex"), CodeBinaryOperatorType.Subtract, PrimitiveExpression(1)) }); ifCondition.Condition = new CodeBinaryOperatorExpression(MethodInvokation, CodeBinaryOperatorType.IdentityInequality, PrimitiveExpression(true)); //content for the if condition MethodInvokation = MethodInvocationExp(TypeReferenceExp(string.Format("{0}_Cyclic", mILBOName)), "Add"); AddParameters(MethodInvokation, new Object[] { new CodeBinaryOperatorExpression(VariableReferenceExp("lILBOIndex"), CodeBinaryOperatorType.Subtract, PrimitiveExpression(1)), new CodeObjectCreateExpression(string.Format("{0}", ilbo.Code)) }); ifCondition.TrueStatements.Add(MethodInvokation); //adding if condition to tryblock TryBlock.TryStatements.Add(ifCondition); //return statement for this case TryBlock.TryStatements.Add(ReturnExpression(new CodeArrayIndexerExpression(VariableReferenceExp(string.Format("{0}_Cyclic", mILBOName)), new CodeBinaryOperatorExpression(VariableReferenceExp("lILBOIndex"), CodeBinaryOperatorType.Subtract, PrimitiveExpression(1))))); } //default case TryBlock.TryStatements.Add(SnippetStatement(string.Format("default:"))); MethodInvokation = MethodInvocationExp(BaseReferenceExp(), GetILBOEx.Name); AddParameters(MethodInvokation, new Object[] { ArgumentReferenceExp(GetILBOEx.Parameters[0].Name), ArgumentReferenceExp(GetILBOEx.Parameters[1].Name) }); TryBlock.TryStatements.Add(ReturnExpression(MethodInvokation)); TryBlock.TryStatements.Add(new CodeSnippetStatement("}//ENDSWITCH")); // close braces for switch case CodeCatchClause catchBlock = CodeDomHelper.AddCatchBlock(TryBlock); catchBlock.Statements.Add(AddTrace(GetILBOEx, TraceSeverity.Error)); CodeDomHelper.ThrowException(catchBlock); } catch (Exception ex) { throw new Exception(string.Format("GetILBOEx->{0}", !object.Equals(ex.InnerException, null) ? ex.InnerException.Message : ex.Message)); } return(GetILBOEx); }
/// <summary> /// Initializes a new instance of the <see cref="SpecBindTestGeneratorProvider" /> class. /// </summary> /// <param name="codeDomHelper">The code DOM helper.</param> /// <param name="configurationProvider">The configuration provider.</param> public SpecBindTestGeneratorProvider(CodeDomHelper codeDomHelper, ISpecBindConfigurationProvider configurationProvider) : base(codeDomHelper) { this.configurationProvider = configurationProvider; }
private void AddSpecFlowFooter(CodeDomProvider codeProvider, TextWriter outputWriter, CodeDomHelper codeDomHelper) { codeProvider.GenerateCodeFromStatement(codeDomHelper.GetEndRegionStatement(), outputWriter, null); }
public SeleniumNUnitTestGeneratorProvider(CodeDomHelper codeDomHelper, ProjectSettings projectSettings) { this.codeDomHelper = codeDomHelper; this.projectSettings = projectSettings; this.customConfigResolver = new CustomConfigResolver(); }
public XUnitTestGeneratorProvider(CodeDomHelper codeDomHelper) { CodeDomHelper = codeDomHelper; }
private string GenerateError(Exception ex, CodeDomHelper codeDomHelper) { TestGenerationError testGenerationError = new TestGenerationError(ex); OnGenerationError(testGenerationError); return codeDomHelper.GetErrorStatementString(testGenerationError.Message); }
public MsTest2010GeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }
private CodeNamespace GenerateTestFileCode(FeatureFileInput featureFileInput, CodeDomHelper codeDomHelper) { string targetNamespace = GetTargetNamespace(featureFileInput) ?? "SpecFlow.GeneratedTests"; SpecFlowLangParser parser = new SpecFlowLangParser(generatorConfiguration.FeatureLanguage); Feature feature; using (var contentReader = featureFileInput.GetFeatureFileContentReader(projectSettings)) { feature = parser.Parse(contentReader, featureFileInput.GetFullPath(projectSettings)); } IUnitTestGeneratorProvider generatorProvider = ConfigurationServices.CreateInstance<IUnitTestGeneratorProvider>(generatorConfiguration.GeneratorUnitTestProviderType); codeDomHelper.InjectIfRequired(generatorProvider); ISpecFlowUnitTestConverter testConverter = new SpecFlowUnitTestConverter(generatorProvider, codeDomHelper, generatorConfiguration); var codeNamespace = testConverter.GenerateUnitTestFixture(feature, null, targetNamespace); return codeNamespace; }
public XunitRetryTestGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }
// IUnitTestGeneratorProvider public NullUnitTestGeneratorProvider(CodeDomHelper codeDomHelper) { }
public MsTestSilverlightGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }
public SimpleTestGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }
public override void SetTestClassInitializeMethod(TestClassGenerationContext generationContext) { generationContext.TestClassInitializeMethod.Attributes |= MemberAttributes.Static; CodeDomHelper.AddAttribute(generationContext.TestClassInitializeMethod, TESTFIXTURESETUP_ATTR); }
public BlueTestGeneratorProvider(CodeDomHelper codeDomHelper) { CodeDomHelper = codeDomHelper; }
public virtual void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable <string> scenarioCategories) { CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, scenarioCategories); }
public XUnit2TestGeneratorProvider(CodeDomHelper codeDomHelper, ProjectSettings projectSettings) { CodeDomHelper = codeDomHelper; _projectSettings = projectSettings; }
public MsTestWebDriverGenerator(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }
public UnitTestFeatureGenerator(IUnitTestGeneratorProvider testGeneratorProvider, CodeDomHelper codeDomHelper, SpecFlow.Configuration.SpecFlowConfiguration specFlowConfiguration, IDecoratorRegistry decoratorRegistry) { this.testGeneratorProvider = testGeneratorProvider; this.codeDomHelper = codeDomHelper; this._specFlowConfiguration = specFlowConfiguration; this.decoratorRegistry = decoratorRegistry; }
public CodeNamespace GenerateTestFileCode(FeatureFileInput featureFile, TextReader inputReader, CodeDomProvider codeProvider, CodeDomHelper codeDomHelper) { string targetNamespace = GetTargetNamespace(featureFile); SpecFlowLangParser parser = new SpecFlowLangParser(project.Configuration.GeneratorConfiguration.FeatureLanguage); Feature feature = parser.Parse(inputReader, featureFile.GetFullPath(project.ProjectSettings)); IUnitTestGeneratorProvider generatorProvider = ConfigurationServices.CreateInstance <IUnitTestGeneratorProvider>(project.Configuration.GeneratorConfiguration.GeneratorUnitTestProviderType); codeDomHelper.InjectIfRequired(generatorProvider); ISpecFlowUnitTestConverter testConverter = new SpecFlowUnitTestConverter(generatorProvider, codeDomHelper, project.Configuration.GeneratorConfiguration); var codeNamespace = testConverter.GenerateUnitTestFixture(feature, null, targetNamespace); return(codeNamespace); }
public NUnitTestGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }
private CodeMemberField GenerateStaticAttributeField(IReference property, ITransformationContext context) { var typedElementType = CodeDomHelper.ToTypeReference(typeof(ITypedElement)); var staticAttributeField = new CodeMemberField() { Name = "_" + property.Name.ToCamelCase() + "Reference", Attributes = MemberAttributes.Static | MemberAttributes.Private, Type = new CodeTypeReference(typeof(Lazy <>).Name, typedElementType) }; var staticAttributeFieldInit = new CodeMemberMethod() { Name = "Retrieve" + property.Name.ToPascalCase() + "Reference", Attributes = MemberAttributes.Private | MemberAttributes.Static, ReturnType = typedElementType }; var declaringTypeRef = CreateReference(property.DeclaringType, true, context, implementation: true); staticAttributeFieldInit.Statements.Add(new CodeMethodReturnStatement(new CodeCastExpression(typedElementType, new CodeMethodInvokeExpression(new CodeCastExpression(CodeDomHelper.ToTypeReference(typeof(ModelElement)), new CodePropertyReferenceExpression(new CodeTypeReferenceExpression(declaringTypeRef), "ClassInstance")), "Resolve", new CodePrimitiveExpression(property.Name))))); staticAttributeField.InitExpression = new CodeObjectCreateExpression(staticAttributeField.Type, new CodeMethodReferenceExpression(null, staticAttributeFieldInit.Name)); CodeDomHelper.DependentMembers(staticAttributeField, true).Add(staticAttributeFieldInit); return(staticAttributeField); }
protected void SetProperty(CodeTypeMember codeTypeMember, string name, string value) { CodeDomHelper.AddAttribute(codeTypeMember, TRAIT_ATTRIBUTE, name, value); }
/// <summary> /// Constructs DisposeILBO method /// </summary> /// <returns>CodeMemberMethod</returns> private CodeMemberMethod DisposeILBO() { CodeMemberMethod DisposeILBO = null; CodeMethodInvokeExpression MethodInvokation = null; try { DisposeILBO = new CodeMemberMethod { Name = "DisposeILBO", Attributes = MemberAttributes.Public | MemberAttributes.Override }; //method parameters DisposeILBO.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "sILBOCode")); //method summary AddMethodSummary(DisposeILBO, "Disposes the Object Handle of the ILBO"); //try block CodeTryCatchFinallyStatement TryBlock = CodeDomHelper.AddTryBlock(DisposeILBO); TryBlock.TryStatements.Add(AddTrace(DisposeILBO, TraceSeverity.Info)); //switch case TryBlock.TryStatements.Add(SnippetStatement("switch(sILBOCode)")); TryBlock.TryStatements.Add(SnippetStatement("{")); //case for each ilbo foreach (ILBO ilbo in this._activity.ILBOs) { string mILBOName = string.Format("m_o{0}", ilbo.Code); TryBlock.TryStatements.Add(SnippetStatement(string.Format("case \"{0}\":", ilbo.Code))); CodeConditionStatement ILBONullCheck = new CodeConditionStatement(new CodeBinaryOperatorExpression(TypeReferenceExp(string.Format("{0}", mILBOName)), CodeBinaryOperatorType.IdentityInequality, SnippetExpression("null"))); //ILBONullCheck.TrueStatements.Add(MethodInvocationExp(TypeReferenceExp(mILBOName), "Clear")); ILBONullCheck.TrueStatements.Add(AssignVariable(mILBOName, SnippetExpression("null"))); AddExpressionToTryBlock(TryBlock, ILBONullCheck); TryBlock.TryStatements.Add(SnippetExpression("break")); } //default case TryBlock.TryStatements.Add(SnippetStatement(string.Format("default:"))); MethodInvokation = MethodInvocationExp(BaseReferenceExp(), "DisposeILBO"); AddParameters(MethodInvokation, new Object[] { VariableReferenceExp("sILBOCode") }); TryBlock.TryStatements.Add(MethodInvokation); TryBlock.TryStatements.Add(SnippetExpression("break")); TryBlock.TryStatements.Add(SnippetStatement("}//ENDSWITCH"));//close braces for switch case CodeCatchClause catchBlock = CodeDomHelper.AddCatchBlock(TryBlock); catchBlock.Statements.Add(FillMessageObject(DisposeILBO, SnippetExpression("string.Format(\"activity : DisposeILBO(sILBOCode=\\\"{0}\\\")\",sILBOCode)"))); CodeDomHelper.ThrowException(catchBlock); } catch (Exception ex) { throw new Exception(string.Format("DisposeILBO->{0}", !object.Equals(ex.InnerException, null) ? ex.InnerException.Message : ex.Message)); } return(DisposeILBO); }
public void MarkCodeMethodInvokeExpressionAsAwait(CodeMethodInvokeExpression expression) { CodeDomHelper.MarkCodeMethodInvokeExpressionAsAwait(expression); }
/// <summary> /// Constructs DisposeILBOEx /// </summary> /// <returns>CodeMemberMethod</returns> private CodeMemberMethod DisposeILBOEx() { CodeMemberMethod DisposeILBOEx = null; CodeMethodInvokeExpression MethodInvokation = null; try { DisposeILBOEx = new CodeMemberMethod { Name = "DisposeILBOEx", Attributes = MemberAttributes.Public | MemberAttributes.Override }; //method parameters DisposeILBOEx.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(System.String)), "sILBOCode")); DisposeILBOEx.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(typeof(long)), "lILBOIndex")); //method summary AddMethodSummary(DisposeILBOEx, "Disposes the Object Handle of the ILBO"); CodeTryCatchFinallyStatement TryBlock = CodeDomHelper.AddTryBlock(DisposeILBOEx); TryBlock.TryStatements.Add(AddTrace(DisposeILBOEx, TraceSeverity.Info)); //switch case TryBlock.TryStatements.Add(SnippetStatement("switch(sILBOCode)")); TryBlock.TryStatements.Add(SnippetStatement("{")); //for each ilbo foreach (ILBO ilbo in this._activity.ILBOs) { string mILBOName = string.Format("m_o{0}", ilbo.Code); TryBlock.TryStatements.Add(SnippetStatement(string.Format("case \"{0}\":", ilbo.Code))); CodeConditionStatement ILBOIndexCheck = new CodeConditionStatement(new CodeBinaryOperatorExpression(ArgumentReferenceExp(DisposeILBOEx.Parameters[1].Name), CodeBinaryOperatorType.GreaterThan, PrimitiveExpression(0))); //ILBOIndexCheck.TrueStatements.Add( MethodInvocationExp( CastExpression(ilbo.Name.ToLowerInvariant(), ArrayIndexerExpression(string.Format("{0}_Cyclic", mILBOName), BinaryOpertorExpression(ArgumentReferenceExp("lILBOIndex"), CodeBinaryOperatorType.Subtract, PrimitiveExpression(1)))),"Clear")); MethodInvokation = MethodInvocationExp(TypeReferenceExp(string.Format("{0}_Cyclic", mILBOName)), "Remove"); AddParameters(MethodInvokation, new Object[] { new CodeBinaryOperatorExpression(ArgumentReferenceExp(DisposeILBOEx.Parameters[1].Name), CodeBinaryOperatorType.Subtract, PrimitiveExpression(1)) }); ILBOIndexCheck.TrueStatements.Add(MethodInvokation); MethodInvokation = MethodInvocationExp(TypeReferenceExp(string.Format("{0}_Cyclic", mILBOName)), "Clear"); ILBOIndexCheck.FalseStatements.Add(MethodInvokation); TryBlock.TryStatements.Add(ILBOIndexCheck); TryBlock.TryStatements.Add(SnippetExpression("break")); } //default case TryBlock.TryStatements.Add(SnippetStatement(string.Format("default:"))); MethodInvokation = MethodInvocationExp(BaseReferenceExp(), DisposeILBOEx.Name); AddParameters(MethodInvokation, new Object[] { ArgumentReferenceExp(DisposeILBOEx.Parameters[0].Name), ArgumentReferenceExp(DisposeILBOEx.Parameters[1].Name) }); TryBlock.TryStatements.Add(MethodInvokation); TryBlock.TryStatements.Add(SnippetExpression("break")); TryBlock.TryStatements.Add(SnippetStatement("}//ENDSWITCH")); //close braces for switch case CodeCatchClause catchBlock = CodeDomHelper.AddCatchBlock(TryBlock); catchBlock.Statements.Add(FillMessageObject(DisposeILBOEx, SnippetExpression("string.Format(\"activity : DisposeILBOEx(sILBOCode=\\\"{0}\\\")\",sILBOCode)"))); ThrowException(catchBlock); } catch (Exception ex) { throw new Exception(string.Format("DiposeILBOEx->{0}", !object.Equals(ex.InnerException, null) ? ex.InnerException.Message : ex.Message)); } return(DisposeILBOEx); }
public MbUnit3TestGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }
public virtual void SetTestClassParallelize(TestClassGenerationContext generationContext) { CodeDomHelper.AddAttribute(generationContext.TestClass, COLLECTION_ATTRIBUTE, new CodeAttributeArgument(new CodePrimitiveExpression(Guid.NewGuid()))); }
public MasterClassGenerator(IObjectContainer container, TestClassGenerationContext context, CodeDomHelper codeDomHelper) { _context = context; _codeDomHelper = codeDomHelper; _container = container; }
public void MarkCodeMemberMethodAsAsync(CodeMemberMethod testMethod) { CodeDomHelper.MarkCodeMemberMethodAsAsync(testMethod); }
protected TestGenerator CreateTestGenerator(ProjectSettings projectSettings) { GeneratorConfiguration generatorConfiguration = new GeneratorConfiguration(); CodeDomHelper codeDomHelper = new CodeDomHelper(CodeDomProviderLanguage.CSharp); UnitTestFeatureGenerator unitTestFeatureGenerator = new UnitTestFeatureGenerator(new NUnitTestGeneratorProvider(codeDomHelper), codeDomHelper, generatorConfiguration, new DecoratorRegistryStub()); var generatorRegistryStub = new Mock<IFeatureGeneratorRegistry>(); generatorRegistryStub.Setup(r => r.CreateGenerator(It.IsAny<SpecFlowDocument>())).Returns(unitTestFeatureGenerator); return new TestGenerator(generatorConfiguration, projectSettings, TestHeaderWriterStub.Object, TestUpToDateCheckerStub.Object, generatorRegistryStub.Object, codeDomHelper); }
public override void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle) { CodeDomHelper.AddAttribute(testMethod, TEST_ATTR); CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, scenarioTitle); }
private void AddSpecFlowHeader(CodeDomProvider codeProvider, TextWriter outputWriter, CodeDomHelper codeDomHelper) { var specFlowHeaderTemplate = @"------------------------------------------------------------------------------ <auto-generated> This code was generated by SpecFlow (http://www.specflow.org/). SpecFlow Version:{0} Runtime Version:{1} Changes to this file may cause incorrect behavior and will be lost if the code is regenerated. </auto-generated> ------------------------------------------------------------------------------"; var headerReader = new StringReader(string.Format(specFlowHeaderTemplate, GetCurrentSpecFlowVersion(), Environment.Version )); string line; while ((line = headerReader.ReadLine()) != null) { codeProvider.GenerateCodeFromStatement(new CodeCommentStatement(line), outputWriter, null); } codeProvider.GenerateCodeFromStatement(codeDomHelper.GetStartRegionStatement("Designer generated code"), outputWriter, null); }
private void SetupAsyncTest(CodeMemberMethod testMethod) { CodeDomHelper.AddAttribute(testMethod, ASYNCTEST_ATTR); }
public override void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable <string> featureCategories) { var categories = featureCategories.ToArray(); CodeDomHelper.AddAttributeForEachValue(generationContext.TestClass, TAG_ATTR, categories); }
public void SetTestInitializeMethod(TestClassGenerationContext generationContext) { CodeDomHelper.AddAttribute(generationContext.TestInitializeMethod, TESTSETUP_ATTR); }
public SpecFlowCodedUITestGenerator(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }
public void SetTestCleanupMethod(TestClassGenerationContext generationContext) { CodeDomHelper.AddAttribute(generationContext.TestCleanupMethod, TESTTEARDOWN_ATTR); }
public void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName) { CodeDomHelper.AddAttribute(testMethod, TEST_ATTR); CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, friendlyTestName); }
public SeleniumNUnitTestGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }
public static SpecFlowUnitTestConverter CreateUnitTestConverter(IUnitTestGeneratorProvider testGeneratorProvider) { var codeDomHelper = new CodeDomHelper(CodeDomProviderLanguage.CSharp); return new SpecFlowUnitTestConverter(testGeneratorProvider, codeDomHelper, new GeneratorConfiguration { AllowRowTests = true, AllowDebugGeneratedFiles = true}); }
public TestGenerator(GeneratorConfiguration generatorConfiguration, ProjectSettings projectSettings, ITestHeaderWriter testHeaderWriter, ITestUpToDateChecker testUpToDateChecker, IFeatureGeneratorRegistry featureGeneratorRegistry, CodeDomHelper codeDomHelper) { if (generatorConfiguration == null) { throw new ArgumentNullException("generatorConfiguration"); } if (projectSettings == null) { throw new ArgumentNullException("projectSettings"); } if (testHeaderWriter == null) { throw new ArgumentNullException("testHeaderWriter"); } if (testUpToDateChecker == null) { throw new ArgumentNullException("testUpToDateChecker"); } if (featureGeneratorRegistry == null) { throw new ArgumentNullException("featureGeneratorRegistry"); } this.generatorConfiguration = generatorConfiguration; this.testUpToDateChecker = testUpToDateChecker; this.featureGeneratorRegistry = featureGeneratorRegistry; this.codeDomHelper = codeDomHelper; this.testHeaderWriter = testHeaderWriter; this.projectSettings = projectSettings; }
/// <summary> /// Initializes a new instance of the <see cref="CodedUiGeneratorProvider"/> class. /// </summary> /// <param name="codeDomHelper"> /// The code dom helper. /// </param> public CodedUIGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper) { }