本文整理汇总了C#中ITestFrameworkDiscoveryOptions.MethodDisplayOptionsOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# ITestFrameworkDiscoveryOptions.MethodDisplayOptionsOrDefault方法的具体用法?C# ITestFrameworkDiscoveryOptions.MethodDisplayOptionsOrDefault怎么用?C# ITestFrameworkDiscoveryOptions.MethodDisplayOptionsOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITestFrameworkDiscoveryOptions
的用法示例。
在下文中一共展示了ITestFrameworkDiscoveryOptions.MethodDisplayOptionsOrDefault方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Discover
public IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
var ctorArgs = factAttribute.GetConstructorArguments().ToArray();
var cultures = Reflector.ConvertArguments(ctorArgs, new[] { typeof(string[]) }).Cast<string[]>().Single();
if (cultures == null || cultures.Length == 0)
cultures = new[] { "en-US", "fr-FR" };
var methodDisplay = discoveryOptions.MethodDisplayOrDefault();
var methodDisplayOptions = discoveryOptions.MethodDisplayOptionsOrDefault();
return cultures.Select(culture => new CulturedXunitTestCase(diagnosticMessageSink, methodDisplay, methodDisplayOptions, testMethod, culture)).ToList();
}
示例2: Discover
/// <summary>
/// Discover test cases from a test method. By default, inspects the test method's argument list
/// to ensure it's empty, and if not, returns a single <see cref="ExecutionErrorTestCase"/>;
/// otherwise, it returns the result of calling <see cref="CreateTestCase"/>.
/// </summary>
/// <param name="discoveryOptions">The discovery options to be used.</param>
/// <param name="testMethod">The test method the test cases belong to.</param>
/// <param name="factAttribute">The fact attribute attached to the test method.</param>
/// <returns>Returns zero or more test cases represented by the test method.</returns>
public virtual IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
var testCase =
testMethod.Method.GetParameters().Any()
? new ExecutionErrorTestCase(
diagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod,
"[Fact] methods are not allowed to have parameters. Did you mean to use [Theory]?")
: CreateTestCase(discoveryOptions, testMethod, factAttribute);
return new[] { testCase };
}
示例3: Discover
/// <summary>
/// Discover test cases from a test method.
/// </summary>
/// <remarks>
/// This method performs the following steps:
/// - If the theory attribute is marked with Skip, returns the single test case from <see cref="CreateTestCaseForSkip"/>;
/// - If pre-enumeration is off, or any of the test data is non serializable, returns the single test case from <see cref="CreateTestCaseForTheory"/>;
/// - If there is no theory data, returns a single test case of <see cref="ExecutionErrorTestCase"/> with the error in it;
/// - Otherwise, it returns one test case per data row, created by calling <see cref="CreateTestCaseForDataRow"/> or <see cref="CreateTestCaseForSkippedDataRow"/> if the data attribute has a skip reason.
/// </remarks>
/// <param name="discoveryOptions">The discovery options to be used.</param>
/// <param name="testMethod">The test method the test cases belong to.</param>
/// <param name="theoryAttribute">The theory attribute attached to the test method.</param>
/// <returns>Returns zero or more test cases represented by the test method.</returns>
public virtual IEnumerable<IXunitTestCase> Discover(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute)
{
// Special case Skip, because we want a single Skip (not one per data item); plus, a skipped test may
// not actually have any data (which is quasi-legal, since it's skipped).
var skipReason = theoryAttribute.GetNamedArgument<string>("Skip");
if (skipReason != null)
return new[] { CreateTestCaseForSkip(discoveryOptions, testMethod, theoryAttribute, skipReason) };
if (discoveryOptions.PreEnumerateTheoriesOrDefault())
{
try
{
var dataAttributes = testMethod.Method.GetCustomAttributes(typeof(DataAttribute));
var results = new List<IXunitTestCase>();
foreach (var dataAttribute in dataAttributes)
{
var discovererAttribute = dataAttribute.GetCustomAttributes(typeof(DataDiscovererAttribute)).First();
var discoverer = ExtensibilityPointFactory.GetDataDiscoverer(diagnosticMessageSink, discovererAttribute);
skipReason = dataAttribute.GetNamedArgument<string>("Skip");
if (!discoverer.SupportsDiscoveryEnumeration(dataAttribute, testMethod.Method))
return new[] { CreateTestCaseForTheory(discoveryOptions, testMethod, theoryAttribute) };
IEnumerable<object[]> data = discoverer.GetData(dataAttribute, testMethod.Method);
if (data == null)
{
results.Add(new ExecutionErrorTestCase(diagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod,
$"Test data returned null for {testMethod.TestClass.Class.Name}.{testMethod.Method.Name}. Make sure it is statically initialized before this test method is called."));
continue;
}
foreach (var dataRow in data)
{
// Determine whether we can serialize the test case, since we need a way to uniquely
// identify a test and serialization is the best way to do that. If it's not serializable,
// this will throw and we will fall back to a single theory test case that gets its data at runtime.
if (!SerializationHelper.IsSerializable(dataRow))
{
diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Non-serializable data ('{dataRow.GetType().FullName}') found for '{testMethod.TestClass.Class.Name}.{testMethod.Method.Name}'; falling back to single test case."));
return new[] { CreateTestCaseForTheory(discoveryOptions, testMethod, theoryAttribute) };
}
var testCase =
skipReason != null
? CreateTestCaseForSkippedDataRow(discoveryOptions, testMethod, theoryAttribute, dataRow, skipReason)
: CreateTestCaseForDataRow(discoveryOptions, testMethod, theoryAttribute, dataRow);
results.Add(testCase);
}
}
if (results.Count == 0)
results.Add(new ExecutionErrorTestCase(diagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
discoveryOptions.MethodDisplayOptionsOrDefault(),
testMethod,
$"No data found for {testMethod.TestClass.Class.Name}.{testMethod.Method.Name}"));
return results;
}
catch (Exception ex) // If something goes wrong, fall through to return just the XunitTestCase
{
diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception thrown during theory discovery on '{testMethod.TestClass.Class.Name}.{testMethod.Method.Name}'; falling back to single test case.{Environment.NewLine}{ex}"));
}
}
return new[] { CreateTestCaseForTheory(discoveryOptions, testMethod, theoryAttribute) };
}
示例4: CreateTestCaseForSkippedDataRow
/// <summary>
/// Creates a test case for a single row of data. By default, returns an instance of <see cref="XunitSkippedDataRowTestCase"/>
/// with the data row inside of it.
/// </summary>
/// <remarks>If this method is overridden, the implementation will have to override <see cref="TestMethodTestCase.SkipReason"/> otherwise
/// the default behavior will look at the <see cref="TheoryAttribute"/> and the test case will not be skipped.</remarks>
/// <param name="discoveryOptions">The discovery options to be used.</param>
/// <param name="testMethod">The test method the test cases belong to.</param>
/// <param name="theoryAttribute">The theory attribute attached to the test method.</param>
/// <param name="dataRow">The row of data for this test case.</param>
/// <param name="skipReason">The reason this test case is to be skipped</param>
/// <returns>The test case</returns>
protected virtual IXunitTestCase CreateTestCaseForSkippedDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[] dataRow, string skipReason)
=> new XunitSkippedDataRowTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, skipReason, dataRow);
示例5: CreateTestCaseForTheory
/// <summary>
/// Creates a test case for the entire theory. This is used when one or more of the theory data items
/// are not serializable, or if the user has requested to skip theory pre-enumeration. By default,
/// returns an instance of <see cref="XunitTheoryTestCase"/>, which performs the data discovery at runtime.
/// </summary>
/// <param name="discoveryOptions">The discovery options to be used.</param>
/// <param name="testMethod">The test method the test cases belong to.</param>
/// <param name="theoryAttribute">The theory attribute attached to the test method.</param>
/// <returns>The test case</returns>
protected virtual IXunitTestCase CreateTestCaseForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute)
=> new XunitTheoryTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod);