public void MethodFormat_Full_ShouldIncludeNamespaceAndClass()
        {
            DotnetTestFixture.Execute("method-full-test-results.xml;MethodFormat=Full");
            string    resultsFile = Path.Combine(DotnetTestFixture.RootDirectory, "method-full-test-results.xml");
            XDocument resultsXml  = XDocument.Load(resultsFile);

            var testcases = resultsXml.XPathSelectElements("/testsuites/testsuite")
                            .Descendants()
                            .Where(x => x.Name.LocalName == "testcase")
                            .ToList();

            foreach (var testcase in testcases)
            {
                var parsedName = new TestCaseNameParser().Parse(testcase.Attribute("name").Value);

                // We expect the full name would be the class name plus the parsed method
                var expectedFullName = parsedName.Namespace + "." + parsedName.Type + "." + parsedName.Method;

                // If the name is parsable into two pieces, then we have at least a two piece name
                Assert.AreNotEqual(parsedName.Type, TestCaseNameParser.TestCaseParserUnknownType);
                Assert.AreEqual(expectedFullName, testcase.Attribute("name").Value);
            }

            Assert.IsTrue(new JunitXmlValidator().IsValid(resultsXml));
        }
Exemplo n.º 2
0
        public void Parse_ParsesAllParseableInputs_WithoutConsoleOutput(string testCaseName, string expectedNamespace, string expectedType, string expectedMethod)
        {
            using (var sw = new StringWriter())
            {
                Console.SetOut(sw);
                var actual = new TestCaseNameParser().Parse(testCaseName);

                Assert.AreEqual(expectedNamespace, actual.Namespace);
                Assert.AreEqual(expectedType, actual.Type);
                Assert.AreEqual(expectedMethod, actual.Method);
                Assert.AreEqual(0, sw.ToString().Length);
            }
        }
Exemplo n.º 3
0
        public void Parse_FailsGracefullyOnNonParseableInputs_WithConsoleOutput(string testCaseName)
        {
            using var sw = new StringWriter();

            Console.SetOut(sw);
            var actual = new TestCaseNameParser().Parse(testCaseName);

            Assert.AreEqual(TestCaseNameParser.TestCaseParserUnknownNamespace, actual.Namespace);
            Assert.AreEqual(TestCaseNameParser.TestCaseParserUnknownType, actual.Type);
            Assert.AreEqual(testCaseName, actual.Method);

            // Remove the trailing new line before comparing.
            Assert.AreEqual(TestCaseNameParser.TestCaseParserError, sw.ToString().Replace(sw.NewLine, string.Empty));
        }
Exemplo n.º 4
0
        public void MethodFormat_Default_ShouldBeOnlyTheMethod()
        {
            DotnetTestFixture.Execute("method-default-test-results.xml;MethodFormat=Default");
            string    resultsFile = Path.Combine(DotnetTestFixture.RootDirectory, "method-default-test-results.xml");
            XDocument resultsXml  = XDocument.Load(resultsFile);

            var testcases = resultsXml.XPathSelectElements("/testsuites/testsuite")
                            .Descendants()
                            .Where(x => x.Name.LocalName == "testcase")
                            .ToList();

            foreach (var testcase in testcases)
            {
                var parsedName = TestCaseNameParser.Parse(testcase.Attribute("name").Value);

                // A method name only will not be parsable into two pieces
                Assert.AreEqual(parsedName.TypeName, TestCaseNameParser.TestCaseParserUnknownType);
            }
        }
Exemplo n.º 5
0
        public void MethodFormat_Class_ShouldIncludeClass()
        {
            DotnetTestFixture.Execute("method-class-test-results.xml;MethodFormat=Class");
            string    resultsFile = Path.Combine(DotnetTestFixture.RootDirectory, "method-class-test-results.xml");
            XDocument resultsXml  = XDocument.Load(resultsFile);

            var testcases = resultsXml.XPathSelectElements("/testsuites/testsuite")
                            .Descendants()
                            .Where(x => x.Name.LocalName == "testcase")
                            .ToList();

            foreach (var testcase in testcases)
            {
                var parsedName = TestCaseNameParser.Parse(testcase.Attribute("name").Value);

                // If the name is parsable into two pieces, then we have a two piece name and
                // consider that to be a passing result.
                Assert.AreNotEqual(parsedName.TypeName, TestCaseNameParser.TestCaseParserUnknownType);
            }
        }
Exemplo n.º 6
0
        public void Parse_ParsesAllParsableInputsWithoutNamespace_WithoutConsoleOutput(string testCaseName, string expectedNamespace, string expectedType, string expectedMethod)
        {
            var expectedConsole = string.Format(
                TestCaseNameParser.TestCaseParserErrorTemplate,
                testCaseName,
                expectedNamespace,
                expectedType,
                expectedMethod);

            using (var sw = new StringWriter())
            {
                Console.SetOut(sw);
                var actual = TestCaseNameParser.Parse(testCaseName);

                Assert.AreEqual(expectedNamespace, actual.NamespaceName);
                Assert.AreEqual(expectedType, actual.TypeName);
                Assert.AreEqual(expectedMethod, actual.MethodName);

                // Remove the trailing new line before comparing.
                Assert.AreEqual(expectedConsole, sw.ToString().Replace(sw.NewLine, string.Empty));
            }
        }
Exemplo n.º 7
0
        public void Parse_FailsGracefullyOnNonParsableInputs_WithConsoleOutput(string testCaseName)
        {
            var expectedConsole = string.Format(
                TestCaseNameParser.TestCaseParserErrorTemplate,
                testCaseName,
                TestCaseNameParser.TestCaseParserUnknownNamsepace,
                TestCaseNameParser.TestCaseParserUnknownType,
                testCaseName);

            using (var sw = new StringWriter())
            {
                Console.SetOut(sw);
                var actual = TestCaseNameParser.Parse(testCaseName);

                Assert.AreEqual(TestCaseNameParser.TestCaseParserUnknownNamsepace, actual.NamespaceName);
                Assert.AreEqual(TestCaseNameParser.TestCaseParserUnknownType, actual.TypeName);
                Assert.AreEqual(testCaseName, actual.MethodName);

                // Remove the trailing new line before comparing.
                Assert.AreEqual(expectedConsole, sw.ToString().Replace(sw.NewLine, string.Empty));
            }
        }