本文整理汇总了C#中TestClassGenerationContext类的典型用法代码示例。如果您正苦于以下问题:C# TestClassGenerationContext类的具体用法?C# TestClassGenerationContext怎么用?C# TestClassGenerationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestClassGenerationContext类属于命名空间,在下文中一共展示了TestClassGenerationContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: FinalizeTestClass
public override void FinalizeTestClass(TestClassGenerationContext generationContext)
{
base.FinalizeTestClass(generationContext);
if (generationContext.GenerateAsynchTests)
SetupAsyncTestClass(generationContext);
}
开发者ID:rdhatt,项目名称:SpecFlow,代码行数:7,代码来源:MsTestSilverlightGeneratorProvider.cs
示例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));
}
开发者ID:ethanmoffat,项目名称:SpecFlow,代码行数:28,代码来源:MsTest2010GeneratorProvider.cs
示例3: SetTestMethod
public override void SetTestMethod(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
{
base.SetTestMethod(generationContext, testMethod, scenarioTitle);
if (generationContext.GenerateAsynchTests)
SetupAsyncTest(testMethod);
}
开发者ID:rdhatt,项目名称:SpecFlow,代码行数:7,代码来源:MsTestSilverlightGeneratorProvider.cs
示例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));
}
开发者ID:roffster,项目名称:SpecFlow,代码行数:35,代码来源:XUnitTestGeneratorProvider.cs
示例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);
}
}
}
开发者ID:ethanmoffat,项目名称:SpecFlow,代码行数:27,代码来源:MsTest2010GeneratorProvider.cs
示例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))
);
}
}
开发者ID:tmulkern,项目名称:SpecFlow,代码行数:26,代码来源:XUnit2TestGeneratorProvider.cs
示例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);
}
开发者ID:tmulkern,项目名称:SpecFlow,代码行数:7,代码来源:XUnit2TestGeneratorProvider.cs
示例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)))));
}
开发者ID:mdellanoce,项目名称:SpecFlow,代码行数:31,代码来源:MsTestGeneratorProvider.cs
示例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());
}
开发者ID:citizenmatt,项目名称:SpecFlow,代码行数:25,代码来源:NUnitTestGeneratorProvider.cs
示例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);
}
开发者ID:blinkbox,项目名称:SpecFlow,代码行数:8,代码来源:MsTestGeneratorProvider.cs
示例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);
}
}
开发者ID:roffster,项目名称:SpecFlow,代码行数:9,代码来源:MsTest2010GeneratorProvider.cs
示例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);
}
开发者ID:blinkbox,项目名称:SpecFlow,代码行数:9,代码来源:MsTestGeneratorProvider.cs
示例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));
}
开发者ID:rdhatt,项目名称:SpecFlow,代码行数:14,代码来源:MsTestSilverlightGeneratorProvider.cs
示例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());
}
开发者ID:tmulkern,项目名称:SpecFlow,代码行数:15,代码来源:XUnitTestGeneratorProvider.cs
示例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));
}
开发者ID:rdhatt,项目名称:SpecFlow,代码行数:16,代码来源:MsTestSilverlightGeneratorProvider.cs
示例16: SetTestClassCleanupMethod
public void SetTestClassCleanupMethod(TestClassGenerationContext generationContext)
{
// xUnit uses IUseFixture<T> on the class
generationContext.TestClassCleanupMethod.Attributes |= MemberAttributes.Static;
_currentFixtureDataTypeDeclaration.BaseTypes.Add(typeof(IDisposable));
// void IDisposable.Dispose() { <fixtureTearDownMethod>(); }
CodeMemberMethod disposeMethod = new CodeMemberMethod();
disposeMethod.PrivateImplementationType = new CodeTypeReference(typeof(IDisposable));
disposeMethod.Name = "Dispose";
_currentFixtureDataTypeDeclaration.Members.Add(disposeMethod);
disposeMethod.Statements.Add(
new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression(new CodeTypeReference(generationContext.TestClass.Name)),
generationContext.TestClassCleanupMethod.Name));
}
开发者ID:roffster,项目名称:SpecFlow,代码行数:20,代码来源:XUnitTestGeneratorProvider.cs
示例17: SetTestClassCategories
public override void SetTestClassCategories(TestClassGenerationContext generationContext, IEnumerable<string> featureCategories)
{
generationContext.CustomData["featureCategories"] = GetNonMSTestSpecificTags(featureCategories).ToArray();
IEnumerable<string> ownerTags = featureCategories.Where(t => t.StartsWith(OWNER_TAG, StringComparison.InvariantCultureIgnoreCase)).Select(t => t);
if(ownerTags.Any())
{
generationContext.CustomData[OWNER_TAG] = ownerTags.Select(t => t.Substring(OWNER_TAG.Length).Trim('\"')).FirstOrDefault();
}
IEnumerable<string> workitemTags = featureCategories.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('\"'));
if(workitemsAsStrings.Any())
{
generationContext.CustomData[WORKITEM_TAG] = workitemsAsStrings.Where(t => int.TryParse(t, out temp)).Select(t => int.Parse(t));
}
}
}
开发者ID:ethanmoffat,项目名称:SpecFlow,代码行数:21,代码来源:MsTest2010GeneratorProvider.cs
示例18: SetTestClassIgnore
public override void SetTestClassIgnore(TestClassGenerationContext generationContext)
{
CodeDomHelper.AddAttribute(generationContext.TestClass, IGNORE_ATTR, "Ignored feature");
}
开发者ID:tmulkern,项目名称:SpecFlow,代码行数:4,代码来源:NUnit3TestGeneratorProvider.cs
示例19: SetTestClassCleanupMethod
public override void SetTestClassCleanupMethod(TestClassGenerationContext generationContext)
{
CodeDomHelper.AddAttribute(generationContext.TestClassCleanupMethod, TESTFIXTURETEARDOWN_ATTR_NUNIT3);
}
开发者ID:tmulkern,项目名称:SpecFlow,代码行数:4,代码来源:NUnit3TestGeneratorProvider.cs
示例20: SetRowTest
public override void SetRowTest(TestClassGenerationContext generationContext, CodeMemberMethod testMethod, string scenarioTitle)
{
CodeDomHelper.AddAttribute(testMethod, TEST_ATTR);
CodeDomHelper.AddAttribute(testMethod, DESCRIPTION_ATTR, scenarioTitle);
}
开发者ID:tmulkern,项目名称:SpecFlow,代码行数:5,代码来源:MbUnit3TestGeneratorProvider.cs
注:本文中的TestClassGenerationContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论