Task ITestDiscoverer.AnalyzeDocumentAsync(DocumentTestDiscoveryContext context)
        {
            if (context.CancellationToken.IsCancellationRequested)
            {
                return(Task.FromCanceled(context.CancellationToken));
            }

            using (var discoverySink = new TestDiscoveryVisitor())
                using (var xunit2 = new Xunit2Discoverer(
                           AppDomainSupport.Denied,
                           sourceInformationProvider: DummySourceInformationProvider.Instance,
                           assemblyInfo: new SourceAssemblyInfo(context),
                           xunitExecutionAssemblyPath: XunitExecutionAssemblyPath.Value,
                           verifyAssembliesOnDisk: false))
                {
                    xunit2.Find(includeSourceInformation: false, messageSink: discoverySink, discoveryOptions: TestFrameworkOptions.ForDiscovery());

                    while (!discoverySink.Finished.WaitOne(50))
                    {
                        if (context.CancellationToken.IsCancellationRequested)
                        {
                            break;
                        }

                        TrySendDiscoveredTestCases(context, discoverySink);
                    }

                    TrySendDiscoveredTestCases(context, discoverySink);
                }

            return(context.CancellationToken.IsCancellationRequested ?
                   Task.FromCanceled(context.CancellationToken) :
                   Task.CompletedTask);
        }
        private void TrySendDiscoveredTestCases(TestDiscoveryContext context, TestDiscoveryVisitor discoverySink)
        {
            if (context.CancellationToken.IsCancellationRequested)
            {
                return;
            }

            while (discoverySink.TestCases.TryDequeue(out var test))
            {
                var testCase = new TestCase(
                    $"{test.TestMethod.TestClass.Class.Name}.{test.TestMethod.Method.Name}",
                    ExecutorUri,
                    context.Source)
                {
                    DisplayName  = test.DisplayName,
                    CodeFilePath = test.SourceInformation?.FileName,
                    LineNumber   = test.SourceInformation?.LineNumber ?? 0
                };

                var traits = test.Traits;
                foreach (var key in traits.Keys)
                {
                    foreach (var value in traits[key])
                    {
                        testCase.Traits.Add(new Trait(key, value));
                    }
                }

                context.ReportDiscoveredTest(testCase);
            }
        }
Пример #3
0
        /// <inheritdoc/>
        public virtual void RunAll(IMessageSink messageSink, ITestFrameworkOptions discoveryOptions, ITestFrameworkOptions executionOptions)
        {
            var discoverySink = new TestDiscoveryVisitor();

            using (var discoverer = CreateDiscoverer())
            {
                discoverer.Find(false, discoverySink, discoveryOptions);
                discoverySink.Finished.WaitOne();
            }

            RunTestCases(discoverySink.TestCases.Cast <TTestCase>(), messageSink, executionOptions);
        }
Пример #4
0
        /// <inheritdoc/>
        public void Run(IMessageSink messageSink, ITestFrameworkOptions discoveryOptions, ITestFrameworkOptions executionOptions)
        {
            var discoverySink = new TestDiscoveryVisitor();

            using (var discoverer = new XunitTestFrameworkDiscoverer(assemblyInfo, sourceInformationProvider))
            {
                discoverer.Find(false, discoverySink, discoveryOptions);
                discoverySink.Finished.WaitOne();
            }

            Run(discoverySink.TestCases, messageSink, executionOptions);
        }
Пример #5
0
        /// <inheritdoc/>
        public virtual void RunAll(IMessageSink executionMessageSink, ITestFrameworkDiscoveryOptions discoveryOptions, ITestFrameworkExecutionOptions executionOptions)
        {
            Guard.ArgumentNotNull("executionMessageSink", executionMessageSink);
            Guard.ArgumentNotNull("discoveryOptions", discoveryOptions);
            Guard.ArgumentNotNull("executionOptions", executionOptions);

            var discoverySink = new TestDiscoveryVisitor();

            using (var discoverer = CreateDiscoverer())
            {
                discoverer.Find(false, discoverySink, discoveryOptions);
                discoverySink.Finished.WaitOne();
            }

            RunTestCases(discoverySink.TestCases.Cast <TTestCase>(), executionMessageSink, executionOptions);
        }
Пример #6
0
    public static void TheoriesAlwaysComeBackAsSingleXunitTheoryTestCase()
    {
        var sourceProvider = new NullSourceInformationProvider();
        var assemblyInfo = Reflector.Wrap(Assembly.GetExecutingAssembly());
        var discoverer = new XunitTestFrameworkDiscoverer(assemblyInfo, sourceProvider);
        var visitor = new TestDiscoveryVisitor();

        discoverer.Find(typeof(ClassWithTheory).FullName, false, visitor, new XunitDiscoveryOptions());
        visitor.Finished.WaitOne();

        var testCase = Assert.Single(visitor.TestCases);
        Assert.IsType<XunitTheoryTestCase>(testCase);

        var deserialized = SerializationHelper.Deserialize<ITestCase>(SerializationHelper.Serialize(testCase));
        Assert.IsType<XunitTheoryTestCase>(deserialized);
    }
Пример #7
0
    public static void SerializedTestsInSameCollectionRemainInSameCollection()
    {
        var sourceProvider = new NullSourceInformationProvider();
        var assemblyInfo = Reflector.Wrap(Assembly.GetExecutingAssembly());
        var discoverer = new XunitTestFrameworkDiscoverer(assemblyInfo, sourceProvider);
        var visitor = new TestDiscoveryVisitor();

        discoverer.Find(typeof(ClassUnderTest).FullName, false, visitor, new XunitDiscoveryOptions());
        visitor.Finished.WaitOne();

        var first = visitor.TestCases[0];
        var second = visitor.TestCases[1];

        Assert.True(TestCollectionComparer.Instance.Equals(first.TestCollection, second.TestCollection));

        var serializedFirst = SerializationHelper.Deserialize<ITestCase>(SerializationHelper.Serialize(first));
        var serializedSecond = SerializationHelper.Deserialize<ITestCase>(SerializationHelper.Serialize(second));

        Assert.NotSame(serializedFirst.TestCollection, serializedSecond.TestCollection);
        Assert.True(TestCollectionComparer.Instance.Equals(serializedFirst.TestCollection, serializedSecond.TestCollection));
    }
Пример #8
0
    public static void TheoriesWithSerializableData_ReturnAsIndividualTestCases()
    {
        var sourceProvider = new NullSourceInformationProvider();
        var assemblyInfo = Reflector.Wrap(Assembly.GetExecutingAssembly());
        var discoverer = new XunitTestFrameworkDiscoverer(assemblyInfo, sourceProvider, SpyMessageSink.Create());
        var visitor = new TestDiscoveryVisitor();

        discoverer.Find(typeof(ClassWithTheory).FullName, false, visitor, TestFrameworkOptions.ForDiscovery());
        visitor.Finished.WaitOne();

        var first = visitor.TestCases[0];
        var second = visitor.TestCases[1];
        Assert.NotEqual(first.UniqueID, second.UniqueID);

        Assert.True(TestCollectionComparer.Instance.Equals(first.TestMethod.TestClass.TestCollection, second.TestMethod.TestClass.TestCollection));

        var serializedFirst = SerializationHelper.Deserialize<ITestCase>(SerializationHelper.Serialize(first));
        var serializedSecond = SerializationHelper.Deserialize<ITestCase>(SerializationHelper.Serialize(second));

        Assert.NotSame(serializedFirst.TestMethod.TestClass.TestCollection, serializedSecond.TestMethod.TestClass.TestCollection);
        Assert.True(TestCollectionComparer.Instance.Equals(serializedFirst.TestMethod.TestClass.TestCollection, serializedSecond.TestMethod.TestClass.TestCollection));
    }
 protected TestableXunitTestFrameworkDiscoverer(IAssemblyInfo assembly,
                                                ISourceInformationProvider sourceProvider,
                                                IMessageSink diagnosticMessageSink,
                                                IXunitTestCollectionFactory collectionFactory)
     : base(assembly,
            sourceProvider ?? Substitute.For<ISourceInformationProvider>(),
            diagnosticMessageSink ?? new Xunit.NullMessageSink(),
            collectionFactory)
 {
     Assembly = assembly;
     Visitor = new TestDiscoveryVisitor();
 }
 protected TestableXunitTestFrameworkDiscoverer(IAssemblyInfo assembly,
                                                ISourceInformationProvider sourceProvider,
                                                IXunitTestCollectionFactory collectionFactory,
                                                IMessageAggregator messageAggregator)
     : base(assembly,
            sourceProvider ?? Substitute.For<ISourceInformationProvider>(),
            collectionFactory,
            messageAggregator)
 {
     Assembly = assembly;
     Visitor = new TestDiscoveryVisitor();
 }
Пример #11
0
        /// <summary>
        /// Starts the process of running all the xUnit.net v1 tests in the assembly.
        /// </summary>
        /// <param name="messageSink">The message sink to report results back to.</param>
        public void Run(IMessageSink messageSink)
        {
            var discoverySink = new TestDiscoveryVisitor();
            toDispose.Push(discoverySink);

            Find(false, discoverySink);
            discoverySink.Finished.WaitOne();

            Run(discoverySink.TestCases, messageSink);
        }
 TestableXunitTestFrameworkDiscoverer(IAssemblyInfo assembly, ISourceInformationProvider sourceProvider)
     : base(assembly, sourceProvider)
 {
     Assembly = assembly;
     Visitor = new TestDiscoveryVisitor();
 }
Пример #13
0
    public static void TheoryWithNonSerializableData_ReturnsAsASingleTestCase()
    {
        var sourceProvider = new NullSourceInformationProvider();
        var assemblyInfo = Reflector.Wrap(Assembly.GetExecutingAssembly());
        var discoverer = new XunitTestFrameworkDiscoverer(assemblyInfo, sourceProvider, SpyMessageSink.Create());
        var visitor = new TestDiscoveryVisitor();

        discoverer.Find(typeof(ClassWithNonSerializableTheoryData).FullName, false, visitor, TestFrameworkOptions.ForDiscovery());
        visitor.Finished.WaitOne();

        var testCase = Assert.Single(visitor.TestCases);
        Assert.IsType<XunitTheoryTestCase>(testCase);

        var deserialized = SerializationHelper.Deserialize<ITestCase>(SerializationHelper.Serialize(testCase));
        Assert.IsType<XunitTheoryTestCase>(deserialized);
    }