From e9d2ddaf9fa39db0fcf54a46a2c41cbd4c84f633 Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Fri, 10 May 2019 17:24:29 +0530 Subject: [PATCH 1/6] DataCollector Search in output directory --- .../DataCollectionRequestHandler.cs | 35 +++++++++++------- .../DataCollectionRequestHandlerTests.cs | 36 +++++++++++++++++-- .../TestableDataCollectionRequestHandler.cs | 5 +-- 3 files changed, 58 insertions(+), 18 deletions(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs index 62b1c088b1..62fc507c90 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs @@ -7,6 +7,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollect using System.Collections.Generic; using System.Globalization; using System.IO; + using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -25,7 +26,7 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollect using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; - + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using CommunicationUtilitiesResources = Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Resources.Resources; using CoreUtilitiesConstants = Microsoft.VisualStudio.TestPlatform.CoreUtilities.Constants; @@ -48,6 +49,8 @@ internal class DataCollectionRequestHandler : IDataCollectionRequestHandler, IDi private IDataSerializer dataSerializer; + private IFileHelper fileHelper; + /// /// Use to cancel data collection test case events monitoring if test run is cancelled. /// @@ -65,7 +68,8 @@ protected DataCollectionRequestHandler(IMessageSink messageSink) messageSink, DataCollectionManager.Create(messageSink), new DataCollectionTestCaseEventHandler(), - JsonDataSerializer.Instance) + JsonDataSerializer.Instance, + new FileHelper()) { this.messageSink = messageSink; } @@ -88,12 +92,16 @@ protected DataCollectionRequestHandler(IMessageSink messageSink) /// /// Serializer for serialization and deserialization of the messages. /// + /// + /// File Helper + /// protected DataCollectionRequestHandler( ICommunicationManager communicationManager, IMessageSink messageSink, IDataCollectionManager dataCollectionManager, IDataCollectionTestCaseEventHandler dataCollectionTestCaseEventHandler, - IDataSerializer dataSerializer) + IDataSerializer dataSerializer, + IFileHelper fileHelper) { this.communicationManager = communicationManager; this.messageSink = messageSink; @@ -101,6 +109,7 @@ protected DataCollectionRequestHandler( this.dataSerializer = dataSerializer; this.dataCollectionTestCaseEventHandler = dataCollectionTestCaseEventHandler; this.cancellationTokenSource = new CancellationTokenSource(); + this.fileHelper = fileHelper; } /// @@ -137,7 +146,8 @@ public static DataCollectionRequestHandler Create( messageSink, DataCollectionManager.Create(messageSink), new DataCollectionTestCaseEventHandler(), - JsonDataSerializer.Instance); + JsonDataSerializer.Instance, + new FileHelper()); } } } @@ -228,31 +238,30 @@ public void Close() /// /// Update the test adapter paths provided through run settings to be used by the test plugin cache. /// - /// - /// The run Settings. + /// + /// The before test run start payload /// - private void AddExtensionAssemblies(string runSettings) + private void AddExtensionAssemblies(BeforeTestRunStartPayload payload) { try { - IEnumerable customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(runSettings); + IEnumerable customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(payload.SettingsXml); + customTestAdaptersPaths = customTestAdaptersPaths.Concat(payload.Sources.Select(x => Path.GetDirectoryName(x)).Distinct()); if (customTestAdaptersPaths != null) { - var fileHelper = new FileHelper(); - List extensionAssemblies = new List(); foreach (var customTestAdaptersPath in customTestAdaptersPaths) { var adapterPath = Path.GetFullPath(Environment.ExpandEnvironmentVariables(customTestAdaptersPath)); - if (!fileHelper.DirectoryExists(adapterPath)) + if (!this.fileHelper.DirectoryExists(adapterPath)) { EqtTrace.Warning(string.Format("AdapterPath Not Found:", adapterPath)); continue; } extensionAssemblies.AddRange( - fileHelper.EnumerateFiles( + this.fileHelper.EnumerateFiles( adapterPath, SearchOption.AllDirectories, TestPlatformConstants.DataCollectorEndsWithPattern)); @@ -278,7 +287,7 @@ private void HandleBeforeTestRunStart(Message message) { // Initialize datacollectors and get enviornment variables. var payload = this.dataSerializer.DeserializePayload(message); - this.AddExtensionAssemblies(payload.SettingsXml); + this.AddExtensionAssemblies(payload); var envVariables = this.dataCollectionManager.InitializeDataCollectors(payload.SettingsXml); diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs index b70096adb2..42823de4c2 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs @@ -4,16 +4,16 @@ namespace Microsoft.TestPlatform.CommunicationUtilities.UnitTests { using System; - using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; - using System.Globalization; + using System.IO; using System.Linq; using System.Net; using Microsoft.TestPlatform.CommunicationUtilities.UnitTests.TestDoubles; using Microsoft.VisualStudio.TestPlatform.Common.DataCollection; using Microsoft.VisualStudio.TestPlatform.Common.DataCollector.Interfaces; + using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; @@ -21,6 +21,7 @@ namespace Microsoft.TestPlatform.CommunicationUtilities.UnitTests using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -39,6 +40,7 @@ public class DataCollectionRequestHandlerTests private Mock mockDataCollectionTestCaseEventHandler; private TestableDataCollectionRequestHandler requestHandler; private Mock mockDataSerializer; + private Mock mockFileHelper; private Message afterTestRunEnd = new Message() { MessageType = MessageType.AfterTestRunEnd, Payload = "false" }; private Message beforeTestRunStart = new Message() { @@ -54,7 +56,8 @@ public DataCollectionRequestHandlerTests() this.mockDataSerializer = new Mock(); this.mockDataCollectionTestCaseEventHandler = new Mock(); this.mockDataCollectionTestCaseEventHandler.Setup(x => x.WaitForRequestHandlerConnection(It.IsAny())).Returns(true); - this.requestHandler = new TestableDataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object, this.mockDataSerializer.Object); + this.mockFileHelper = new Mock(); + this.requestHandler = new TestableDataCollectionRequestHandler(this.mockCommunicationManager.Object, this.mockMessageSink.Object, this.mockDataCollectionManager.Object, this.mockDataCollectionTestCaseEventHandler.Object, this.mockDataSerializer.Object, this.mockFileHelper.Object); this.mockCommunicationManager.SetupSequence(x => x.ReceiveMessage()).Returns(this.beforeTestRunStart).Returns(this.afterTestRunEnd); @@ -226,6 +229,33 @@ public void ProcessRequestsShouldDisposeDataCollectorsOnAfterTestRunEnd() this.mockDataCollectionManager.Verify(x => x.Dispose()); } + [TestMethod] + public void ProcessRequestsShouldAddSourceDirectoryToTestPluginCache() + { + var testHostLaunchedPayload = new TestHostLaunchedPayload(); + testHostLaunchedPayload.ProcessId = 1234; + + string runSettings = "\r\n\r\n"; + + this.mockCommunicationManager.SetupSequence(x => x.ReceiveMessage()).Returns(this.beforeTestRunStart) + .Returns(new Message() { MessageType = MessageType.TestHostLaunched, Payload = JToken.FromObject(testHostLaunchedPayload) }) + .Returns(this.afterTestRunEnd); + + this.mockDataCollectionManager.Setup(x => x.SessionStarted(It.IsAny())).Returns(true); + this.mockDataCollectionManager.Setup(x => x.TestHostLaunched(It.IsAny())); + this.mockDataSerializer.Setup(x => x.DeserializePayload(It.Is(y => y.MessageType == MessageType.TestHostLaunched))) + .Returns(testHostLaunchedPayload); + var beforeTestRunSTartPayload = new BeforeTestRunStartPayload { SettingsXml = runSettings, Sources = new List { @"E:\dir1\test1.dll", @"E:\dir2\test2.dll" } }; + this.mockDataSerializer.Setup(x => x.DeserializePayload(It.Is(y => y.MessageType == MessageType.BeforeTestRunStart))) + .Returns(beforeTestRunSTartPayload); + this.mockFileHelper.Setup(x => x.DirectoryExists(@"E:\dir1")).Returns(true); + this.mockFileHelper.Setup(x => x.EnumerateFiles(It.IsAny(), SearchOption.AllDirectories, @"Collector.dll")).Returns(new List { @"E:\dir1\abc.datacollector.dll" }); + + this.requestHandler.ProcessRequests(); + + Assert.IsTrue(TestPluginCache.Instance.GetExtensionPaths(@"Collector.dll").Contains(@"E:\dir1\abc.datacollector.dll")); + } + [TestMethod] public void ProcessRequestsShouldThrowExceptionIfThrownByCommunicationManager() { diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestDoubles/TestableDataCollectionRequestHandler.cs b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestDoubles/TestableDataCollectionRequestHandler.cs index 861f602f1f..812e68f659 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestDoubles/TestableDataCollectionRequestHandler.cs +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestDoubles/TestableDataCollectionRequestHandler.cs @@ -6,11 +6,12 @@ namespace Microsoft.TestPlatform.CommunicationUtilities.UnitTests.TestDoubles using Microsoft.VisualStudio.TestPlatform.Common.DataCollector.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; + using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; internal class TestableDataCollectionRequestHandler : DataCollectionRequestHandler { - public TestableDataCollectionRequestHandler(ICommunicationManager communicationManager, IMessageSink messageSink, IDataCollectionManager dataCollectionManager, IDataCollectionTestCaseEventHandler dataCollectionTestCaseEventHandler, IDataSerializer dataSerializer) - : base(communicationManager, messageSink, dataCollectionManager, dataCollectionTestCaseEventHandler, dataSerializer) + public TestableDataCollectionRequestHandler(ICommunicationManager communicationManager, IMessageSink messageSink, IDataCollectionManager dataCollectionManager, IDataCollectionTestCaseEventHandler dataCollectionTestCaseEventHandler, IDataSerializer dataSerializer, IFileHelper fIleHelper) + : base(communicationManager, messageSink, dataCollectionManager, dataCollectionTestCaseEventHandler, dataSerializer, fIleHelper) { } } From a5533d0a03a524b7fef3f0f0ae3cf09f8fa135a9 Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Fri, 10 May 2019 18:35:54 +0530 Subject: [PATCH 2/6] Updating type for linux failure --- .../DataCollectionRequestHandler.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs index 62fc507c90..b1935817a5 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs @@ -245,7 +245,7 @@ private void AddExtensionAssemblies(BeforeTestRunStartPayload payload) { try { - IEnumerable customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(payload.SettingsXml); + var customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(payload.SettingsXml); customTestAdaptersPaths = customTestAdaptersPaths.Concat(payload.Sources.Select(x => Path.GetDirectoryName(x)).Distinct()); if (customTestAdaptersPaths != null) { From 22eb68a3eee565d537ecb668c169e0ff2257962f Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Fri, 10 May 2019 19:02:42 +0530 Subject: [PATCH 3/6] Adding system.runtime reference --- .../Microsoft.TestPlatform.CommunicationUtilities.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj b/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj index 6dc08b7b28..1a31c26d3c 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj @@ -26,6 +26,7 @@ 4.1.1 + From 9e62d0971fdf550321337c5de7153e818b720216 Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Fri, 10 May 2019 19:13:19 +0530 Subject: [PATCH 4/6] Updating System.Runtime reference --- .../Microsoft.TestPlatform.CommunicationUtilities.csproj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj b/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj index 1a31c26d3c..e481180c92 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj @@ -17,6 +17,9 @@ + + 4.1.0 + $(JsonNetVersion) @@ -26,7 +29,6 @@ 4.1.1 - From d816fd0cd4396ac8fd48c71aa5d3b6d964407f30 Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Fri, 10 May 2019 19:31:54 +0530 Subject: [PATCH 5/6] Removing Linq query --- .../DataCollectionRequestHandler.cs | 16 +++++++++++----- ...ft.TestPlatform.CommunicationUtilities.csproj | 3 --- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs index b1935817a5..9edb0b6335 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs @@ -7,7 +7,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollect using System.Collections.Generic; using System.Globalization; using System.IO; - using System.Linq; using System.Net; using System.Threading; using System.Threading.Tasks; @@ -246,14 +245,21 @@ private void AddExtensionAssemblies(BeforeTestRunStartPayload payload) try { var customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(payload.SettingsXml); - customTestAdaptersPaths = customTestAdaptersPaths.Concat(payload.Sources.Select(x => Path.GetDirectoryName(x)).Distinct()); - if (customTestAdaptersPaths != null) + var datacollectorSearchPaths = new List(); + foreach (var source in payload.Sources) + { + datacollectorSearchPaths.Add(Path.GetDirectoryName(source)); + } + + datacollectorSearchPaths.AddRange(customTestAdaptersPaths); + + if (datacollectorSearchPaths != null) { List extensionAssemblies = new List(); - foreach (var customTestAdaptersPath in customTestAdaptersPaths) + foreach (var datacollectorSearchPath in datacollectorSearchPaths) { var adapterPath = - Path.GetFullPath(Environment.ExpandEnvironmentVariables(customTestAdaptersPath)); + Path.GetFullPath(Environment.ExpandEnvironmentVariables(datacollectorSearchPath)); if (!this.fileHelper.DirectoryExists(adapterPath)) { EqtTrace.Warning(string.Format("AdapterPath Not Found:", adapterPath)); diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj b/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj index e481180c92..6dc08b7b28 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/Microsoft.TestPlatform.CommunicationUtilities.csproj @@ -17,9 +17,6 @@ - - 4.1.0 - $(JsonNetVersion) From a5c11f808a8f2af853a258881f192ed4dbd1f09b Mon Sep 17 00:00:00 2001 From: Vagisha Nidhi Date: Mon, 13 May 2019 15:14:39 +0530 Subject: [PATCH 6/6] Review comments addressed --- .../DataCollectionRequestHandler.cs | 47 ++++++++++--------- .../DataCollectionRequestHandlerTests.cs | 8 ++-- .../TestableDataCollectionRequestHandler.cs | 3 ++ 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs index 9edb0b6335..80508b75dd 100644 --- a/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs +++ b/src/Microsoft.TestPlatform.CommunicationUtilities/DataCollectionRequestHandler.cs @@ -245,38 +245,41 @@ private void AddExtensionAssemblies(BeforeTestRunStartPayload payload) try { var customTestAdaptersPaths = RunSettingsUtilities.GetTestAdaptersPaths(payload.SettingsXml); - var datacollectorSearchPaths = new List(); + + // In case of dotnet vstest with code coverage, data collector needs to be picked up from publish folder. + // Therefore, adding source dll folders to search datacollectors in these. + var datacollectorSearchPaths = new HashSet(); foreach (var source in payload.Sources) { datacollectorSearchPaths.Add(Path.GetDirectoryName(source)); } - datacollectorSearchPaths.AddRange(customTestAdaptersPaths); + if (customTestAdaptersPaths != null) + { + datacollectorSearchPaths.UnionWith(customTestAdaptersPaths); + } - if (datacollectorSearchPaths != null) + List extensionAssemblies = new List(); + foreach (var datacollectorSearchPath in datacollectorSearchPaths) { - List extensionAssemblies = new List(); - foreach (var datacollectorSearchPath in datacollectorSearchPaths) + var adapterPath = + Path.GetFullPath(Environment.ExpandEnvironmentVariables(datacollectorSearchPath)); + if (!this.fileHelper.DirectoryExists(adapterPath)) { - var adapterPath = - Path.GetFullPath(Environment.ExpandEnvironmentVariables(datacollectorSearchPath)); - if (!this.fileHelper.DirectoryExists(adapterPath)) - { - EqtTrace.Warning(string.Format("AdapterPath Not Found:", adapterPath)); - continue; - } - - extensionAssemblies.AddRange( - this.fileHelper.EnumerateFiles( - adapterPath, - SearchOption.AllDirectories, - TestPlatformConstants.DataCollectorEndsWithPattern)); + EqtTrace.Warning(string.Format("AdapterPath Not Found:", adapterPath)); + continue; } - if (extensionAssemblies.Count > 0) - { - TestPluginCache.Instance.UpdateExtensions(extensionAssemblies, skipExtensionFilters: false); - } + extensionAssemblies.AddRange( + this.fileHelper.EnumerateFiles( + adapterPath, + SearchOption.AllDirectories, + TestPlatformConstants.DataCollectorEndsWithPattern)); + } + + if (extensionAssemblies.Count > 0) + { + TestPluginCache.Instance.UpdateExtensions(extensionAssemblies, skipExtensionFilters: false); } } catch (Exception e) diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs index 42823de4c2..d8855489a8 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/DataCollectionRequestHandlerTests.cs @@ -16,6 +16,7 @@ namespace Microsoft.TestPlatform.CommunicationUtilities.UnitTests using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection; + using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.DataCollection.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel; @@ -235,7 +236,7 @@ public void ProcessRequestsShouldAddSourceDirectoryToTestPluginCache() var testHostLaunchedPayload = new TestHostLaunchedPayload(); testHostLaunchedPayload.ProcessId = 1234; - string runSettings = "\r\n\r\n"; + string runSettings = "d:\\users;f:\\users"; this.mockCommunicationManager.SetupSequence(x => x.ReceiveMessage()).Returns(this.beforeTestRunStart) .Returns(new Message() { MessageType = MessageType.TestHostLaunched, Payload = JToken.FromObject(testHostLaunchedPayload) }) @@ -245,14 +246,15 @@ public void ProcessRequestsShouldAddSourceDirectoryToTestPluginCache() this.mockDataCollectionManager.Setup(x => x.TestHostLaunched(It.IsAny())); this.mockDataSerializer.Setup(x => x.DeserializePayload(It.Is(y => y.MessageType == MessageType.TestHostLaunched))) .Returns(testHostLaunchedPayload); - var beforeTestRunSTartPayload = new BeforeTestRunStartPayload { SettingsXml = runSettings, Sources = new List { @"E:\dir1\test1.dll", @"E:\dir2\test2.dll" } }; + var beforeTestRunSTartPayload = new BeforeTestRunStartPayload { SettingsXml = runSettings, Sources = new List { @"E:\dir1\test1.dll", @"E:\dir2\test2.dll", @"E:\dir1\test2.dll" } }; this.mockDataSerializer.Setup(x => x.DeserializePayload(It.Is(y => y.MessageType == MessageType.BeforeTestRunStart))) .Returns(beforeTestRunSTartPayload); this.mockFileHelper.Setup(x => x.DirectoryExists(@"E:\dir1")).Returns(true); - this.mockFileHelper.Setup(x => x.EnumerateFiles(It.IsAny(), SearchOption.AllDirectories, @"Collector.dll")).Returns(new List { @"E:\dir1\abc.datacollector.dll" }); + this.mockFileHelper.Setup(x => x.EnumerateFiles("E:\\dir1", SearchOption.AllDirectories, @"Collector.dll")).Returns(new List { @"E:\dir1\abc.datacollector.dll" }); this.requestHandler.ProcessRequests(); + this.mockFileHelper.Verify(x => x.EnumerateFiles("E:\\dir1", SearchOption.AllDirectories, @"Collector.dll"), Times.Once); Assert.IsTrue(TestPluginCache.Instance.GetExtensionPaths(@"Collector.dll").Contains(@"E:\dir1\abc.datacollector.dll")); } diff --git a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestDoubles/TestableDataCollectionRequestHandler.cs b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestDoubles/TestableDataCollectionRequestHandler.cs index 812e68f659..375272f712 100644 --- a/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestDoubles/TestableDataCollectionRequestHandler.cs +++ b/test/Microsoft.TestPlatform.CommunicationUtilities.UnitTests/TestDoubles/TestableDataCollectionRequestHandler.cs @@ -8,6 +8,9 @@ namespace Microsoft.TestPlatform.CommunicationUtilities.UnitTests.TestDoubles using Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.Interfaces; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; + /// + /// Testable class for DataCollectionRequestHandler since all constructors of DataCollectionRequestHandler are protected. + /// internal class TestableDataCollectionRequestHandler : DataCollectionRequestHandler { public TestableDataCollectionRequestHandler(ICommunicationManager communicationManager, IMessageSink messageSink, IDataCollectionManager dataCollectionManager, IDataCollectionTestCaseEventHandler dataCollectionTestCaseEventHandler, IDataSerializer dataSerializer, IFileHelper fIleHelper)