Skip to content

Commit

Permalink
fixed paths duplicates (#3907)
Browse files Browse the repository at this point in the history
  • Loading branch information
engyebrahim committed Aug 1, 2022
1 parent f3b91eb commit bb9a1b8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ internal class InProcDataCollectionExtensionManager

private readonly IDataCollectionSink _inProcDataCollectionSink;
private readonly string? _defaultCodeBase;
private readonly List<string?> _codeBasePaths;
internal /* for testing purposes */ readonly HashSet<string?> CodeBasePaths;
private readonly IFileHelper _fileHelper;

internal IDictionary<string, IInProcDataCollector> InProcDataCollectors;
Expand Down Expand Up @@ -61,13 +61,13 @@ protected InProcDataCollectionExtensionManager(string? runSettings, ITestEventsP
_inProcDataCollectionSink = new InProcDataCollectionSink();
_defaultCodeBase = defaultCodeBase;
_fileHelper = fileHelper;
_codeBasePaths = new List<string?> { _defaultCodeBase };
CodeBasePaths = new HashSet<string?>(StringComparer.OrdinalIgnoreCase) { _defaultCodeBase };

// Get Datacollector code base paths from test plugin cache
var extensionPaths = testPluginCache.GetExtensionPaths(DataCollectorEndsWithPattern);
foreach (var extensionPath in extensionPaths)
{
_codeBasePaths.Add(Path.GetDirectoryName(extensionPath)!);
CodeBasePaths.Add(Path.GetDirectoryName(extensionPath)!);
}

// Initialize InProcDataCollectors
Expand Down Expand Up @@ -248,7 +248,7 @@ private string GetCodebase(string codeBase)
return codeBase;
}

foreach (var extensionPath in _codeBasePaths)
foreach (var extensionPath in CodeBasePaths)
{
if (extensionPath is null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Reflection;
using System.Xml;

using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection;
using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.DataCollection.Interfaces;
Expand Down Expand Up @@ -53,6 +54,26 @@ public InProcDataCollectionExtensionManagerTests()
_inProcDataCollectionManager = new TestableInProcDataCollectionExtensionManager(_settingsXml, _mockTestEventsPublisher.Object, _defaultCodebase, _testPluginCache, _mockFileHelper.Object);
}

[TestMethod]
public void CodeBasePathsAreDeduplicatedWithCaseIgnoring()
{
var testPluginCache = new TestableTestPluginCache();
// the boolean argument refers to adding the paths to which list(we have two lists)and the duplicate happened when we merged the two lists and they had the same path
testPluginCache.UpdateExtensions(new List<string> { Path.Combine(Temp, "DEDUPLICATINGWITHCASEIGNORING1", "Collector.dll") }, false);
var directory1 = Path.Combine(Temp, "DeduplicatingWithCaseIgnoring1");
var directory2 = Path.Combine(Temp, "DeduplicatingWithCaseIgnoring2");
testPluginCache.UpdateExtensions(new List<string> { Path.Combine(directory1, "Collector.dll"), Path.Combine(directory2, "Collector.dll") }, true);

var inProcDataCollectionExtensionManager = new TestableInProcDataCollectionExtensionManager(_settingsXml, _mockTestEventsPublisher.Object, null, testPluginCache, _mockFileHelper.Object);

Assert.AreEqual(3, inProcDataCollectionExtensionManager.CodeBasePaths.Count); // "CodeBasePaths" contains the two extensions(after removing duplicates) and the "_defaultCodebase"

Assert.IsTrue(inProcDataCollectionExtensionManager.CodeBasePaths.Contains(null));
Assert.IsTrue(inProcDataCollectionExtensionManager.CodeBasePaths.Contains(directory1));
Assert.IsTrue(inProcDataCollectionExtensionManager.CodeBasePaths.Contains(directory2));
}


[TestMethod]
public void InProcDataCollectionExtensionManagerShouldLoadsDataCollectorsFromRunSettings()
{
Expand Down Expand Up @@ -275,7 +296,7 @@ public void TriggerTestCaseEndShouldtBeCalledMultipleTimesInDataDrivenScenario()

internal class TestableInProcDataCollectionExtensionManager : InProcDataCollectionExtensionManager
{
public TestableInProcDataCollectionExtensionManager(string runSettings, ITestEventsPublisher mockTestEventsPublisher, string defaultCodebase, TestPluginCache testPluginCache, IFileHelper fileHelper)
public TestableInProcDataCollectionExtensionManager(string runSettings, ITestEventsPublisher mockTestEventsPublisher, string? defaultCodebase, TestPluginCache testPluginCache, IFileHelper fileHelper)
: base(runSettings, mockTestEventsPublisher, defaultCodebase, testPluginCache, fileHelper)
{
}
Expand Down

0 comments on commit bb9a1b8

Please sign in to comment.