Update tests to reflect portable tools
This commit is contained in:
parent
51dcb6063f
commit
bd3ba0bd41
3 changed files with 78 additions and 8 deletions
|
@ -16,11 +16,14 @@ using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NuGet.Frameworks;
|
using NuGet.Frameworks;
|
||||||
|
using NuGet.Versioning;
|
||||||
|
using NuGet.ProjectModel;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Utils.Tests
|
namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
{
|
{
|
||||||
public class GivenAProjectToolsCommandResolver
|
public class GivenAProjectToolsCommandResolver
|
||||||
{
|
{
|
||||||
|
private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetStandardApp15;
|
||||||
|
|
||||||
private static readonly string s_liveProjectDirectory =
|
private static readonly string s_liveProjectDirectory =
|
||||||
Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithToolDependency");
|
Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithToolDependency");
|
||||||
|
@ -83,7 +86,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
|
|
||||||
var commandResolverArguments = new CommandResolverArguments()
|
var commandResolverArguments = new CommandResolverArguments()
|
||||||
{
|
{
|
||||||
CommandName = "dotnet-hello",
|
CommandName = "dotnet-portable",
|
||||||
CommandArguments = null,
|
CommandArguments = null,
|
||||||
ProjectDirectory = s_liveProjectDirectory
|
ProjectDirectory = s_liveProjectDirectory
|
||||||
};
|
};
|
||||||
|
@ -106,7 +109,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
|
|
||||||
var commandResolverArguments = new CommandResolverArguments()
|
var commandResolverArguments = new CommandResolverArguments()
|
||||||
{
|
{
|
||||||
CommandName = "dotnet-hello",
|
CommandName = "dotnet-portable",
|
||||||
CommandArguments = new [] { "arg with space"},
|
CommandArguments = new [] { "arg with space"},
|
||||||
ProjectDirectory = s_liveProjectDirectory
|
ProjectDirectory = s_liveProjectDirectory
|
||||||
};
|
};
|
||||||
|
@ -118,13 +121,13 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void It_returns_a_CommandSpec_with_Args_as_CommandPath_when_returning_a_CommandSpec_and_CommandArguments_are_null()
|
public void It_returns_a_CommandSpec_with_Args_containing_CommandPath_when_returning_a_CommandSpec_and_CommandArguments_are_null()
|
||||||
{
|
{
|
||||||
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
|
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
|
||||||
|
|
||||||
var commandResolverArguments = new CommandResolverArguments()
|
var commandResolverArguments = new CommandResolverArguments()
|
||||||
{
|
{
|
||||||
CommandName = "dotnet-hello",
|
CommandName = "dotnet-portable",
|
||||||
CommandArguments = null,
|
CommandArguments = null,
|
||||||
ProjectDirectory = s_liveProjectDirectory
|
ProjectDirectory = s_liveProjectDirectory
|
||||||
};
|
};
|
||||||
|
@ -134,9 +137,51 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
result.Should().NotBeNull();
|
result.Should().NotBeNull();
|
||||||
|
|
||||||
var commandPath = result.Args.Trim('"');
|
var commandPath = result.Args.Trim('"');
|
||||||
commandPath.Should().Contain("dotnet-hello");
|
commandPath.Should().Contain("dotnet-portable.dll");
|
||||||
|
}
|
||||||
|
|
||||||
File.Exists(commandPath).Should().BeTrue();
|
[Fact]
|
||||||
|
public void It_writes_a_deps_json_file_next_to_the_lockfile()
|
||||||
|
{
|
||||||
|
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
|
||||||
|
|
||||||
|
var commandResolverArguments = new CommandResolverArguments()
|
||||||
|
{
|
||||||
|
CommandName = "dotnet-portable",
|
||||||
|
CommandArguments = null,
|
||||||
|
ProjectDirectory = s_liveProjectDirectory
|
||||||
|
};
|
||||||
|
|
||||||
|
var context = ProjectContext.Create(Path.Combine(s_liveProjectDirectory, "project.json"), s_toolPackageFramework);
|
||||||
|
|
||||||
|
var nugetPackagesRoot = context.PackagesDirectory;
|
||||||
|
var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);
|
||||||
|
|
||||||
|
var lockFilePath = toolPathCalculator.GetLockFilePath(
|
||||||
|
"dotnet-portable",
|
||||||
|
new NuGetVersion("1.0.0"),
|
||||||
|
s_toolPackageFramework);
|
||||||
|
|
||||||
|
var directory = Path.GetDirectoryName(lockFilePath);
|
||||||
|
|
||||||
|
var depsJsonFile = Directory
|
||||||
|
.EnumerateFiles(directory)
|
||||||
|
.FirstOrDefault(p => Path.GetFileName(p).EndsWith(FileNameSuffixes.DepsJson));
|
||||||
|
|
||||||
|
if (depsJsonFile != null)
|
||||||
|
{
|
||||||
|
File.Delete(depsJsonFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = projectToolsCommandResolver.Resolve(commandResolverArguments);
|
||||||
|
result.Should().NotBeNull();
|
||||||
|
|
||||||
|
|
||||||
|
depsJsonFile = Directory
|
||||||
|
.EnumerateFiles(directory)
|
||||||
|
.FirstOrDefault(p => Path.GetFileName(p).EndsWith(FileNameSuffixes.DepsJson));
|
||||||
|
|
||||||
|
depsJsonFile.Should().NotBeNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ProjectToolsCommandResolver SetupProjectToolsCommandResolver(
|
private ProjectToolsCommandResolver SetupProjectToolsCommandResolver(
|
||||||
|
|
|
@ -5,6 +5,11 @@
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"NETStandard.Library": "1.5.0-rc2-23911",
|
"NETStandard.Library": "1.5.0-rc2-23911",
|
||||||
|
"NuGet.Versioning": "3.4.0-rtm-0763",
|
||||||
|
"NuGet.Packaging": "3.4.0-rtm-0763",
|
||||||
|
"NuGet.Frameworks": "3.4.0-rtm-0763",
|
||||||
|
"NuGet.ProjectModel": "3.4.0-rtm-0763",
|
||||||
|
|
||||||
"Microsoft.DotNet.ProjectModel": {
|
"Microsoft.DotNet.ProjectModel": {
|
||||||
"target": "project"
|
"target": "project"
|
||||||
},
|
},
|
||||||
|
|
|
@ -36,9 +36,9 @@ namespace Microsoft.DotNet.Tests
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
CommandResult result = new HelloCommand().ExecuteWithCapturedOutput();
|
CommandResult result = new PortableCommand().ExecuteWithCapturedOutput();
|
||||||
|
|
||||||
result.Should().HaveStdOut("Hello World!" + Environment.NewLine);
|
result.Should().HaveStdOut("Hello Portable World!" + Environment.NewLine);
|
||||||
result.Should().NotHaveStdErr();
|
result.Should().NotHaveStdErr();
|
||||||
result.Should().Pass();
|
result.Should().Pass();
|
||||||
}
|
}
|
||||||
|
@ -94,5 +94,25 @@ namespace Microsoft.DotNet.Tests
|
||||||
return base.ExecuteWithCapturedOutput(args);
|
return base.ExecuteWithCapturedOutput(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PortableCommand : TestCommand
|
||||||
|
{
|
||||||
|
public PortableCommand()
|
||||||
|
: base("dotnet")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override CommandResult Execute(string args = "")
|
||||||
|
{
|
||||||
|
args = $"portable {args}";
|
||||||
|
return base.Execute(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
||||||
|
{
|
||||||
|
args = $"portable {args}";
|
||||||
|
return base.ExecuteWithCapturedOutput(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue