Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed paths duplicates #3907

Merged
merged 12 commits into from
Aug 1, 2022
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