From a12f543a3678685b491de6faf56e73579a85c0dc Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Feb 2021 08:48:56 +0100 Subject: [PATCH 1/2] Generating cc attachments with correct uri --- .../DataCollection/DataCollectionAttachmentManager.cs | 4 +--- src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs | 6 ++++++ .../CodeCoverageDataAttachmentsHandler.cs | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs index 953c79974c..cfbf1d4057 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs @@ -328,11 +328,9 @@ private void AddNewFileTransfer(FileTransferInformation fileTransferInfo, AsyncC { if (t.Exception == null) { - // Uri doesn't recognize file paths in unix. See https://github.com/dotnet/corefx/issues/1745 - var attachmentUri = new UriBuilder() { Scheme = "file", Host = "", Path = localFilePath }.Uri; lock (attachmentTaskLock) { - this.AttachmentSets[fileTransferInfo.Context][uri].Attachments.Add(new UriDataAttachment(attachmentUri, fileTransferInfo.Description)); + this.AttachmentSets[fileTransferInfo.Context][uri].Attachments.Add(new UriDataAttachment(localFilePath, fileTransferInfo.Description)); } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs b/src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs index 3f2b043b90..bb274870d9 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs @@ -73,6 +73,12 @@ public UriDataAttachment(Uri uri, string description) Description = description; } + public UriDataAttachment(string localFilePath, string description) + { + Uri = new UriBuilder() { Scheme = "file", Host = "", Path = localFilePath }.Uri; + Description = description; + } + public override string ToString() { return $"{nameof(Uri)}: {Uri.AbsoluteUri}, {nameof(Description)}: {Description}"; diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 9e9d559190..2c8ecea5f2 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -59,11 +59,11 @@ public async Task> ProcessAttachmentSetsAsync(ICollec if (!string.IsNullOrEmpty(mergedCoverageReportFilePath)) { var resultAttachmentSet = new AttachmentSet(CodeCoverageDataCollectorUri, CoverageFriendlyName); - resultAttachmentSet.Attachments.Add(new UriDataAttachment(new Uri(mergedCoverageReportFilePath), CoverageFriendlyName)); + resultAttachmentSet.Attachments.Add(new UriDataAttachment(mergedCoverageReportFilePath, CoverageFriendlyName)); foreach (var coverageOtherFilePath in coverageOtherFilePaths) { - resultAttachmentSet.Attachments.Add(new UriDataAttachment(new Uri(coverageOtherFilePath), string.Empty)); + resultAttachmentSet.Attachments.Add(new UriDataAttachment(coverageOtherFilePath, string.Empty)); } return new Collection { resultAttachmentSet }; From 1d740b94d0f5de7e6f297a023a9597f1d104343c Mon Sep 17 00:00:00 2001 From: Jakub Chocholowicz Date: Tue, 16 Feb 2021 09:25:28 +0100 Subject: [PATCH 2/2] Remove constructor --- .../DataCollection/DataCollectionAttachmentManager.cs | 2 +- .../AttachmentSet.cs | 10 +++++----- .../CodeCoverageDataAttachmentsHandler.cs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs index cfbf1d4057..29e7325482 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionAttachmentManager.cs @@ -330,7 +330,7 @@ private void AddNewFileTransfer(FileTransferInformation fileTransferInfo, AsyncC { lock (attachmentTaskLock) { - this.AttachmentSets[fileTransferInfo.Context][uri].Attachments.Add(new UriDataAttachment(localFilePath, fileTransferInfo.Description)); + this.AttachmentSets[fileTransferInfo.Context][uri].Attachments.Add(UriDataAttachment.CreateFrom(localFilePath, fileTransferInfo.Description)); } } diff --git a/src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs b/src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs index bb274870d9..3cdd52665a 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/AttachmentSet.cs @@ -73,15 +73,15 @@ public UriDataAttachment(Uri uri, string description) Description = description; } - public UriDataAttachment(string localFilePath, string description) + public override string ToString() { - Uri = new UriBuilder() { Scheme = "file", Host = "", Path = localFilePath }.Uri; - Description = description; + return $"{nameof(Uri)}: {Uri.AbsoluteUri}, {nameof(Description)}: {Description}"; } - public override string ToString() + public static UriDataAttachment CreateFrom(string localFilePath, string description) { - return $"{nameof(Uri)}: {Uri.AbsoluteUri}, {nameof(Description)}: {Description}"; + var uri = new UriBuilder() { Scheme = "file", Host = "", Path = localFilePath }.Uri; + return new UriDataAttachment(uri, description); } } } diff --git a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs index 2c8ecea5f2..46cd936844 100644 --- a/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs +++ b/src/Microsoft.TestPlatform.Utilities/CodeCoverageDataAttachmentsHandler.cs @@ -59,11 +59,11 @@ public async Task> ProcessAttachmentSetsAsync(ICollec if (!string.IsNullOrEmpty(mergedCoverageReportFilePath)) { var resultAttachmentSet = new AttachmentSet(CodeCoverageDataCollectorUri, CoverageFriendlyName); - resultAttachmentSet.Attachments.Add(new UriDataAttachment(mergedCoverageReportFilePath, CoverageFriendlyName)); + resultAttachmentSet.Attachments.Add(UriDataAttachment.CreateFrom(mergedCoverageReportFilePath, CoverageFriendlyName)); foreach (var coverageOtherFilePath in coverageOtherFilePaths) { - resultAttachmentSet.Attachments.Add(new UriDataAttachment(coverageOtherFilePath, string.Empty)); + resultAttachmentSet.Attachments.Add(UriDataAttachment.CreateFrom(coverageOtherFilePath, string.Empty)); } return new Collection { resultAttachmentSet };