dotnet-installer/test/dotnet.Tests/PackagedCommandTests.cs

72 lines
2.1 KiB
C#
Raw Normal View History

// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.Tests
{
public class PackagedCommandTests : TestBase
{
private readonly string _testProjectsRoot;
public PackagedCommandTests()
{
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
}
[Theory]
[InlineData("AppWithDirectAndToolDependency")]
[InlineData("AppWithDirectDependency")]
[InlineData("AppWithToolDependency")]
public void TestPackagedCommandDependency(string appName)
{
string appDirectory = Path.Combine(_testProjectsRoot, appName);
new BuildCommand(Path.Combine(appDirectory, "project.json"))
.Execute()
.Should()
.Pass();
var currentDirectory = Directory.GetCurrentDirectory();
Directory.SetCurrentDirectory(appDirectory);
try
{
CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();
result.Should().HaveStdOut("Hello" + Environment.NewLine);
result.Should().NotHaveStdErr();
result.Should().Pass();
}
finally
{
Directory.SetCurrentDirectory(currentDirectory);
}
}
class HelloCommand : TestCommand
{
public HelloCommand()
: base("dotnet")
{
}
public override CommandResult Execute(string args = "")
{
args = $"hello {args}";
return base.Execute(args);
}
public override CommandResult ExecuteWithCapturedOutput(string args = "")
{
args = $"hello {args}";
return base.ExecuteWithCapturedOutput(args);
}
}
}
}