/// <summary>
        /// Asserts general test properties
        /// </summary>
        /// <param name="tests">The enumeration of discovered tests</param>
        /// <param name="qualifiedName">The qualified test name which is to be tested</param>
        /// <param name="source">The source from which the test should have been discovered</param>
        /// <param name="info">Optional source file information related to the test under question</param>
        private void AssertVSTestCaseProperties(IEnumerable <VSTestCase> tests, QualifiedNameBuilder qualifiedName, string source, SourceFileInfo info)
        {
            VSTestCase test = tests.FirstOrDefault((_test) => (_test.FullyQualifiedName == qualifiedName.ToString()));

            Assert.That(test, Is.Not.Null);
            Assert.That(test.DisplayName, Is.EqualTo(qualifiedName.Peek()));
            Assert.That(test.Source, Is.EqualTo(source));
            Assert.That(test.ExecutorUri, Is.EqualTo(BoostTestExecutor.ExecutorUri));

            if (info != null)
            {
                Assert.That(test.CodeFilePath, Is.EqualTo(info.File));
                Assert.That(test.LineNumber, Is.EqualTo(info.LineNumber));
            }

            Assert.That(test.Traits.Count(), Is.EqualTo(1));

            Trait trait = test.Traits.First();

            Assert.That(trait.Name, Is.EqualTo(VSTestModel.TestSuiteTrait));

            string suite = qualifiedName.Pop().ToString();

            if (string.IsNullOrEmpty(suite))
            {
                suite = qualifiedName.MasterTestSuite;
            }

            Assert.That(trait.Value, Is.EqualTo(suite));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Parses a TestCase node.
        /// </summary>
        /// <param name="node">The XPathNavigator pointing to a TestCase node.</param>
        /// <param name="parent">The parent TestSuite to which TestUnits are attached to.</param>
        /// <param name="collection">The TestResultCollection which will host the result.</param>
        private static void ParseTestCaseReport(XPathNavigator node, TestSuite parent, TestResultCollection collection)
        {
            QualifiedNameBuilder fullname = new QualifiedNameBuilder(parent);

            fullname.Push(node.GetAttribute(Xml.Name, string.Empty));

            TestCase testCase = null;

            // If the test is already available, reuse it
            TestResult current = collection[fullname.ToString()];

            if (current != null)
            {
                testCase = current.Unit as TestCase;
            }

            // Else construct and add it to the appropriate parent
            if (testCase == null)
            {
                testCase = new TestCase(fullname.Peek(), parent);
            }

            TestResult result = ParseTestResult(node, testCase, collection);

            // Aggregate results. Common use-case in BOOST_DATA_TEST_CASE.
            collection[fullname.ToString()] = Aggregate(result, current);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Given a fully qualified name of a <b>test case</b>, generates the respective test unit hierarchy.
        /// </summary>
        /// <param name="fullyQualifiedName">The fully qualified name of the <b>test case</b></param>
        /// <returns>The test case hierarchy represented by the provided fully qualified name</returns>
        /// <remarks>The parameter 'fullyQualifiedName' will be modified and emptied in due process</remarks>
        private static TestCase FromFullyQualifiedName(QualifiedNameBuilder fullyQualifiedName)
        {
            // Reverse the fully qualified name stack i.e. Master Test Suite should be first element and Test Case should be last element
            Stack <string> hierarchy = new Stack <string>();

            while (fullyQualifiedName.Peek() != null)
            {
                hierarchy.Push(fullyQualifiedName.Peek());
                fullyQualifiedName.Pop();
            }

            TestSuite parent = null;

            // Treat each entry (except for the last) as a test suite
            while (hierarchy.Count > 1)
            {
                parent = new TestSuite(hierarchy.Peek(), parent);
                hierarchy.Pop();
            }

            // Treat the last entry as a test case
            return((hierarchy.Count == 1) ? new TestCase(hierarchy.Peek(), parent) : null);
        }
        /// <summary>
        /// Asserts general test details for the provided test case
        /// </summary>
        /// <param name="vsTest">The test case to test</param>
        /// <param name="fqn">The expected test case fully qualified name</param>
        /// <param name="source">The expected test case source</param>
        private void AssertTestDetails(VSTestCase vsTest, QualifiedNameBuilder fqn, string source)
        {
            Assert.That(vsTest, Is.Not.Null);
            Assert.That(vsTest.DisplayName, Is.EqualTo(fqn.Peek()));
            Assert.That(vsTest.ExecutorUri, Is.EqualTo(BoostTestExecutor.ExecutorUri));
            Assert.That(vsTest.Source, Is.EqualTo(source));

            string suite = fqn.Pop().ToString();

            if (string.IsNullOrEmpty(suite))
            {
                suite = QualifiedNameBuilder.DefaultMasterTestSuiteName;
            }

            Assert.That(vsTest.Traits.Where((trait) => (trait.Name == VSTestModel.TestSuiteTrait) && (trait.Value == suite)).Count(), Is.EqualTo(1));
        }