本文整理汇总了C#中IAssemblyInfo.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# IAssemblyInfo.GetCustomAttributes方法的具体用法?C# IAssemblyInfo.GetCustomAttributes怎么用?C# IAssemblyInfo.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAssemblyInfo
的用法示例。
在下文中一共展示了IAssemblyInfo.GetCustomAttributes方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTestFrameworkType
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);
}
示例2: GetAssemblyLoaders
public static IList<AssemblyLoaderAttribute> GetAssemblyLoaders(IAssemblyInfo assemblyInfo) {
return assemblyInfo.GetCustomAttributes(typeof(AssemblyLoaderAttribute))
.OfType<IReflectionAttributeInfo>()
.Select(ai => ai.Attribute)
.OfType<AssemblyLoaderAttribute>()
.ToList();
}
示例3: SpecThisTestFrameworkDiscoverer
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");
}
示例4: EvaluateSkipConditions
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;
}
示例5: XunitTestFrameworkDiscoverer
/// <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");
}
示例6: XunitTestFrameworkDiscoverer
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")}]";
}
示例7: XunitTestFrameworkExecutor
/// <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");
}
示例8: XunitTestFrameworkDiscoverer
/// <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");
}
示例9: TestFrameworkDiscoverer
/// <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 ?? "";
});
}
示例10: GetTestCollectionFactory
static IXunitTestCollectionFactory GetTestCollectionFactory(IAssemblyInfo assemblyInfo)
{
var collectionBehavior = assemblyInfo.GetCustomAttributes(typeof(CollectionBehaviorAttribute)).SingleOrDefault();
var factoryType = GetTestCollectionFactoryType(collectionBehavior);
return (IXunitTestCollectionFactory)Activator.CreateInstance(factoryType, new[] { assemblyInfo });
}