コード例 #1
0
        RunSummary RunTest_DataDiscoveryException()
        {
            // Use -1 for the index here so we don't collide with any legitimate test case IDs that might've been used
            var test = new XunitTest(TestCase, DisplayName, testIndex: -1);

            var testAssemblyUniqueID   = TestCase.TestMethod.TestClass.TestCollection.TestAssembly.UniqueID;
            var testCollectionUniqueID = TestCase.TestMethod.TestClass.TestCollection.UniqueID;
            var testClassUniqueID      = TestCase.TestMethod.TestClass.UniqueID;
            var testMethodUniqueID     = TestCase.TestMethod.UniqueID;
            var testCaseUniqueID       = TestCase.UniqueID;

            var testStarting = new _TestStarting
            {
                AssemblyUniqueID       = testAssemblyUniqueID,
                TestCaseUniqueID       = testCaseUniqueID,
                TestClassUniqueID      = testClassUniqueID,
                TestCollectionUniqueID = testCollectionUniqueID,
                TestDisplayName        = test.DisplayName,
                TestMethodUniqueID     = testMethodUniqueID,
                TestUniqueID           = test.UniqueID
            };

            if (!MessageBus.QueueMessage(testStarting))
            {
                CancellationTokenSource.Cancel();
            }
            else
            {
                var errorMetadata = ExceptionUtility.ExtractMetadata(dataDiscoveryException !.Unwrap());
                var testFailed    = new _TestFailed
                {
                    AssemblyUniqueID       = testAssemblyUniqueID,
                    ExceptionParentIndices = errorMetadata.ExceptionParentIndices,
                    ExceptionTypes         = errorMetadata.ExceptionTypes,
                    ExecutionTime          = 0m,
                    Messages               = errorMetadata.Messages,
                    Output                 = "",
                    StackTraces            = errorMetadata.StackTraces,
                    TestCaseUniqueID       = testCaseUniqueID,
                    TestClassUniqueID      = testClassUniqueID,
                    TestCollectionUniqueID = testCollectionUniqueID,
                    TestMethodUniqueID     = testMethodUniqueID,
                    TestUniqueID           = test.UniqueID
                };
                if (!MessageBus.QueueMessage(testFailed))
                {
                    CancellationTokenSource.Cancel();
                }
            }

            var testFinished = new _TestFinished
            {
                AssemblyUniqueID       = testAssemblyUniqueID,
                ExecutionTime          = 0m,
                Output                 = "",
                TestCaseUniqueID       = testCaseUniqueID,
                TestClassUniqueID      = testClassUniqueID,
                TestCollectionUniqueID = testCollectionUniqueID,
                TestMethodUniqueID     = testMethodUniqueID,
                TestUniqueID           = test.UniqueID
            };

            if (!MessageBus.QueueMessage(testFinished))
            {
                CancellationTokenSource.Cancel();
            }

            return(new RunSummary {
                Total = 1, Failed = 1
            });
        }
コード例 #2
0
        /// <inheritdoc/>
        protected override Task <RunSummary> RunTestAsync()
        {
            // Use -1 for the index here so we don't collide with any legitimate test case IDs that might've been used
            var test    = new XunitTest(TestCase, TestCase.DisplayName, testIndex: -1);
            var summary = new RunSummary {
                Total = 1
            };

            var testAssemblyUniqueID   = TestCase.TestMethod.TestClass.TestCollection.TestAssembly.UniqueID;
            var testCaseUniqueID       = TestCase.UniqueID;
            var testClassUniqueID      = TestCase.TestMethod.TestClass.UniqueID;
            var testCollectionUniqueID = TestCase.TestMethod.TestClass.TestCollection.UniqueID;
            var testMethodUniqueID     = TestCase.TestMethod.UniqueID;

            var testStarting = new _TestStarting
            {
                AssemblyUniqueID       = testAssemblyUniqueID,
                TestCaseUniqueID       = testCaseUniqueID,
                TestClassUniqueID      = testClassUniqueID,
                TestCollectionUniqueID = testCollectionUniqueID,
                TestDisplayName        = test.DisplayName,
                TestMethodUniqueID     = testMethodUniqueID,
                TestUniqueID           = test.UniqueID
            };

            if (!MessageBus.QueueMessage(testStarting))
            {
                CancellationTokenSource.Cancel();
            }
            else
            {
                summary.Failed = 1;

                var testFailed = new _TestFailed
                {
                    AssemblyUniqueID       = testAssemblyUniqueID,
                    ExceptionParentIndices = new[] { -1 },
                    ExceptionTypes         = new[] { typeof(InvalidOperationException).FullName },
                    ExecutionTime          = 0m,
                    Messages               = new[] { TestCase.ErrorMessage },
                    StackTraces            = new[] { "" },
                    Output                 = "",
                    TestCaseUniqueID       = testCaseUniqueID,
                    TestClassUniqueID      = testClassUniqueID,
                    TestCollectionUniqueID = testCollectionUniqueID,
                    TestMethodUniqueID     = testMethodUniqueID,
                    TestUniqueID           = test.UniqueID
                };

                if (!MessageBus.QueueMessage(testFailed))
                {
                    CancellationTokenSource.Cancel();
                }

                var testFinished = new _TestFinished
                {
                    AssemblyUniqueID       = testAssemblyUniqueID,
                    ExecutionTime          = 0m,
                    Output                 = "",
                    TestCaseUniqueID       = testCaseUniqueID,
                    TestClassUniqueID      = testClassUniqueID,
                    TestCollectionUniqueID = testCollectionUniqueID,
                    TestMethodUniqueID     = testMethodUniqueID,
                    TestUniqueID           = test.UniqueID
                };

                if (!MessageBus.QueueMessage(testFinished))
                {
                    CancellationTokenSource.Cancel();
                }
            }

            return(Task.FromResult(summary));
        }