Remove TAM (#5670)

* remove reference to TestAssetsManager in dotnet-add-reference

* remove TestAssetsManager dependency from dotnet-build

* remove TAM ref from dotnet-list-reference

* remove TAM dependency from dotnet-msbuild

* remove TAM dependency from ProjectJsonMigration tests

* remove TAM dependency from dotnet.Tests

* remove TAM dependency from dotnet-new.Tests

* remove TAM from dotnet-pack.Tests

* remove TAM from dotnet-publish.Tests

* remove TAM from dotnet-restore.Tests

* remove TAM dependency from dotnet-remove-reference.Tests

* remove TAM dependency from dotnet-run.Tests

* remove TAM dependency from dotnet-test.Tests

* remove TAM dependency from Microsoft.DotNet.Cli.Utils.Tests

* remove TAM from TestBase

* remove TAM

* remove newly introduced dependency on TAM
This commit is contained in:
Krzysztof Wicher 2017-02-15 15:35:03 -08:00 committed by Livar
parent 511d7e96a1
commit a6bc22e499
30 changed files with 238 additions and 517 deletions

View file

@ -94,9 +94,9 @@ namespace Microsoft.DotNet.TestFramework
ProjectJsonSearchPattern); ProjectJsonSearchPattern);
} }
public DirectoryInfo CreateTestDirectory([CallerMemberName] string callingMethod = "", string identifier = "") public DirectoryInfo CreateTestDirectory(string testProjectName = "temp", [CallerMemberName] string callingMethod = "", string identifier = "")
{ {
var testDestination = GetTestDestinationDirectoryPath("temp", callingMethod, identifier); var testDestination = GetTestDestinationDirectoryPath(testProjectName, callingMethod, identifier);
var testDirectory = new DirectoryInfo(testDestination); var testDirectory = new DirectoryInfo(testDestination);

View file

@ -1,118 +0,0 @@
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.DotNet.Cli.Utils;
namespace Microsoft.DotNet.TestFramework
{
public class TestAssetsManager
{
public string AssetsRoot
{
get; private set;
}
public TestAssetsManager(string assetsRoot, bool doRestore = false, bool doBuild = false)
{
if (!Directory.Exists(assetsRoot))
{
throw new DirectoryNotFoundException($"Directory not found at '{assetsRoot}'");
}
AssetsRoot = assetsRoot;
if (doRestore)
{
Restore();
}
if (doBuild)
{
Build();
}
}
private void Restore()
{
string[] restoreArgs = new string[] { "restore", AssetsRoot };
Console.WriteLine("Executing - 'dotnet {0}'", string.Join(" ", restoreArgs));
var commandResult = Command.Create("dotnet", restoreArgs)
.CaptureStdOut()
.CaptureStdErr()
.Execute();
int exitCode = commandResult.ExitCode;
if (exitCode != 0)
{
Console.WriteLine(commandResult.StdOut);
Console.WriteLine(commandResult.StdErr);
string message = string.Format("Command Failed - 'dotnet {0}' with exit code - {1}", string.Join(" ", restoreArgs), exitCode);
throw new Exception(message);
}
}
private void Build()
{
var projects = Directory.GetFiles(AssetsRoot, "project.json", SearchOption.AllDirectories);
foreach (var project in projects)
{
string[] buildArgs = new string[] { "build", project };
Console.WriteLine("Executing - 'dotnet {0}'", string.Join(" ", buildArgs));
var commandResult = Command.Create("dotnet", buildArgs)
.CaptureStdOut()
.CaptureStdErr()
.Execute();
int exitCode = commandResult.ExitCode;
if (exitCode != 0)
{
Console.WriteLine(commandResult.StdOut);
Console.WriteLine(commandResult.StdErr);
string message = string.Format("Command Failed - 'dotnet {0}' with exit code - {1}", string.Join(" ", buildArgs), exitCode);
throw new Exception(message);
}
}
}
public TestInstance CreateTestInstance(string testProjectName, [CallerMemberName] string callingMethod = "", string identifier = "")
{
string testProjectDir = Path.Combine(AssetsRoot, testProjectName);
if (!Directory.Exists(testProjectDir))
{
throw new Exception($"Cannot find '{testProjectName}' at '{AssetsRoot}'");
}
var testDestination = GetTestDestinationDirectoryPath(testProjectName, callingMethod, identifier);
var testInstance = new TestInstance(testProjectDir, testDestination);
return testInstance;
}
public TestDirectory CreateTestDirectory([CallerMemberName] string callingMethod = "", string identifier = "")
{
var testDestination = GetTestDestinationDirectoryPath(string.Empty, callingMethod, identifier);
return new TestDirectory(testDestination);
}
private string GetTestDestinationDirectoryPath(string testProjectName, string callingMethod, string identifier)
{
#if NET451
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
#else
string baseDirectory = AppContext.BaseDirectory;
#endif
return Path.Combine(baseDirectory, callingMethod + identifier, testProjectName);
}
}
}

View file

@ -1,48 +0,0 @@
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.TestFramework
{
public class TestDirectory
{
internal TestDirectory(string path)
{
if (string.IsNullOrEmpty(path))
{
throw new ArgumentException(nameof(path));
}
Path = path;
EnsureDirectoryAndBackupDirectoryExistAndAreEmpty(Path);
}
public string Path { get; private set; }
private static void EnsureDirectoryAndBackupDirectoryExistAndAreEmpty(string path)
{
var testDirectory = new DirectoryInfo(path);
var migrationBackupDirectory = new DirectoryInfo(
System.IO.Path.Combine(testDirectory.FullName, "backup"));
if (testDirectory.Exists)
{
testDirectory.Delete(true);
}
if (migrationBackupDirectory.Exists)
{
migrationBackupDirectory.Delete(true);
}
Directory.CreateDirectory(path);
}
}
}

View file

@ -1,131 +0,0 @@
// 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.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.TestFramework
{
public class TestInstance: TestDirectory
{
// made tolower because the rest of the class works with normalized tolower strings
private static readonly IEnumerable<string> BuildArtifactBlackList = new List<string>() {".IncrementalCache", ".SDKVersion"}.Select(s => s.ToLower()).ToArray();
private string _testAssetRoot;
internal TestInstance(string testAssetRoot, string testDestination) : base(testDestination)
{
if (string.IsNullOrEmpty(testAssetRoot))
{
throw new ArgumentException("testAssetRoot");
}
_testAssetRoot = testAssetRoot;
CopySource();
}
private void CopySource()
{
var sourceDirs = Directory.GetDirectories(_testAssetRoot, "*", SearchOption.AllDirectories)
.Where(dir =>
{
dir = dir.ToLower();
return !dir.EndsWith($"{System.IO.Path.DirectorySeparatorChar}bin")
&& !dir.Contains($"{System.IO.Path.DirectorySeparatorChar}bin{System.IO.Path.DirectorySeparatorChar}")
&& !dir.EndsWith($"{System.IO.Path.DirectorySeparatorChar}obj")
&& !dir.Contains($"{System.IO.Path.DirectorySeparatorChar}obj{System.IO.Path.DirectorySeparatorChar}");
});
foreach (string sourceDir in sourceDirs)
{
Directory.CreateDirectory(sourceDir.Replace(_testAssetRoot, Path));
}
var sourceFiles = Directory.GetFiles(_testAssetRoot, "*.*", SearchOption.AllDirectories)
.Where(file =>
{
file = file.ToLower();
return !file.EndsWith("project.assets.json")
&& !file.Contains($"{System.IO.Path.DirectorySeparatorChar}bin{System.IO.Path.DirectorySeparatorChar}")
&& !file.Contains($"{System.IO.Path.DirectorySeparatorChar}obj{System.IO.Path.DirectorySeparatorChar}");
});
foreach (string srcFile in sourceFiles)
{
string destFile = srcFile.Replace(_testAssetRoot, Path);
File.Copy(srcFile, destFile, true);
}
}
public TestInstance WithNuGetMSBuildFiles()
{
foreach (string file in Directory.GetFiles(_testAssetRoot, "*.nuget.g.*", SearchOption.AllDirectories))
{
string destinationLockFile = file.Replace(_testAssetRoot, Path);
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(destinationLockFile));
File.Copy(file, destinationLockFile, true);
}
return this;
}
public TestInstance WithLockFiles()
{
foreach (string lockFile in Directory.GetFiles(_testAssetRoot, "project.assets.json", SearchOption.AllDirectories))
{
string destinationLockFile = lockFile.Replace(_testAssetRoot, Path);
Directory.CreateDirectory(System.IO.Path.GetDirectoryName(destinationLockFile));
File.Copy(lockFile, destinationLockFile, true);
}
return this;
}
public TestInstance WithBuildArtifacts()
{
var binDirs = Directory.GetDirectories(_testAssetRoot, "*", SearchOption.AllDirectories)
.Where(dir =>
{
dir = dir.ToLower();
return dir.EndsWith($"{System.IO.Path.DirectorySeparatorChar}bin")
|| dir.Contains($"{System.IO.Path.DirectorySeparatorChar}bin{System.IO.Path.DirectorySeparatorChar}")
|| dir.EndsWith($"{System.IO.Path.DirectorySeparatorChar}obj")
|| dir.Contains($"{System.IO.Path.DirectorySeparatorChar}obj{System.IO.Path.DirectorySeparatorChar}");
});
foreach (string dirPath in binDirs)
{
Directory.CreateDirectory(dirPath.Replace(_testAssetRoot, Path));
}
var binFiles = Directory.GetFiles(_testAssetRoot, "*.*", SearchOption.AllDirectories)
.Where(file =>
{
file = file.ToLower();
var isArtifact = file.Contains($"{System.IO.Path.DirectorySeparatorChar}bin{System.IO.Path.DirectorySeparatorChar}")
|| file.Contains($"{System.IO.Path.DirectorySeparatorChar}obj{System.IO.Path.DirectorySeparatorChar}");
var isBlackListed = BuildArtifactBlackList.Any(b => file.Contains(b));
return isArtifact && !isBlackListed;
});
foreach (string binFile in binFiles)
{
string destFile = binFile.Replace(_testAssetRoot, Path);
File.Copy(binFile, destFile, true);
}
return this;
}
public string TestRoot => Path;
}
}

View file

@ -61,13 +61,13 @@ namespace Microsoft.DotNet.Tests
{ {
var projectToolsCommandResolver = SetupProjectToolsCommandResolver(); var projectToolsCommandResolver = SetupProjectToolsCommandResolver();
var projectDirectory = TestAssetsManager.CreateTestDirectory(); var projectDirectory = TestAssets.CreateTestDirectory();
var commandResolverArguments = new CommandResolverArguments() var commandResolverArguments = new CommandResolverArguments()
{ {
CommandName = "command", CommandName = "command",
CommandArguments = new string[] { "" }, CommandArguments = new string[] { "" },
ProjectDirectory = projectDirectory.Path ProjectDirectory = projectDirectory.Root.FullName
}; };
var result = projectToolsCommandResolver.Resolve(commandResolverArguments); var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

View file

@ -115,16 +115,17 @@ namespace StreamForwarderTests
private string SetupTestProject() private string SetupTestProject()
{ {
var testInstance = TestAssetsManager var testPath = TestAssets.Get("OutputStandardOutputAndError")
.CreateTestInstance("OutputStandardOutputAndError") .CreateInstance()
.WithLockFiles(); .WithRestoreFiles()
.Root.FullName;
var buildCommand = new BuildCommand() var buildCommand = new BuildCommand()
.WithProjectFile(new FileInfo(Path.Combine(testInstance.Path, "project.json"))) .WithProjectFile(new FileInfo(Path.Combine(testPath, "project.json")))
.Execute(); .Execute();
var buildOutputExe = "OutputStandardOutputAndError" + Constants.ExeSuffix; var buildOutputExe = "OutputStandardOutputAndError" + Constants.ExeSuffix;
var buildOutputPath = Path.Combine(testInstance.Path, "bin/Debug/netcoreapp1.0", buildOutputExe); var buildOutputPath = Path.Combine(testPath, "bin/Debug/netcoreapp1.0", buildOutputExe);
return buildOutputPath; return buildOutputPath;
} }

View file

@ -19,9 +19,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Fact] [Fact]
public void ItCopiesProjectDirectoryContentsToOutputDirectoryWhenTheDirectoriesAreDifferent() public void ItCopiesProjectDirectoryContentsToOutputDirectoryWhenTheDirectoriesAreDifferent()
{ {
var testProjectDirectory = TestAssetsManager var testProjectDirectory = TestAssets.Get("PJTestAppSimple")
.CreateTestInstance("PJTestAppSimple", callingMethod: "z") .CreateInstance(callingMethod: "z")
.Path; .WithSourceFiles().Root.FullName;
var outputDirectory = Temp.CreateDirectory().Path; var outputDirectory = Temp.CreateDirectory().Path;
@ -93,9 +93,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Fact] [Fact]
public void ItHasErrorWhenMigratingANonCsharpApp() public void ItHasErrorWhenMigratingANonCsharpApp()
{ {
var testProjectDirectory = var testProjectDirectory = TestAssets.Get("FSharpTestProjects")
TestAssetsManager.CreateTestInstance("FSharpTestProjects/TestApp", callingMethod: "z") .CreateInstance(callingMethod: "z")
.Path; .WithSourceFiles()
.Root.GetDirectory("TestApp").FullName;
var mockProj = ProjectRootElement.Create(); var mockProj = ProjectRootElement.Create();
var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, testProjectDirectory, mockProj); var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, testProjectDirectory, mockProj);

View file

@ -13,14 +13,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
/// </summary> /// </summary>
public class ProjectJsonBuilder public class ProjectJsonBuilder
{ {
private readonly TestAssetsManager _testAssetsManager; private readonly TestAssets _testAssets;
private JObject _projectJson; private JObject _projectJson;
private bool _baseDefined = false; private bool _baseDefined = false;
public ProjectJsonBuilder(TestAssetsManager testAssetsManager) public ProjectJsonBuilder(TestAssets testAssets)
{ {
_testAssetsManager = testAssetsManager; _testAssets = testAssets;
} }
public string SaveToDisk(string outputDirectory) public string SaveToDisk(string outputDirectory)
@ -40,7 +40,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public ProjectJsonBuilder FromTestAssetBase(string testAssetName) public ProjectJsonBuilder FromTestAssetBase(string testAssetName)
{ {
var testProjectDirectory = _testAssetsManager.CreateTestInstance(testAssetName).Path; var testProjectDirectory = _testAssets.Get(testAssetName)
.CreateInstance()
.WithSourceFiles()
.Root.FullName;
var testProject = Path.Combine(testProjectDirectory, "project.json"); var testProject = Path.Combine(testProjectDirectory, "project.json");
SetBase(JObject.Parse(File.ReadAllText(testProject))); SetBase(JObject.Parse(File.ReadAllText(testProject)));

View file

@ -20,8 +20,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public GivenThatIWantToMigrateAssemblyInfo() public GivenThatIWantToMigrateAssemblyInfo()
{ {
var projectDirectory = var projectDirectory = TestAssets.Get("AppWithAssemblyInfo")
TestAssetsManager.CreateTestInstance("AppWithAssemblyInfo").Path; .CreateInstance()
.WithSourceFiles()
.Root.FullName;
var projectContext = var projectContext =
ProjectContext.Create(projectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); ProjectContext.Create(projectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
_mockProject = ProjectRootElement.Create(); _mockProject = ProjectRootElement.Create();

View file

@ -37,7 +37,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
} }
// Setup projectcontext // Setup projectcontext
var testProjectDirectory = TestAssetsManager.CreateTestInstance("TestAppWithRuntimeOptions").Path; var testProjectDirectory = TestAssets.Get("TestAppWithRuntimeOptions")
.CreateInstance()
.WithSourceFiles()
.Root.FullName;
var projectContext = ProjectContext.Create(testProjectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(testProjectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, testProjectDirectory, templateProj); var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, testProjectDirectory, templateProj);

View file

@ -20,8 +20,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Fact] [Fact]
public void ProjectDependenciesAreMigratedToProjectReference() public void ProjectDependenciesAreMigratedToProjectReference()
{ {
var solutionDirectory = var solutionDirectory = TestAssets.Get("TestAppWithLibrary")
TestAssetsManager.CreateTestInstance("TestAppWithLibrary", callingMethod: "p").Path; .CreateInstance(callingMethod: "p")
.WithSourceFiles()
.Root.FullName;
var appDirectory = Path.Combine(solutionDirectory, "TestApp"); var appDirectory = Path.Combine(solutionDirectory, "TestApp");
@ -43,9 +45,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Fact] [Fact]
public void ItDoesNotMigrateADependencyWithTargetPackageThatHasAMatchingProjectAsAProjectReference() public void ItDoesNotMigrateADependencyWithTargetPackageThatHasAMatchingProjectAsAProjectReference()
{ {
var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects"); var solutionDirectory = TestAssets.Get("NonRestoredTestProjects", "AppWithProjectDependencyAsTarget")
var solutionDirectory = .CreateInstance(callingMethod: "p")
testAssetsManager.CreateTestInstance("AppWithProjectDependencyAsTarget", callingMethod: "p").Path; .WithSourceFiles()
.Root.FullName;
var appDirectory = Path.Combine(solutionDirectory, "TestApp"); var appDirectory = Path.Combine(solutionDirectory, "TestApp");
@ -64,8 +67,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Fact] [Fact]
public void TFMSpecificProjectDependenciesAreMigratedToProjectReferenceUnderConditionItemGroup() public void TFMSpecificProjectDependenciesAreMigratedToProjectReferenceUnderConditionItemGroup()
{ {
var solutionDirectory = var solutionDirectory = TestAssets.Get("TestAppWithLibraryUnderTFM")
TestAssetsManager.CreateTestInstance("TestAppWithLibraryUnderTFM", callingMethod: "p").Path; .CreateInstance(callingMethod: "p")
.WithSourceFiles()
.Root.FullName;
var appDirectory = Path.Combine(solutionDirectory, "TestApp"); var appDirectory = Path.Combine(solutionDirectory, "TestApp");
@ -88,8 +93,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void ItThrowsWhenProjectDependencyIsUnresolved() public void ItThrowsWhenProjectDependencyIsUnresolved()
{ {
// No Lock file => unresolved // No Lock file => unresolved
var solutionDirectory = var solutionDirectory = TestAssets.Get("TestAppWithLibrary")
TestAssetsManager.CreateTestInstance("TestAppWithLibrary").Path; .CreateInstance()
.WithSourceFiles()
.Root.FullName;
var appDirectory = Path.Combine(solutionDirectory, "TestApp"); var appDirectory = Path.Combine(solutionDirectory, "TestApp");
var libraryDirectory = Path.Combine(solutionDirectory, "TestLibrary"); var libraryDirectory = Path.Combine(solutionDirectory, "TestLibrary");
@ -305,8 +312,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Fact] [Fact]
public void ItDoesNotReferenceTheProjectUnderBackupWhenMigratingAPartiallyMigratedStructure() public void ItDoesNotReferenceTheProjectUnderBackupWhenMigratingAPartiallyMigratedStructure()
{ {
var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects"); var solutionDirectory = TestAssets.Get("NonRestoredTestProjects", "PJHalfMigrated")
var solutionDirectory = testAssetsManager.CreateTestInstance("PJHalfMigrated").Path; .CreateInstance()
.WithSourceFiles()
.Root.FullName;
var appDirectory = Path.Combine(solutionDirectory, "ProjectB"); var appDirectory = Path.Combine(solutionDirectory, "ProjectB");
@ -333,8 +342,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
string project, string project,
NuGetFramework targetFramework) NuGetFramework targetFramework)
{ {
var solutionDirectory = var solutionDirectory = TestAssets.Get(solution)
TestAssetsManager.CreateTestInstance(solution, callingMethod: "p").Path; .CreateInstance(callingMethod: "p")
.WithSourceFiles()
.Root.FullName;
var appDirectory = Path.Combine(solutionDirectory, project); var appDirectory = Path.Combine(solutionDirectory, project);

View file

@ -25,9 +25,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Fact] [Fact]
public void RuntimeOptionsAreCopiedFromProjectJsonToRuntimeConfigTemplateJsonFile() public void RuntimeOptionsAreCopiedFromProjectJsonToRuntimeConfigTemplateJsonFile()
{ {
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithRuntimeOptions"); var testInstance = TestAssets.Get("TestAppWithRuntimeOptions")
var projectDir = testInstance.Path; .CreateInstance()
var projectPath = Path.Combine(testInstance.Path, "project.json"); .WithSourceFiles()
.Root;
var projectDir = testInstance.FullName;
var projectPath = Path.Combine(projectDir, "project.json");
var project = JObject.Parse(File.ReadAllText(projectPath)); var project = JObject.Parse(File.ReadAllText(projectPath));
var rawRuntimeOptions = (JObject)project.GetValue("runtimeOptions"); var rawRuntimeOptions = (JObject)project.GetValue("runtimeOptions");
@ -49,8 +53,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
[Fact] [Fact]
public void MigratingProjectJsonWithNoRuntimeOptionsProducesNoRuntimeConfigTemplateJsonFile() public void MigratingProjectJsonWithNoRuntimeOptionsProducesNoRuntimeConfigTemplateJsonFile()
{ {
var testInstance = TestAssetsManager.CreateTestInstance("PJTestAppSimple"); var testInstance = TestAssets.Get("PJTestAppSimple")
var projectDir = testInstance.Path; .CreateInstance()
.WithSourceFiles()
.Root;
var projectDir = testInstance.FullName;
var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10); var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10);

View file

@ -19,7 +19,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void MigratingNetcoreappProjectDoesNotPopulateTargetFrameworkIdentifierAndTargetFrameworkVersion() public void MigratingNetcoreappProjectDoesNotPopulateTargetFrameworkIdentifierAndTargetFrameworkVersion()
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager) var testPJ = new ProjectJsonBuilder(TestAssets)
.FromTestAssetBase("TestAppWithRuntimeOptions") .FromTestAssetBase("TestAppWithRuntimeOptions")
.WithCustomProperty("buildOptions", new Dictionary<string, string> .WithCustomProperty("buildOptions", new Dictionary<string, string>
{ {
@ -47,7 +47,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void MigratingMultiTFMProjectPopulatesTargetFrameworksWithShortTfms() public void MigratingMultiTFMProjectPopulatesTargetFrameworksWithShortTfms()
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager) var testPJ = new ProjectJsonBuilder(TestAssets)
.FromTestAssetBase("TestLibraryWithMultipleFrameworks") .FromTestAssetBase("TestLibraryWithMultipleFrameworks")
.SaveToDisk(testDirectory); .SaveToDisk(testDirectory);
@ -72,7 +72,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void MigratingCoreAndDesktopTFMsAddsAllRuntimeIdentifiersIfTheProjectDoesNothaveAnyAlready() public void MigratingCoreAndDesktopTFMsAddsAllRuntimeIdentifiersIfTheProjectDoesNothaveAnyAlready()
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager) var testPJ = new ProjectJsonBuilder(TestAssets)
.FromTestAssetBase("PJAppWithMultipleFrameworks") .FromTestAssetBase("PJAppWithMultipleFrameworks")
.SaveToDisk(testDirectory); .SaveToDisk(testDirectory);
@ -97,7 +97,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void MigratingCoreAndDesktopTFMsAddsRuntimeIdentifierWithWin7x86ConditionOnAllFullFrameworksWhenNoRuntimesExistAlready() public void MigratingCoreAndDesktopTFMsAddsRuntimeIdentifierWithWin7x86ConditionOnAllFullFrameworksWhenNoRuntimesExistAlready()
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager) var testPJ = new ProjectJsonBuilder(TestAssets)
.FromTestAssetBase("PJAppWithMultipleFrameworks") .FromTestAssetBase("PJAppWithMultipleFrameworks")
.SaveToDisk(testDirectory); .SaveToDisk(testDirectory);
@ -123,7 +123,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void MigrateTFMRuleDoesNotAddRuntimesWhenMigratingDesktopTFMsWithRuntimesAlready() public void MigrateTFMRuleDoesNotAddRuntimesWhenMigratingDesktopTFMsWithRuntimesAlready()
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager) var testPJ = new ProjectJsonBuilder(TestAssets)
.FromTestAssetBase("TestAppWithMultipleFrameworksAndRuntimes") .FromTestAssetBase("TestAppWithMultipleFrameworksAndRuntimes")
.SaveToDisk(testDirectory); .SaveToDisk(testDirectory);
@ -147,7 +147,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void MigratingProjectWithFullFrameworkTFMsOnlyAddsARuntimeIdentifierWin7x86WhenNoRuntimesExistAlready() public void MigratingProjectWithFullFrameworkTFMsOnlyAddsARuntimeIdentifierWin7x86WhenNoRuntimesExistAlready()
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager) var testPJ = new ProjectJsonBuilder(TestAssets)
.FromTestAssetBase("TestAppWithMultipleFullFrameworksOnly") .FromTestAssetBase("TestAppWithMultipleFullFrameworksOnly")
.SaveToDisk(testDirectory); .SaveToDisk(testDirectory);
@ -173,7 +173,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void MigratingSingleTFMProjectPopulatesTargetFramework() public void MigratingSingleTFMProjectPopulatesTargetFramework()
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager) var testPJ = new ProjectJsonBuilder(TestAssets)
.FromTestAssetBase("TestAppWithRuntimeOptions") .FromTestAssetBase("TestAppWithRuntimeOptions")
.WithCustomProperty("buildOptions", new Dictionary<string, string> .WithCustomProperty("buildOptions", new Dictionary<string, string>
{ {
@ -202,7 +202,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
public void MigratingLibWithMultipleTFMsDoesNotAddRuntimes() public void MigratingLibWithMultipleTFMsDoesNotAddRuntimes()
{ {
var testDirectory = Temp.CreateDirectory().Path; var testDirectory = Temp.CreateDirectory().Path;
var testPJ = new ProjectJsonBuilder(TestAssetsManager) var testPJ = new ProjectJsonBuilder(TestAssets)
.FromTestAssetBase("PJLibWithMultipleFrameworks") .FromTestAssetBase("PJLibWithMultipleFrameworks")
.SaveToDisk(testDirectory); .SaveToDisk(testDirectory);

View file

@ -20,7 +20,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
protected const string DefaultFramework = "netcoreapp1.0"; protected const string DefaultFramework = "netcoreapp1.0";
protected const string DefaultLibraryFramework = "netstandard1.5"; protected const string DefaultLibraryFramework = "netstandard1.5";
private TempRoot _temp; private TempRoot _temp;
private static TestAssetsManager s_testsAssetsMgr;
private static TestAssets s_testAssets; private static TestAssets s_testAssets;
@ -32,19 +31,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
} }
} }
protected static TestAssetsManager TestAssetsManager
{
get
{
if (s_testsAssetsMgr == null)
{
s_testsAssetsMgr = GetTestGroupTestAssetsManager("TestProjects");
}
return s_testsAssetsMgr;
}
}
protected static TestAssets TestAssets protected static TestAssets TestAssets
{ {
get get
@ -63,14 +49,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
} }
} }
protected static TestAssetsManager GetTestGroupTestAssetsManager(string testGroup)
{
string assetsRoot = Path.Combine(RepoRoot, "TestAssets", testGroup);
var testAssetsMgr = new TestAssetsManager(assetsRoot);
return testAssetsMgr;
}
protected TestBase() protected TestBase()
{ {
} }

View file

@ -49,27 +49,27 @@ Additional Arguments:
private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "") private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
{ {
return new ProjDir(TestAssetsManager.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).Path); return new ProjDir(TestAssets.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).FullName);
} }
private ProjDir NewLib([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "") private ProjDir NewLib(string dir = null, [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
{ {
var dir = NewDir(callingMethod: callingMethod, identifier: identifier); var projDir = dir == null ? NewDir(callingMethod: callingMethod, identifier: identifier) : new ProjDir(dir);
try try
{ {
string args = $"classlib -o \"{dir.Path}\" --debug:ephemeral-hive"; string args = $"classlib -o \"{projDir.Path}\" --debug:ephemeral-hive";
new NewCommandShim() new NewCommandShim()
.WithWorkingDirectory(dir.Path) .WithWorkingDirectory(projDir.Path)
.ExecuteWithCapturedOutput(args) .ExecuteWithCapturedOutput(args)
.Should().Pass(); .Should().Pass();
} }
catch (System.ComponentModel.Win32Exception e) catch (System.ComponentModel.Win32Exception e)
{ {
throw new Exception($"Intermittent error in `dotnet new` occurred when running it in dir `{dir.Path}`\nException:\n{e}"); throw new Exception($"Intermittent error in `dotnet new` occurred when running it in dir `{projDir.Path}`\nException:\n{e}");
} }
return dir; return projDir;
} }
private static void SetTargetFrameworks(ProjDir proj, string[] frameworks) private static void SetTargetFrameworks(ProjDir proj, string[] frameworks)
@ -79,9 +79,9 @@ Additional Arguments:
csproj.Save(); csproj.Save();
} }
private ProjDir NewLibWithFrameworks([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "") private ProjDir NewLibWithFrameworks(string dir = null, [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
{ {
var ret = NewLib(callingMethod: callingMethod, identifier: identifier); var ret = NewLib(dir, callingMethod: callingMethod, identifier: identifier);
SetTargetFrameworks(ret, DefaultFrameworks); SetTargetFrameworks(ret, DefaultFrameworks);
return ret; return ret;
} }
@ -179,8 +179,8 @@ Additional Arguments:
[Fact] [Fact]
public void ItAddsRefWithoutCondAndPrintsStatus() public void ItAddsRefWithoutCondAndPrintsStatus()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition(); int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new AddReferenceCommand() var cmd = new AddReferenceCommand()
@ -188,7 +188,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"\"{setup.ValidRefCsprojPath}\""); .Execute($"\"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Reference `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj` added to the project."); cmd.StdOut.Should().Be("Reference `ValidRef\\ValidRef.csproj` added to the project.");
cmd.StdErr.Should().BeEmpty(); cmd.StdErr.Should().BeEmpty();
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
@ -198,8 +198,8 @@ Additional Arguments:
[Fact] [Fact]
public void ItAddsRefWithCondAndPrintsStatus() public void ItAddsRefWithCondAndPrintsStatus()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451); int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
var cmd = new AddReferenceCommand() var cmd = new AddReferenceCommand()
@ -207,7 +207,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\""); .Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Reference `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj` added to the project."); cmd.StdOut.Should().Be("Reference `ValidRef\\ValidRef.csproj` added to the project.");
cmd.StdErr.Should().BeEmpty(); cmd.StdErr.Should().BeEmpty();
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1); csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
@ -217,8 +217,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithoutCondIsPresentItAddsDifferentRefWithoutCond() public void WhenRefWithoutCondIsPresentItAddsDifferentRefWithoutCond()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand() new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot) .WithWorkingDirectory(setup.TestRoot)
@ -232,7 +232,7 @@ Additional Arguments:
.WithProject(lib.CsProjName) .WithProject(lib.CsProjName)
.Execute($"\"{setup.ValidRefCsprojPath}\""); .Execute($"\"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Reference `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj` added to the project."); cmd.StdOut.Should().Be("Reference `ValidRef\\ValidRef.csproj` added to the project.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1); csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
@ -241,8 +241,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithCondIsPresentItAddsDifferentRefWithCond() public void WhenRefWithCondIsPresentItAddsDifferentRefWithCond()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand() new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot) .WithWorkingDirectory(setup.TestRoot)
@ -256,7 +256,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\""); .Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Reference `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj` added to the project."); cmd.StdOut.Should().Be("Reference `ValidRef\\ValidRef.csproj` added to the project.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore); csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore);
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1); csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
@ -265,8 +265,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithCondIsPresentItAddsRefWithDifferentCond() public void WhenRefWithCondIsPresentItAddsRefWithDifferentCond()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand() new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot) .WithWorkingDirectory(setup.TestRoot)
@ -280,7 +280,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\""); .Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Reference `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj` added to the project."); cmd.StdOut.Should().Be("Reference `ValidRef\\ValidRef.csproj` added to the project.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1); csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1); csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
@ -289,8 +289,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithConditionIsPresentItAddsDifferentRefWithoutCond() public void WhenRefWithConditionIsPresentItAddsDifferentRefWithoutCond()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand() new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot) .WithWorkingDirectory(setup.TestRoot)
@ -304,7 +304,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"\"{setup.ValidRefCsprojPath}\""); .Execute($"\"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Reference `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj` added to the project."); cmd.StdOut.Should().Be("Reference `ValidRef\\ValidRef.csproj` added to the project.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1); csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
@ -313,8 +313,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithNoCondAlreadyExistsItDoesntDuplicate() public void WhenRefWithNoCondAlreadyExistsItDoesntDuplicate()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand() new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot) .WithWorkingDirectory(setup.TestRoot)
@ -328,7 +328,7 @@ Additional Arguments:
.WithProject(lib.CsProjName) .WithProject(lib.CsProjName)
.Execute($"\"{setup.ValidRefCsprojPath}\""); .Execute($"\"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Project already has a reference to `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj`."); cmd.StdOut.Should().Be("Project already has a reference to `ValidRef\\ValidRef.csproj`.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
@ -354,8 +354,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithCondOnItemGroupAlreadyExistsItDoesntDuplicate() public void WhenRefWithCondOnItemGroupAlreadyExistsItDoesntDuplicate()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand() new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot) .WithWorkingDirectory(setup.TestRoot)
@ -369,7 +369,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\""); .Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Project already has a reference to `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj`."); cmd.StdOut.Should().Be("Project already has a reference to `ValidRef\\ValidRef.csproj`.");
lib.CsProjContent().Should().BeEquivalentTo(csprojContentBefore); lib.CsProjContent().Should().BeEquivalentTo(csprojContentBefore);
} }
@ -478,11 +478,11 @@ Additional Arguments:
[Fact] [Fact]
public void ItAddsMultipleRefsNoCondToTheSameItemGroup() public void ItAddsMultipleRefsNoCondToTheSameItemGroup()
{ {
const string OutputText = @"Reference `DotnetAddP2PProjects\Lib\Lib.csproj` added to the project. const string OutputText = @"Reference `Lib\Lib.csproj` added to the project.
Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."; Reference `ValidRef\ValidRef.csproj` added to the project.";
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition(); int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new AddReferenceCommand() var cmd = new AddReferenceCommand()
@ -500,11 +500,11 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
[Fact] [Fact]
public void ItAddsMultipleRefsWithCondToTheSameItemGroup() public void ItAddsMultipleRefsWithCondToTheSameItemGroup()
{ {
const string OutputText = @"Reference `DotnetAddP2PProjects\Lib\Lib.csproj` added to the project. const string OutputText = @"Reference `Lib\Lib.csproj` added to the project.
Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."; Reference `ValidRef\ValidRef.csproj` added to the project.";
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451); int noCondBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
var cmd = new AddReferenceCommand() var cmd = new AddReferenceCommand()
@ -522,15 +522,15 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
[Fact] [Fact]
public void WhenProjectNameIsNotPassedItFindsItAndAddsReference() public void WhenProjectNameIsNotPassedItFindsItAndAddsReference()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition(); int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new AddReferenceCommand() var cmd = new AddReferenceCommand()
.WithWorkingDirectory(lib.Path) .WithWorkingDirectory(lib.Path)
.Execute($"\"{setup.ValidRefCsprojPath}\""); .Execute($"\"{setup.ValidRefCsprojPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Reference `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj` added to the project."); cmd.StdOut.Should().Be("Reference `ValidRef\\ValidRef.csproj` added to the project.");
cmd.StdErr.Should().BeEmpty(); cmd.StdErr.Should().BeEmpty();
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
@ -571,8 +571,8 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
[Fact] [Fact]
public void WhenPassedReferenceIsUsingSlashesItNormalizesItToBackslashes() public void WhenPassedReferenceIsUsingSlashesItNormalizesItToBackslashes()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition(); int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new AddReferenceCommand() var cmd = new AddReferenceCommand()
@ -580,7 +580,7 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
.WithProject(lib.CsProjName) .WithProject(lib.CsProjName)
.Execute($"\"{setup.ValidRefCsprojPath.Replace('\\', '/')}\""); .Execute($"\"{setup.ValidRefCsprojPath.Replace('\\', '/')}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be("Reference `DotnetAddP2PProjects\\ValidRef\\ValidRef.csproj` added to the project."); cmd.StdOut.Should().Be("Reference `ValidRef\\ValidRef.csproj` added to the project.");
cmd.StdErr.Should().BeEmpty(); cmd.StdErr.Should().BeEmpty();
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);

View file

@ -41,7 +41,7 @@ namespace Microsoft.DotNet.Cli.Build.Tests
[Fact] [Fact]
public void ItRunsWhenRestoringToSpecificPackageDir() public void ItRunsWhenRestoringToSpecificPackageDir()
{ {
var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootPath = TestAssets.CreateTestDirectory().FullName;
string dir = "pkgs"; string dir = "pkgs";
string args = $"--packages {dir}"; string args = $"--packages {dir}";

View file

@ -134,10 +134,10 @@ Options:
{ {
const string OutputText = @"Project reference(s) const string OutputText = @"Project reference(s)
-------------------- --------------------
..\ItPrintsSingleReferenceref\ItPrintsSingleReferenceref.csproj"; ..\ref\ref.csproj";
var lib = NewLib("ItPrintsSingleReference", "lib"); var lib = NewLib("lib");
string ref1 = NewLib("ItPrintsSingleReference", "ref").CsProjPath; string ref1 = NewLib("ref").CsProjPath;
AddValidRef(ref1, lib); AddValidRef(ref1, lib);
var cmd = new ListReferenceCommand() var cmd = new ListReferenceCommand()
@ -152,14 +152,14 @@ Options:
{ {
const string OutputText = @"Project reference(s) const string OutputText = @"Project reference(s)
-------------------- --------------------
..\ItPrintsSingleReferenceref1\ItPrintsSingleReferenceref1.csproj ..\ref1\ref1.csproj
..\ItPrintsSingleReferenceref2\ItPrintsSingleReferenceref2.csproj ..\ref2\ref2.csproj
..\ItPrintsSingleReferenceref3\ItPrintsSingleReferenceref3.csproj"; ..\ref3\ref3.csproj";
var lib = NewLib("ItPrintsSingleReference", "lib"); var lib = NewLib("lib");
string ref1 = NewLib("ItPrintsSingleReference", "ref1").CsProjPath; string ref1 = NewLib("ref1").CsProjPath;
string ref2 = NewLib("ItPrintsSingleReference", "ref2").CsProjPath; string ref2 = NewLib("ref2").CsProjPath;
string ref3 = NewLib("ItPrintsSingleReference", "ref3").CsProjPath; string ref3 = NewLib("ref3").CsProjPath;
AddValidRef(ref1, lib); AddValidRef(ref1, lib);
AddValidRef(ref2, lib); AddValidRef(ref2, lib);
@ -182,14 +182,14 @@ Options:
.FullName); .FullName);
} }
private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "") private ProjDir NewDir(string testProjectName = "temp", [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
{ {
return new ProjDir(TestAssetsManager.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).Path); return new ProjDir(TestAssets.CreateTestDirectory(testProjectName: testProjectName, callingMethod: callingMethod, identifier: identifier).FullName);
} }
private ProjDir NewLib([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "") private ProjDir NewLib(string testProjectName = "temp", [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
{ {
var dir = NewDir(callingMethod: callingMethod, identifier: identifier); var dir = NewDir(testProjectName: testProjectName, callingMethod: callingMethod, identifier: identifier);
try try
{ {

View file

@ -29,10 +29,11 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
[Fact] [Fact]
public void ItRunsSpecifiedTargetsWithPropertiesCorrectly() public void ItRunsSpecifiedTargetsWithPropertiesCorrectly()
{ {
var testInstance = TestAssetsManager var testInstance = TestAssets.Get("MSBuildBareBonesProject")
.CreateTestInstance("MSBuildBareBonesProject"); .CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root;
new MSBuildCommand() new MSBuildCommand()
.WithWorkingDirectory(testProjectDirectory) .WithWorkingDirectory(testProjectDirectory)
@ -60,29 +61,22 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
} }
[Theory] [Theory]
[InlineData("build", true)] [InlineData("build")]
[InlineData("clean", true)] [InlineData("clean")]
[InlineData("pack", true)] [InlineData("pack")]
[InlineData("publish", true)] [InlineData("publish")]
[InlineData("restore", true)] [InlineData("restore")]
public void When_help_is_invoked_Then_MSBuild_extra_options_text_is_included_in_output(string commandName, bool isMSBuildCommand) public void When_help_is_invoked_Then_MSBuild_extra_options_text_is_included_in_output(string commandName)
{ {
const string MSBuildHelpText = " Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options."; const string MSBuildHelpText = " Any extra options that should be passed to MSBuild. See 'dotnet msbuild -h' for available options.";
var projectDirectory = TestAssetsManager.CreateTestDirectory("ItContainsMSBuildHelpText"); var projectDirectory = TestAssets.CreateTestDirectory(commandName);
var result = new TestCommand("dotnet") var result = new TestCommand("dotnet")
.WithWorkingDirectory(projectDirectory.Path) .WithWorkingDirectory(projectDirectory)
.ExecuteWithCapturedOutput($"{commandName} --help"); .ExecuteWithCapturedOutput($"{commandName} --help");
result.ExitCode.Should().Be(0); result.ExitCode.Should().Be(0);
if (isMSBuildCommand) result.StdOut.Should().Contain(MSBuildHelpText);
{
result.StdOut.Should().Contain(MSBuildHelpText);
}
else
{
result.StdOut.Should().NotContain(MSBuildHelpText);
}
} }
[Fact] [Fact]
@ -121,9 +115,9 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
{ {
const string AppArgumentsText = "Arguments passed to the application that is being run."; const string AppArgumentsText = "Arguments passed to the application that is being run.";
var projectDirectory = TestAssetsManager.CreateTestDirectory("RunContainsAppArgumentsText"); var projectDirectory = TestAssets.CreateTestDirectory("RunContainsAppArgumentsText");
var result = new TestCommand("dotnet") var result = new TestCommand("dotnet")
.WithWorkingDirectory(projectDirectory.Path) .WithWorkingDirectory(projectDirectory)
.ExecuteWithCapturedOutput("run --help"); .ExecuteWithCapturedOutput("run --help");
result.ExitCode.Should().Be(0); result.ExitCode.Should().Be(0);

View file

@ -16,7 +16,7 @@ namespace Microsoft.DotNet.New.Tests
[Fact] [Fact]
public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail() public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail()
{ {
var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootPath = TestAssets.CreateTestDirectory().FullName;
new NewCommand() new NewCommand()
.WithWorkingDirectory(rootPath) .WithWorkingDirectory(rootPath)
@ -40,7 +40,7 @@ namespace Microsoft.DotNet.New.Tests
{ {
string[] cSharpTemplates = new[] { "console", "classlib", "mstest", "xunit", "web", "mvc", "webapi" }; string[] cSharpTemplates = new[] { "console", "classlib", "mstest", "xunit", "web", "mvc", "webapi" };
var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootPath = TestAssets.CreateTestDirectory().FullName;
var packagesDirectory = Path.Combine(rootPath, "packages"); var packagesDirectory = Path.Combine(rootPath, "packages");
foreach (string cSharpTemplate in cSharpTemplates) foreach (string cSharpTemplate in cSharpTemplates)
@ -73,7 +73,7 @@ namespace Microsoft.DotNet.New.Tests
[Fact] [Fact]
public void NewClassLibRestoresCorrectNetStandardLibraryVersion() public void NewClassLibRestoresCorrectNetStandardLibraryVersion()
{ {
var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootPath = TestAssets.CreateTestDirectory().FullName;
var packagesDirectory = Path.Combine(rootPath, "packages"); var packagesDirectory = Path.Combine(rootPath, "packages");
var projectName = "Library"; var projectName = "Library";
var projectFileName = $"{projectName}.csproj"; var projectFileName = $"{projectName}.csproj";

View file

@ -30,7 +30,7 @@ namespace Microsoft.DotNet.New.Tests
string projectType, string projectType,
bool useNuGetConfigForAspNet) bool useNuGetConfigForAspNet)
{ {
string rootPath = TestAssetsManager.CreateTestDirectory(identifier: $"{language}_{projectType}").Path; string rootPath = TestAssets.CreateTestDirectory(identifier: $"{language}_{projectType}").FullName;
new TestCommand("dotnet") { WorkingDirectory = rootPath } new TestCommand("dotnet") { WorkingDirectory = rootPath }
.Execute($"new {projectType} -lang {language} -o {rootPath} --debug:ephemeral-hive") .Execute($"new {projectType} -lang {language} -o {rootPath} --debug:ephemeral-hive")
@ -38,7 +38,7 @@ namespace Microsoft.DotNet.New.Tests
if (useNuGetConfigForAspNet) if (useNuGetConfigForAspNet)
{ {
var configFile = new FileInfo(Path.Combine(rootPath,"..","..","..","..","NuGet.tempaspnetpatch.config")); var configFile = new FileInfo(Path.Combine(rootPath, "..", "..", "..", "..", "..", "NuGet.tempaspnetpatch.config"));
File.Copy(configFile.FullName, Path.Combine(rootPath, "NuGet.Config")); File.Copy(configFile.FullName, Path.Combine(rootPath, "NuGet.Config"));
} }

View file

@ -210,7 +210,7 @@ namespace Microsoft.DotNet.Tools.Pack.Tests
[Fact] [Fact]
public void ItPacksAppWhenRestoringToSpecificPackageDirectory() public void ItPacksAppWhenRestoringToSpecificPackageDirectory()
{ {
var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootPath = TestAssets.CreateTestDirectory().FullName;
var rootDir = new DirectoryInfo(rootPath); var rootDir = new DirectoryInfo(rootPath);
string dir = "pkgs"; string dir = "pkgs";

View file

@ -19,10 +19,11 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
public void ItPublishesARunnablePortableApp() public void ItPublishesARunnablePortableApp()
{ {
var testAppName = "MSBuildTestApp"; var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager var testInstance = TestAssets.Get(testAppName)
.CreateTestInstance(testAppName); .CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
new RestoreCommand() new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory) .WithWorkingDirectory(testProjectDirectory)
@ -87,7 +88,7 @@ namespace Microsoft.DotNet.Cli.Publish.Tests
[Fact] [Fact]
public void ItPublishesAppWhenRestoringToSpecificPackageDirectory() public void ItPublishesAppWhenRestoringToSpecificPackageDirectory()
{ {
var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootPath = TestAssets.CreateTestDirectory().FullName;
var rootDir = new DirectoryInfo(rootPath); var rootDir = new DirectoryInfo(rootPath);
string dir = "pkgs"; string dir = "pkgs";

View file

@ -46,27 +46,27 @@ Additional Arguments:
private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "") private ProjDir NewDir([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
{ {
return new ProjDir(TestAssetsManager.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).Path); return new ProjDir(TestAssets.CreateTestDirectory(callingMethod: callingMethod, identifier: identifier).FullName);
} }
private ProjDir NewLib([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "") private ProjDir NewLib(string dir = null, [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
{ {
var dir = NewDir(callingMethod: callingMethod, identifier: identifier); var projDir = dir == null ? NewDir(callingMethod: callingMethod, identifier: identifier) : new ProjDir(dir);
try try
{ {
string newArgs = $"classlib -o \"{dir.Path}\""; string newArgs = $"classlib -o \"{projDir.Path}\"";
new NewCommandShim() new NewCommandShim()
.WithWorkingDirectory(dir.Path) .WithWorkingDirectory(projDir.Path)
.ExecuteWithCapturedOutput(newArgs) .ExecuteWithCapturedOutput(newArgs)
.Should().Pass(); .Should().Pass();
} }
catch (System.ComponentModel.Win32Exception e) catch (System.ComponentModel.Win32Exception e)
{ {
throw new Exception($"Intermittent error in `dotnet new` occurred when running it in dir `{dir.Path}`\nException:\n{e}"); throw new Exception($"Intermittent error in `dotnet new` occurred when running it in dir `{projDir.Path}`\nException:\n{e}");
} }
return dir; return projDir;
} }
private static void SetTargetFrameworks(ProjDir proj, string[] frameworks) private static void SetTargetFrameworks(ProjDir proj, string[] frameworks)
@ -76,9 +76,9 @@ Additional Arguments:
csproj.Save(); csproj.Save();
} }
private ProjDir NewLibWithFrameworks([System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "") private ProjDir NewLibWithFrameworks(string dir = null, [System.Runtime.CompilerServices.CallerMemberName] string callingMethod = nameof(NewDir), string identifier = "")
{ {
var ret = NewLib(callingMethod: callingMethod, identifier: identifier); var ret = NewLib(dir, callingMethod: callingMethod, identifier: identifier);
SetTargetFrameworks(ret, DefaultFrameworks); SetTargetFrameworks(ret, DefaultFrameworks);
return ret; return ret;
} }
@ -205,8 +205,8 @@ Additional Arguments:
[Fact] [Fact]
public void ItRemovesRefWithoutCondAndPrintsStatus() public void ItRemovesRefWithoutCondAndPrintsStatus()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = AddLibRef(setup, lib); var libref = AddLibRef(setup, lib);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition(); int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
@ -215,7 +215,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"\"{libref.CsProjPath}\""); .Execute($"\"{libref.CsProjPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be($"Project reference `{Path.Combine(TestSetup.ProjectName, "Lib", setup.LibCsprojName)}` removed."); cmd.StdOut.Should().Be($"Project reference `{Path.Combine("Lib", setup.LibCsprojName)}` removed.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0); csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
@ -224,8 +224,8 @@ Additional Arguments:
[Fact] [Fact]
public void ItRemovesRefWithCondAndPrintsStatus() public void ItRemovesRefWithCondAndPrintsStatus()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = AddLibRef(setup, lib, FrameworkNet451Arg); var libref = AddLibRef(setup, lib, FrameworkNet451Arg);
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451); int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
@ -234,7 +234,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{libref.CsProjPath}\""); .Execute($"{FrameworkNet451Arg} \"{libref.CsProjPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be($"Project reference `{Path.Combine(TestSetup.ProjectName, "Lib", setup.LibCsprojName)}` removed."); cmd.StdOut.Should().Be($"Project reference `{Path.Combine("Lib", setup.LibCsprojName)}` removed.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore - 1); csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore - 1);
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(libref.Name, ConditionFrameworkNet451).Should().Be(0); csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(libref.Name, ConditionFrameworkNet451).Should().Be(0);
@ -243,8 +243,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenTwoDifferentRefsArePresentItDoesNotRemoveBoth() public void WhenTwoDifferentRefsArePresentItDoesNotRemoveBoth()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = AddLibRef(setup, lib); var libref = AddLibRef(setup, lib);
var validref = AddValidRef(setup, lib); var validref = AddValidRef(setup, lib);
@ -254,7 +254,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"\"{libref.CsProjPath}\""); .Execute($"\"{libref.CsProjPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be($"Project reference `{Path.Combine(TestSetup.ProjectName, "Lib", setup.LibCsprojName)}` removed."); cmd.StdOut.Should().Be($"Project reference `{Path.Combine("Lib", setup.LibCsprojName)}` removed.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0); csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
@ -263,8 +263,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithoutCondIsNotThereItPrintsMessage() public void WhenRefWithoutCondIsNotThereItPrintsMessage()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = GetLibRef(setup); var libref = GetLibRef(setup);
string csprojContetntBefore = lib.CsProjContent(); string csprojContetntBefore = lib.CsProjContent();
@ -280,8 +280,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithCondIsNotThereItPrintsMessage() public void WhenRefWithCondIsNotThereItPrintsMessage()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = GetLibRef(setup); var libref = GetLibRef(setup);
string csprojContetntBefore = lib.CsProjContent(); string csprojContetntBefore = lib.CsProjContent();
@ -297,8 +297,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithAndWithoutCondArePresentAndRemovingNoCondItDoesNotRemoveOther() public void WhenRefWithAndWithoutCondArePresentAndRemovingNoCondItDoesNotRemoveOther()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var librefCond = AddLibRef(setup, lib, FrameworkNet451Arg); var librefCond = AddLibRef(setup, lib, FrameworkNet451Arg);
var librefNoCond = AddLibRef(setup, lib); var librefNoCond = AddLibRef(setup, lib);
@ -310,7 +310,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"\"{librefNoCond.CsProjPath}\""); .Execute($"\"{librefNoCond.CsProjPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be($"Project reference `{Path.Combine(TestSetup.ProjectName, "Lib", setup.LibCsprojName)}` removed."); cmd.StdOut.Should().Be($"Project reference `{Path.Combine("Lib", setup.LibCsprojName)}` removed.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
csproj.NumberOfProjectReferencesWithIncludeContaining(librefNoCond.Name).Should().Be(0); csproj.NumberOfProjectReferencesWithIncludeContaining(librefNoCond.Name).Should().Be(0);
@ -322,8 +322,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithAndWithoutCondArePresentAndRemovingCondItDoesNotRemoveOther() public void WhenRefWithAndWithoutCondArePresentAndRemovingCondItDoesNotRemoveOther()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var librefCond = AddLibRef(setup, lib, FrameworkNet451Arg); var librefCond = AddLibRef(setup, lib, FrameworkNet451Arg);
var librefNoCond = AddLibRef(setup, lib); var librefNoCond = AddLibRef(setup, lib);
@ -335,7 +335,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{librefCond.CsProjPath}\""); .Execute($"{FrameworkNet451Arg} \"{librefCond.CsProjPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be($"Project reference `{Path.Combine(TestSetup.ProjectName, "Lib", setup.LibCsprojName)}` removed."); cmd.StdOut.Should().Be($"Project reference `{Path.Combine("Lib", setup.LibCsprojName)}` removed.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore); csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
csproj.NumberOfProjectReferencesWithIncludeContaining(librefNoCond.Name).Should().Be(1); csproj.NumberOfProjectReferencesWithIncludeContaining(librefNoCond.Name).Should().Be(1);
@ -347,8 +347,8 @@ Additional Arguments:
[Fact] [Fact]
public void WhenRefWithDifferentCondIsPresentItDoesNotRemoveIt() public void WhenRefWithDifferentCondIsPresentItDoesNotRemoveIt()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var librefCondNet451 = AddLibRef(setup, lib, FrameworkNet451Arg); var librefCondNet451 = AddLibRef(setup, lib, FrameworkNet451Arg);
var librefCondNetCoreApp10 = AddLibRef(setup, lib, FrameworkNetCoreApp10Arg); var librefCondNetCoreApp10 = AddLibRef(setup, lib, FrameworkNetCoreApp10Arg);
@ -360,7 +360,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath) .WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{librefCondNet451.CsProjPath}\""); .Execute($"{FrameworkNet451Arg} \"{librefCondNet451.CsProjPath}\"");
cmd.Should().Pass(); cmd.Should().Pass();
cmd.StdOut.Should().Be($"Project reference `{Path.Combine(TestSetup.ProjectName, "Lib", setup.LibCsprojName)}` removed."); cmd.StdOut.Should().Be($"Project reference `{Path.Combine("Lib", setup.LibCsprojName)}` removed.");
var csproj = lib.CsProj(); var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condNet451Before - 1); csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condNet451Before - 1);
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(librefCondNet451.Name, ConditionFrameworkNet451).Should().Be(0); csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(librefCondNet451.Name, ConditionFrameworkNet451).Should().Be(0);
@ -452,13 +452,13 @@ Project reference `{setup.LibCsprojRelPath}` removed.";
[Fact] [Fact]
public void WhenPassingMultipleReferencesItRemovesThemAll() public void WhenPassingMultipleReferencesItRemovesThemAll()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = AddLibRef(setup, lib); var libref = AddLibRef(setup, lib);
var validref = AddValidRef(setup, lib); var validref = AddValidRef(setup, lib);
string outputText = $@"Project reference `{Path.Combine(TestSetup.ProjectName, "Lib", setup.LibCsprojName)}` removed. string outputText = $@"Project reference `{Path.Combine("Lib", setup.LibCsprojName)}` removed.
Project reference `{Path.Combine(TestSetup.ProjectName, setup.ValidRefCsprojRelPath)}` removed."; Project reference `{Path.Combine(setup.ValidRefCsprojRelPath)}` removed.";
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition(); int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new RemoveReferenceCommand() var cmd = new RemoveReferenceCommand()
@ -476,13 +476,13 @@ Project reference `{Path.Combine(TestSetup.ProjectName, setup.ValidRefCsprojRelP
[Fact] [Fact]
public void WhenPassingMultipleReferencesAndOneOfThemDoesNotExistItRemovesOne() public void WhenPassingMultipleReferencesAndOneOfThemDoesNotExistItRemovesOne()
{ {
var lib = NewLibWithFrameworks();
var setup = Setup(); var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = GetLibRef(setup); var libref = GetLibRef(setup);
var validref = AddValidRef(setup, lib); var validref = AddValidRef(setup, lib);
string OutputText = $@"Project reference `{setup.LibCsprojPath}` could not be found. string OutputText = $@"Project reference `{setup.LibCsprojPath}` could not be found.
Project reference `{Path.Combine(TestSetup.ProjectName, setup.ValidRefCsprojRelPath)}` removed."; Project reference `{Path.Combine(setup.ValidRefCsprojRelPath)}` removed.";
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition(); int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new RemoveReferenceCommand() var cmd = new RemoveReferenceCommand()

View file

@ -17,7 +17,7 @@ namespace Microsoft.DotNet.Restore.Tests
[Fact] [Fact]
public void ItRestoresAppToSpecificDirectory() public void ItRestoresAppToSpecificDirectory()
{ {
var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootPath = TestAssets.CreateTestDirectory().FullName;
string dir = "pkgs"; string dir = "pkgs";
string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir)); string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir));
@ -44,7 +44,7 @@ namespace Microsoft.DotNet.Restore.Tests
[Fact] [Fact]
public void ItRestoresLibToSpecificDirectory() public void ItRestoresLibToSpecificDirectory()
{ {
var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootPath = TestAssets.CreateTestDirectory().FullName;
string dir = "pkgs"; string dir = "pkgs";
string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir)); string fullPath = Path.GetFullPath(Path.Combine(rootPath, dir));

View file

@ -13,10 +13,11 @@ namespace Microsoft.DotNet.Cli.Run.Tests
public void ItCanRunAMSBuildProject() public void ItCanRunAMSBuildProject()
{ {
var testAppName = "MSBuildTestApp"; var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager var testInstance = TestAssets.Get(testAppName)
.CreateTestInstance(testAppName); .CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
new RestoreCommand() new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory) .WithWorkingDirectory(testProjectDirectory)
@ -39,10 +40,11 @@ namespace Microsoft.DotNet.Cli.Run.Tests
public void ItBuildsTheProjectBeforeRunning() public void ItBuildsTheProjectBeforeRunning()
{ {
var testAppName = "MSBuildTestApp"; var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager var testInstance = TestAssets.Get(testAppName)
.CreateTestInstance(testAppName); .CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
new RestoreCommand() new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory) .WithWorkingDirectory(testProjectDirectory)
@ -60,10 +62,11 @@ namespace Microsoft.DotNet.Cli.Run.Tests
public void ItCanRunAMSBuildProjectWhenSpecifyingAFramework() public void ItCanRunAMSBuildProjectWhenSpecifyingAFramework()
{ {
var testAppName = "MSBuildTestApp"; var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager var testInstance = TestAssets.Get(testAppName)
.CreateTestInstance(testAppName); .CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
new RestoreCommand() new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory) .WithWorkingDirectory(testProjectDirectory)
@ -118,7 +121,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests
[Fact] [Fact]
public void ItRunsAppWhenRestoringToSpecificPackageDirectory() public void ItRunsAppWhenRestoringToSpecificPackageDirectory()
{ {
var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootPath = TestAssets.CreateTestDirectory().FullName;
string dir = "pkgs"; string dir = "pkgs";
string args = $"--packages {dir}"; string args = $"--packages {dir}";

View file

@ -47,9 +47,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests
{ {
// Copy VSTestXunitDesktopAndNetCore project in output directory of project dotnet-test.Tests // Copy VSTestXunitDesktopAndNetCore project in output directory of project dotnet-test.Tests
string testAppName = "VSTestXunitDesktopAndNetCore"; string testAppName = "VSTestXunitDesktopAndNetCore";
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName); var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
string testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestXunitDesktopAndNetCore // Restore project VSTestXunitDesktopAndNetCore
new RestoreCommand() new RestoreCommand()

View file

@ -18,9 +18,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests
{ {
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests // Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDotNetCore"; string testAppName = "VSTestDotNetCore";
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName); var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
string testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestDotNetCore // Restore project VSTestDotNetCore
new RestoreCommand() new RestoreCommand()
@ -46,9 +48,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests
{ {
// Copy VSTestXunitDotNetCore project in output directory of project dotnet-vstest.Tests // Copy VSTestXunitDotNetCore project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestXunitDotNetCore"; string testAppName = "VSTestXunitDotNetCore";
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName); var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
string testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestXunitDotNetCore // Restore project VSTestXunitDotNetCore
new RestoreCommand() new RestoreCommand()
@ -74,9 +78,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests
{ {
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests // Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDotNetCore"; string testAppName = "VSTestDotNetCore";
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName); var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
string testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestDotNetCore // Restore project VSTestDotNetCore
new RestoreCommand() new RestoreCommand()
@ -104,9 +110,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests
{ {
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests // Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDotNetCore"; string testAppName = "VSTestDotNetCore";
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName); var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
string testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestDotNetCore // Restore project VSTestDotNetCore
new RestoreCommand() new RestoreCommand()
@ -118,7 +126,7 @@ namespace Microsoft.DotNet.Cli.Test.Tests
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TestResults"); string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TestResults");
// Delete trxLoggerDirectory if it exist // Delete trxLoggerDirectory if it exist
if(Directory.Exists(trxLoggerDirectory)) if (Directory.Exists(trxLoggerDirectory))
{ {
Directory.Delete(trxLoggerDirectory, true); Directory.Delete(trxLoggerDirectory, true);
} }
@ -145,9 +153,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests
{ {
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests // Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
string testAppName = "VSTestDotNetCore"; string testAppName = "VSTestDotNetCore";
TestInstance testInstance = TestAssetsManager.CreateTestInstance(testAppName); var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
string testProjectDirectory = testInstance.TestRoot; var testProjectDirectory = testInstance.Root.FullName;
// Restore project VSTestDotNetCore // Restore project VSTestDotNetCore
new RestoreCommand() new RestoreCommand()

View file

@ -14,18 +14,19 @@ namespace Microsoft.DotNet.Tests
[Fact] [Fact]
public void UnresolvedPlatformReferencesFailAsExpected() public void UnresolvedPlatformReferencesFailAsExpected()
{ {
var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects"); var testInstance = TestAssets.Get("NonRestoredTestProjects", "TestProjectWithUnresolvedPlatformDependency")
.CreateInstance()
var testInstance = testAssetsManager.CreateTestInstance("TestProjectWithUnresolvedPlatformDependency"); .WithSourceFiles()
.Root.FullName;
new RestoreCommand() new RestoreCommand()
.WithWorkingDirectory(testInstance.TestRoot) .WithWorkingDirectory(testInstance)
.ExecuteWithCapturedOutput("/p:SkipInvalidConfigurations=true") .ExecuteWithCapturedOutput("/p:SkipInvalidConfigurations=true")
.Should() .Should()
.Fail(); .Fail();
new DotnetCommand() new DotnetCommand()
.WithWorkingDirectory(testInstance.TestRoot) .WithWorkingDirectory(testInstance)
.ExecuteWithCapturedOutput("crash") .ExecuteWithCapturedOutput("crash")
.Should().Fail() .Should().Fail()
.And.HaveStdErrContaining("No executable found matching command \"dotnet-crash\""); .And.HaveStdErrContaining("No executable found matching command \"dotnet-crash\"");

View file

@ -27,14 +27,14 @@ namespace Microsoft.DotNet.Tests
[Fact] [Fact]
public void WhenInvokedThenDotnetWritesOptimizationDataToTheProfileRoot() public void WhenInvokedThenDotnetWritesOptimizationDataToTheProfileRoot()
{ {
var testDirectory = TestAssetsManager.CreateTestDirectory(); var testDirectory = TestAssets.CreateTestDirectory();
var testStartTime = GetTruncatedDateTime(); var testStartTime = GetTruncatedDateTime();
new TestCommand("dotnet") new TestCommand("dotnet")
.WithUserProfileRoot(testDirectory.Path) .WithUserProfileRoot(testDirectory.FullName)
.ExecuteWithCapturedOutput("--help"); .ExecuteWithCapturedOutput("--help");
var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.Path); var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.FullName);
new FileInfo(optimizationProfileFilePath) new FileInfo(optimizationProfileFilePath)
.Should().Exist("Because dotnet CLI creates it after each run") .Should().Exist("Because dotnet CLI creates it after each run")
@ -45,15 +45,15 @@ namespace Microsoft.DotNet.Tests
[Fact] [Fact]
public void WhenInvokedWithMulticoreJitDisabledThenDotnetDoesNotWriteOptimizationDataToTheProfileRoot() public void WhenInvokedWithMulticoreJitDisabledThenDotnetDoesNotWriteOptimizationDataToTheProfileRoot()
{ {
var testDirectory = TestAssetsManager.CreateTestDirectory(); var testDirectory = TestAssets.CreateTestDirectory();
var testStartTime = GetTruncatedDateTime(); var testStartTime = GetTruncatedDateTime();
new TestCommand("dotnet") new TestCommand("dotnet")
.WithUserProfileRoot(testDirectory.Path) .WithUserProfileRoot(testDirectory.FullName)
.WithEnvironmentVariable("DOTNET_DISABLE_MULTICOREJIT", "1") .WithEnvironmentVariable("DOTNET_DISABLE_MULTICOREJIT", "1")
.ExecuteWithCapturedOutput("--help"); .ExecuteWithCapturedOutput("--help");
var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.Path); var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.FullName);
File.Exists(optimizationProfileFilePath) File.Exists(optimizationProfileFilePath)
.Should().BeFalse("Because multicore JIT is disabled"); .Should().BeFalse("Because multicore JIT is disabled");
@ -62,10 +62,10 @@ namespace Microsoft.DotNet.Tests
[Fact] [Fact]
public void WhenTheProfileRootIsUndefinedThenDotnetDoesNotCrash() public void WhenTheProfileRootIsUndefinedThenDotnetDoesNotCrash()
{ {
var testDirectory = TestAssetsManager.CreateTestDirectory(); var testDirectory = TestAssets.CreateTestDirectory();
var testStartTime = GetTruncatedDateTime(); var testStartTime = GetTruncatedDateTime();
var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.Path); var optimizationProfileFilePath = GetOptimizationProfileFilePath(testDirectory.FullName);
new TestCommand("dotnet") new TestCommand("dotnet")
.WithUserProfileRoot("") .WithUserProfileRoot("")

View file

@ -23,11 +23,11 @@ namespace Microsoft.DotNet.Tests
static GivenThatTheUserIsRunningDotNetForTheFirstTime() static GivenThatTheUserIsRunningDotNetForTheFirstTime()
{ {
var testDirectory = TestAssetsManager.CreateTestDirectory("Dotnet_first_time_experience_tests"); var testDirectory = TestAssets.CreateTestDirectory("Dotnet_first_time_experience_tests");
var testNugetCache = Path.Combine(testDirectory.Path, "nuget_cache"); var testNugetCache = Path.Combine(testDirectory.FullName, "nuget_cache");
var command = new DotnetCommand() var command = new DotnetCommand()
.WithWorkingDirectory(testDirectory.Path); .WithWorkingDirectory(testDirectory);
command.Environment["NUGET_PACKAGES"] = testNugetCache; command.Environment["NUGET_PACKAGES"] = testNugetCache;
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = ""; command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
command.Environment["SkipInvalidConfigurations"] = "true"; command.Environment["SkipInvalidConfigurations"] = "true";