Add WorkingDirectory to TestCommand
This commit is contained in:
parent
203b56509d
commit
1a42fa05a4
2 changed files with 15 additions and 27 deletions
|
@ -13,6 +13,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
{
|
{
|
||||||
protected string _command;
|
protected string _command;
|
||||||
|
|
||||||
|
public string WorkingDirectory { get; set; }
|
||||||
|
|
||||||
public Dictionary<string, string> Environment { get; } = new Dictionary<string, string>();
|
public Dictionary<string, string> Environment { get; } = new Dictionary<string, string>();
|
||||||
|
|
||||||
public TestCommand(string command)
|
public TestCommand(string command)
|
||||||
|
@ -53,7 +55,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
|
|
||||||
return RunProcess(commandPath, args, stdOut, stdErr);
|
return RunProcess(commandPath, args, stdOut, stdErr);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ResolveCommand(ref string executable, ref string args)
|
private void ResolveCommand(ref string executable, ref string args)
|
||||||
{
|
{
|
||||||
if (executable.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
|
if (executable.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
|
||||||
|
@ -89,9 +91,14 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
psi.Environment[item.Key] = item.Value;
|
psi.Environment[item.Key] = item.Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(WorkingDirectory))
|
||||||
|
{
|
||||||
|
psi.WorkingDirectory = WorkingDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
var process = new Process
|
var process = new Process
|
||||||
{
|
{
|
||||||
StartInfo = psi,
|
StartInfo = psi
|
||||||
};
|
};
|
||||||
|
|
||||||
process.EnableRaisingEvents = true;
|
process.EnableRaisingEvents = true;
|
||||||
|
|
|
@ -32,21 +32,12 @@ namespace Microsoft.DotNet.Tests
|
||||||
.Should()
|
.Should()
|
||||||
.Pass();
|
.Pass();
|
||||||
|
|
||||||
var currentDirectory = Directory.GetCurrentDirectory();
|
CommandResult result = new PortableCommand { WorkingDirectory = appDirectory }
|
||||||
Directory.SetCurrentDirectory(appDirectory);
|
.ExecuteWithCapturedOutput();
|
||||||
|
|
||||||
try
|
result.Should().HaveStdOut("Hello Portable World!" + Environment.NewLine);
|
||||||
{
|
result.Should().NotHaveStdErr();
|
||||||
CommandResult result = new PortableCommand().ExecuteWithCapturedOutput();
|
result.Should().Pass();
|
||||||
|
|
||||||
result.Should().HaveStdOut("Hello Portable World!" + Environment.NewLine);
|
|
||||||
result.Should().NotHaveStdErr();
|
|
||||||
result.Should().Pass();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Directory.SetCurrentDirectory(currentDirectory);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// need conditional theories so we can skip on non-Windows
|
// need conditional theories so we can skip on non-Windows
|
||||||
|
@ -67,22 +58,12 @@ namespace Microsoft.DotNet.Tests
|
||||||
.Should()
|
.Should()
|
||||||
.Pass();
|
.Pass();
|
||||||
|
|
||||||
var currentDirectory = Directory.GetCurrentDirectory();
|
CommandResult result = new DependencyToolInvokerCommand { WorkingDirectory = appDirectory }
|
||||||
Directory.SetCurrentDirectory(appDirectory);
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CommandResult result = new DependencyToolInvokerCommand()
|
|
||||||
.ExecuteWithCapturedOutput(framework);
|
.ExecuteWithCapturedOutput(framework);
|
||||||
|
|
||||||
result.Should().HaveStdOutContaining(framework);
|
result.Should().HaveStdOutContaining(framework);
|
||||||
result.Should().NotHaveStdErr();
|
result.Should().NotHaveStdErr();
|
||||||
result.Should().Pass();
|
result.Should().Pass();
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
Directory.SetCurrentDirectory(currentDirectory);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue