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 ThrowingData()
    {
        var discoverer = new TheoryDiscoverer();
        var testMethod = Mocks.TestMethod(typeof(ThrowingDataClass), "TheoryWithMisbehavingData");
        var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).Single();

        var testCases = discoverer.Discover(testMethod, factAttribute);

        var testCase = Assert.Single(testCases);
        var theoryTestCase = Assert.IsType<XunitTheoryTestCase>(testCase);
        Assert.Equal("TheoryDiscovererTests+ThrowingDataClass.TheoryWithMisbehavingData", theoryTestCase.DisplayName);
    }
示例#3
0
    public void NonSerializableDataYieldsSingleTheoryTestCase()
    {
        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(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);
    }
示例#4
0
    public void DataDiscovererReturningNullYieldsSingleTheoryTestCase()
    {
        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(assembly, type, method, theory);

        var testCase = Assert.Single(testCases);
        var theoryTestCase = Assert.IsType<XunitTheoryTestCase>(testCase);
        Assert.Equal("MockType.MockMethod", theoryTestCase.DisplayName);
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="SkippableTheoryDiscoverer"/> class.
 /// </summary>
 /// <param name="diagnosticMessageSink">The message sink used to send diagnostic messages</param>
 public SkippableTheoryDiscoverer(IMessageSink diagnosticMessageSink)
 {
     this.diagnosticMessageSink = diagnosticMessageSink;
     this.theoryDiscoverer      = new TheoryDiscoverer(diagnosticMessageSink);
 }
示例#6
0
    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);
    }
 /// <summary>
 /// Initializes a new instance of the <see cref="SkippableTheoryDiscoverer"/> class.
 /// </summary>
 /// <param name="diagnosticMessageSink">The message sink used to send diagnostic messages</param>
 public SkippableTheoryDiscoverer(IMessageSink diagnosticMessageSink)
 {
     this.diagnosticMessageSink = diagnosticMessageSink;
     this.theoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink);
 }
    public static 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(testMethod, factAttribute);

        var testCase = Assert.Single(testCases);
        var theoryTestCase = Assert.IsType<XunitTheoryTestCase>(testCase);
        Assert.Equal("TheoryDiscovererTests+MixedDiscoveryEnumeratedData.TheoryMethod", theoryTestCase.DisplayName);
    }
    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(testMethod, factAttribute);

        var testCase = Assert.Single(testCases);
        var theoryTestCase = Assert.IsType<XunitTheoryTestCase>(testCase);
        Assert.Equal("TheoryDiscovererTests+NonSerializableDataClass.TheoryMethod", theoryTestCase.DisplayName);
    }
示例#10
0
    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(testMethod, theoryAttribute);

        var testCase = Assert.Single(testCases);
        var theoryTestCase = Assert.IsType<XunitTheoryTestCase>(testCase);
        Assert.Equal("MockType.MockMethod", theoryTestCase.DisplayName);
    }
 public WpfTheoryDiscoverer(IMessageSink diagnosticMessageSink)
 {
     theoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink);
 }
 public CompositeTestDiscoverer(IMessageSink diagnosticMessageSink)
 {
     _theoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink);
 }
        public ScenarioTheoryDiscoverer(IMessageSink diagnosticMessageSink)
        {
            this.diagnosticMessageSink = diagnosticMessageSink;

            theoryDiscoverer = new TheoryDiscoverer(diagnosticMessageSink);
        }