예제 #1
0
        public void Issue8214Test()
        {
            string expectedResultLine = "Tests run: 2376 Passed: 2301 Inconclusive: 13 Failed: 1 Ignored: 74";
            // get the sample that was added to the issue to validate that we do parse the resuls correctly and copy it to a local
            // path to be parsed
            var name            = GetType().Assembly.GetManifestResourceNames().Where(a => a.EndsWith("Issue8214.xml", StringComparison.Ordinal)).FirstOrDefault();
            var tempPath        = Path.GetTempFileName();
            var destinationFile = Path.GetTempFileName();

            using (var outputStream = new StreamWriter(tempPath))
                using (var sampleStream = new StreamReader(GetType().Assembly.GetManifestResourceStream(name)))
                {
                    string line;
                    while ((line = sampleStream.ReadLine()) != null)
                    {
                        outputStream.WriteLine(line);
                    }
                }
            var(resultLine, failed) = _resultParser.GenerateHumanReadableResults(tempPath, destinationFile, XmlResultJargon.NUnitV3);
            Assert.True(failed, "failed");
            Assert.Equal(expectedResultLine, resultLine);
            // verify that the destination does contain the result line
            string resultLineInDestinationFile = null;

            using (var resultReader = new StreamReader(destinationFile))
            {
                string line;
                while ((line = resultReader.ReadLine()) != null)
                {
                    if (line.Contains("Tests run:"))
                    {
                        resultLineInDestinationFile = line;
                        break;
                    }
                }
            }
            Assert.NotNull(resultLineInDestinationFile);
            Assert.Equal(expectedResultLine, resultLineInDestinationFile);
        }
예제 #2
0
        public void HumanReadableResultsTest(string xmlFile, bool expectedFailure, string expectedResultLine, string [] additionalLines = null)
        {
            // get the sample xml to parse
            var name = GetType().Assembly.GetManifestResourceNames().Where(a => a.EndsWith(xmlFile, StringComparison.Ordinal)).FirstOrDefault();

            using var validXmlSource = new StreamReader(GetType().Assembly.GetManifestResourceStream(name));
            using var source         = new StreamReader(GetType().Assembly.GetManifestResourceStream(name));
            using var destination    = new StringWriter();

            // Get the xml type
            Assert.IsTrue(resultParser.IsValidXml(validXmlSource, out var type), "Valid Xml");

            // generate the results
            var(resultLine, failed) = resultParser.GenerateHumanReadableResults(source, destination, type);
            var output = destination.ToString();

            Assert.AreEqual(expectedFailure, failed, "failed");
            Assert.AreEqual(expectedResultLine, resultLine, "result line");

            if (additionalLines != null)
            {
                var lines = output.Split('\n');
                foreach (var line in additionalLines)
                {
                    Assert.That(lines, Does.Contain(line), "Expected line");
                }
            }

            if (expectedFailure)
            {
                Assert.That(output, Does.Contain("[FAIL]"), "FAIL");
            }
            else
            {
                Assert.That(output, Does.Not.Contain("[FAIL]"), "Not FAIL");
            }
        }