private void AddGeneratedMethod(CodeTypeDeclaration generatedClass, MultiDirectionTestMethod testMethod) { foreach (var transferDirection in testMethod.GetTransferDirections()) { string generatedMethodName = this.GetGeneratedMethodName(testMethod, transferDirection); CodeMemberMethod generatedMethod = new CodeMemberMethod(); generatedMethod.Name = generatedMethodName; generatedMethod.Attributes = MemberAttributes.Public | MemberAttributes.Final; // Add TestCategoryAttribute to the generated method this.AddTestCategoryAttributes(generatedMethod, testMethod); this.AddTestCategoryAttribute(generatedMethod, MultiDirectionTag.MultiDirection); foreach (var tag in transferDirection.GetTags()) { this.AddTestCategoryAttribute(generatedMethod, tag); } CodeAttributeDeclaration testMethodAttribute = new CodeAttributeDeclaration( new CodeTypeReference(typeof(TestMethodAttribute))); generatedMethod.CustomAttributes.Add(testMethodAttribute); foreach (var statement in transferDirection.EnumerateUpdateContextStatements()) { generatedMethod.Statements.Add(statement); } CodeMethodReferenceExpression callee = new CodeMethodReferenceExpression( new CodeBaseReferenceExpression(), testMethod.MethodInfoObj.Name); CodeMethodInvokeExpression invokeExp = new CodeMethodInvokeExpression(callee); generatedMethod.Statements.Add(invokeExp); generatedClass.Members.Add(generatedMethod); } }
private void AddGeneratedMethod(CodeTypeDeclaration generatedClass, MultiDirectionTestMethod testMethod) { foreach (var transferDirection in testMethod.GetTransferDirections()) { string generatedMethodName = this.GetGeneratedMethodName(testMethod, transferDirection); CodeMemberMethod generatedMethod = new CodeMemberMethod(); generatedMethod.Name = generatedMethodName; generatedMethod.Attributes = MemberAttributes.Public | MemberAttributes.Final; // Add TestCategoryAttribute to the generated method this.AddTestCategoryAttributes(generatedMethod, testMethod); this.AddTestCategoryAttribute(generatedMethod, MultiDirectionTag.MultiDirection); foreach (var tag in transferDirection.GetTags()) { this.AddTestCategoryAttribute(generatedMethod, tag); } CodeAttributeDeclaration testMethodAttribute = null; testMethodAttribute = new CodeAttributeDeclaration( new CodeTypeReference(typeof(MSUnittest.TestMethodAttribute))); generatedMethod.CustomAttributes.Add(testMethodAttribute); if (Program.FrameWorkType == FrameworkType.DNetCore) { // add TestStartEndAttribute to ensure Test.Start and Test.End will be called as expected generatedMethod.CustomAttributes.Add(new CodeAttributeDeclaration("TestStartEnd")); } foreach (var statement in TransferDirectionExtensions.EnumerateUpdateContextStatements(transferDirection as DMLibTransferDirection)) { generatedMethod.Statements.Add(statement); } CodeMethodReferenceExpression callee = new CodeMethodReferenceExpression( new CodeBaseReferenceExpression(), testMethod.MethodInfoObj.Name); CodeMethodInvokeExpression invokeExp = new CodeMethodInvokeExpression(callee); generatedMethod.Statements.Add(invokeExp); generatedClass.Members.Add(generatedMethod); } }