public void NonDiscoveryEnumeratedDataYieldsSingleTheoryTestCase()
    {
        var discoverer    = TestableTheoryDiscoverer.Create();
        var testMethod    = Mocks.TestMethod(typeof(NonDiscoveryEnumeratedData), "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+NonDiscoveryEnumeratedData.TheoryMethod", theoryTestCase.DisplayName);
    }
    public void DiscoverOptions_PreEnumerateTheoriesSetToTrueWithSkipOnData_YieldsSkippedTestCasePerDataRow()
    {
        discoveryOptions.SetPreEnumerateTheories(true);
        var discoverer    = TestableTheoryDiscoverer.Create();
        var testMethod    = Mocks.TestMethod(typeof(MultipleDataClassSkipped), "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+MultipleDataClassSkipped.TheoryMethod(x: 42)" && testCase.SkipReason == "Skip this attribute");
        Assert.Single(testCases, testCase => testCase.DisplayName == "TheoryDiscovererTests+MultipleDataClassSkipped.TheoryMethod(x: 2112)" && testCase.SkipReason == "Skip this attribute");
    }
    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);
    }
Esempio n. 4
0
    public void TheoryWithNonSerializableEnumYieldsSingleTheoryTestCase()
    {
        var discoverer    = TestableTheoryDiscoverer.Create();
        var testMethod    = Mocks.TestMethod(typeof(NonSerializableEnumDataClass), "TheTest");
        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+NonSerializableEnumDataClass.TheTest", theoryTestCase.DisplayName);
    }
Esempio n. 5
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);
    }
    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);
    }
    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);
    }
    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);
    }