2016-04-18 17:51:15 +00:00
|
|
|
// 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.
|
|
|
|
|
2016-10-24 19:41:27 +00:00
|
|
|
using System;
|
2016-04-18 17:51:15 +00:00
|
|
|
using System.IO;
|
2016-04-28 23:30:32 +00:00
|
|
|
using FluentAssertions;
|
2016-04-18 17:51:15 +00:00
|
|
|
using Microsoft.DotNet.TestFramework;
|
2016-04-28 23:30:32 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2016-04-18 17:51:15 +00:00
|
|
|
using NuGet.Frameworks;
|
2016-04-28 23:30:32 +00:00
|
|
|
using Xunit;
|
2017-08-19 01:07:14 +00:00
|
|
|
using Microsoft.DotNet.Tools.Tests.Utilities;
|
2016-04-18 17:51:15 +00:00
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Utils.Tests
|
|
|
|
{
|
|
|
|
public class GivenAProjectDependenciesCommandFactory : TestBase
|
|
|
|
{
|
2016-04-20 23:05:53 +00:00
|
|
|
private static readonly NuGetFramework s_desktopTestFramework = FrameworkConstants.CommonFrameworks.Net451;
|
|
|
|
|
2016-10-24 19:41:27 +00:00
|
|
|
private RepoDirectoriesProvider _repoDirectoriesProvider;
|
|
|
|
|
|
|
|
public GivenAProjectDependenciesCommandFactory()
|
|
|
|
{
|
|
|
|
_repoDirectoriesProvider = new RepoDirectoriesProvider();
|
|
|
|
Environment.SetEnvironmentVariable(
|
|
|
|
Constants.MSBUILD_EXE_PATH,
|
|
|
|
Path.Combine(_repoDirectoriesProvider.Stage2Sdk, "MSBuild.dll"));
|
|
|
|
}
|
|
|
|
|
2016-04-18 17:51:15 +00:00
|
|
|
[WindowsOnlyFact]
|
2016-04-20 17:47:50 +00:00
|
|
|
public void It_resolves_desktop_apps_defaulting_to_Debug_Configuration()
|
2016-04-18 17:51:15 +00:00
|
|
|
{
|
|
|
|
var configuration = "Debug";
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
2016-10-31 23:22:10 +00:00
|
|
|
.WithNuGetConfig(_repoDirectoriesProvider.TestPackages);
|
|
|
|
|
|
|
|
var restoreCommand = new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
.Should().Pass();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.WithConfiguration(configuration)
|
|
|
|
.WithCapturedOutput()
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
2016-04-18 17:51:15 +00:00
|
|
|
var factory = new ProjectDependenciesCommandFactory(
|
|
|
|
s_desktopTestFramework,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
2016-10-28 01:46:43 +00:00
|
|
|
testInstance.Root.FullName);
|
2016-04-18 17:51:15 +00:00
|
|
|
|
|
|
|
var command = factory.Create("dotnet-desktop-and-portable", null);
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
command.CommandName.Should().Contain(testInstance.Root.GetDirectory("bin", configuration).FullName);
|
2016-10-24 19:41:27 +00:00
|
|
|
|
|
|
|
Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe");
|
|
|
|
}
|
|
|
|
|
2016-04-18 17:51:15 +00:00
|
|
|
[WindowsOnlyFact]
|
2016-04-20 17:47:50 +00:00
|
|
|
public void It_resolves_desktop_apps_when_configuration_is_Debug()
|
2016-04-18 17:51:15 +00:00
|
|
|
{
|
|
|
|
var configuration = "Debug";
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
2016-10-31 23:22:10 +00:00
|
|
|
.WithNuGetConfig(_repoDirectoriesProvider.TestPackages);
|
|
|
|
|
|
|
|
var restoreCommand = new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
.Should().Pass();
|
2016-04-18 17:51:15 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.WithConfiguration(configuration)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
2016-04-18 17:51:15 +00:00
|
|
|
|
|
|
|
var factory = new ProjectDependenciesCommandFactory(
|
|
|
|
s_desktopTestFramework,
|
|
|
|
configuration,
|
|
|
|
null,
|
|
|
|
null,
|
2016-10-28 01:46:43 +00:00
|
|
|
testInstance.Root.FullName);
|
2016-04-18 17:51:15 +00:00
|
|
|
|
|
|
|
var command = factory.Create("dotnet-desktop-and-portable", null);
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
command.CommandName.Should().Contain(testInstance.Root.GetDirectory("bin", configuration).FullName);
|
2016-04-18 17:51:15 +00:00
|
|
|
Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe");
|
|
|
|
}
|
|
|
|
|
|
|
|
[WindowsOnlyFact]
|
2016-04-20 17:47:50 +00:00
|
|
|
public void It_resolves_desktop_apps_when_configuration_is_Release()
|
2016-04-18 17:51:15 +00:00
|
|
|
{
|
2016-10-31 23:22:10 +00:00
|
|
|
var configuration = "Debug";
|
2016-04-18 17:51:15 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
2016-10-31 23:22:10 +00:00
|
|
|
.WithNuGetConfig(_repoDirectoriesProvider.TestPackages);
|
|
|
|
|
|
|
|
var restoreCommand = new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
.Should().Pass();
|
2016-04-18 17:51:15 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.WithConfiguration(configuration)
|
|
|
|
.WithCapturedOutput()
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
2016-04-18 17:51:15 +00:00
|
|
|
|
|
|
|
var factory = new ProjectDependenciesCommandFactory(
|
|
|
|
s_desktopTestFramework,
|
|
|
|
configuration,
|
|
|
|
null,
|
|
|
|
null,
|
2016-10-28 01:46:43 +00:00
|
|
|
testInstance.Root.FullName);
|
2016-04-18 17:51:15 +00:00
|
|
|
|
|
|
|
var command = factory.Create("dotnet-desktop-and-portable", null);
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
command.CommandName.Should().Contain(testInstance.Root.GetDirectory("bin", configuration).FullName);
|
|
|
|
|
2016-04-18 17:51:15 +00:00
|
|
|
Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe");
|
|
|
|
}
|
|
|
|
|
|
|
|
[WindowsOnlyFact]
|
2016-04-20 17:47:50 +00:00
|
|
|
public void It_resolves_desktop_apps_using_configuration_passed_to_create()
|
2016-04-18 17:51:15 +00:00
|
|
|
{
|
2016-10-31 23:22:10 +00:00
|
|
|
var configuration = "Debug";
|
2016-04-18 17:51:15 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
2016-10-31 23:22:10 +00:00
|
|
|
.WithNuGetConfig(_repoDirectoriesProvider.TestPackages);
|
|
|
|
|
|
|
|
var restoreCommand = new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
.Should().Pass();
|
2016-04-18 17:51:15 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
.WithWorkingDirectory(testInstance.Root)
|
|
|
|
.WithConfiguration(configuration)
|
|
|
|
.WithCapturedOutput()
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
2016-04-18 17:51:15 +00:00
|
|
|
|
|
|
|
var factory = new ProjectDependenciesCommandFactory(
|
|
|
|
s_desktopTestFramework,
|
|
|
|
"Debug",
|
|
|
|
null,
|
|
|
|
null,
|
2016-10-28 01:46:43 +00:00
|
|
|
testInstance.Root.FullName);
|
2016-04-18 17:51:15 +00:00
|
|
|
|
|
|
|
var command = factory.Create("dotnet-desktop-and-portable", null, configuration: configuration);
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
command.CommandName.Should().Contain(testInstance.Root.GetDirectory("bin", configuration).FullName);
|
|
|
|
|
2016-04-18 17:51:15 +00:00
|
|
|
Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe");
|
|
|
|
}
|
2016-04-20 23:05:53 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void It_resolves_tools_whose_package_name_is_different_than_dll_name()
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
Environment.SetEnvironmentVariable(
|
|
|
|
Constants.MSBUILD_EXE_PATH,
|
|
|
|
Path.Combine(new RepoDirectoriesProvider().Stage2Sdk, "MSBuild.dll"));
|
2016-04-20 23:05:53 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var configuration = "Debug";
|
2016-04-20 23:05:53 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var testInstance = TestAssets.Get("AppWithDirectDepWithOutputName")
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
2016-04-20 23:05:53 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var buildCommand = new BuildCommand()
|
|
|
|
.WithProjectDirectory(testInstance.Root)
|
|
|
|
.WithConfiguration(configuration)
|
|
|
|
.WithCapturedOutput()
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
2016-04-20 23:05:53 +00:00
|
|
|
|
|
|
|
var factory = new ProjectDependenciesCommandFactory(
|
2017-08-19 01:07:14 +00:00
|
|
|
NuGetFrameworks.NetCoreApp21,
|
2016-04-20 23:05:53 +00:00
|
|
|
configuration,
|
|
|
|
null,
|
|
|
|
null,
|
2016-10-28 01:46:43 +00:00
|
|
|
testInstance.Root.FullName);
|
2016-04-20 23:05:53 +00:00
|
|
|
|
|
|
|
var command = factory.Create("dotnet-tool-with-output-name", null);
|
|
|
|
|
|
|
|
command.CommandArgs.Should().Contain(
|
2017-08-18 22:36:01 +00:00
|
|
|
Path.Combine("toolwithoutputname", "1.0.0", "lib", "netcoreapp2.1", "dotnet-tool-with-output-name.dll"));
|
2016-04-20 23:05:53 +00:00
|
|
|
}
|
2016-04-18 17:51:15 +00:00
|
|
|
}
|
|
|
|
}
|