Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ private void AddResultSummary(XElement testRun, string resultSummaryOutcome, str
AddArtifactsToCollection(_artifactsByExtension, collectorDataEntries, runDeploymentRoot);
}

private string CopyArtifactIntoTrxDirectoryAndReturnHrefValue(FileInfo artifact, string runDeploymentRoot)
private string CopyArtifactIntoTrxDirectoryAndReturnHrefValue(FileInfo artifact, string runDeploymentRoot, string? relativeResultsDirectory = null)
{
string artifactDirectory = CreateOrGetTrxArtifactDirectory(runDeploymentRoot);
string artifactDirectory = CreateOrGetTrxArtifactDirectory(runDeploymentRoot, relativeResultsDirectory);
string fileName = artifact.Name;

string destination = Path.Combine(artifactDirectory, fileName);
Expand All @@ -386,9 +386,11 @@ private string CopyArtifactIntoTrxDirectoryAndReturnHrefValue(FileInfo artifact,
return Path.Combine(_environment.MachineName, Path.GetFileName(destination));
}

private string CreateOrGetTrxArtifactDirectory(string runDeploymentRoot)
private string CreateOrGetTrxArtifactDirectory(string runDeploymentRoot, string? relativeResultsDirectory = null)
{
string directoryName = Path.Combine(_configuration.GetTestResultDirectory(), runDeploymentRoot, "In", _environment.MachineName);
string directoryName = relativeResultsDirectory is null
? Path.Combine(_configuration.GetTestResultDirectory(), runDeploymentRoot, "In", _environment.MachineName)
: Path.Combine(_configuration.GetTestResultDirectory(), runDeploymentRoot, "In", relativeResultsDirectory, _environment.MachineName);
if (!Directory.Exists(directoryName))
{
Directory.CreateDirectory(directoryName);
Expand Down Expand Up @@ -580,7 +582,7 @@ private SummaryCounts AddResults(TestNodeUpdateMessage[] testNodeUpdateMessages,
{
resultFiles ??= new XElement("ResultFiles");

string href = CopyArtifactIntoTrxDirectoryAndReturnHrefValue(testFileArtifact.FileInfo, runDeploymentRoot);
string href = CopyArtifactIntoTrxDirectoryAndReturnHrefValue(testFileArtifact.FileInfo, runDeploymentRoot, executionId);
resultFiles.Add(new XElement(
"ResultFile",
new XAttribute("path", href)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,8 @@ public async Task TrxReportEngine_GenerateReportAsync_WithArtifactsByTestNode_Tr
Assert.IsNotNull(memoryStream.TrxContent);
XDocument xml = memoryStream.TrxContent;
AssertTrxOutcome(xml, "Completed");
string relativeResultsDirectory = xml.Descendants().Single(x => x.Name.LocalName == "UnitTestResult").Attribute("relativeResultsDirectory")!.Value;
string expectedDestinationSuffix = Path.Combine("_MachineName_0001-01-01_00_00_00.0000000", "In", relativeResultsDirectory, "MachineName", "fileName");
string trxContent = xml.ToString();
string trxContentsPattern = @"
<UnitTestResult .* testName=""TestMethod"" .* outcome=""Passed"" .*>
Expand All @@ -478,6 +480,13 @@ public async Task TrxReportEngine_GenerateReportAsync_WithArtifactsByTestNode_Tr
</UnitTestResult>
";
Assert.IsTrue(Regex.IsMatch(trxContent, trxContentsPattern));
_fileSystem.Verify(
x => x.CopyFile(
It.Is<string>(source => source.EndsWith("fileName", StringComparison.Ordinal)),
It.Is<string>(destination => destination.EndsWith(
expectedDestinationSuffix,
StringComparison.Ordinal))),
Times.Once);
}

[TestMethod]
Expand Down
Loading