コード例 #1
1
		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);
		}
コード例 #2
0
 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());
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
ファイル: TestGenerator.cs プロジェクト: ethanmoffat/SpecFlow
        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;
        }
コード例 #6
0
        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;
        }
コード例 #7
0
        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();
        }
コード例 #8
0
        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;
        }
コード例 #9
0
        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));
                    }
                }
            }
        }
コード例 #10
0
        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());
        }
コード例 #11
0
 public TestGeneratorProvider(CodeDomHelper codeDomHelper)
 {
     _codeDomHelper = codeDomHelper;
 }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
 /// <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;
 }
コード例 #14
0
 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();
 }
コード例 #16
0
 public XUnitTestGeneratorProvider(CodeDomHelper codeDomHelper)
 {
     CodeDomHelper = codeDomHelper;
 }
コード例 #17
0
 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)
		{
		}
コード例 #19
0
ファイル: TestGenerator.cs プロジェクト: roffster/SpecFlow
        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;
        }
コード例 #20
0
 public XunitRetryTestGeneratorProvider(CodeDomHelper codeDomHelper)
     : base(codeDomHelper)
 {
 }
コード例 #21
0
 // IUnitTestGeneratorProvider
 public NullUnitTestGeneratorProvider(CodeDomHelper codeDomHelper)
 {
 }
コード例 #22
0
 public MsTestSilverlightGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper)
 {
 }
コード例 #23
0
 public SimpleTestGeneratorProvider(CodeDomHelper codeDomHelper)
     : base(codeDomHelper)
 {
 }
コード例 #24
0
        public override void SetTestClassInitializeMethod(TestClassGenerationContext generationContext)
        {
            generationContext.TestClassInitializeMethod.Attributes |= MemberAttributes.Static;

            CodeDomHelper.AddAttribute(generationContext.TestClassInitializeMethod, TESTFIXTURESETUP_ATTR);
        }
コード例 #25
0
 public BlueTestGeneratorProvider(CodeDomHelper codeDomHelper)
 {
     CodeDomHelper = codeDomHelper;
 }
コード例 #26
0
 public virtual void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable <string> scenarioCategories)
 {
     CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, scenarioCategories);
 }
コード例 #27
0
 public XUnit2TestGeneratorProvider(CodeDomHelper codeDomHelper, ProjectSettings projectSettings)
 {
     CodeDomHelper    = codeDomHelper;
     _projectSettings = projectSettings;
 }
コード例 #28
0
 public MsTestWebDriverGenerator(CodeDomHelper codeDomHelper)
     : base(codeDomHelper)
 {
 }
コード例 #29
0
 public UnitTestFeatureGenerator(IUnitTestGeneratorProvider testGeneratorProvider, CodeDomHelper codeDomHelper, SpecFlow.Configuration.SpecFlowConfiguration specFlowConfiguration, IDecoratorRegistry decoratorRegistry)
 {
     this.testGeneratorProvider  = testGeneratorProvider;
     this.codeDomHelper          = codeDomHelper;
     this._specFlowConfiguration = specFlowConfiguration;
     this.decoratorRegistry      = decoratorRegistry;
 }
コード例 #30
0
        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);
        }
コード例 #31
0
		public NUnitTestGeneratorProvider(CodeDomHelper codeDomHelper)
			: base(codeDomHelper)
		{
		}
コード例 #32
0
            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);
            }
コード例 #33
0
 protected void SetProperty(CodeTypeMember codeTypeMember, string name, string value)
 {
     CodeDomHelper.AddAttribute(codeTypeMember, TRAIT_ATTRIBUTE, name, value);
 }
コード例 #34
0
        /// <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);
        }
コード例 #35
0
 public void MarkCodeMethodInvokeExpressionAsAwait(CodeMethodInvokeExpression expression)
 {
     CodeDomHelper.MarkCodeMethodInvokeExpressionAsAwait(expression);
 }
コード例 #36
0
        /// <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);
        }
コード例 #37
0
 public MbUnit3TestGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper)
 {
 }
コード例 #38
0
 public virtual void SetTestClassParallelize(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestClass, COLLECTION_ATTRIBUTE, new CodeAttributeArgument(new CodePrimitiveExpression(Guid.NewGuid())));
 }
コード例 #39
0
 public MasterClassGenerator(IObjectContainer container, TestClassGenerationContext context, CodeDomHelper codeDomHelper)
 {
     _context       = context;
     _codeDomHelper = codeDomHelper;
     _container     = container;
 }
コード例 #40
0
 public void MarkCodeMemberMethodAsAsync(CodeMemberMethod testMethod)
 {
     CodeDomHelper.MarkCodeMemberMethodAsAsync(testMethod);
 }
コード例 #41
0
 public XUnitTestGeneratorProvider(CodeDomHelper codeDomHelper)
 {
     CodeDomHelper = codeDomHelper;
 }
コード例 #42
0
 public SimpleTestGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper)
 {
 }
コード例 #43
0
        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);
        }
コード例 #44
0
 public override void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
 {
     CodeDomHelper.AddAttribute(testMethod, TEST_ATTR);
     CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, scenarioTitle);
 }
コード例 #45
0
ファイル: SpecFlowGenerator.cs プロジェクト: nandrew/SpecFlow
        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);
        }
コード例 #46
0
 private void SetupAsyncTest(CodeMemberMethod testMethod)
 {
     CodeDomHelper.AddAttribute(testMethod, ASYNCTEST_ATTR);
 }
コード例 #47
0
ファイル: SpecFlowGenerator.cs プロジェクト: nandrew/SpecFlow
 private void AddSpecFlowFooter(CodeDomProvider codeProvider, TextWriter outputWriter, CodeDomHelper codeDomHelper)
 {
     codeProvider.GenerateCodeFromStatement(codeDomHelper.GetEndRegionStatement(), outputWriter, null);
 }
コード例 #48
0
        public override void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable <string> featureCategories)
        {
            var categories = featureCategories.ToArray();

            CodeDomHelper.AddAttributeForEachValue(generationContext.TestClass, TAG_ATTR, categories);
        }
コード例 #49
0
 public void SetTestInitializeMethod(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestInitializeMethod, TESTSETUP_ATTR);
 }
コード例 #50
0
 public SpecFlowCodedUITestGenerator(CodeDomHelper codeDomHelper)
     : base(codeDomHelper)
 {
 }
コード例 #51
0
 public void SetTestCleanupMethod(TestClassGenerationContext generationContext)
 {
     CodeDomHelper.AddAttribute(generationContext.TestCleanupMethod, TESTTEARDOWN_ATTR);
 }
コード例 #52
0
 public void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName)
 {
     CodeDomHelper.AddAttribute(testMethod, TEST_ATTR);
     CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, friendlyTestName);
 }
コード例 #53
0
 public SeleniumNUnitTestGeneratorProvider(CodeDomHelper codeDomHelper) : base(codeDomHelper)
 {
 }
コード例 #54
0
ファイル: FactoryMethods.cs プロジェクト: roffster/SpecFlow
 public static SpecFlowUnitTestConverter CreateUnitTestConverter(IUnitTestGeneratorProvider testGeneratorProvider)
 {
     var codeDomHelper = new CodeDomHelper(CodeDomProviderLanguage.CSharp);
     return new SpecFlowUnitTestConverter(testGeneratorProvider, codeDomHelper, 
                                          new GeneratorConfiguration { AllowRowTests = true, AllowDebugGeneratedFiles = true});
 }
コード例 #55
0
ファイル: TestGenerator.cs プロジェクト: elv1s42/SpecFlow
        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;
        }
コード例 #56
0
        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);
        }
コード例 #57
0
 /// <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)
 {
 }