Skip to content

Commit

Permalink
Include faulty adapter path in message (#992)
Browse files Browse the repository at this point in the history
  • Loading branch information
Faizan2304 committed Aug 14, 2017
1 parent 069e859 commit e2d4651
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public TestAdapterPathArgumentExecutor(CommandLineOptions options, IRunSettingsP
/// <param name="argument">Argument that was provided with the command.</param>
public void Initialize(string argument)
{
string invalidAdapterPathArgument = argument;

if (string.IsNullOrWhiteSpace(argument))
{
throw new CommandLineException(
Expand Down Expand Up @@ -181,6 +183,7 @@ public void Initialize(string argument)

if (!this.fileHelper.DirectoryExists(testAdapterFullPath))
{
invalidAdapterPathArgument = testadapterPath;
throw new DirectoryNotFoundException(CommandLineResources.TestAdapterPathDoesNotExist);
}

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,40 @@ public void InitializeShouldMergeTestAdapterPathsInRunSettingsIgnoringDuplicateP
Assert.AreEqual("d:\\users;c:\\users", runConfiguration.TestAdaptersPaths);
}

[TestMethod]
public void InitializeShouldAddRightAdapterPathInErrorMessage()
{
var runSettingsXml = "<RunSettings><RunConfiguration><TestAdaptersPaths>d:\\users</TestAdaptersPaths></RunConfiguration></RunSettings>";
var runSettings = new RunSettings();
runSettings.LoadSettingsXml(runSettingsXml);
RunSettingsManager.Instance.SetActiveRunSettings(runSettings);
var mockFileHelper = new Mock<IFileHelper>();
var mockOutput = new Mock<IOutput>();

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
Expand Down

0 comments on commit e2d4651

Please sign in to comment.