Merge pull request #4059 from dotnet/piotrpMSFT/TestAssetManager

Migrate to Test Asset Manager
This commit is contained in:
Piotr Puszkiewicz 2016-08-18 17:55:02 -04:00 committed by GitHub
commit 08fe61aa00
24 changed files with 201 additions and 175 deletions

View file

@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var configuration = "Debug";
var testAssetManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects"));
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDependencyDesktopAndPortable")
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDepDesktopAndPortable")
.WithLockFiles();
var buildCommand = new BuildCommand(
@ -52,7 +52,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var configuration = "Debug";
var testAssetManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects"));
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDependencyDesktopAndPortable")
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDepDesktopAndPortable")
.WithLockFiles();
var buildCommand = new BuildCommand(
@ -83,7 +83,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var configuration = "Release";
var testAssetManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects"));
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDependencyDesktopAndPortable")
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDepDesktopAndPortable")
.WithLockFiles();
var buildCommand = new BuildCommand(
@ -114,7 +114,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var configuration = "Release";
var testAssetManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects"));
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDependencyDesktopAndPortable")
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDepDesktopAndPortable")
.WithLockFiles();
var buildCommand = new BuildCommand(
@ -145,7 +145,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var configuration = "Debug";
var testAssetManager = new TestAssetsManager(Path.Combine(RepoRoot, "TestAssets", "TestProjects"));
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDependencyWithOutputName")
var testInstance = testAssetManager.CreateTestInstance("AppWithDirectDepWithOutputName")
.WithLockFiles();
var buildCommand = new BuildCommand(

View file

@ -12,11 +12,10 @@ using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
public class GivenAProjectDependenciesCommandResolver
public class GivenAProjectDependenciesCommandResolver : TestBase
{
private static readonly string s_liveProjectDirectory =
Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithDirectDependency");
private const string TestProjectName = "AppWithDirectDep";
[Fact]
public void It_returns_null_when_CommandName_is_null()
@ -61,11 +60,14 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "command",
CommandArguments = new string[] { "" },
ProjectDirectory = s_liveProjectDirectory,
ProjectDirectory = testInstance.Path,
Configuration = "Debug",
Framework = null
};
@ -80,11 +82,14 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "command",
CommandArguments = new string[] { "" },
ProjectDirectory = s_liveProjectDirectory,
ProjectDirectory = testInstance.Path,
Configuration = null,
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
};
@ -99,11 +104,14 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "nonexistent-command",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory,
ProjectDirectory = testInstance.Path,
Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
};
@ -118,11 +126,15 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithBuildArtifacts()
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "dotnet-hello",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory,
ProjectDirectory = testInstance.Path,
Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
};
@ -143,11 +155,15 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithBuildArtifacts()
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "dotnet-hello",
CommandArguments = new[] { "arg with space" },
ProjectDirectory = s_liveProjectDirectory,
ProjectDirectory = testInstance.Path,
Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
};
@ -159,15 +175,19 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
}
[Fact]
public void It_passes_depsfile_arg_to_host_when_returning_a_commandspec()
public void It_passes_depsfile_arg_to_host_when_returning_a_CommandSpec()
{
var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithBuildArtifacts()
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "dotnet-hello",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory,
ProjectDirectory = testInstance.Path,
Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
};
@ -182,26 +202,30 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
public void It_sets_depsfile_in_output_path_in_commandspec()
{
var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
var outputDir = Path.Combine(AppContext.BaseDirectory, "outdir");
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var outputDir = Path.Combine(testInstance.Path, "outdir");
var commandResolverArguments = new CommandResolverArguments
{
CommandName = "dotnet-hello",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory,
ProjectDirectory = testInstance.Path,
Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10,
OutputPath = outputDir
};
var buildCommand = new BuildCommand(
Path.Combine(s_liveProjectDirectory, "project.json"),
Path.Combine(testInstance.Path, "project.json"),
output: outputDir,
framework: FrameworkConstants.CommonFrameworks.NetCoreApp10.ToString())
.Execute().Should().Pass();
var projectContext = ProjectContext.Create(
s_liveProjectDirectory,
testInstance.Path,
FrameworkConstants.CommonFrameworks.NetCoreApp10,
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
@ -218,26 +242,30 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
public void It_sets_depsfile_in_build_base_path_in_commandspec()
{
var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
var buildBasePath = Path.Combine(AppContext.BaseDirectory, "basedir");
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var buildBasePath = Path.Combine(testInstance.Path, "basedir");
var commandResolverArguments = new CommandResolverArguments
{
CommandName = "dotnet-hello",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory,
ProjectDirectory = testInstance.Path,
Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10,
BuildBasePath = buildBasePath
};
var buildCommand = new BuildCommand(
Path.Combine(s_liveProjectDirectory, "project.json"),
Path.Combine(testInstance.Path, "project.json"),
buildBasePath: buildBasePath,
framework: FrameworkConstants.CommonFrameworks.NetCoreApp10.ToString())
.Execute().Should().Pass();
var projectContext = ProjectContext.Create(
s_liveProjectDirectory,
testInstance.Path,
FrameworkConstants.CommonFrameworks.NetCoreApp10,
RuntimeEnvironmentRidExtensions.GetAllCandidateRuntimeIdentifiers());
@ -255,11 +283,15 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectDependenciesCommandResolver = SetupProjectDependenciesCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithBuildArtifacts()
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "dotnet-hello",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory,
ProjectDirectory = testInstance.Path,
Configuration = "Debug",
Framework = FrameworkConstants.CommonFrameworks.NetCoreApp10
};

View file

@ -7,6 +7,7 @@ using System.Linq;
using FluentAssertions;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using NuGet.Versioning;
@ -14,12 +15,11 @@ using Xunit;
namespace Microsoft.DotNet.Cli.Utils.Tests
{
public class GivenAProjectToolsCommandResolver
public class GivenAProjectToolsCommandResolver : TestBase
{
private static readonly NuGetFramework s_toolPackageFramework = FrameworkConstants.CommonFrameworks.NetCoreApp10;
private static readonly string s_liveProjectDirectory =
Path.Combine(AppContext.BaseDirectory, "TestAssets/TestProjects/AppWithToolDependency");
private const string TestProjectName = "AppWithToolDependency";
[Fact]
public void It_returns_null_when_CommandName_is_null()
@ -60,11 +60,14 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "nonexistent-command",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory
ProjectDirectory = testInstance.Path
};
var result = projectToolsCommandResolver.Resolve(commandResolverArguments);
@ -77,11 +80,14 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "dotnet-portable",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory
ProjectDirectory = testInstance.Path
};
var result = projectToolsCommandResolver.Resolve(commandResolverArguments);
@ -100,11 +106,14 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "dotnet-portable",
CommandArguments = new[] { "arg with space" },
ProjectDirectory = s_liveProjectDirectory
ProjectDirectory = testInstance.Path
};
var result = projectToolsCommandResolver.Resolve(commandResolverArguments);
@ -118,11 +127,14 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "dotnet-portable",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory
ProjectDirectory = testInstance.Path
};
var result = projectToolsCommandResolver.Resolve(commandResolverArguments);
@ -138,14 +150,17 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
{
var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "dotnet-portable",
CommandArguments = null,
ProjectDirectory = s_liveProjectDirectory
ProjectDirectory = testInstance.Path
};
var context = ProjectContext.Create(Path.Combine(s_liveProjectDirectory, "project.json"), s_toolPackageFramework);
var context = ProjectContext.Create(Path.Combine(testInstance.Path, "project.json"), s_toolPackageFramework);
var nugetPackagesRoot = context.PackagesDirectory;
var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);
@ -180,7 +195,10 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
[Fact]
public void Generate_deps_json_method_doesnt_overwrite_when_deps_file_already_exists()
{
var context = ProjectContext.Create(Path.Combine(s_liveProjectDirectory, "project.json"), s_toolPackageFramework);
var testInstance = TestAssetsManager.CreateTestInstance(TestProjectName)
.WithLockFiles();
var context = ProjectContext.Create(Path.Combine(testInstance.Path, "project.json"), s_toolPackageFramework);
var nugetPackagesRoot = context.PackagesDirectory;
var toolPathCalculator = new ToolPathCalculator(nugetPackagesRoot);

View file

@ -14,20 +14,12 @@ namespace StreamForwarderTests
public class StreamForwarderTests : TestBase
{
private static readonly string s_rid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier();
private static readonly string s_testProjectRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
private TempDirectory _root;
public static void Main()
{
Console.WriteLine("Dummy Entrypoint");
}
public StreamForwarderTests()
{
_root = Temp.CreateDirectory();
}
public static IEnumerable<object[]> ForwardingTheoryVariations
{
get
@ -127,15 +119,15 @@ namespace StreamForwarderTests
private string SetupTestProject()
{
var sourceTestProjectPath = Path.Combine(s_testProjectRoot, "OutputStandardOutputAndError");
var binTestProjectPath = _root.CopyDirectory(sourceTestProjectPath).Path;
var testInstance = TestAssetsManager.CreateTestInstance("OutputStandardOutputAndError")
.WithLockFiles();
var buildCommand = new BuildCommand(Path.Combine(binTestProjectPath, "project.json"));
var buildCommand = new BuildCommand(Path.Combine(testInstance.Path, "project.json"));
buildCommand.Execute();
var buildOutputExe = "OutputStandardOutputAndError" + Constants.ExeSuffix;
var buildOutputPath = Path.Combine(binTestProjectPath, "bin/Debug/netcoreapp1.0", buildOutputExe);
var buildOutputPath = Path.Combine(testInstance.Path, "bin/Debug/netcoreapp1.0", buildOutputExe);
return buildOutputPath;
}

View file

@ -7,24 +7,18 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
public class LibraryExporterTests : TestBase
{
private readonly string _testProjectsRoot;
public LibraryExporterTests()
{
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
}
[Fact]
public void GetLibraryExportsWithoutLockFile()
{
var root = Temp.CreateDirectory().CopyDirectory(Path.Combine(_testProjectsRoot, "TestAppWithLibrary"));
foreach (var lockfile in Directory.GetFiles(root.Path, "project.lock.json"))
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary");
foreach (var lockfile in Directory.GetFiles(testInstance.Path, "project.lock.json"))
{
File.Delete(lockfile);
}
var builder = new ProjectContextBuilder().WithProjectDirectory(Path.Combine(root.Path, "TestApp"));
var builder = new ProjectContextBuilder().WithProjectDirectory(Path.Combine(testInstance.Path, "TestApp"));
foreach (var context in builder.BuildAllTargets())
{

View file

@ -13,28 +13,18 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
{
public class CompilerTests : TestBase
{
private readonly string _testProjectsRoot;
public CompilerTests()
{
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
}
[Fact]
public void XmlDocumentationFileIsGenerated()
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var testInstance = TestAssetsManager
.CreateTestInstance("TestAppWithLibrary")
.WithLockFiles();
var testLibDir = root.CreateDirectory("TestLibrary");
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestAppWithLibrary", "TestLibrary");
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
var testLibDir = Path.Combine(testInstance.TestRoot, "TestLibrary");
// run compile
var outputDir = Path.Combine(testLibDir.Path, "bin");
var testProject = GetProjectPath(testLibDir);
var outputDir = Path.Combine(testLibDir, "bin");
var testProject = Path.Combine(testLibDir, "project.json");
var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultLibraryFramework);
var result = buildCommand.ExecuteWithCapturedOutput();
result.Should().Pass();
@ -49,16 +39,15 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
[Fact]
public void SatelliteAssemblyIsGeneratedByDotnetBuild()
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
var testLibDir = root.CreateDirectory("TestProjectWithCultureSpecificResource");
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestProjectWithCultureSpecificResource");
var testInstance = TestAssetsManager
.CreateTestInstance("TestProjectWithCultureSpecificResource")
.WithLockFiles();
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
var testLibDir = testInstance.TestRoot;
// run compile on a project with resources
var outputDir = Path.Combine(testLibDir.Path, "bin");
var testProject = GetProjectPath(testLibDir);
var outputDir = Path.Combine(testLibDir, "bin");
var testProject = Path.Combine(testLibDir, "project.json");
var buildCmd = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
var result = buildCmd.ExecuteWithCapturedOutput();
result.Should().Pass();
@ -75,15 +64,15 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
[Fact]
public void LibraryWithAnalyzer()
{
var root = Temp.CreateDirectory();
var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer");
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer");
var testInstance = TestAssetsManager
.CreateTestInstance("TestLibraryWithAnalyzer")
.WithLockFiles();
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
var testLibDir = testInstance.TestRoot;
// run compile
var outputDir = Path.Combine(testLibDir.Path, "bin");
var testProject = GetProjectPath(testLibDir);
var outputDir = Path.Combine(testLibDir, "bin");
var testProject = Path.Combine(testLibDir, "project.json");
var buildCmd = new BuildCommand(testProject, output: outputDir, framework: DefaultLibraryFramework);
var result = buildCmd.ExecuteWithCapturedOutput();
result.Should().Pass();
@ -96,12 +85,15 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
{
var root = Temp.CreateDirectory();
var spaceBufferDirectory = root.CreateDirectory("space directory");
var testAppDir = spaceBufferDirectory.CreateDirectory("TestAppCompilationContext");
var testInstance = TestAssetsManager
.CreateTestInstance("TestAppCompilationContext", identifier: "A SPACE")
.WithLockFiles();
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), testAppDir);
var testProjectDir = Path.Combine(
Directory.GetParent(testInstance.TestRoot).FullName,
"TestAppCompilationContext",
"TestApp");
var testProjectDir = Path.Combine(_testProjectsRoot, "TestAppCompilationContext", "TestApp");
var testProject = Path.Combine(testProjectDir, "project.json");
var buildCommand = new BuildCommand(testProject);

View file

@ -17,49 +17,41 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
{
private readonly string _testProjectsRoot;
public PackTests()
{
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
}
[Fact]
public void OutputsPackagesToConfigurationSubdirWhenOutputParameterIsNotPassed()
{
var root = Temp.CreateDirectory();
var testInstance = TestAssetsManager
.CreateTestInstance("TestLibraryWithConfiguration")
.WithBuildArtifacts()
.WithLockFiles();
var testLibDir = root.CreateDirectory("TestLibrary");
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithConfiguration");
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
var testProject = GetProjectPath(testLibDir);
var testProject = Path.Combine(testInstance.Path, "project.json");
var packCommand = new PackCommand(testProject, configuration: "Test");
var result = packCommand.Execute();
result.Should().Pass();
var outputDir = new DirectoryInfo(Path.Combine(testLibDir.Path, "bin", "Test"));
var outputDir = new DirectoryInfo(Path.Combine(testInstance.Path, "bin", "Test"));
outputDir.Should().Exist();
outputDir.Should().HaveFiles(new [] { "TestLibrary.1.0.0.nupkg" , "TestLibrary.1.0.0.symbols.nupkg" });
outputDir.Should().HaveFiles(new [] { "TestLibraryWithConfiguration.1.0.0.nupkg" , "TestLibraryWithConfiguration.1.0.0.symbols.nupkg" });
}
[Fact]
public void OutputsPackagesFlatIntoOutputDirWhenOutputParameterIsPassed()
{
var root = Temp.CreateDirectory();
var testInstance = TestAssetsManager
.CreateTestInstance("TestLibraryWithConfiguration")
.WithBuildArtifacts()
.WithLockFiles();
var testLibDir = root.CreateDirectory("TestLibrary");
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithConfiguration");
var testProject = Path.Combine(testInstance.Path, "project.json");
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
var outputDir = new DirectoryInfo(Path.Combine(testLibDir.Path, "bin2"));
var testProject = GetProjectPath(testLibDir);
var outputDir = new DirectoryInfo(Path.Combine(testInstance.Path, "bin2"));
var packCommand = new PackCommand(testProject, output: outputDir.FullName);
var result = packCommand.Execute();
result.Should().Pass();
outputDir.Should().Exist();
outputDir.Should().HaveFiles(new[] { "TestLibrary.1.0.0.nupkg", "TestLibrary.1.0.0.symbols.nupkg" });
outputDir.Should().HaveFiles(new[] { "TestLibraryWithConfiguration.1.0.0.nupkg", "TestLibraryWithConfiguration.1.0.0.symbols.nupkg" });
}
[Fact]
@ -100,9 +92,10 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
[Fact]
public void HasIncludedFiles()
{
var testInstance = TestAssetsManager.CreateTestInstance("EndToEndTestApp")
.WithLockFiles()
.WithBuildArtifacts();
var testInstance = TestAssetsManager
.CreateTestInstance("EndToEndTestApp")
.WithLockFiles()
.WithBuildArtifacts();
var cmd = new PackCommand(Path.Combine(testInstance.TestRoot, Project.FileName));
cmd.Execute().Should().Pass();
@ -156,27 +149,25 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
[Fact]
public void HasServiceableFlagWhenArgumentPassed()
{
var root = Temp.CreateDirectory();
var testInstance = TestAssetsManager
.CreateTestInstance("TestLibraryWithConfiguration")
.WithBuildArtifacts()
.WithLockFiles();
var testLibDir = root.CreateDirectory("TestLibrary");
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithConfiguration");
CopyProjectToTempDir(sourceTestLibDir, testLibDir);
var testProject = GetProjectPath(testLibDir);
var testProject = Path.Combine(testInstance.Path, "project.json");
var packCommand = new PackCommand(testProject, configuration: "Debug", serviceable: true);
var result = packCommand.Execute();
result.Should().Pass();
var outputDir = new DirectoryInfo(Path.Combine(testLibDir.Path, "bin", "Debug"));
var outputDir = new DirectoryInfo(Path.Combine(testInstance.Path, "bin", "Debug"));
outputDir.Should().Exist();
outputDir.Should().HaveFiles(new[] { "TestLibrary.1.0.0.nupkg", "TestLibrary.1.0.0.symbols.nupkg" });
outputDir.Should().HaveFiles(new[] { "TestLibraryWithConfiguration.1.0.0.nupkg", "TestLibraryWithConfiguration.1.0.0.symbols.nupkg" });
var outputPackage = Path.Combine(outputDir.FullName, "TestLibrary.1.0.0.nupkg");
var outputPackage = Path.Combine(outputDir.FullName, "TestLibraryWithConfiguration.1.0.0.nupkg");
var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read);
zip.Entries.Should().Contain(e => e.FullName == "TestLibrary.nuspec");
zip.Entries.Should().Contain(e => e.FullName == "TestLibraryWithConfiguration.nuspec");
var manifestReader = new StreamReader(zip.Entries.First(e => e.FullName == "TestLibrary.nuspec").Open());
var manifestReader = new StreamReader(zip.Entries.First(e => e.FullName == "TestLibraryWithConfiguration.nuspec").Open());
var nuspecXml = XDocument.Parse(manifestReader.ReadToEnd());
var node = nuspecXml.Descendants().Single(e => e.Name.LocalName == "serviceable");
Assert.Equal("true", node.Value);

View file

@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void PublishExcludesBuildDependencies()
{
var testInstance = TestAssetsManager.CreateTestInstance("AppWithDirectDependencyAndTypeBuild")
var testInstance = TestAssetsManager.CreateTestInstance("AppWithDirectDepAndTypeBuild")
.WithLockFiles();
var publishCommand = new PublishCommand(testInstance.TestRoot);
@ -37,7 +37,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
// Check the deps file
var reader = new DependencyContextJsonReader();
DependencyContext context;
using (var file = File.OpenRead(Path.Combine(publishDir.FullName, "AppWithDirectDependencyAndTypeBuild.deps.json")))
using (var file = File.OpenRead(Path.Combine(publishDir.FullName, "AppWithDirectDepAndTypeBuild.deps.json")))
{
context = reader.Read(file);
}

View file

@ -14,14 +14,8 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{
public class PublishTests : TestBase
{
private readonly string _testProjectsRoot;
private readonly Func<string, string, string> _getProjectJson = ProjectUtils.GetProjectJson;
public PublishTests()
{
_testProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "TestProjects");
}
private static readonly dynamic[] CrossPublishTestData = new[]
{
new

View file

@ -12,24 +12,16 @@ namespace Microsoft.DotNet.Tools.Resgen.Tests
{
public class ResgenTests : TestBase
{
private readonly string _testProjectsRoot;
private readonly TempDirectory _root;
public ResgenTests()
{
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
_root = Temp.CreateDirectory();
}
[Fact]
public void Test_Build_Project_with_Resources_with_Space_in_Path_Should_Succeed()
{
var spaceBufferDirectory = _root.CreateDirectory("space directory");
var testAppDir = spaceBufferDirectory.CreateDirectory("TestProjectWithResource");
var testInstance = TestAssetsManager
.CreateTestInstance("TestProjectWithResource", identifier: "A SPACE")
.WithBuildArtifacts()
.WithLockFiles();
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestProjectWithResource"), testAppDir);
var testProject = GetProjectPath(testAppDir);
var testProject = Path.Combine(testInstance.Path, "project.json");
var buildCommand = new BuildCommand(testProject);
buildCommand.Execute().Should().Pass();

View file

@ -7,6 +7,7 @@ using System.IO;
using System.Runtime.InteropServices;
using FluentAssertions;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.DotNet.InternalAbstractions;
using Xunit;
@ -15,19 +16,18 @@ namespace Microsoft.DotNet.Tests
{
public class PackagedCommandTests : TestBase
{
private readonly string _testProjectsRoot;
private readonly string _desktopTestProjectsRoot;
private readonly TestAssetsManager _desktopTestAssetsManager = GetTestGroupTestAssetsManager("DesktopTestProjects");
public static IEnumerable<object[]> DependencyToolArguments
{
get
{
var rid = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier();
var projectOutputPath = $"AppWithDirectDependencyDesktopAndPortable\\bin\\Debug\\net451\\{rid}\\dotnet-desktop-and-portable.exe";
var projectOutputPath = $"AppWithDirectDepDesktopAndPortable\\bin\\Debug\\net451\\{rid}\\dotnet-desktop-and-portable.exe";
return new[]
{
new object[] { ".NETCoreApp,Version=v1.0", "CoreFX", "lib\\netcoreapp1.0\\dotnet-desktop-and-portable.dll", true },
new object[] { ".NETFramework,Version=v4.5.1", "NetFX", projectOutputPath, true }
new object[] { "CoreFX", ".NETCoreApp,Version=v1.0", "lib\\netcoreapp1.0\\dotnet-desktop-and-portable.dll", true },
new object[] { "NetFX", ".NETFramework,Version=v4.5.1", projectOutputPath, true }
};
}
}
@ -40,24 +40,22 @@ namespace Microsoft.DotNet.Tests
var projectOutputPath = $"LibraryWithDirectDependencyDesktopAndPortable\\bin\\Debug\\net451\\dotnet-desktop-and-portable.exe";
return new[]
{
new object[] { ".NETStandard,Version=v1.6", "CoreFX", "lib\\netstandard1.6\\dotnet-desktop-and-portable.dll", true },
new object[] { ".NETFramework,Version=v4.5.1", "NetFX", projectOutputPath, true }
new object[] { "CoreFX", ".NETStandard,Version=v1.6", "lib\\netstandard1.6\\dotnet-desktop-and-portable.dll", true },
new object[] { "NetFX", ".NETFramework,Version=v4.5.1", projectOutputPath, true }
};
}
}
public PackagedCommandTests()
{
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
_desktopTestProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "DesktopTestProjects");
}
[Theory]
[InlineData("AppWithDirectAndToolDependency")]
[InlineData("AppWithDirectAndToolDep")]
[InlineData("AppWithToolDependency")]
public void TestProjectToolIsAvailableThroughDriver(string appName)
{
var appDirectory = Path.Combine(_testProjectsRoot, appName);
var testInstance = TestAssetsManager
.CreateTestInstance(appName, identifier: appName)
.WithLockFiles();
var appDirectory = testInstance.Path;
new BuildCommand(Path.Combine(appDirectory, "project.json"))
.Execute()
@ -75,7 +73,11 @@ namespace Microsoft.DotNet.Tests
[Fact]
public void CanInvokeToolWhosePackageNameIsDifferentFromDllName()
{
var appDirectory = Path.Combine(_testProjectsRoot, "AppWithDependencyOnToolWithOutputName");
var testInstance = TestAssetsManager
.CreateTestInstance("AppWithDepOnToolWithOutputName")
.WithLockFiles();
var appDirectory = testInstance.Path;
new BuildCommand(Path.Combine(appDirectory, "project.json"))
.Execute()
@ -93,7 +95,12 @@ namespace Microsoft.DotNet.Tests
[Fact]
public void CanInvokeToolFromDirectDependenciesIfPackageNameDifferentFromToolName()
{
var appDirectory = Path.Combine(_testProjectsRoot, "AppWithDirectDependencyWithOutputName");
var testInstance = TestAssetsManager
.CreateTestInstance("AppWithDirectDepWithOutputName")
.WithBuildArtifacts()
.WithLockFiles();
var appDirectory = testInstance.Path;
const string framework = ".NETCoreApp,Version=v1.0";
new BuildCommand(Path.Combine(appDirectory, "project.json"))
@ -112,14 +119,19 @@ namespace Microsoft.DotNet.Tests
// need conditional theories so we can skip on non-Windows
[Theory]
[MemberData("DependencyToolArguments")]
public void TestFrameworkSpecificDependencyToolsCanBeInvoked(string framework, string args, string expectedDependencyToolPath, bool windowsOnly)
public void TestFrameworkSpecificDependencyToolsCanBeInvoked(string identifier, string framework, string expectedDependencyToolPath, bool windowsOnly)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && windowsOnly)
{
return;
}
var appDirectory = Path.Combine(_desktopTestProjectsRoot, "AppWithDirectDependencyDesktopAndPortable");
var testInstance = _desktopTestAssetsManager
.CreateTestInstance("AppWithDirectDepDesktopAndPortable", identifier: identifier)
.WithBuildArtifacts()
.WithLockFiles();
var appDirectory = testInstance.Path;
new BuildCommand(Path.Combine(appDirectory, "project.json"))
.Execute()
@ -127,10 +139,10 @@ namespace Microsoft.DotNet.Tests
.Pass();
CommandResult result = new DependencyToolInvokerCommand { WorkingDirectory = appDirectory }
.ExecuteWithCapturedOutput("desktop-and-portable", framework, args);
.ExecuteWithCapturedOutput("desktop-and-portable", framework, identifier);
result.Should().HaveStdOutContaining(framework);
result.Should().HaveStdOutContaining(args);
result.Should().HaveStdOutContaining(identifier);
result.Should().HaveStdOutContaining(expectedDependencyToolPath);
result.Should().NotHaveStdErr();
result.Should().Pass();
@ -138,14 +150,18 @@ namespace Microsoft.DotNet.Tests
[Theory]
[MemberData("LibraryDependencyToolArguments")]
public void TestFrameworkSpecificLibraryDependencyToolsCannotBeInvoked(string framework, string args, string expectedDependencyToolPath, bool windowsOnly)
public void TestFrameworkSpecificLibraryDependencyToolsCannotBeInvoked(string identifier, string framework, string expectedDependencyToolPath, bool windowsOnly)
{
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && windowsOnly)
{
return;
}
var testInstance = _desktopTestAssetsManager
.CreateTestInstance("LibraryWithDirectDependencyDesktopAndPortable", identifier: identifier)
.WithLockFiles();
var appDirectory = Path.Combine(_desktopTestProjectsRoot, "LibraryWithDirectDependencyDesktopAndPortable");
var appDirectory = testInstance.Path;
new BuildCommand(Path.Combine(appDirectory, "project.json"))
.Execute()
@ -153,7 +169,7 @@ namespace Microsoft.DotNet.Tests
.Pass();
CommandResult result = new DependencyToolInvokerCommand { WorkingDirectory = appDirectory }
.ExecuteWithCapturedOutput("desktop-and-portable", framework, args);
.ExecuteWithCapturedOutput("desktop-and-portable", framework, identifier);
result.Should().HaveStdOutContaining("Command not found");
result.Should().Fail();
@ -162,7 +178,9 @@ namespace Microsoft.DotNet.Tests
[Fact]
public void ToolsCanAccessDependencyContextProperly()
{
var appDirectory = Path.Combine(_testProjectsRoot, "DependencyContextFromTool");
var testInstance = TestAssetsManager.CreateTestInstance("DependencyContextFromTool");
var appDirectory = testInstance.Path;
CommandResult result = new DependencyContextTestCommand() { WorkingDirectory = appDirectory }
.Execute(Path.Combine(appDirectory, "project.json"));
@ -173,8 +191,11 @@ namespace Microsoft.DotNet.Tests
[Fact]
public void TestProjectDependencyIsNotAvailableThroughDriver()
{
var appName = "AppWithDirectDependency";
var appDirectory = Path.Combine(_testProjectsRoot, appName);
var testInstance = TestAssetsManager
.CreateTestInstance("AppWithDirectDep")
.WithLockFiles();
var appDirectory = testInstance.Path;
new BuildCommand(Path.Combine(appDirectory, "project.json"))
.Execute()