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

Include faulty testAdapterPath name in error message #992

Merged
merged 2 commits into from
Aug 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we not use Assert.ThrowsException<> ?

}
catch (Exception ex)
{
isExceptionThrown = true;
Assert.IsTrue(ex is CommandLineException);
Assert.AreEqual(message, ex.Message);
}

Assert.IsTrue(isExceptionThrown);
}

#endregion

#region Testable implementations
Expand Down