diff --git a/src/NUnitTestAdapter/TestConverter.cs b/src/NUnitTestAdapter/TestConverter.cs index c1172f1c..9e8122d1 100644 --- a/src/NUnitTestAdapter/TestConverter.cs +++ b/src/NUnitTestAdapter/TestConverter.cs @@ -240,6 +240,7 @@ private VSTestResult GetBasicResult(XmlNode resultNode) /// attachments to be added to the test, it will be empty if no attachments are found private AttachmentSet ParseAttachments(XmlNode resultNode) { + const string fileUriScheme = "file://"; var attachmentSet = new AttachmentSet(new Uri(NUnitTestAdapter.ExecutorUri), "Attachments"); foreach (XmlNode attachment in resultNode.SelectNodes("attachments/attachment")) @@ -247,6 +248,11 @@ private AttachmentSet ParseAttachments(XmlNode resultNode) var path = attachment.SelectSingleNode("filePath")?.InnerText ?? string.Empty; var description = attachment.SelectSingleNode("description")?.InnerText; + if ( !(string.IsNullOrEmpty(path) || path.StartsWith(fileUriScheme, StringComparison.OrdinalIgnoreCase))) + { + path = fileUriScheme + path; + } + try { // We only support absolute paths since we dont lookup working directory here diff --git a/src/NUnitTestAdapterTests/Fakes/FakeTestData.cs b/src/NUnitTestAdapterTests/Fakes/FakeTestData.cs index fb8cf83d..d0c19a16 100644 --- a/src/NUnitTestAdapterTests/Fakes/FakeTestData.cs +++ b/src/NUnitTestAdapterTests/Fakes/FakeTestData.cs @@ -8,10 +8,10 @@ // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: -// +// // The above copyright notice and this permission notice shall be // included in all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND @@ -46,7 +46,7 @@ private static void FakeTestCase() { } // LineNumber should be this line "; public const string HierarchyTestXml = @" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + "; #endregion @@ -127,7 +127,7 @@ private static void FakeTestCase() { } // LineNumber should be this line It passed! + + + c:\results\att.log + win, no scheme + + + file://c:\results\att.log + win, with scheme + + + /home/results/att.log + lin, no scheme + + + file:///home/results/att.log + lin, with scheme + + + + empty path + + "; @@ -150,12 +172,12 @@ private static void FakeTestCase() { } // LineNumber should be this line public const string FullyQualifiedName = "NUnit.VisualStudio.TestAdapter.Tests.Fakes.FakeTestData.FakeTestCase"; - public static readonly string AssemblyPath = + public static readonly string AssemblyPath = typeof(FakeTestData).GetTypeInfo().Assembly.ManifestModule.FullyQualifiedName; public static readonly string CodeFile = Path.Combine(Path.GetDirectoryName(AssemblyPath), @"..\..\..\Fakes\FakeTestData.cs"); - // NOTE: If the location of the FakeTestCase method defined + // NOTE: If the location of the FakeTestCase method defined // above changes, update the value of LineNumber. public const int LineNumber = 36; diff --git a/src/NUnitTestAdapterTests/TestConverterTests.cs b/src/NUnitTestAdapterTests/TestConverterTests.cs index 48569f5f..cd8efe87 100644 --- a/src/NUnitTestAdapterTests/TestConverterTests.cs +++ b/src/NUnitTestAdapterTests/TestConverterTests.cs @@ -147,6 +147,56 @@ public void CanMakeTestResultFromNUnitTestResult() Assert.That(testResult.Duration, Is.EqualTo(TimeSpan.FromSeconds(1.234))); } + #region Attachment tests + + [Test] + public void Attachments_CorrectAmountOfConvertedAttachments() + { + var cachedTestCase = testConverter.ConvertTestCase(fakeTestNode); + var fakeResultNode = FakeTestData.GetResultNode(); + + var testResults = testConverter.GetVSTestResults(fakeResultNode); + + var fakeAttachments = fakeResultNode.SelectNodes("attachments/attachment") + .OfType() + .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"); + }); + } + + [Test] + 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 = FakeTestData.GetResultNode(); + + var testResults = testConverter.GetVSTestResults(fakeResultNode); + + 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); + } + } + + #endregion Attachment tests + private void CheckTestCase(TestCase testCase) { Assert.That(testCase.FullyQualifiedName, Is.EqualTo(FakeTestData.FullyQualifiedName));