public void DiscoveryOptions_PreEnumerateTheoriesSetToTrue_YieldsTestCasePerDataRow()
    {
        discoveryOptions.SetPreEnumerateTheories(true);
        var discoverer    = TestableTheoryDiscoverer.Create();
        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 NonSerializableDataYieldsSingleTheoryTestCase()
    {
        var discoverer    = TestableTheoryDiscoverer.Create();
        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    = TestableTheoryDiscoverer.Create();
        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 ThrowingData()
    {
        var discoverer    = TestableTheoryDiscoverer.Create();
        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);
    }
예제 #5
0
    public void TheoryWithSerializableInputDataThatIsntSerializableAfterConversion_YieldsSingleTheoryTestCase()
    {
        var discoverer    = TestableTheoryDiscoverer.Create();
        var testMethod    = Mocks.TestMethod <ClassWithExplicitConvertedData>("ParameterDeclaredExplicitConversion");
        var factAttribute = testMethod.Method.GetCustomAttributes(typeof(FactAttribute)).Single();

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

        var testCase = Assert.Single(testCases);

        Assert.IsType <XunitDelayEnumeratedTheoryTestCase>(testCase);
        Assert.Equal("TheoryDiscovererTests+ClassWithExplicitConvertedData.ParameterDeclaredExplicitConversion", testCase.DisplayName);
    }
    public void DiscoveryOptions_PreEnumerateTheoriesSetToFalse_YieldsSingleTheoryTestCase()
    {
        discoveryOptions.SetPreEnumerateTheories(false);
        var discoverer    = TestableTheoryDiscoverer.Create();
        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 void DataDiscovererReturningNullYieldsSingleTheoryTestCase()
    {
        var discoverer      = TestableTheoryDiscoverer.Create();
        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);
    }
예제 #8
0
    public void NonSerializableDataYieldsSingleTheoryTestCase()
    {
        var discoverer    = TestableTheoryDiscoverer.Create();
        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);
        var message    = Assert.Single(discoverer.DiagnosticMessages);
        var diagnostic = Assert.IsAssignableFrom <IDiagnosticMessage>(message);

        Assert.Equal("Non-serializable data ('System.Object[]') found for 'TheoryDiscovererTests+NonSerializableDataClass.TheoryMethod'; falling back to single test case.", diagnostic.Message);
    }
예제 #9
0
    public void ThrowingData()
    {
        var discoverer    = TestableTheoryDiscoverer.Create();
        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);
        var message    = Assert.Single(discoverer.DiagnosticMessages);
        var diagnostic = Assert.IsAssignableFrom <IDiagnosticMessage>(message);

        Assert.StartsWith($"Exception thrown during theory discovery on 'TheoryDiscovererTests+ThrowingDataClass.TheoryWithMisbehavingData'; falling back to single test case.{Environment.NewLine}System.DivideByZeroException: Attempted to divide by zero.", diagnostic.Message);
    }