|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.DotNet.XUnitExtensions;
using Xunit.Sdk;
namespace Xunit
{
#if !USES_XUNIT_3
[XunitTestCaseDiscoverer("Microsoft.DotNet.XUnitExtensions.ConditionalFactDiscoverer", "Microsoft.DotNet.XUnitExtensions")]
#endif
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public sealed class ConditionalFactAttribute : FactAttribute
{
[DynamicallyAccessedMembers(StaticReflectionConstants.ConditionalMemberKinds)]
public Type CalleeType { get; private set; }
public string[] ConditionMemberNames { get; private set; }
public ConditionalFactAttribute(
[DynamicallyAccessedMembers(StaticReflectionConstants.ConditionalMemberKinds)]
Type calleeType,
params string[] conditionMemberNames)
{
CalleeType = calleeType;
ConditionMemberNames = conditionMemberNames;
#if USES_XUNIT_3
string skipReason = ConditionalTestDiscoverer.EvaluateSkipConditions(calleeType, conditionMemberNames);
if (skipReason != null)
Skip = skipReason;
#endif
}
#if USES_XUNIT_3
[Obsolete("Use the overload that takes a Type parameter: ConditionalFact(typeof(MyClass), nameof(MyCondition)).")]
#endif
public ConditionalFactAttribute(params string[] conditionMemberNames)
{
ConditionMemberNames = conditionMemberNames;
}
}
}
|