From e2d4651196d1f6dac1c43b27dd73387578cae333 Mon Sep 17 00:00:00 2001 From: Faizan2304 Date: Tue, 15 Aug 2017 00:34:58 +0530 Subject: [PATCH] Include faulty adapter path in message (#992) --- .../TestAdapterPathArgumentProcessor.cs | 5 ++- .../TestAdapterPathArgumentProcessorTests.cs | 34 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/vstest.console/Processors/TestAdapterPathArgumentProcessor.cs b/src/vstest.console/Processors/TestAdapterPathArgumentProcessor.cs index c17b38a0be..299c78d0c0 100644 --- a/src/vstest.console/Processors/TestAdapterPathArgumentProcessor.cs +++ b/src/vstest.console/Processors/TestAdapterPathArgumentProcessor.cs @@ -149,6 +149,8 @@ public TestAdapterPathArgumentExecutor(CommandLineOptions options, IRunSettingsP /// Argument that was provided with the command. public void Initialize(string argument) { + string invalidAdapterPathArgument = argument; + if (string.IsNullOrWhiteSpace(argument)) { throw new CommandLineException( @@ -181,6 +183,7 @@ public void Initialize(string argument) if (!this.fileHelper.DirectoryExists(testAdapterFullPath)) { + invalidAdapterPathArgument = testadapterPath; throw new DirectoryNotFoundException(CommandLineResources.TestAdapterPathDoesNotExist); } @@ -197,7 +200,7 @@ public void Initialize(string argument) catch (Exception e) { throw new CommandLineException( - string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidTestAdapterPathCommand, argument, e.Message)); + string.Format(CultureInfo.CurrentCulture, CommandLineResources.InvalidTestAdapterPathCommand, invalidAdapterPathArgument, e.Message)); } this.commandLineOptions.TestAdapterPath = customAdaptersPath; diff --git a/test/vstest.console.UnitTests/Processors/TestAdapterPathArgumentProcessorTests.cs b/test/vstest.console.UnitTests/Processors/TestAdapterPathArgumentProcessorTests.cs index 55be4fee76..ce6a088662 100644 --- a/test/vstest.console.UnitTests/Processors/TestAdapterPathArgumentProcessorTests.cs +++ b/test/vstest.console.UnitTests/Processors/TestAdapterPathArgumentProcessorTests.cs @@ -210,6 +210,40 @@ public void InitializeShouldMergeTestAdapterPathsInRunSettingsIgnoringDuplicateP Assert.AreEqual("d:\\users;c:\\users", runConfiguration.TestAdaptersPaths); } + [TestMethod] + public void InitializeShouldAddRightAdapterPathInErrorMessage() + { + var runSettingsXml = "d:\\users"; + var runSettings = new RunSettings(); + runSettings.LoadSettingsXml(runSettingsXml); + RunSettingsManager.Instance.SetActiveRunSettings(runSettings); + var mockFileHelper = new Mock(); + var mockOutput = new Mock(); + + mockFileHelper.Setup(x => x.DirectoryExists("d:\\users")).Returns(false); + mockFileHelper.Setup(x => x.DirectoryExists("c:\\users")).Returns(true); + var executor = new TestAdapterPathArgumentExecutor(CommandLineOptions.Instance, RunSettingsManager.Instance, mockOutput.Object, mockFileHelper.Object); + + var message = string.Format( + @"The path '{0}' specified in the 'TestAdapterPath' is invalid. Error: {1}", + "d:\\users", + "The custom test adapter search path provided was not found, provide a valid path and try again."); + + var isExceptionThrown = false; + try + { + executor.Initialize("c:\\users"); + } + catch (Exception ex) + { + isExceptionThrown = true; + Assert.IsTrue(ex is CommandLineException); + Assert.AreEqual(message, ex.Message); + } + + Assert.IsTrue(isExceptionThrown); + } + #endregion #region Testable implementations