protected override IEnumerable <IXunitTestCase> CreateTestCasesForDataRow(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute, object[] dataRow) { IMethodInfo methodInfo = testMethod.Method; List <IXunitTestCase> skippedTestCase = new List <IXunitTestCase>(); if (!_conditionCache.TryGetValue(methodInfo, out string skipReason)) { if (!ConditionalTestDiscoverer.TryEvaluateSkipConditions(discoveryOptions, DiagnosticMessageSink, testMethod, theoryAttribute.GetConstructorArguments().ToArray(), out skipReason, out ExecutionErrorTestCase errorTestCase)) { return(new IXunitTestCase[] { errorTestCase }); } _conditionCache.Add(methodInfo, skipReason); if (skipReason != null) { // If this is the first time we evalute the condition we return a SkippedTestCase to avoid printing a skip for every inline-data. skippedTestCase.Add(new SkippedTestCase(skipReason, DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod)); } } return(skipReason != null ? (IEnumerable <IXunitTestCase>)skippedTestCase : new [] { new SkippedFactTestCase(DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod, dataRow) }); // Test case skippable at runtime. }
public override IEnumerable <IXunitTestCase> Discover( ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) { IEnumerable <IXunitTestCase> testCases = base.Discover(discoveryOptions, testMethod, factAttribute).Select(tc => new SkippedFactTestCase(_diagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod)); return(ConditionalTestDiscoverer.Discover(discoveryOptions, _diagnosticMessageSink, testMethod, testCases, factAttribute.GetConstructorArguments().ToArray())); }
public override IEnumerable <IXunitTestCase> Discover( ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) { IEnumerable <IXunitTestCase> testCases = base.Discover(discoveryOptions, testMethod, theoryAttribute); return(ConditionalTestDiscoverer.Discover(discoveryOptions, _diagnosticMessageSink, testMethod, testCases, theoryAttribute.GetConstructorArguments().ToArray())); }
protected override IEnumerable <IXunitTestCase> CreateTestCasesForTheory(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo theoryAttribute) { if (ConditionalTestDiscoverer.TryEvaluateSkipConditions(discoveryOptions, DiagnosticMessageSink, testMethod, theoryAttribute.GetConstructorArguments().ToArray(), out string skipReason, out ExecutionErrorTestCase errorTestCase)) { return(skipReason != null ? new[] { new SkippedTestCase(skipReason, DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod) } : new IXunitTestCase[] { new SkippedTheoryTestCase(DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod) }); // Theory skippable at runtime. } return(new IXunitTestCase[] { errorTestCase }); }
protected override IXunitTestCase CreateTestCase(ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) { if (ConditionalTestDiscoverer.TryEvaluateSkipConditions(discoveryOptions, DiagnosticMessageSink, testMethod, factAttribute.GetConstructorArguments().ToArray(), out string skipReason, out ExecutionErrorTestCase errorTestCase)) { return(skipReason != null ? (IXunitTestCase) new SkippedTestCase(skipReason, DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod) : new SkippedFactTestCase(DiagnosticMessageSink, discoveryOptions.MethodDisplayOrDefault(), discoveryOptions.MethodDisplayOptionsOrDefault(), testMethod)); // Test case skippable at runtime. } return(errorTestCase); }
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); } return(DiscovererHelpers.Evaluate(calleeType, conditionMemberNames)); }
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) { throw new InvalidOperationException($"Unable to get MethodInfo, please check input for {entry}."); } // If one of the conditions is false, then return the category failing trait. if (!(bool)conditionMethodInfo.Invoke(null, null)) { return(false); } } return(true); }
internal static bool Evaluate(Type calleeType, string[] conditionMemberNames) { 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) { throw new InvalidOperationException($"Unable to get MethodInfo, please check input for {entry}."); } if (!(bool)conditionMethodInfo.Invoke(null, null)) { return(false); } } return(true); }