Add WorkingDirectory to TestCommand

This commit is contained in:
piotrp 2016-03-28 03:18:13 -07:00 committed by Piotr Puszkiewicz
parent 203b56509d
commit 1a42fa05a4
2 changed files with 15 additions and 27 deletions

View file

@ -13,6 +13,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{
protected string _command;
public string WorkingDirectory { get; set; }
public Dictionary<string, string> Environment { get; } = new Dictionary<string, string>();
public TestCommand(string command)
@ -53,7 +55,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
return RunProcess(commandPath, args, stdOut, stdErr);
}
private void ResolveCommand(ref string executable, ref string args)
{
if (executable.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
@ -89,9 +91,14 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
psi.Environment[item.Key] = item.Value;
}
if (!string.IsNullOrWhiteSpace(WorkingDirectory))
{
psi.WorkingDirectory = WorkingDirectory;
}
var process = new Process
{
StartInfo = psi,
StartInfo = psi
};
process.EnableRaisingEvents = true;

View file

@ -32,21 +32,12 @@ namespace Microsoft.DotNet.Tests
.Should()
.Pass();
var currentDirectory = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(appDirectory);
CommandResult result = new PortableCommand { WorkingDirectory = appDirectory }
.ExecuteWithCapturedOutput();
try
{
CommandResult result = new PortableCommand().ExecuteWithCapturedOutput();
result.Should().HaveStdOut("Hello Portable World!" + Environment.NewLine);
result.Should().NotHaveStdErr();
result.Should().Pass();
}
finally
{
Directory.SetCurrentDirectory(currentDirectory);
}
result.Should().HaveStdOut("Hello Portable World!" + Environment.NewLine);
result.Should().NotHaveStdErr();
result.Should().Pass();
}
// need conditional theories so we can skip on non-Windows
@ -67,22 +58,12 @@ namespace Microsoft.DotNet.Tests
.Should()
.Pass();
var currentDirectory = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(appDirectory);
try
{
CommandResult result = new DependencyToolInvokerCommand()
CommandResult result = new DependencyToolInvokerCommand { WorkingDirectory = appDirectory }
.ExecuteWithCapturedOutput(framework);
result.Should().HaveStdOutContaining(framework);
result.Should().NotHaveStdErr();
result.Should().Pass();
}
finally
{
Directory.SetCurrentDirectory(currentDirectory);
}
}
[Fact]