public IEnumerable <IXunitTestCase> Discover( ITestFrameworkDiscoveryOptions discoveryOptions, ITestMethod testMethod, IAttributeInfo factAttribute) { var skipReason = EvaluateSkipConditions(testMethod); var isTheory = false; IXunitTestCaseDiscoverer innerDiscoverer; if (testMethod.Method.GetCustomAttributes(typeof(TheoryAttribute)).Any()) { isTheory = true; innerDiscoverer = new TheoryDiscoverer(_diagnosticMessageSink); } else { innerDiscoverer = new FactDiscoverer(_diagnosticMessageSink); } var testCases = innerDiscoverer .Discover(discoveryOptions, testMethod, factAttribute) .Select(testCase => new SkipReasonTestCase(isTheory, skipReason, testCase)); return(testCases); }
public void NonSerializableDataYieldsSingleTheoryTestCase() { var discoverer = new TheoryDiscoverer(); var testMethod = Mocks.TestMethod(typeof(NonSerializableDataClass), "TheoryMethod"); var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).Single(); var testCases = discoverer.Discover(discoveryOptions, testMethod, factAttribute); var testCase = Assert.Single(testCases); var theoryTestCase = Assert.IsType <XunitTheoryTestCase>(testCase); Assert.Equal("TheoryDiscovererTests+NonSerializableDataClass.TheoryMethod", theoryTestCase.DisplayName); }
public void MixedDiscoveryEnumerationDataYieldSingleTheoryTestCase() { var discoverer = new TheoryDiscoverer(); var testMethod = Mocks.TestMethod(typeof(MixedDiscoveryEnumeratedData), "TheoryMethod"); var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).Single(); var testCases = discoverer.Discover(discoveryOptions, testMethod, factAttribute); var testCase = Assert.Single(testCases); var theoryTestCase = Assert.IsType <XunitTheoryTestCase>(testCase); Assert.Equal("TheoryDiscovererTests+MixedDiscoveryEnumeratedData.TheoryMethod", theoryTestCase.DisplayName); }
public void DiscoveryOptions_PreEnumerateTheoriesSetToTrue_YieldsTestCasePerDataRow() { discoveryOptions.SetPreEnumerateTheories(true); var discoverer = new TheoryDiscoverer(); var testMethod = Mocks.TestMethod(typeof(MultipleDataClass), "TheoryMethod"); var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).Single(); var testCases = discoverer.Discover(discoveryOptions, testMethod, factAttribute).ToList(); Assert.Equal(2, testCases.Count); Assert.Single(testCases, testCase => testCase.DisplayName == "TheoryDiscovererTests+MultipleDataClass.TheoryMethod(x: 42)"); Assert.Single(testCases, testCase => testCase.DisplayName == "TheoryDiscovererTests+MultipleDataClass.TheoryMethod(x: 2112)"); }
public void ThrowingData() { var discoverer = new TheoryDiscoverer(); var testMethod = Mocks.TestMethod(typeof(ThrowingDataClass), "TheoryWithMisbehavingData"); var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).Single(); var testCases = discoverer.Discover(discoveryOptions, testMethod, factAttribute); var testCase = Assert.Single(testCases); var theoryTestCase = Assert.IsType <XunitTheoryTestCase>(testCase); Assert.Equal("TheoryDiscovererTests+ThrowingDataClass.TheoryWithMisbehavingData", theoryTestCase.DisplayName); }
public void DiscoveryOptions_PreEnumerateTheoriesSetToFalse_YieldsSingleTheoryTestCase() { discoveryOptions.SetPreEnumerateTheories(false); var discoverer = new TheoryDiscoverer(); var testMethod = Mocks.TestMethod(typeof(MultipleDataClass), "TheoryMethod"); var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).Single(); var testCases = discoverer.Discover(discoveryOptions, testMethod, factAttribute); var testCase = Assert.Single(testCases); var theoryTestCase = Assert.IsType <XunitTheoryTestCase>(testCase); Assert.Equal("TheoryDiscovererTests+MultipleDataClass.TheoryMethod", theoryTestCase.DisplayName); }
public async void DiscoveryOptions_PreEnumerateTheoriesSetToFalse_YieldsSingleTestCase() { discoveryOptions.SetPreEnumerateTheories(false); var discoverer = new TheoryDiscoverer(); var testMethod = Mocks.TestMethod <MultipleDataClass>(nameof(MultipleDataClass.TheoryMethod)); var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).Single(); var testCases = await discoverer.Discover(discoveryOptions, testMethod, factAttribute); var testCase = Assert.Single(testCases); Assert.IsType <XunitDelayEnumeratedTheoryTestCase>(testCase); Assert.Equal($"{typeof(MultipleDataClass).FullName}.{nameof(MultipleDataClass.TheoryMethod)}", testCase.TestCaseDisplayName); }
public void DataDiscovererReturningNullYieldsSingleTheoryTestCase() { var discoverer = new TheoryDiscoverer(); var theoryAttribute = Mocks.TheoryAttribute(); var dataAttribute = Mocks.DataAttribute(); var testMethod = Mocks.TestMethod(methodAttributes: new[] { theoryAttribute, dataAttribute }); var testCases = discoverer.Discover(discoveryOptions, testMethod, theoryAttribute); var testCase = Assert.Single(testCases); var theoryTestCase = Assert.IsType <XunitTheoryTestCase>(testCase); Assert.Equal("MockType.MockMethod", theoryTestCase.DisplayName); }
public async void DiscoveryOptions_PreEnumerateTheoriesSetToTrue_YieldsTestCasePerDataRow() { discoveryOptions.SetPreEnumerateTheories(true); var discoverer = new TheoryDiscoverer(); var testMethod = Mocks.TestMethod <MultipleDataClass>(nameof(MultipleDataClass.TheoryMethod)); var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).Single(); var testCases = (await discoverer.Discover(discoveryOptions, testMethod, factAttribute)).ToList(); Assert.Collection( testCases.Select(tc => tc.TestCaseDisplayName).OrderBy(x => x), displayName => Assert.Equal($"{typeof(MultipleDataClass).FullName}.{nameof(MultipleDataClass.TheoryMethod)}(x: 2112)", displayName), displayName => Assert.Equal($"{typeof(MultipleDataClass).FullName}.{nameof(MultipleDataClass.TheoryMethod)}(x: 42)", displayName) ); }
public void ThrowingData() { var testCollection = new XunitTestCollection(); var discoverer = new TheoryDiscoverer(); var type = typeof(ThrowingDataClass); var method = type.GetMethod("TheoryWithMisbehavingData"); var theory = CustomAttributeData.GetCustomAttributes(method).Single(cad => cad.AttributeType == typeof(TheoryAttribute)); var testCases = discoverer.Discover(testCollection, Reflector.Wrap(type.Assembly), Reflector.Wrap(type), Reflector.Wrap(method), Reflector.Wrap(theory)); var testCase = Assert.Single(testCases); var theoryTestCase = Assert.IsType <XunitTheoryTestCase>(testCase); Assert.Equal("TheoryDiscovererTests+ThrowingDataClass.TheoryWithMisbehavingData", theoryTestCase.DisplayName); }
public void NonSerializableDataYieldsSingleTheoryTestCase() { var testCollection = new XunitTestCollection(); var discoverer = new TheoryDiscoverer(); var type = typeof(NonSerializableDataClass); var method = type.GetMethod("TheoryMethod"); var theory = CustomAttributeData.GetCustomAttributes(method).Single(cad => cad.AttributeType == typeof(TheoryAttribute)); var testCases = discoverer.Discover(testCollection, Reflector.Wrap(type.Assembly), Reflector.Wrap(type), Reflector.Wrap(method), Reflector.Wrap(theory)); var testCase = Assert.Single(testCases); var theoryTestCase = Assert.IsType <XunitTheoryTestCase>(testCase); Assert.Equal("TheoryDiscovererTests+NonSerializableDataClass.TheoryMethod", theoryTestCase.DisplayName); }
public void DataDiscovererReturningNullYieldsSingleTheoryTestCase() { var testCollection = new XunitTestCollection(); var discoverer = new TheoryDiscoverer(); var assembly = Mocks.AssemblyInfo(); var type = Mocks.TypeInfo(); var theory = Mocks.TheoryAttribute(); var data = Substitute.For <IAttributeInfo>(); var method = Mocks.MethodInfo(); method.GetCustomAttributes(typeof(DataAttribute).AssemblyQualifiedName).Returns(new[] { data }); method.GetCustomAttributes(typeof(TheoryAttribute).AssemblyQualifiedName).Returns(new[] { theory }); var testCases = discoverer.Discover(testCollection, assembly, type, method, theory); var testCase = Assert.Single(testCases); var theoryTestCase = Assert.IsType <XunitTheoryTestCase>(testCase); Assert.Equal("MockType.MockMethod", theoryTestCase.DisplayName); }
public CompositeTestDiscoverer(IMessageSink diagnosticMessageSink) { _theoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink); }
public InterpreterTheoryDiscoverer(IMessageSink diagnosticMessageSink) { theoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink); }
public ForegroundTheoryDiscoverer(IMessageSink diagnosticMessageSink) { _inner = new TheoryDiscoverer(diagnosticMessageSink); }
public SkippableTheoryDiscoverer(IMessageSink diagnosticMessageSink) { this.diagnosticMessageSink = diagnosticMessageSink; theoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink); }
public MSBuildTheoryDiscoverer(IMessageSink diagnosticMessageSink) { _theoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink); }
public WpfTheoryDiscoverer(IMessageSink diagnosticMessageSink) { theoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink); }