Adding dotnet run tests for passing arguments to the app.

This commit is contained in:
Eric Erhardt 2016-04-22 23:40:39 -05:00
parent dd327b52a5
commit 5d2da26e74
3 changed files with 90 additions and 14 deletions

View file

@ -82,18 +82,67 @@ namespace Microsoft.DotNet.Tools.Run.Tests
.HaveStdOutContaining("Hélló Wórld!");
}
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
[Fact]
public void ItPassesArgumentsToTheApp()
{
// copy all the files to temp dir
foreach (var file in Directory.EnumerateFiles(projectDir))
{
tempDir.CopyFile(file);
}
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithArgs")
.WithLockFiles()
.WithBuildArtifacts();
new RunCommand(instance.TestRoot)
.ExecuteWithCapturedOutput("one --two -three")
.Should()
.Pass()
.And
.HaveStdOutContaining(
JoinWithNewlines(
"Hello World!",
"I was passed 3 args:",
"arg: [one]",
"arg: [--two]",
"arg: [-three]"));
}
private string GetProjectPath(TempDirectory projectDir)
[Fact]
public void ItPassesAllArgsAfterUnexpectedArg()
{
return Path.Combine(projectDir.Path, "project.json");
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithArgs")
.WithLockFiles()
.WithBuildArtifacts();
new RunCommand(instance.TestRoot)
.ExecuteWithCapturedOutput("Hello -f")
.Should()
.Pass()
.And
.HaveStdOutContaining(
JoinWithNewlines(
"Hello World!",
"I was passed 2 args:",
"arg: [Hello]",
"arg: [-f]"));
}
[Fact]
public void ItHandlesArgSeparatorCorrectly()
{
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithArgs")
.WithLockFiles()
.WithBuildArtifacts();
new RunCommand(instance.TestRoot)
.ExecuteWithCapturedOutput("-- one two")
.Should()
.Pass()
.And
.HaveStdOutContaining(
JoinWithNewlines(
"Hello World!",
"I was passed 2 args:",
"arg: [one]",
"arg: [two]"));
}
private static string JoinWithNewlines(params string[] values)
{
return string.Join(Environment.NewLine, values);
}
}
}