public static IList<AssemblyLoaderAttribute> GetAssemblyLoaders(IAssemblyInfo assemblyInfo) { return assemblyInfo.GetCustomAttributes(typeof(AssemblyLoaderAttribute)) .OfType<IReflectionAttributeInfo>() .Select(ai => ai.Attribute) .OfType<AssemblyLoaderAttribute>() .ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="sourceProvider">The source information provider.</param> /// <param name="messageAggregator">The message aggregator to receive environmental warnings from.</param> public TestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IMessageAggregator messageAggregator) { Guard.ArgumentNotNull("assemblyInfo", assemblyInfo); Guard.ArgumentNotNull("sourceProvider", sourceProvider); Aggregator = messageAggregator ?? MessageAggregator.Instance; AssemblyInfo = assemblyInfo; DisposalTracker = new DisposalTracker(); SourceProvider = sourceProvider; targetFramework = new Lazy <string>(() => { string result = null; var attrib = AssemblyInfo.GetCustomAttributes(typeof(TargetFrameworkAttribute)).FirstOrDefault(); if (attrib != null) { result = attrib.GetConstructorArguments().Cast <string>().First(); } return(result ?? ""); }); }
private static void SetupTracing(IAssemblyInfo assemblyInfo) { var attr = assemblyInfo.GetCustomAttributes(typeof(VsixRunnerAttribute)).FirstOrDefault(); s_tracer.Switch.Level = attr? .GetInitializedArgument <SourceLevels?>(nameof(VsixRunnerAttribute.TraceLevel)) .GetValueOrDefault(SourceLevels.Error) ?? SourceLevels.Error; var logFile = Path.ChangeExtension(assemblyInfo.AssemblyPath, ".log"); if (File.Exists(logFile)) { try { File.Delete(logFile); } catch (IOException) { } } if (!s_tracer.Listeners.OfType <TraceListener>().Any(x => x.Name == assemblyInfo.Name)) { var listener = new TextWriterTraceListener(logFile, assemblyInfo.Name); s_tracer.Listeners.Add(listener); Trace.Listeners.Add(listener); } }
static Type GetTestFrameworkType(IAssemblyInfo testAssembly, IMessageSink diagnosticMessageSink) { try { var testFrameworkAttr = testAssembly.GetCustomAttributes(typeof(ITestFrameworkAttribute)).FirstOrDefault(); if (testFrameworkAttr != null) { var discovererAttr = testFrameworkAttr.GetCustomAttributes(typeof(TestFrameworkDiscovererAttribute)).FirstOrDefault(); if (discovererAttr != null) { var discoverer = ExtensibilityPointFactory.GetTestFrameworkTypeDiscoverer(diagnosticMessageSink, discovererAttr); if (discoverer != null) { return(discoverer.GetTestFrameworkType(testFrameworkAttr)); } var ctorArgs = discovererAttr.GetConstructorArguments().ToArray(); diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Unable to create custom test framework discoverer type '{ctorArgs[1]}, {ctorArgs[0]}'")); } else { diagnosticMessageSink.OnMessage(new DiagnosticMessage("Assembly-level test framework attribute was not decorated with [TestFrameworkDiscoverer]")); } } } catch (Exception ex) { diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception thrown during test framework discoverer construction: {ex.Unwrap()}")); } return(typeof(XunitTestFramework)); }
static Type GetTestFrameworkType(IAssemblyInfo testAssembly, IMessageSink diagnosticMessageSink) { try { var testFrameworkAttr = testAssembly.GetCustomAttributes(typeof(ITestFrameworkAttribute)).FirstOrDefault(); if (testFrameworkAttr != null) { var discovererAttr = testFrameworkAttr.GetCustomAttributes(typeof(TestFrameworkDiscovererAttribute)).FirstOrDefault(); if (discovererAttr != null) { var discoverer = ExtensibilityPointFactory.GetTestFrameworkTypeDiscoverer(diagnosticMessageSink, discovererAttr); if (discoverer != null) return discoverer.GetTestFrameworkType(testFrameworkAttr); var ctorArgs = discovererAttr.GetConstructorArguments().ToArray(); diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Unable to create custom test framework discoverer type '{ctorArgs[1]}, {ctorArgs[0]}'")); } else { diagnosticMessageSink.OnMessage(new DiagnosticMessage("Assembly-level test framework attribute was not decorated with [TestFrameworkDiscoverer]")); } } } catch (Exception ex) { diagnosticMessageSink.OnMessage(new DiagnosticMessage($"Exception thrown during test framework discoverer construction: {ex.Unwrap()}")); } return typeof(XunitTestFramework); }
public static IList <AssemblyLoaderAttribute> GetAssemblyLoaders(IAssemblyInfo assemblyInfo) { return(assemblyInfo.GetCustomAttributes(typeof(AssemblyLoaderAttribute)) .OfType <IReflectionAttributeInfo>() .Select(ai => ai.Attribute) .OfType <AssemblyLoaderAttribute>() .ToList()); }
public SpecThisTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory = null) : base(assemblyInfo, sourceProvider, diagnosticMessageSink) { IAttributeInfo collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault<IAttributeInfo>(); bool flag = collectionBehaviorAttribute != null && collectionBehaviorAttribute.GetNamedArgument<bool>("DisableTestParallelization"); string configurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; TestAssembly testAssembly = new TestAssembly(assemblyInfo, configurationFile); this.TestCollectionFactory = collectionFactory ?? ExtensibilityPointFactory.GetXunitTestCollectionFactory(diagnosticMessageSink, collectionBehaviorAttribute, (ITestAssembly)testAssembly); this.TestFrameworkDisplayName = string.Format("{0} [{1}, {2}]", XunitTestFrameworkDiscoverer.DisplayName, this.TestCollectionFactory.DisplayName, flag ? "non-parallel" : "parallel"); }
private string EvaluateSkipConditions(IAssemblyInfo assembly) { var reasons = assembly .GetCustomAttributes(typeof(ITestCondition)) .OfType<ReflectionAttributeInfo>() .Select(attributeInfo => (ITestCondition)attributeInfo.Attribute) .Where(condition => !condition.IsMet) .Select(condition => condition.SkipReason) .ToList(); return reasons.Count > 0 ? string.Join(Environment.NewLine, reasons) : null; }
private static string EvaluateSkipConditions(IAssemblyInfo assembly) { var reasons = assembly .GetCustomAttributes(typeof(ITestCondition)) .OfType <ReflectionAttributeInfo>() .Select(attributeInfo => (ITestCondition)attributeInfo.Attribute) .Where(condition => !condition.IsMet) .Select(condition => condition.SkipReason) .ToList(); return(reasons.Count > 0 ? string.Join(Environment.NewLine, reasons) : null); }
ITestFramework GetFramework(IAssemblyInfo assemblyInfo) { var frameworkAttribute = assemblyInfo.GetCustomAttributes(typeof(TestFrameworkAttribute)).FirstOrDefault(); if (frameworkAttribute == null) { return(new XunitTestFramework()); } var ctorArgs = frameworkAttribute.GetConstructorArguments().Cast <string>().ToArray(); var testFrameworkType = Reflector.GetType(ctorArgs[1], ctorArgs[0]); var framework = Activator.CreateInstance(testFrameworkType) as ITestFramework; return(framework ?? new XunitTestFramework()); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="configFileName">The test configuration file.</param> /// <param name="sourceProvider">The source information provider.</param> /// <param name="diagnosticMessageSink">The message sink used to send diagnostic messages</param> /// <param name="collectionFactory">The test collection factory used to look up test collections.</param> public XunitTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, string configFileName, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory = null) : base(assemblyInfo, sourceProvider, diagnosticMessageSink) { var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); var disableParallelization = collectionBehaviorAttribute != null && collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization"); var testAssembly = new TestAssembly(assemblyInfo, configFileName); TestCollectionFactory = collectionFactory ?? ExtensibilityPointFactory.GetXunitTestCollectionFactory(diagnosticMessageSink, collectionBehaviorAttribute, testAssembly); TestFrameworkDisplayName = $"{DisplayName} [{TestCollectionFactory.DisplayName}, {(disableParallelization ? "non-parallel" : "parallel")}]"; }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="sourceProvider">The source information provider.</param> /// <param name="collectionFactory">The test collection factory used to look up test collections.</param> /// <param name="messageAggregator">The message aggregator to receive environmental warnings from.</param> public XunitTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IXunitTestCollectionFactory collectionFactory, IMessageAggregator messageAggregator) : base(assemblyInfo, sourceProvider, messageAggregator) { var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); var disableParallelization = collectionBehaviorAttribute == null ? false : collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization"); TestCollectionFactory = collectionFactory ?? GetTestCollectionFactory(this.AssemblyInfo, collectionBehaviorAttribute); TestFrameworkDisplayName = String.Format("{0} [{1}, {2}]", DisplayName, TestCollectionFactory.DisplayName, disableParallelization ? "non-parallel" : "parallel"); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="sourceProvider">The source information provider.</param> /// <param name="collectionFactory">The test collection factory used to look up test collections.</param> /// <param name="messageAggregator">The message aggregator to receive environmental warnings from.</param> public XunitTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IXunitTestCollectionFactory collectionFactory, IMessageAggregator messageAggregator) : base(assemblyInfo, sourceProvider, messageAggregator) { var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); var disableParallelization = collectionBehaviorAttribute == null ? false : collectionBehaviorAttribute.GetNamedArgument<bool>("DisableTestParallelization"); TestCollectionFactory = collectionFactory ?? GetTestCollectionFactory(this.AssemblyInfo, collectionBehaviorAttribute); TestFrameworkDisplayName = String.Format("{0} [{1}, {2}]", DisplayName, TestCollectionFactory.DisplayName, disableParallelization ? "non-parallel" : "parallel"); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkExecutor"/> class. /// </summary> /// <param name="assemblyFileName">Path of the test assembly.</param> public XunitTestFrameworkExecutor(string assemblyFileName) { this.assemblyFileName = assemblyFileName; var assembly = Assembly.Load(AssemblyName.GetAssemblyName(assemblyFileName)); assemblyInfo = Reflector.Wrap(assembly); var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); if (collectionBehaviorAttribute != null) disableParallelization = collectionBehaviorAttribute.GetNamedArgument<bool>("DisableTestParallelization"); var testCollectionFactory = XunitTestFrameworkDiscoverer.GetTestCollectionFactory(assemblyInfo, collectionBehaviorAttribute); displayName = String.Format("{0}-bit .NET {1} [{2}, {3}]", IntPtr.Size * 8, Environment.Version, testCollectionFactory.DisplayName, disableParallelization ? "non-parallel" : "parallel"); }
readonly Dictionary<Type, Type> discovererTypeCache = new Dictionary<Type, Type>(); // key is a Type that is or derives from FactAttribute /// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="sourceProvider">The source information provider.</param> /// <param name="diagnosticMessageSink">The message sink used to send diagnostic messages</param> /// <param name="collectionFactory">The test collection factory used to look up test collections.</param> public XunitTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory = null) : base(assemblyInfo, sourceProvider, diagnosticMessageSink) { var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); var disableParallelization = collectionBehaviorAttribute != null && collectionBehaviorAttribute.GetNamedArgument<bool>("DisableTestParallelization"); string config = null; #if !PLATFORM_DOTNET config = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; #endif var testAssembly = new TestAssembly(assemblyInfo, config); TestCollectionFactory = collectionFactory ?? ExtensibilityPointFactory.GetXunitTestCollectionFactory(diagnosticMessageSink, collectionBehaviorAttribute, testAssembly); TestFrameworkDisplayName = $"{DisplayName} [{TestCollectionFactory.DisplayName}, {(disableParallelization ? "non-parallel" : "parallel")}]"; }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="sourceProvider">The source information provider.</param> /// <param name="diagnosticMessageSink">The message sink used to send diagnostic messages</param> /// <param name="collectionFactory">The test collection factory used to look up test collections.</param> public XunitTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory = null) : base(assemblyInfo, sourceProvider, diagnosticMessageSink) { var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); var disableParallelization = collectionBehaviorAttribute != null && collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization"); string config = null; #if !WINDOWS_PHONE_APP && !WINDOWS_PHONE && !DOTNETCORE config = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; #endif var testAssembly = new TestAssembly(assemblyInfo, config); TestCollectionFactory = collectionFactory ?? ExtensibilityPointFactory.GetXunitTestCollectionFactory(diagnosticMessageSink, collectionBehaviorAttribute, testAssembly); TestFrameworkDisplayName = $"{DisplayName} [{TestCollectionFactory.DisplayName}, {(disableParallelization ? "non-parallel" : "parallel")}]"; }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="sourceProvider">The source information provider.</param> /// <param name="diagnosticMessageSink">The message sink used to send diagnostic messages</param> /// <param name="collectionFactory">The test collection factory used to look up test collections.</param> public XunitTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IMessageSink diagnosticMessageSink, IXunitTestCollectionFactory collectionFactory = null) : base(assemblyInfo, sourceProvider, diagnosticMessageSink) { var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); var disableParallelization = collectionBehaviorAttribute == null ? false : collectionBehaviorAttribute.GetNamedArgument<bool>("DisableTestParallelization"); string config = null; #if !WINDOWS_PHONE_APP && !WINDOWS_PHONE && !DNXCORE50 config = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; #endif var testAssembly = new TestAssembly(assemblyInfo, config); TestCollectionFactory = collectionFactory ?? ExtensibilityPointFactory.GetXunitTestCollectionFactory(diagnosticMessageSink, collectionBehaviorAttribute, testAssembly); TestFrameworkDisplayName = string.Format("{0} [{1}, {2}]", DisplayName, TestCollectionFactory.DisplayName, disableParallelization ? "non-parallel" : "parallel"); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="sourceProvider">The source information provider.</param> /// <param name="collectionFactory">The test collection factory used to look up test collections.</param> /// <param name="messageAggregator">The message aggregator to receive environmental warnings from.</param> public XunitTestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IXunitTestCollectionFactory collectionFactory, IMessageAggregator messageAggregator) : base(assemblyInfo, sourceProvider, messageAggregator) { var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); var disableParallelization = collectionBehaviorAttribute == null ? false : collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization"); string config = null; #if !WINDOWS_PHONE_APP && !WINDOWS_PHONE && !ASPNETCORE50 config = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; #endif var testAssembly = new TestAssembly(assemblyInfo, config); TestCollectionFactory = collectionFactory ?? ExtensibilityPointFactory.GetXunitTestCollectionFactory(collectionBehaviorAttribute, testAssembly); TestFrameworkDisplayName = String.Format("{0} [{1}, {2}]", DisplayName, TestCollectionFactory.DisplayName, disableParallelization ? "non-parallel" : "parallel"); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkExecutor"/> class. /// </summary> /// <param name="assemblyFileName">Path of the test assembly.</param> public XunitTestFrameworkExecutor(string assemblyFileName) { this.assemblyFileName = assemblyFileName; var assembly = Assembly.Load(AssemblyName.GetAssemblyName(assemblyFileName)); assemblyInfo = Reflector.Wrap(assembly); var collectionBehaviorAttribute = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); if (collectionBehaviorAttribute != null) { disableParallelization = collectionBehaviorAttribute.GetNamedArgument <bool>("DisableTestParallelization"); } var testCollectionFactory = XunitTestFrameworkDiscoverer.GetTestCollectionFactory(assemblyInfo, collectionBehaviorAttribute); displayName = String.Format("{0}-bit .NET {1} [{2}, {3}]", IntPtr.Size * 8, Environment.Version, testCollectionFactory.DisplayName, disableParallelization ? "non-parallel" : "parallel"); }
/// <summary> /// Initializes a new instance of the <see cref="XunitTestFrameworkDiscoverer"/> class. /// </summary> /// <param name="assemblyInfo">The test assembly.</param> /// <param name="sourceProvider">The source information provider.</param> /// <param name="messageAggregator">The message aggregator to receive environmental warnings from.</param> public TestFrameworkDiscoverer(IAssemblyInfo assemblyInfo, ISourceInformationProvider sourceProvider, IMessageAggregator messageAggregator) { Guard.ArgumentNotNull("assemblyInfo", assemblyInfo); Guard.ArgumentNotNull("sourceProvider", sourceProvider); Aggregator = messageAggregator ?? MessageAggregator.Instance; AssemblyInfo = assemblyInfo; DisposalTracker = new DisposalTracker(); SourceProvider = sourceProvider; targetFramework = new Lazy<string>(() => { string result = null; var attrib = AssemblyInfo.GetCustomAttributes(typeof(TargetFrameworkAttribute)).FirstOrDefault(); if (attrib != null) result = attrib.GetConstructorArguments().Cast<string>().First(); return result ?? ""; }); }
/// <summary> /// Gets all the custom attributes for the given assembly. /// </summary> /// <param name="assemblyInfo">The assembly.</param> /// <param name="attributeType">The type of the attribute.</param> /// <returns>The matching attributes that decorate the assembly.</returns> public static IEnumerable <IAttributeInfo> GetCustomAttributes(this IAssemblyInfo assemblyInfo, Type attributeType) { return(assemblyInfo.GetCustomAttributes(attributeType.AssemblyQualifiedName)); }
public IEnumerable <IAttributeInfo> GetCustomAttributes(string assemblyQualifiedAttributeTypeName) { return(_assemblyInfoImplementation.GetCustomAttributes(assemblyQualifiedAttributeTypeName)); }
public IEnumerable <IAttributeInfo> GetCustomAttributes(string assemblyQualifiedAttributeTypeName) { return(originalAssemblyInfo.GetCustomAttributes(assemblyQualifiedAttributeTypeName)); }
private static IEnumerable <IAttributeInfo> GetCachedTraitAttributes(IAssemblyInfo assembly) => assemblyTraitAttributeCache.GetOrAdd(assembly.Name, () => assembly.GetCustomAttributes(typeof(ITraitAttribute)));
static IXunitTestCollectionFactory GetTestCollectionFactory(IAssemblyInfo assemblyInfo) { var collectionBehavior = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault(); var factoryType = GetTestCollectionFactoryType(collectionBehavior); return (IXunitTestCollectionFactory)Activator.CreateInstance(factoryType, new[] { assemblyInfo }); }
public static string EvaluateSkipConditions(this ITestMethod testMethod) { ITypeInfo testClass = testMethod.TestClass.Class; IAssemblyInfo assembly = testMethod.TestClass.TestCollection.TestAssembly.Assembly; System.Collections.Generic.IEnumerable <System.Attribute> conditionAttributes = testMethod.Method .GetCustomAttributes(typeof(ITestCondition)) .Concat(testClass.GetCustomAttributes(typeof(ITestCondition))) .Concat(assembly.GetCustomAttributes(typeof(ITestCondition))) .OfType <ReflectionAttributeInfo>() .Select(attributeInfo => attributeInfo.Attribute); foreach (ITestCondition condition in conditionAttributes) { if (!condition.IsMet) { return(condition.SkipReason); } } return(null); }