本文整理汇总了C#中TestClassGenerationContext类的典型用法代码示例。如果您正苦于以下问题:C# TestClassGenerationContext类的具体用法?C# TestClassGenerationContext怎么用?C# TestClassGenerationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestClassGenerationContext类属于命名空间,在下文中一共展示了TestClassGenerationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FinalizeTestClass
public override void FinalizeTestClass(TestClassGenerationContext generationContext)
{
base.FinalizeTestClass(generationContext);
if (generationContext.GenerateAsynchTests)
SetupAsyncTestClass(generationContext);
}
示例2: SetTestMethodCategories
public override void SetTestMethodCategories(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> scenarioCategories)
{
IEnumerable<string> tags = scenarioCategories.ToList();
IEnumerable<string> ownerTags = tags.Where(t => t.StartsWith(OWNER_TAG, StringComparison.InvariantCultureIgnoreCase)).Select(t => t);
if(ownerTags.Any())
{
string ownerName = ownerTags.Select(t => t.Substring(OWNER_TAG.Length).Trim('\"')).FirstOrDefault();
if(!String.IsNullOrEmpty(ownerName))
{
CodeDomHelper.AddAttribute(testMethod, OWNER_ATTR, ownerName);
}
}
IEnumerable<string> workitemTags = tags.Where(t => t.StartsWith(WORKITEM_TAG, StringComparison.InvariantCultureIgnoreCase)).Select(t => t);
if(workitemTags.Any())
{
int temp;
IEnumerable<string> workitemsAsStrings = workitemTags.Select(t => t.Substring(WORKITEM_TAG.Length).Trim('\"'));
IEnumerable<int> workitems = workitemsAsStrings.Where(t => int.TryParse(t, out temp)).Select(t => int.Parse(t));
foreach(int workitem in workitems)
{
CodeDomHelper.AddAttribute(testMethod, WORKITEM_ATTR, workitem);
}
}
CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, GetNonMSTestSpecificTags(tags));
}
示例3: SetTestMethod
public override void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
{
base.SetTestMethod(generationContext, testMethod, scenarioTitle);
if (generationContext.GenerateAsynchTests)
SetupAsyncTest(testMethod);
}
示例4: SetTestClassInitializeMethod
public void SetTestClassInitializeMethod(TestClassGenerationContext generationContext)
{
// xUnit uses IUseFixture<T> on the class
generationContext.TestClassInitializeMethod.Attributes |= MemberAttributes.Static;
_currentFixtureDataTypeDeclaration = CodeDomHelper.CreateGeneratedTypeDeclaration("FixtureData");
generationContext.TestClass.Members.Add(_currentFixtureDataTypeDeclaration);
var fixtureDataType =
CodeDomHelper.CreateNestedTypeReference(generationContext.TestClass, _currentFixtureDataTypeDeclaration.Name);
var useFixtureType = new CodeTypeReference(IUSEFIXTURE_INTERFACE, fixtureDataType);
CodeDomHelper.SetTypeReferenceAsInterface(useFixtureType);
generationContext.TestClass.BaseTypes.Add(useFixtureType);
// public void SetFixture(T) { } // explicit interface implementation for generic interfaces does not work with codedom
CodeMemberMethod setFixtureMethod = new CodeMemberMethod();
setFixtureMethod.Attributes = MemberAttributes.Public;
setFixtureMethod.Name = "SetFixture";
setFixtureMethod.Parameters.Add(new CodeParameterDeclarationExpression(fixtureDataType, "fixtureData"));
setFixtureMethod.ImplementationTypes.Add(useFixtureType);
generationContext.TestClass.Members.Add(setFixtureMethod);
// public <_currentFixtureTypeDeclaration>() { <fixtureSetupMethod>(); }
CodeConstructor ctorMethod = new CodeConstructor();
ctorMethod.Attributes = MemberAttributes.Public;
_currentFixtureDataTypeDeclaration.Members.Add(ctorMethod);
ctorMethod.Statements.Add(
new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(new CodeTypeReference(generationContext.TestClass.Name)),
generationContext.TestClassInitializeMethod.Name));
}
示例5: SetTestMethod
public override void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string friendlyTestName)
{
base.SetTestMethod(generationContext, testMethod, friendlyTestName);
if(generationContext.CustomData.ContainsKey("featureCategories"))
{
var featureCategories = (string[])generationContext.CustomData["featureCategories"];
CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, featureCategories);
}
if(generationContext.CustomData.ContainsKey(OWNER_TAG))
{
string ownerName = generationContext.CustomData[OWNER_TAG] as string;
if(!String.IsNullOrEmpty(ownerName))
{
CodeDomHelper.AddAttribute(testMethod, OWNER_ATTR, ownerName);
}
}
if(generationContext.CustomData.ContainsKey(WORKITEM_TAG))
{
IEnumerable<int> workitems = generationContext.CustomData[WORKITEM_TAG] as IEnumerable<int>;
foreach(int workitem in workitems)
{
CodeDomHelper.AddAttribute(testMethod, WORKITEM_ATTR, workitem);
}
}
}
示例6: SetTestMethodIgnore
public override void SetTestMethodIgnore(TestClassGenerationContext generationContext, CodeMemberMethod testMethod)
{
var factAttr = testMethod.CustomAttributes.OfType<CodeAttributeDeclaration>()
.FirstOrDefault(codeAttributeDeclaration => codeAttributeDeclaration.Name == FACT_ATTRIBUTE);
if (factAttr != null)
{
// set [FactAttribute(Skip="reason")]
factAttr.Arguments.Add
(
new CodeAttributeArgument(FACT_ATTRIBUTE_SKIP_PROPERTY_NAME, new CodePrimitiveExpression(SKIP_REASON))
);
}
var theoryAttr = testMethod.CustomAttributes.OfType<CodeAttributeDeclaration>()
.FirstOrDefault(codeAttributeDeclaration => codeAttributeDeclaration.Name == THEORY_ATTRIBUTE);
if (theoryAttr != null)
{
// set [TheoryAttribute(Skip="reason")]
theoryAttr.Arguments.Add
(
new CodeAttributeArgument(THEORY_ATTRIBUTE_SKIP_PROPERTY_NAME, new CodePrimitiveExpression(SKIP_REASON))
);
}
}
示例7: SetRowTest
public override void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
{
CodeDomHelper.AddAttribute(testMethod, THEORY_ATTRIBUTE);
SetProperty(testMethod, FEATURE_TITLE_PROPERTY_NAME, generationContext.Feature.Name);
SetDescription(testMethod, scenarioTitle);
}
示例8: FixTestRunOrderingIssue
protected virtual void FixTestRunOrderingIssue(TestClassGenerationContext generationContext)
{
//see https://github.com/techtalk/SpecFlow/issues/96
generationContext.TestInitializeMethod.Statements.Add(
new CodeConditionStatement(
new CodeBinaryOperatorExpression(
new CodeBinaryOperatorExpression(
new CodePropertyReferenceExpression(
new CodeTypeReferenceExpression(typeof (FeatureContext)),
"Current"),
CodeBinaryOperatorType.IdentityInequality,
new CodePrimitiveExpression(null)),
CodeBinaryOperatorType.BooleanAnd,
new CodeBinaryOperatorExpression(
new CodePropertyReferenceExpression(
new CodePropertyReferenceExpression(
new CodePropertyReferenceExpression(
new CodeTypeReferenceExpression(typeof (FeatureContext)),
"Current"),
"FeatureInfo"),
"Title"),
CodeBinaryOperatorType.IdentityInequality,
new CodePrimitiveExpression(generationContext.Feature.Title))),
new CodeExpressionStatement(
new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(
generationContext.Namespace.Name + "." + generationContext.TestClass.Name
),
generationContext.TestClassInitializeMethod.Name,
new CodePrimitiveExpression(null)))));
}
示例9: SetRow
public void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> tags, bool isIgnored)
{
var args = arguments.Select(
arg => new CodeAttributeArgument(new CodePrimitiveExpression(arg))).ToList();
// addressing ReSharper bug: TestCase attribute with empty string[] param causes inconclusive result - https://github.com/techtalk/SpecFlow/issues/116
bool hasExampleTags = tags.Any();
var exampleTagExpressionList = tags.Select(t => new CodePrimitiveExpression(t));
CodeExpression exampleTagsExpression = hasExampleTags ?
(CodeExpression)new CodePrimitiveExpression(null) :
new CodeArrayCreateExpression(typeof(string[]), exampleTagExpressionList.ToArray());
args.Add(new CodeAttributeArgument(exampleTagsExpression));
// adds 'Category' named parameter so that NUnit also understands that this test case belongs to the given categories
if (hasExampleTags)
{
CodeExpression exampleTagsStringExpr = new CodePrimitiveExpression(string.Join(",", tags.ToArray()));
args.Add(new CodeAttributeArgument("Category", exampleTagsStringExpr));
}
if (isIgnored)
args.Add(new CodeAttributeArgument("Ignored", new CodePrimitiveExpression(true)));
CodeDomHelper.AddAttribute(testMethod, ROW_ATTR, args.ToArray());
}
示例10: SetTestClassInitializeMethod
public virtual void SetTestClassInitializeMethod(TestClassGenerationContext generationContext)
{
generationContext.TestClassInitializeMethod.Attributes |= MemberAttributes.Static;
generationContext.TestClassInitializeMethod.Parameters.Add(new CodeParameterDeclarationExpression(
TESTCONTEXT_TYPE, "testContext"));
CodeDomHelper.AddAttribute(generationContext.TestClassInitializeMethod, TESTFIXTURESETUP_ATTR);
}
示例11: SetTestMethod
public override void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
{
base.SetTestMethod(generationContext, testMethod, scenarioTitle);
if (generationContext.CustomData.ContainsKey("featureCategories"))
{
var featureCategories = (string[])generationContext.CustomData["featureCategories"];
CodeDomHelper.AddAttributeForEachValue(testMethod, CATEGORY_ATTR, featureCategories);
}
}
示例12: SetTestInitializeMethod
public virtual void SetTestInitializeMethod(TestClassGenerationContext generationContext)
{
CodeDomHelper.AddAttribute(generationContext.TestInitializeMethod, TESTSETUP_ATTR);
//if (FeatureContext.Current != null && FeatureContext.Current.FeatureInfo.Title != "<current_feature_title>")
// <TestClass>.<TestClassInitialize>(null);
FixTestRunOrderingIssue(generationContext);
}
示例13: SetTestInitializeMethod
public override void SetTestInitializeMethod(TestClassGenerationContext generationContext)
{
base.SetTestInitializeMethod(generationContext);
// SenarioContext.Current.SetTestInstance(this);
var scenarioContext = new CodeTypeReferenceExpression("ScenarioContext");
var currentContext = new CodePropertyReferenceExpression(scenarioContext, "Current");
var scenarioContextExtensions = new CodeTypeReferenceExpression("ScenarioContextExtensions");
var setTestInstance = new CodeMethodInvokeExpression(scenarioContextExtensions, "SetTestInstance",
currentContext, new CodeThisReferenceExpression());
// Add it to ScenarioSetup
generationContext.ScenarioInitializeMethod.Statements.Add(new CodeExpressionStatement(setTestInstance));
}
示例14: SetRow
public virtual void SetRow(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, IEnumerable<string> arguments, IEnumerable<string> tags, bool isIgnored)
{
//TODO: better handle "ignored"
if (isIgnored)
return;
var args = arguments.Select(
arg => new CodeAttributeArgument(new CodePrimitiveExpression(arg))).ToList();
args.Add(
new CodeAttributeArgument(
new CodeArrayCreateExpression(typeof(string[]), tags.Select(t => new CodePrimitiveExpression(t)).ToArray())));
CodeDomHelper.AddAttribute(testMethod, INLINEDATA_ATTRIBUTE, args.ToArray());
}
示例15: SetupAsyncTestClass
private void SetupAsyncTestClass(TestClassGenerationContext generationContext)
{
generationContext.TestClass.BaseTypes.Add(new CodeTypeReference(ASYNCTEST_INTERFACE));
//AsyncTestRunner.RegisterAsyncTestExecutor(testRunner, new TechTalk.SpecFlow.Async.SilverlightAsyncTestExecutor(this));
var nawSilverlightAsyncTestExecutorExpr = new CodeObjectCreateExpression("TechTalk.SpecFlow.Async.SilverlightAsyncTestExecutor", new CodeThisReferenceExpression());
var registerAsyncExpression = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(typeof(AsyncTestRunner)),
"RegisterAsyncTestExecutor",
new CodeVariableReferenceExpression("testRunner"),
nawSilverlightAsyncTestExecutorExpr);
generationContext.TestInitializeMethod.Statements.Add(new CodeExpressionStatement(registerAsyncExpression));
}