static Type GetTestCollectionFactoryType(IAttributeInfo collectionBehaviorAttribute) { if (collectionBehaviorAttribute == null) { return(typeof(CollectionPerClassTestCollectionFactory)); } var ctorArgs = collectionBehaviorAttribute.GetConstructorArguments().ToList(); if (ctorArgs.Count == 0) { return(typeof(CollectionPerClassTestCollectionFactory)); } if (ctorArgs.Count == 1) { if ((CollectionBehavior)ctorArgs[0] == CollectionBehavior.CollectionPerAssembly) { return(typeof(CollectionPerAssemblyTestCollectionFactory)); } return(typeof(CollectionPerClassTestCollectionFactory)); } var result = Reflector.GetType((string)ctorArgs[1], (string)ctorArgs[0]); if (result == null || !IsCompatibleTestCollectionFactory(result)) { return(typeof(CollectionPerClassTestCollectionFactory)); } return(result); }
public ITypeInfo GetType(string typeName) { EnsureArg.IsNotNull(typeName, nameof(typeName)); // parse out the (Arg1, Arg2) var match = _argumentsRegex.Match(typeName); if (!match.Success) { return(_assemblyInfoImplementation.GetType(typeName)); } // retrieve the real type var typeInfo = _assemblyInfoImplementation.GetType(typeName.Substring(0, match.Index)); Debug.Assert(typeInfo != null, $"Could not find type {typeName} in assembly"); // now get the the arguments. We don't know what type they are, so we look at the FixtureArgumentSetsAttribute on the class and look at its arguments IAttributeInfo attributeInfo = typeInfo.GetCustomAttributes(typeof(FixtureArgumentSetsAttribute)).Single(); SingleFlag[] arguments = attributeInfo .GetConstructorArguments() .Cast <Enum>() .Zip( match.Groups["VALUE"].Captures, (e, c) => new SingleFlag((Enum)Enum.Parse(e.GetType(), c.Value))) .ToArray(); return(new TestClassWithFixtureArgumentsTypeInfo(typeInfo, arguments)); }
private static SingleFlagEnum[][] ExpandEnumFlagsFromAttributeData(IAttributeInfo attributeInfo) { bool IsPowerOfTwo(long x) { return((x != 0) && ((x & (x - 1)) == 0)); } IEnumerable <SingleFlagEnum> GetSingleValuedFlags(Enum e) { if (e is null) { yield break; } var enumAsLong = Convert.ToInt64(e); foreach (Enum value in Enum.GetValues(e.GetType())) { var flagAsLong = Convert.ToInt64(value); if (IsPowerOfTwo(flagAsLong)) { if ((enumAsLong & flagAsLong) != 0) { yield return(new SingleFlagEnum(value)); } } } } return(attributeInfo .GetConstructorArguments() .Cast <Enum>() .Select(e => GetSingleValuedFlags(e).ToArray()) .ToArray()); }
static ITestCaseOrderer GetXunitTestCaseOrderer(IAttributeInfo ordererAttribute) { var args = ordererAttribute.GetConstructorArguments().Cast <string>().ToList(); var ordererType = Reflector.GetType(args[1], args[0]); return(ExtensibilityPointFactory.GetTestCaseOrderer(ordererType)); }
internal static Type GetTestCollectionFactoryType(IAttributeInfo collectionBehavior) { if (collectionBehavior == null) { return(typeof(CollectionPerClassTestCollectionFactory)); } var ctorArgs = collectionBehavior.GetConstructorArguments().ToList(); if (ctorArgs.Count == 0) { return(typeof(CollectionPerClassTestCollectionFactory)); } if (ctorArgs.Count == 1 && (CollectionBehavior)ctorArgs[0] == CollectionBehavior.CollectionPerAssembly) { return(typeof(CollectionPerAssemblyTestCollectionFactory)); } var result = Reflector.GetType((string)ctorArgs[1], (string)ctorArgs[0]); if (!typeof(IXunitTestCollectionFactory).IsAssignableFrom(result) || result.GetConstructor(new[] { typeof(IAssemblyInfo) }) == null) { return(typeof(CollectionPerClassTestCollectionFactory)); } return(result); }
/// <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)); } if (!platform.HasFlag(PlatformID.NetBSD)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonNetBSDTest)); } }
/// <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.Any; TargetFrameworkMonikers frameworks = (TargetFrameworkMonikers)0; foreach (object arg in ctorArgs.Skip(1)) // First argument is the issue number. { if (arg is TestPlatforms) { platforms = (TestPlatforms)arg; } else if (arg is TargetFrameworkMonikers) { frameworks = (TargetFrameworkMonikers)arg; } } 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))) { if (frameworks.HasFlag(TargetFrameworkMonikers.NetFramework)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonNetfxTest)); } if (frameworks.HasFlag(TargetFrameworkMonikers.Mono)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonMonoTest)); } if (frameworks.HasFlag(TargetFrameworkMonikers.Netcoreapp)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonNetcoreappTest)); } if (frameworks.HasFlag(TargetFrameworkMonikers.UapNotUapAot)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonUapTest)); } if (frameworks.HasFlag(TargetFrameworkMonikers.UapAot)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonUapAotTest)); } if (frameworks.HasFlag(TargetFrameworkMonikers.NetcoreCoreRT)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonNetcoreCoreRTTest)); } if (frameworks == (TargetFrameworkMonikers)0) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.Failing)); } yield return(new KeyValuePair <string, string>(XunitConstants.ActiveIssue, issue)); } }
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)); } }
/// <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); }
/// <inheritdoc/> public IEnumerable <object[]> GetData(IAttributeInfo dataAttribute, IMethodInfo testMethod) { var args = dataAttribute.GetConstructorArguments().ToList(); var start = 0; var count = 1; var step = 1; if (args.Count == 1) { count = (int)args[0]; } else if (args.Count >= 2) { start = (int)args[0]; count = (int)args[1]; } if (args.Count >= 3) { step = (int)args[2]; } for (var i = 0; i < count; i++) { yield return(new object[] { start + i * step }); } }
public virtual IEnumerable <object[]> GetData(IAttributeInfo dataAttribute, IMethodInfo testMethod) { string methodName = (string)dataAttribute.GetConstructorArguments().Single(); Func <CTestModule> moduleGenerator = XmlTestsAttribute.GetGenerator(GetDeclaringType(testMethod), methodName); return(GenerateTestCases(moduleGenerator)); }
static ITestCaseOrderer GetTestCaseOrderer(IAttributeInfo ordererAttribute) { var args = ordererAttribute.GetConstructorArguments().Cast <string>().ToList(); var ordererType = Reflector.GetType(args[1], args[0]); return((ITestCaseOrderer)Activator.CreateInstance(ordererType)); }
public IEnumerable <KeyValuePair <string, string> > GetTraits(IAttributeInfo traitAttribute) { if (!SkipOnMonoDiscoverer.IsMonoRuntime) { TestPlatforms testPlatforms = TestPlatforms.Any; RuntimeStressTestModes stressMode = RuntimeStressTestModes.Any; foreach (object arg in traitAttribute.GetConstructorArguments().Skip(1)) // We skip the first one as it is the reason { if (arg is TestPlatforms tp) { testPlatforms = tp; } else if (arg is RuntimeStressTestModes rstm) { stressMode = rstm; } } if (DiscovererHelpers.TestPlatformApplies(testPlatforms) && StressModeApplies(stressMode)) { if (IsCheckedRuntime() || (IsRuntimeStressTesting && !stressMode.HasFlag(RuntimeStressTestModes.CheckedRuntime))) { return(new[] { new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.Failing) }); } } } return(Array.Empty <KeyValuePair <string, string> >()); }
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))); } }
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); }
public IEnumerable <KeyValuePair <string, string> > GetTraits(IAttributeInfo traitAttribute) { if (!DiscovererHelpers.IsMonoRuntime) { TestPlatforms testPlatforms = TestPlatforms.Any; RuntimeTestModes stressMode = RuntimeTestModes.Any; RuntimeConfiguration runtimeConfigurations = RuntimeConfiguration.Any; foreach (object arg in traitAttribute.GetConstructorArguments().Skip(1)) // We skip the first one as it is the reason { if (arg is TestPlatforms tp) { testPlatforms = tp; } else if (arg is RuntimeTestModes rtm) { stressMode = rtm; } else if (arg is RuntimeConfiguration rc) { runtimeConfigurations = rc; } } if (DiscovererHelpers.TestPlatformApplies(testPlatforms) && RuntimeConfigurationApplies(runtimeConfigurations) && StressModeApplies(stressMode)) { return(new[] { new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.Failing) }); } } return(Array.Empty <KeyValuePair <string, string> >()); }
public IEnumerable <PerformanceMetricInfo> GetMetrics(IAttributeInfo metricAttribute) { if (ProfileSource != -1) { var interval = (int)(metricAttribute.GetConstructorArguments().FirstOrDefault() ?? DefaultInterval); yield return(new InstructionsRetiredMetric(interval, ProfileSource)); } }
/// <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 frameworks = (TargetFrameworkMonikers)traitAttribute.GetConstructorArguments().First(); return(DiscovererHelpers.TestFrameworkApplies(frameworks) ? new[] { new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.Failing) } : Array.Empty <KeyValuePair <string, string> >()); }
/// <summary> /// Gets the trait metadata for XUnit to consume and surface for attribution to tests. /// </summary> /// /// <param name="traitAttribute">An attribute identified as a trait to be processed by the XUnit framework.</param> /// /// <returns>The properties of the trait to associate with the decorated tests.</returns> /// public IEnumerable <KeyValuePair <string, string> > GetTraits(IAttributeInfo traitAttribute) { yield return(new KeyValuePair <string, string> ( TestCategoryAttribute.TraitName, traitAttribute.GetConstructorArguments().FirstOrDefault()?.ToString() ?? Category.Unknown.ToString() )); }
public IEnumerable<PerformanceMetricInfo> GetMetrics(IAttributeInfo metricAttribute) { if (_profileSource != -1) { var interval = (int)(metricAttribute.GetConstructorArguments().FirstOrDefault() ?? DefaultInterval); yield return new InstructionsRetiredMetric(interval, _profileSource); } }
/// <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(), ""); } }
public IEnumerable <PerformanceMetricInfo> GetMetrics(IAttributeInfo metricAttribute) { if (_pmcId != -1) { var interval = (int)(metricAttribute.GetConstructorArguments().FirstOrDefault() ?? _performanceMonitorCounter.Interval); yield return(new GenericPerformanceMonitorCounterMetric <T>(_performanceMonitorCounter)); } }
public override IEnumerable <IXunitTestCase> Discover( ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) { string[] conditionMemberNames = theoryAttribute.GetConstructorArguments().FirstOrDefault() as string[]; IEnumerable <IXunitTestCase> testCases = base.Discover(discoveryOptions, testMethod, theoryAttribute); return(ConditionalTestDiscoverer.Discover(discoveryOptions, _diagnosticMessageSink, testMethod, testCases, conditionMemberNames)); }
/// <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) { TestPlatforms platforms = (TestPlatforms)traitAttribute.GetConstructorArguments().First(); return(DiscovererHelpers.TestPlatformApplies(platforms) ? Array.Empty <KeyValuePair <string, string> >() : new[] { new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.Failing) }); }
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); } }
/// <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(), "")); } }
/// <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) { string issue = traitAttribute.GetConstructorArguments().First().ToString(); PlatformID platforms = (PlatformID)traitAttribute.GetConstructorArguments().Last(); if (platforms.HasFlag(PlatformID.Windows)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonWindowsTest)); } if (platforms.HasFlag(PlatformID.Linux)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonLinuxTest)); } if (platforms.HasFlag(PlatformID.OSX)) { yield return(new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.NonOSXTest)); } }
/// <summary> /// Gets the trait values from the <paramref name="traitAttribute"/>. /// </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) { var names = traitAttribute.GetConstructorArguments().First() as string[]; foreach (var name in names) { yield return(new KeyValuePair <string, string>("Category", name)); } }
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(); }
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(); }
/// <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(); if (ctorArgs.Count() < 2) { return(new[] { new KeyValuePair <string, string>(XunitConstants.Category, XunitConstants.OuterLoop) }); } return(DiscovererHelpers.EvaluateArguments(ctorArgs, XunitConstants.OuterLoop)); }
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; }
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)); } }
public IEnumerable <KeyValuePair <string, string> > GetTraits(IAttributeInfo traitAttribute) { var args = (List <object>)traitAttribute.GetConstructorArguments(); var groups = (Array)args[0]; foreach (var nameGroup in groups) { yield return(new KeyValuePair <string, string>(Category, nameGroup.ToString())); } }
/// <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; } }
public override IEnumerable <KeyValuePair <string, string> > GetTraits(IAttributeInfo traitAttribute) { var result = new List <KeyValuePair <string, string> >(); foreach (uint issueNumber in (uint[])traitAttribute.GetConstructorArguments().Single()) { result.Add(KeyValuePair.Create("GitHub Issue", $"{issueNumber}")); } return(result); }
/// <summary> /// Translates the types of exceptions that should be considered as "skip" exceptions into their full names. /// </summary> /// <param name="factAttribute">The <see cref="SkippableFactAttribute"/>.</param> /// <returns>An array of full names of types.</returns> internal static string[] GetSkippableExceptionNames(IAttributeInfo factAttribute) { object[]? firstArgument = (object[])factAttribute.GetConstructorArguments().FirstOrDefault(); Type[]? skippingExceptions = firstArgument?.Cast <Type>().ToArray() ?? Type.EmptyTypes; Array.Resize(ref skippingExceptions, skippingExceptions.Length + 1); skippingExceptions[skippingExceptions.Length - 1] = typeof(SkipException); var skippingExceptionNames = skippingExceptions.Select(ex => ex.FullName).ToArray(); return(skippingExceptionNames); }
protected virtual int ExtractOrderFromAttribute(IEnumerable <IAttributeInfo> attributes) { IAttributeInfo orderAttribute = attributes.FirstOrDefault(); if (orderAttribute == null) { return(0); } return((int)orderAttribute.GetConstructorArguments().Single()); }
/// <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); }
private static IPerformanceMetricDiscoverer GetPerformanceMetricDiscoverer(IAttributeInfo metricDiscovererAttribute) { if (metricDiscovererAttribute == null) { throw new ArgumentNullException(); } var args = metricDiscovererAttribute.GetConstructorArguments().Cast <string>().ToList(); var discovererType = GetType(args[1], args[0]); return((discovererType == null) ? null : (IPerformanceMetricDiscoverer)Activator.CreateInstance(discovererType)); }
/// <summary> /// Gets a test case orderer, as specified in a reflected <see cref="TestCaseOrdererAttribute"/>. /// </summary> /// <param name="testCaseOrdererAttribute">The test case orderer attribute.</param> /// <returns>The test case orderer, if the type is loadable; <c>null</c>, otherwise.</returns> public static ITestCaseOrderer GetTestCaseOrderer(IAttributeInfo testCaseOrdererAttribute) { var args = testCaseOrdererAttribute.GetConstructorArguments().Cast <string>().ToList(); var ordererType = Reflector.GetType(args[1], args[0]); if (ordererType == null) { return(null); } return(GetTestCaseOrderer(ordererType)); }
/// <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() }; }
/// <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); } }
/// <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); } }
public virtual IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute) { var ctorArgs = traitAttribute.GetConstructorArguments().Cast<string>().ToList(); var traits = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("Category", "All") }; if (!string.IsNullOrWhiteSpace(ctorArgs[1])) { var split = ctorArgs[1].Split(';'); foreach (var s in split) { traits.Add(new KeyValuePair<string, string>(ctorArgs[0], s)); } } return traits; }
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)); } }
/// <inheritdoc/> public IEnumerable<object[]> GetData(IAttributeInfo dataAttribute, IMethodInfo testMethod) { var args = dataAttribute.GetConstructorArguments().ToList(); var start = 0; var count = 1; var step = 1; if (args.Count == 1) { count = (int) args[0]; } else if (args.Count >= 2) { start = (int)args[0]; count = (int)args[1]; } if (args.Count >= 3) { step = (int)args[2]; } for (var i = 0; i < count; i++) { yield return new object[] { start + i * step }; } }
/// <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 count = testMethod.GetParameters().Count(); var arguments = dataAttribute.GetConstructorArguments(); var args = (IEnumerable<object>)arguments.Single() ?? new object[] { null }; var objects = args.ToArray(); var results = objects.Select(x => Enumerable.Empty<object>().Concat(new[] { x })); while (--count > 0) { results = results.Join(objects, o => true, o => true, (enumerable, item) => enumerable.Concat(new[] { item }).ToArray()); } var array = results.Select(x => x.ToArray()).ToArray(); return array; }
public IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute) { var ctorArgs = traitAttribute.GetConstructorArguments().ToList(); yield return new KeyValuePair<string, string>(KEY, ctorArgs[0].ToString()); }
internal static Type GetTestCollectionFactoryType(IAttributeInfo collectionBehavior) { if (collectionBehavior == null) return typeof(CollectionPerClassTestCollectionFactory); var ctorArgs = collectionBehavior.GetConstructorArguments().ToList(); if (ctorArgs.Count == 0) return typeof(CollectionPerClassTestCollectionFactory); if (ctorArgs.Count == 1 && (CollectionBehavior)ctorArgs[0] == CollectionBehavior.CollectionPerAssembly) return typeof(CollectionPerAssemblyTestCollectionFactory); var result = Reflector.GetType((string)ctorArgs[1], (string)ctorArgs[0]); if (!typeof(IXunitTestCollectionFactory).IsAssignableFrom(result) || result.GetConstructor(new[] { typeof(IAssemblyInfo) }) == null) return typeof(CollectionPerClassTestCollectionFactory); return result; }
static ITestCaseOrderer GetTestCaseOrderer(IAttributeInfo ordererAttribute) { var args = ordererAttribute.GetConstructorArguments().Cast<string>().ToList(); var ordererType = Reflector.GetType(args[1], args[0]); return (ITestCaseOrderer)Activator.CreateInstance(ordererType); }
/// <inheritdoc/> public virtual IEnumerable<KeyValuePair<string, string>> GetTraits(IAttributeInfo traitAttribute) { var ctorArgs = traitAttribute.GetConstructorArguments().Cast<string>().ToList(); yield return new KeyValuePair<string, string>(ctorArgs[0], ctorArgs[1]); }
/// <inheritdoc/> public virtual IEnumerable<object[]> GetData(IAttributeInfo dataAttribute, IMethodInfo testMethod) { var args = (IEnumerable<object>)dataAttribute.GetConstructorArguments().Single() ?? Enumerable.Empty<object>(); yield return new object[] { args.ToArray() }; }
public Type GetTestFrameworkType(IAttributeInfo attribute) { var args = attribute.GetConstructorArguments().Cast<string>().ToArray(); return Reflector.GetType(args[1], args[0]); }