Ejemplo n.º 1
0
        public void CannotMakeTestResultWhenTestCaseIsNotInCache()
        {
            var fakeResultNode = FakeTestData.GetResultNode();
            var testResult     = testConverter.ConvertTestResult(fakeResultNode);

            Assert.Null(testResult);
        }
Ejemplo n.º 2
0
        public void CannotMakeTestResultWhenTestCaseIsNotInCache()
        {
            var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode());
            var results        = testConverter.GetVsTestResults(fakeResultNode, Enumerable.Empty <XmlNode>().ToList());

            Assert.That(results.TestResults.Count, Is.EqualTo(0));
        }
Ejemplo n.º 3
0
        public void CanMakeTestCaseShouldBuildTraitsCache()
        {
            var xmlNodeList = FakeTestData.GetTestNodes();

            foreach (XmlNode node in xmlNodeList)
            {
                var testCase = testConverter.ConvertTestCase(new NUnitTestCase(node));
            }

            var traitsCache = testConverter.TraitsCache;

            // There are 12 ids in the TestXml2, but will be storing only ancestor properties.
            // Not the leaf node test-case properties.
            Assert.That(traitsCache.Keys.Count, Is.EqualTo(7));

            // Even though ancestor doesn't have any properties. Will be storing their ids.
            // So that we will not make call SelectNodes call again.
            CheckNodesWithNoProperties(traitsCache);

            // Will not be storing leaf nodes test-case nodes in the cache.
            CheckNoTestCaseNodesExist(traitsCache);

            // Checking assembly level attribute.
            CheckNodeProperties(traitsCache, "0-1009", new[] { new KeyValuePair <string, string>("Category", "AsmCat") });

            // Checking Class level attributes base class & dervied class
            CheckNodeProperties(traitsCache, "0-1000", new[] { new KeyValuePair <string, string>("Category", "BaseClass") });
            CheckNodeProperties(traitsCache, "0-1002", new[] { new KeyValuePair <string, string>("Category", "DerivedClass"), new KeyValuePair <string, string>("Category", "BaseClass") });

            // Checking Nested class attributes.
            CheckNodeProperties(traitsCache, "0-1005", new[] { new KeyValuePair <string, string>("Category", "NS1") });
            CheckNodeProperties(traitsCache, "0-1007", new[] { new KeyValuePair <string, string>("Category", "NS2") });
        }
Ejemplo n.º 4
0
        public void CannotMakeTestResultWhenTestCaseIsNotInCache()
        {
            var fakeResultNode = FakeTestData.GetResultNode();
            var results        = testConverter.GetVSTestResults(fakeResultNode);

            Assert.That(results.Count, Is.EqualTo(0));
        }
        public void Attachments_CorrectAmountOfConvertedAttachments()
        {
            var cachedTestCase = testConverter.ConvertTestCase(fakeTestNode);
            var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode());

            var testResults = testConverter.GetVsTestResults(fakeResultNode, Enumerable.Empty <INUnitTestEventTestOutput>().ToList());

            var fakeAttachments = fakeResultNode.NUnitAttachments
                                  .Where(n => !string.IsNullOrEmpty(n.FilePath))
                                  .ToArray();

            TestContext.Out.WriteLine("Incoming attachments");
            foreach (var attachment in fakeAttachments)
            {
                TestContext.Out.WriteLine($"{attachment.FilePath}");
            }
            var convertedAttachments = testResults.TestResults
                                       .SelectMany(tr => tr.Attachments.SelectMany(ats => ats.Attachments))
                                       .ToArray();

            TestContext.Out.WriteLine("\nConverted attachments (Uri, path)");
            foreach (var attachment in convertedAttachments)
            {
                TestContext.Out.WriteLine($"{attachment.Uri.AbsoluteUri} : {attachment.Uri.LocalPath}");
            }
            Assert.Multiple(() =>
            {
                Assert.That(convertedAttachments.Length, Is.GreaterThan(0), "Some converted attachments were expected");
                Assert.That(convertedAttachments.Length, Is.EqualTo(fakeAttachments.Length), "Attachments are not converted");
            });
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            fakeTestNode = FakeTestData.GetTestNode();
            var settings = Substitute.For <IAdapterSettings>();

            settings.CollectSourceInformation.Returns(true);
            testConverter = new TestConverter(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, settings);
        }
Ejemplo n.º 7
0
 public void TestFinished_CallsRecordEnd_Then_RecordResult()
 {
     listener.TestFinished(new NUnitTestEventTestCase(FakeTestData.GetResultNode().AsString()));
     Assert.That(testLog.Events.Count, Is.EqualTo(2));
     Assert.That(testLog.Events[0].EventType, Is.EqualTo(FakeFrameworkHandle.EventType.RecordEnd));
     Assert.That(
         testLog.Events[1].EventType, Is.EqualTo(FakeFrameworkHandle.EventType.RecordResult));
 }
Ejemplo n.º 8
0
        public void TestFinished_CallsRecordResultCorrectly()
        {
            listener.TestFinished(new NUnitTestEventTestCase(FakeTestData.GetResultNode().AsString()));
            Assume.That(testLog.Events.Count, Is.EqualTo(2));
            Assume.That(testLog.Events[1].EventType, Is.EqualTo(FakeFrameworkHandle.EventType.RecordResult));

            VerifyTestResult(testLog.Events[1].TestResult);
        }
        public void TestFinished_CallsRecordEndCorrectly()
        {
            listener.TestFinished(new NUnitTestEventTestCase(FakeTestData.GetResultNode().AsString()));
            Assume.That(testLog.Events.Count, Is.EqualTo(2));
            Assume.That(testLog.Events[0].EventType, Is.EqualTo(FakeFrameworkHandle.EventType.RecordEnd));

            VerifyTestCase(testLog.Events[0].TestCase);
            Assert.AreEqual(TestOutcome.Passed, testLog.Events[0].TestOutcome);
        }
Ejemplo n.º 10
0
        public void SetUp()
        {
            fakeTestNode = new NUnitTestCase(FakeTestData.GetTestNode());
            var settings = Substitute.For <IAdapterSettings>();

            settings.ConsoleOut.Returns(0);
            settings.UseTestNameInConsoleOutput.Returns(false);
            settings.CollectSourceInformation.Returns(true);
            testConverter = new TestConverter(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, settings);
        }
Ejemplo n.º 11
0
 public void TestFinished_CallsRecordEnd_Then_RecordResult()
 {
     listener.TestFinished(FakeTestData.GetResultNode());
     Assert.AreEqual(2, testLog.Events.Count);
     Assert.AreEqual(
         FakeFrameworkHandle.EventType.RecordEnd,
         testLog.Events[0].EventType);
     Assert.AreEqual(
         FakeFrameworkHandle.EventType.RecordResult,
         testLog.Events[1].EventType);
 }
Ejemplo n.º 12
0
        public void CanMakeTestResultFromNUnitTestResult2(string output, string expectedMessages)
        {
            var cachedTestCase = testConverter.ConvertTestCase(fakeTestNode);
            var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode());
            var outputNodes    = output.Split(';').Select(i => XmlHelper.CreateXmlNode(i.Trim())).ToList();
            var testResults    = testConverter.GetVsTestResults(fakeResultNode, outputNodes);
            var testResult     = testResults.TestResults[0];
            var actualMessages = string.Join(";", testResult.Messages.Select(i => i.Category + ":" + i.Text));

            Assert.That(actualMessages, Is.EqualTo(expectedMessages));
        }
Ejemplo n.º 13
0
        public void SetUp()
        {
            testLog       = new FakeFrameworkHandle();
            testConverter = new TestConverter(new TestLogger(new MessageLoggerStub(), 0), FakeTestData.AssemblyPath);
            fakeTestNode  = FakeTestData.GetTestNode();

            // Ensure that the converted testcase is cached
            testConverter.ConvertTestCase(fakeTestNode);
            Assert.NotNull(testConverter.GetCachedTestCase("123"));

            listener = new NUnitEventListener(testLog, testConverter);
        }
        public void SetUp()
        {
            testLog = new FakeFrameworkHandle();

            using (var testConverter = new TestConverter(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, collectSourceInformation: true))
            {
                fakeTestNode = FakeTestData.GetTestNode();

                // Ensure that the converted testcase is cached
                testConverter.ConvertTestCase(fakeTestNode);
                Assert.NotNull(testConverter.GetCachedTestCase("123"));

                listener = new NUnitEventListener(testLog, testConverter, null);
            }
        }
Ejemplo n.º 15
0
        public void SetUp()
        {
            testLog  = new FakeFrameworkHandle();
            settings = Substitute.For <IAdapterSettings>();
            executor = Substitute.For <INUnit3TestExecutor>();
            executor.Settings.Returns(settings);
            executor.FrameworkHandle.Returns(testLog);
            settings.CollectSourceInformation.Returns(true);
            using var testConverter = new TestConverterForXml(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, settings);
            fakeTestNode            = new NUnitEventTestCase(FakeTestData.GetTestNode());

            // Ensure that the converted testcase is cached
            testConverter.ConvertTestCase(fakeTestNode);
            Assert.That(testConverter.GetCachedTestCase("123"), Is.Not.Null);

            listener = new NUnitEventListener(testConverter, executor);
        }
        public void CanMakeTestCaseShouldBuildTraitsCache()
        {
            var xmlNodeList = FakeTestData.GetTestNodes();
            var tf          = Substitute.For <INUnitDiscoveryCanHaveTestCases>();

            foreach (XmlNode node in xmlNodeList)
            {
                var xElem    = XElement.Load(node.CreateNavigator().ReadSubtree());
                var tc       = DiscoveryConverter.ExtractTestCase(tf, xElem);
                var testCase = testConverter.ConvertTestCase(tc);
            }

            var traitsCache = testConverter.TraitsCache;

            Assert.Multiple(() =>
            {
                // There are 12 ids in the TestXml2, but will be storing only ancestor properties.
                // Not the leaf node test-case properties.
                Assert.That(traitsCache.Keys.Count, Is.EqualTo(7));

                // Even though ancestor doesn't have any properties. Will be storing their ids.
                // So that we will not make call SelectNodes call again.
                CheckNodesWithNoProperties(traitsCache);

                // Will not be storing leaf nodes test-case nodes in the cache.
                CheckNoTestCaseNodesExist(traitsCache);

                // Checking assembly level attribute.
                CheckNodeProperties(traitsCache, "0-1009",
                                    new[] { new KeyValuePair <string, string>("Category", "AsmCat") });

                // Checking Class level attributes base class & dervied class
                CheckNodeProperties(traitsCache, "0-1000",
                                    new[] { new KeyValuePair <string, string>("Category", "BaseClass") });
                CheckNodeProperties(traitsCache, "0-1002",
                                    new[]
                {
                    new KeyValuePair <string, string>("Category", "DerivedClass"),
                    new KeyValuePair <string, string>("Category", "BaseClass")
                });

                // Checking Nested class attributes.
                CheckNodeProperties(traitsCache, "0-1005", new[] { new KeyValuePair <string, string>("Category", "NS1") });
                CheckNodeProperties(traitsCache, "0-1007", new[] { new KeyValuePair <string, string>("Category", "NS2") });
            });
        }
Ejemplo n.º 17
0
        public void CanMakeTestResultFromNUnitTestResult()
        {
            // This should put the TestCase in the cache
            var cachedTestCase = testConverter.ConvertTestCase(fakeTestNode);
            var fakeResultNode = FakeTestData.GetResultNode();

            var testResult = testConverter.ConvertTestResult(fakeResultNode);
            var testCase   = testResult.TestCase;

            Assert.That(testCase, Is.SameAs(cachedTestCase));

            CheckTestCase(testCase);

            Assert.That(testResult.Outcome, Is.EqualTo(TestOutcome.Passed));
            Assert.That(testResult.ErrorMessage, Is.EqualTo("It passed!"));
            Assert.That(testResult.Duration, Is.EqualTo(TimeSpan.FromSeconds(1.234)));
        }
Ejemplo n.º 18
0
        public void CanMakeTestResultFromNUnitTestResult()
        {
            // This should put the TestCase in the cache
            var cachedTestCase = testConverter.ConvertTestCase(fakeTestNode);
            var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode());

            var testResults = testConverter.GetVsTestResults(fakeResultNode, Enumerable.Empty <XmlNode>().ToList());
            var testResult  = testResults.TestResults[0];
            var testCase    = testResult.TestCase;

            Assert.That(testCase, Is.SameAs(cachedTestCase));

            CheckTestCase(testCase);

            Assert.That(testResult.Outcome, Is.EqualTo(TestOutcome.Passed));
            Assert.That(testResult.ErrorMessage, Is.EqualTo(null));
            Assert.That(testResult.Duration, Is.EqualTo(TimeSpan.FromSeconds(1.234)));
        }
Ejemplo n.º 19
0
        public void Attachments_AllFilePathesStartWithFileScheme()
        {
            const string fileUriScheme = "file://";
            const string errorMessage  = "Path must start with file:// uri scheme";

            var cachedTestCase = testConverter.ConvertTestCase(fakeTestNode);
            var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode().AsString());

            var testResults = testConverter.GetVsTestResults(fakeResultNode, Enumerable.Empty <XmlNode>().ToList());

            var convertedAttachments = testResults.TestResults
                                       .SelectMany(tr => tr.Attachments.SelectMany(ats => ats.Attachments))
                                       .ToArray();

            foreach (var attachment in convertedAttachments)
            {
                var originalPath = attachment.Uri.OriginalString;
                Assert.That(originalPath.LastIndexOf(fileUriScheme), Is.EqualTo(0), errorMessage);
            }
        }
        public void Attachments_CorrectAmountOfConvertedAttachments()
        {
            var cachedTestCase = testConverterForXml.ConvertTestCase(fakeTestNode);
            var fakeResultNode = new NUnitTestEventTestCase(FakeTestData.GetResultNode());

            var testResults = testConverterForXml.GetVsTestResults(fakeResultNode, Enumerable.Empty <INUnitTestEventTestOutput>().ToList());

            var fakeAttachments = fakeResultNode.NUnitAttachments
                                  .Where(n => !string.IsNullOrEmpty(n.FilePath))
                                  .ToArray();

            var convertedAttachments = testResults.TestResults
                                       .SelectMany(tr => tr.Attachments.SelectMany(ats => ats.Attachments))
                                       .ToArray();

            Assert.Multiple(() =>
            {
                Assert.That(convertedAttachments.Length, Is.GreaterThan(0), "Some converted attachments were expected");
                Assert.That(convertedAttachments.Length, Is.EqualTo(fakeAttachments.Length), "Attachments are not converted");
            });
        }
Ejemplo n.º 21
0
        public void Attachments_CorrectAmountOfConvertedAttachments()
        {
            var cachedTestCase = testConverter.ConvertTestCase(fakeTestNode);
            var fakeResultNode = FakeTestData.GetResultNode();

            var testResults = testConverter.GetVSTestResults(fakeResultNode, Enumerable.Empty <XmlNode>().ToList());

            var fakeAttachments = fakeResultNode.SelectNodes("attachments/attachment")
                                  .OfType <XmlNode>()
                                  .Where(n => !string.IsNullOrEmpty(n.SelectSingleNode("filePath")?.InnerText))
                                  .ToArray();

            var convertedAttachments = testResults.TestResults
                                       .SelectMany(tr => tr.Attachments.SelectMany(ats => ats.Attachments))
                                       .ToArray();

            Assert.Multiple(() =>
            {
                Assert.That(convertedAttachments.Length, Is.GreaterThan(0), "Some converted attachments were expected");
                Assert.That(convertedAttachments.Length, Is.EqualTo(fakeAttachments.Length), "Attachments are not converted");
            });
        }
Ejemplo n.º 22
0
 public void SetUp()
 {
     fakeTestNode  = FakeTestData.GetTestNode();
     testConverter = new TestConverter(new TestLogger(new MessageLoggerStub()), FakeTestData.AssemblyPath, collectSourceInformation: true);
 }
Ejemplo n.º 23
0
 public void SetUp()
 {
     fakeTestNode  = FakeTestData.GetTestNode();
     testConverter = new TestConverter(new TestLogger(new MessageLoggerStub(), 0), FakeTestData.AssemblyPath);
 }