public override IEnumerable <IXunitTestCase> Discover(
            ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute)
        {
            IEnumerable <IXunitTestCase> testCases = base.Discover(discoveryOptions, testMethod, factAttribute);

            return(ConditionalTestDiscoverer.Discover(discoveryOptions, _diagnosticMessageSink, testMethod, testCases, factAttribute.GetConstructorArguments().ToArray()));
        }
示例#2
0
        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));
        }
示例#3
0
        internal static bool EvaluateParameterHelper(IAttributeInfo traitAttribute)
        {
            // Parse the traitAttribute. We make sure it contains two parts:
            // 1. Type 2. nameof(conditionMemberName)
            object[] conditionArguments = traitAttribute.GetConstructorArguments().ToArray();
            Debug.Assert(conditionArguments.Count() == 2);

            Type calleeType = null;

            string[] conditionMemberNames = null;

            if (ConditionalTestDiscoverer.CheckInputToSkipExecution(conditionArguments, ref calleeType, ref conditionMemberNames))
            {
                return(true);
            }

            foreach (string entry in conditionMemberNames)
            {
                // Null condition member names are silently tolerated.
                if (string.IsNullOrWhiteSpace(entry))
                {
                    continue;
                }

                MethodInfo conditionMethodInfo = ConditionalTestDiscoverer.LookupConditionalMethod(calleeType, entry);
                if (conditionMethodInfo == null)
                {
                    // Unable to get MethodInfo. It's caused by bad user input.
                    // We need to report some error here. For now, just don't run the test.
                    return(false);
                }

                // If one of the conditions is false, then return the category failing trait.
                if (!(bool)conditionMethodInfo.Invoke(null, null))
                {
                    return(false);
                }
            }

            return(true);
        }