Exemple #1
0
        public override IEnumerable <IXunitTestCase> Discover(
            ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute)
        {
            MethodInfo testMethodInfo = testMethod.Method.ToRuntimeMethod();

            string     conditionMemberName = theoryAttribute.GetConstructorArguments().FirstOrDefault() as string;
            MethodInfo conditionMethodInfo;

            if (conditionMemberName == null ||
                (conditionMethodInfo = ConditionalFactDiscoverer.LookupConditionalMethod(testMethodInfo.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)));
            }
        }
Exemple #2
0
        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)));
            }
        }