本文整理汇总了C#中IAttributeInfo.GetConstructorArguments方法的典型用法代码示例。如果您正苦于以下问题:C# IAttributeInfo.GetConstructorArguments方法的具体用法?C# IAttributeInfo.GetConstructorArguments怎么用?C# IAttributeInfo.GetConstructorArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAttributeInfo
的用法示例。
在下文中一共展示了IAttributeInfo.GetConstructorArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTraits
/// <summary>
/// Gets the trait values from the Category attribute.
/// </summary>
/// <param name="traitAttribute">The trait attribute containing the trait values.</param>
/// <returns>The trait values.</returns>
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
TargetFrameworkMonikers platform = (TargetFrameworkMonikers)traitAttribute.GetConstructorArguments().First();
if (platform.HasFlag(TargetFrameworkMonikers.Net45))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNet45Test);
if (platform.HasFlag(TargetFrameworkMonikers.Net451))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNet451Test);
if (platform.HasFlag(TargetFrameworkMonikers.Net452))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNet452Test);
if (platform.HasFlag(TargetFrameworkMonikers.Net46))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNet46Test);
if (platform.HasFlag(TargetFrameworkMonikers.Net461))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNet461Test);
if (platform.HasFlag(TargetFrameworkMonikers.Net462))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNet462Test);
if (platform.HasFlag(TargetFrameworkMonikers.Net463))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNet463Test);
if (platform.HasFlag(TargetFrameworkMonikers.Netcore50))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNetcore50Test);
if (platform.HasFlag(TargetFrameworkMonikers.Netcore50aot))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNetcore50aotTest);
if (platform.HasFlag(TargetFrameworkMonikers.Netcoreapp1_0))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNetcoreapp1_0Test);
if (platform.HasFlag(TargetFrameworkMonikers.Netcoreapp1_1))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonNetcoreapp1_1Test);
}
示例2: Discover
public override IEnumerable<IXunitTestCase> Discover(
ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
string[] conditionMemberNames = factAttribute.GetConstructorArguments().FirstOrDefault() as string[];
IEnumerable<IXunitTestCase> testCases = base.Discover(discoveryOptions, testMethod, factAttribute);
return ConditionalTestDiscoverer.Discover(discoveryOptions, _diagnosticMessageSink, testMethod, testCases, conditionMemberNames);
}
示例3: Discover
public override IEnumerable<IXunitTestCase> Discover(
ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
{
MethodInfo testMethodInfo = testMethod.Method.ToRuntimeMethod();
string conditionMemberName = factAttribute.GetConstructorArguments().FirstOrDefault() as string;
MethodInfo conditionMethodInfo;
if (conditionMemberName == null ||
(conditionMethodInfo = LookupConditionalMethod(testMethodInfo.DeclaringType, conditionMemberName)) == null)
{
return new[] {
new ExecutionErrorTestCase(
_diagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
testMethod,
GetFailedLookupString(conditionMemberName))
};
}
IEnumerable<IXunitTestCase> testCases = base.Discover(discoveryOptions, testMethod, factAttribute);
if ((bool)conditionMethodInfo.Invoke(null, null))
{
return testCases;
}
else
{
string skippedReason = "\"" + conditionMemberName + "\" returned false.";
return testCases.Select(tc => new SkippedTestCase(tc, skippedReason));
}
}
示例4: GetMetrics
public IEnumerable<PerformanceMetricInfo> GetMetrics(IAttributeInfo metricAttribute)
{
if (_profileSource != -1)
{
var interval = (int)(metricAttribute.GetConstructorArguments().FirstOrDefault() ?? DefaultInterval);
yield return new InstructionsRetiredMetric(interval, _profileSource);
}
}
示例5: GetTraits
/// <summary>
/// Gets the trait values from the trait attribute.
/// </summary>
/// <param name="traitAttribute">The trait attribute containing the trait values.</param>
/// <returns>The trait values</returns>
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
IEnumerator<object> enumerator = traitAttribute.GetConstructorArguments().GetEnumerator();
while (enumerator.MoveNext())
{
yield return new KeyValuePair<string, string>(enumerator.Current.ToString(), "");
}
}
示例6: GetTraits
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
var array = (CompilerFeature[])traitAttribute.GetConstructorArguments().Single();
foreach (var feature in array)
{
var value = feature.ToString();
yield return new KeyValuePair<string, string>("Compiler", value);
}
}
示例7: Discover
public IEnumerable<IXunitTestCase> Discover(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" };
return cultures.Select(culture => new CulturedXunitTestCase(testMethod, culture)).ToList();
}
示例8: 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" };
return cultures.Select(culture => new CulturedXunitTestCase(diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), testMethod, culture)).ToList();
}
示例9: GetSkippableExceptionNames
internal static string[] GetSkippableExceptionNames(IAttributeInfo factAttribute)
{
var firstArgument = (object[])factAttribute.GetConstructorArguments().FirstOrDefault();
var skippingExceptions = firstArgument?.Cast<Type>().ToArray() ?? new Type[0];
Array.Resize(ref skippingExceptions, skippingExceptions.Length + 1);
skippingExceptions[skippingExceptions.Length - 1] = typeof(SkipException);
var skippingExceptionNames = skippingExceptions.Select(ex => ex.FullName).ToArray();
return skippingExceptionNames;
}
示例10: GetTraits
/// <summary>
/// Gets the trait values from the Category attribute.
/// </summary>
/// <param name="traitAttribute">The trait attribute containing the trait values.</param>
/// <returns>The trait values.</returns>
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
IEnumerable<object> ctorArgs = traitAttribute.GetConstructorArguments();
foreach (var arg in ctorArgs)
{
string issue = arg.ToString();
yield return new KeyValuePair<string, string>("category", "failing");
yield return new KeyValuePair<string, string>("ActiveIssue", issue);
break;
}
}
示例11: GetTraits
/// <summary>
/// Gets the trait values from the Category attribute.
/// </summary>
/// <param name="traitAttribute">The trait attribute containing the trait values.</param>
/// <returns>The trait values.</returns>
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
PlatformID platform = (PlatformID)traitAttribute.GetConstructorArguments().First();
if (!platform.HasFlag(PlatformID.Windows))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonWindowsTest);
if (!platform.HasFlag(PlatformID.Linux))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonLinuxTest);
if (!platform.HasFlag(PlatformID.OSX))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonOSXTest);
if (!platform.HasFlag(PlatformID.FreeBSD))
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.NonFreeBSDTest);
}
示例12: GetData
/// <inheritdoc/>
public virtual IEnumerable<object[]> GetData(IAttributeInfo dataAttribute, IMethodInfo testMethod)
{
// The data from GetConstructorArguments does not maintain its original form (in particular, collections
// end up as generic IEnumerable<T>). So we end up needing to call .ToArray() on the enumerable so that
// we can restore the correct argument type from InlineDataAttribute.
//
// In addition, [InlineData(null)] gets translated into passing a null array, not a single array with a null
// value in it, which is why the null coalesce operator is required (this is covered by the acceptance test
// in Xunit2TheoryAcceptanceTests.InlineDataTests.SingleNullValuesWork).
var args = (IEnumerable<object>)dataAttribute.GetConstructorArguments().Single() ?? new object[] { null };
return new[] { args.ToArray() };
}
示例13: GetTraits
/// <summary>
/// Gets the trait values from the Category attribute.
/// </summary>
/// <param name="traitAttribute">The trait attribute containing the trait values.</param>
/// <returns>The trait values.</returns>
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
IEnumerable<object> ctorArgs = traitAttribute.GetConstructorArguments();
Debug.Assert(ctorArgs.Count() >= 2);
string issue = ctorArgs.First().ToString();
PlatformID platforms = (PlatformID)ctorArgs.Last();
if ((platforms.HasFlag(PlatformID.FreeBSD) && Interop.IsFreeBSD) ||
(platforms.HasFlag(PlatformID.Linux) && Interop.IsLinux) ||
(platforms.HasFlag(PlatformID.OSX) && Interop.IsOSX) ||
(platforms.HasFlag(PlatformID.Windows) && Interop.IsWindows))
{
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.Failing);
yield return new KeyValuePair<string, string>(XunitConstants.ActiveIssue, issue);
}
}
示例14: GetTraits
/// <summary>
/// Gets the trait values from the Category attribute.
/// </summary>
/// <param name="traitAttribute">The trait attribute containing the trait values.</param>
/// <returns>The trait values.</returns>
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute)
{
IEnumerable<object> ctorArgs = traitAttribute.GetConstructorArguments();
Debug.Assert(ctorArgs.Count() >= 2);
string issue = ctorArgs.First().ToString();
TestPlatforms platforms = (TestPlatforms)ctorArgs.Last();
if ((platforms.HasFlag(TestPlatforms.FreeBSD) && RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"))) ||
(platforms.HasFlag(TestPlatforms.Linux) && RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) ||
(platforms.HasFlag(TestPlatforms.NetBSD) && RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD"))) ||
(platforms.HasFlag(TestPlatforms.OSX) && RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) ||
(platforms.HasFlag(TestPlatforms.Windows) && RuntimeInformation.IsOSPlatform(OSPlatform.Windows)))
{
yield return new KeyValuePair<string, string>(XunitConstants.Category, XunitConstants.Failing);
yield return new KeyValuePair<string, string>(XunitConstants.ActiveIssue, issue);
}
}
示例15: Discover
public override IEnumerable<IXunitTestCase> Discover(
ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute)
{
MethodInfo testMethodInfo = testMethod.Method.ToRuntimeMethod();
string conditionMemberName = theoryAttribute.GetConstructorArguments().FirstOrDefault() as string;
Type declaringType = testMethodInfo.DeclaringType;
string[] symbols = conditionMemberName.Split('.');
if (symbols.Length == 2)
{
conditionMemberName = symbols[1];
ITypeInfo type = testMethod.TestClass.Class.Assembly.GetTypes(false).Where(t => t.Name.Contains(symbols[0])).FirstOrDefault();
if (type != null)
{
declaringType = type.ToRuntimeType();
}
}
MethodInfo conditionMethodInfo;
if (conditionMemberName == null ||
(conditionMethodInfo = ConditionalFactDiscoverer.LookupConditionalMethod(declaringType, conditionMemberName)) == null)
{
return new[] {
new ExecutionErrorTestCase(
_diagnosticMessageSink,
discoveryOptions.MethodDisplayOrDefault(),
testMethod,
ConditionalFactDiscoverer.GetFailedLookupString(conditionMemberName))
};
}
IEnumerable<IXunitTestCase> testCases = base.Discover(discoveryOptions, testMethod, theoryAttribute);
if ((bool)conditionMethodInfo.Invoke(null, null))
{
return testCases;
}
else
{
string skippedReason = "\"" + conditionMemberName + "\" returned false.";
return testCases.Select(tc => new SkippedTestCase(tc, skippedReason));
}
}