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);
}
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);

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 projectDirectory = TestAssetsManager.CreateTestDirectory();
var projectDirectory = TestAssets.CreateTestDirectory();
var commandResolverArguments = new CommandResolverArguments()
{
CommandName = "command",
CommandArguments = new string[] { "" },
ProjectDirectory = projectDirectory.Path
ProjectDirectory = projectDirectory.Root.FullName
};
var result = projectToolsCommandResolver.Resolve(commandResolverArguments);

View file

@ -115,16 +115,17 @@ namespace StreamForwarderTests
private string SetupTestProject()
{
var testInstance = TestAssetsManager
.CreateTestInstance("OutputStandardOutputAndError")
.WithLockFiles();
var testPath = TestAssets.Get("OutputStandardOutputAndError")
.CreateInstance()
.WithRestoreFiles()
.Root.FullName;
var buildCommand = new BuildCommand()
.WithProjectFile(new FileInfo(Path.Combine(testInstance.Path, "project.json")))
.WithProjectFile(new FileInfo(Path.Combine(testPath, "project.json")))
.Execute();
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;
}

View file

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

View file

@ -13,14 +13,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
/// </summary>
public class ProjectJsonBuilder
{
private readonly TestAssetsManager _testAssetsManager;
private readonly TestAssets _testAssets;
private JObject _projectJson;
private bool _baseDefined = false;
public ProjectJsonBuilder(TestAssetsManager testAssetsManager)
public ProjectJsonBuilder(TestAssets testAssets)
{
_testAssetsManager = testAssetsManager;
_testAssets = testAssets;
}
public string SaveToDisk(string outputDirectory)
@ -40,7 +40,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
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");
SetBase(JObject.Parse(File.ReadAllText(testProject)));

View file

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

View file

@ -37,7 +37,10 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
}
// 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 testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, testProjectDirectory, templateProj);

View file

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

View file

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

View file

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

View file

@ -20,7 +20,6 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
protected const string DefaultFramework = "netcoreapp1.0";
protected const string DefaultLibraryFramework = "netstandard1.5";
private TempRoot _temp;
private static TestAssetsManager s_testsAssetsMgr;
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
{
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()
{
}

View file

@ -49,27 +49,27 @@ Additional Arguments:
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
{
string args = $"classlib -o \"{dir.Path}\" --debug:ephemeral-hive";
string args = $"classlib -o \"{projDir.Path}\" --debug:ephemeral-hive";
new NewCommandShim()
.WithWorkingDirectory(dir.Path)
.WithWorkingDirectory(projDir.Path)
.ExecuteWithCapturedOutput(args)
.Should().Pass();
}
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)
@ -79,9 +79,9 @@ Additional Arguments:
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);
return ret;
}
@ -179,8 +179,8 @@ Additional Arguments:
[Fact]
public void ItAddsRefWithoutCondAndPrintsStatus()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new AddReferenceCommand()
@ -188,7 +188,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"\"{setup.ValidRefCsprojPath}\"");
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();
var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
@ -198,8 +198,8 @@ Additional Arguments:
[Fact]
public void ItAddsRefWithCondAndPrintsStatus()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
var cmd = new AddReferenceCommand()
@ -207,7 +207,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
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();
var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
@ -217,8 +217,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithoutCondIsPresentItAddsDifferentRefWithoutCond()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot)
@ -232,7 +232,7 @@ Additional Arguments:
.WithProject(lib.CsProjName)
.Execute($"\"{setup.ValidRefCsprojPath}\"");
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();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
@ -241,8 +241,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithCondIsPresentItAddsDifferentRefWithCond()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot)
@ -256,7 +256,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
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();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore);
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
@ -265,8 +265,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithCondIsPresentItAddsRefWithDifferentCond()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot)
@ -280,7 +280,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
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();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore + 1);
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(setup.ValidRefCsprojName, ConditionFrameworkNet451).Should().Be(1);
@ -289,8 +289,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithConditionIsPresentItAddsDifferentRefWithoutCond()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot)
@ -304,7 +304,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"\"{setup.ValidRefCsprojPath}\"");
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();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
csproj.NumberOfProjectReferencesWithIncludeContaining(setup.ValidRefCsprojName).Should().Be(1);
@ -313,8 +313,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithNoCondAlreadyExistsItDoesntDuplicate()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot)
@ -328,7 +328,7 @@ Additional Arguments:
.WithProject(lib.CsProjName)
.Execute($"\"{setup.ValidRefCsprojPath}\"");
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();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
@ -354,8 +354,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithCondOnItemGroupAlreadyExistsItDoesntDuplicate()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
new AddReferenceCommand()
.WithWorkingDirectory(setup.TestRoot)
@ -369,7 +369,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{setup.ValidRefCsprojPath}\"");
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);
}
@ -478,11 +478,11 @@ Additional Arguments:
[Fact]
public void ItAddsMultipleRefsNoCondToTheSameItemGroup()
{
const string OutputText = @"Reference `DotnetAddP2PProjects\Lib\Lib.csproj` added to the project.
Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project.";
const string OutputText = @"Reference `Lib\Lib.csproj` added to the project.
Reference `ValidRef\ValidRef.csproj` added to the project.";
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new AddReferenceCommand()
@ -500,11 +500,11 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
[Fact]
public void ItAddsMultipleRefsWithCondToTheSameItemGroup()
{
const string OutputText = @"Reference `DotnetAddP2PProjects\Lib\Lib.csproj` added to the project.
Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project.";
const string OutputText = @"Reference `Lib\Lib.csproj` added to the project.
Reference `ValidRef\ValidRef.csproj` added to the project.";
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
var cmd = new AddReferenceCommand()
@ -522,15 +522,15 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
[Fact]
public void WhenProjectNameIsNotPassedItFindsItAndAddsReference()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new AddReferenceCommand()
.WithWorkingDirectory(lib.Path)
.Execute($"\"{setup.ValidRefCsprojPath}\"");
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();
var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);
@ -571,8 +571,8 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
[Fact]
public void WhenPassedReferenceIsUsingSlashesItNormalizesItToBackslashes()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(dir: setup.TestRoot);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new AddReferenceCommand()
@ -580,7 +580,7 @@ Reference `DotnetAddP2PProjects\ValidRef\ValidRef.csproj` added to the project."
.WithProject(lib.CsProjName)
.Execute($"\"{setup.ValidRefCsprojPath.Replace('\\', '/')}\"");
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();
var csproj = lib.CsProj();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore + 1);

View file

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

View file

@ -134,10 +134,10 @@ Options:
{
const string OutputText = @"Project reference(s)
--------------------
..\ItPrintsSingleReferenceref\ItPrintsSingleReferenceref.csproj";
..\ref\ref.csproj";
var lib = NewLib("ItPrintsSingleReference", "lib");
string ref1 = NewLib("ItPrintsSingleReference", "ref").CsProjPath;
var lib = NewLib("lib");
string ref1 = NewLib("ref").CsProjPath;
AddValidRef(ref1, lib);
var cmd = new ListReferenceCommand()
@ -152,14 +152,14 @@ Options:
{
const string OutputText = @"Project reference(s)
--------------------
..\ItPrintsSingleReferenceref1\ItPrintsSingleReferenceref1.csproj
..\ItPrintsSingleReferenceref2\ItPrintsSingleReferenceref2.csproj
..\ItPrintsSingleReferenceref3\ItPrintsSingleReferenceref3.csproj";
..\ref1\ref1.csproj
..\ref2\ref2.csproj
..\ref3\ref3.csproj";
var lib = NewLib("ItPrintsSingleReference", "lib");
string ref1 = NewLib("ItPrintsSingleReference", "ref1").CsProjPath;
string ref2 = NewLib("ItPrintsSingleReference", "ref2").CsProjPath;
string ref3 = NewLib("ItPrintsSingleReference", "ref3").CsProjPath;
var lib = NewLib("lib");
string ref1 = NewLib("ref1").CsProjPath;
string ref2 = NewLib("ref2").CsProjPath;
string ref3 = NewLib("ref3").CsProjPath;
AddValidRef(ref1, lib);
AddValidRef(ref2, lib);
@ -182,14 +182,14 @@ Options:
.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
{

View file

@ -29,10 +29,11 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
[Fact]
public void ItRunsSpecifiedTargetsWithPropertiesCorrectly()
{
var testInstance = TestAssetsManager
.CreateTestInstance("MSBuildBareBonesProject");
var testInstance = TestAssets.Get("MSBuildBareBonesProject")
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.TestRoot;
var testProjectDirectory = testInstance.Root;
new MSBuildCommand()
.WithWorkingDirectory(testProjectDirectory)
@ -60,29 +61,22 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
}
[Theory]
[InlineData("build", true)]
[InlineData("clean", true)]
[InlineData("pack", true)]
[InlineData("publish", true)]
[InlineData("restore", true)]
public void When_help_is_invoked_Then_MSBuild_extra_options_text_is_included_in_output(string commandName, bool isMSBuildCommand)
[InlineData("build")]
[InlineData("clean")]
[InlineData("pack")]
[InlineData("publish")]
[InlineData("restore")]
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.";
var projectDirectory = TestAssetsManager.CreateTestDirectory("ItContainsMSBuildHelpText");
var projectDirectory = TestAssets.CreateTestDirectory(commandName);
var result = new TestCommand("dotnet")
.WithWorkingDirectory(projectDirectory.Path)
.WithWorkingDirectory(projectDirectory)
.ExecuteWithCapturedOutput($"{commandName} --help");
result.ExitCode.Should().Be(0);
if (isMSBuildCommand)
{
result.StdOut.Should().Contain(MSBuildHelpText);
}
else
{
result.StdOut.Should().NotContain(MSBuildHelpText);
}
result.StdOut.Should().Contain(MSBuildHelpText);
}
[Fact]
@ -121,9 +115,9 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
{
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")
.WithWorkingDirectory(projectDirectory.Path)
.WithWorkingDirectory(projectDirectory)
.ExecuteWithCapturedOutput("run --help");
result.ExitCode.Should().Be(0);

View file

@ -16,7 +16,7 @@ namespace Microsoft.DotNet.New.Tests
[Fact]
public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail()
{
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
var rootPath = TestAssets.CreateTestDirectory().FullName;
new NewCommand()
.WithWorkingDirectory(rootPath)
@ -40,7 +40,7 @@ namespace Microsoft.DotNet.New.Tests
{
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");
foreach (string cSharpTemplate in cSharpTemplates)
@ -73,7 +73,7 @@ namespace Microsoft.DotNet.New.Tests
[Fact]
public void NewClassLibRestoresCorrectNetStandardLibraryVersion()
{
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
var rootPath = TestAssets.CreateTestDirectory().FullName;
var packagesDirectory = Path.Combine(rootPath, "packages");
var projectName = "Library";
var projectFileName = $"{projectName}.csproj";

View file

@ -30,7 +30,7 @@ namespace Microsoft.DotNet.New.Tests
string projectType,
bool useNuGetConfigForAspNet)
{
string rootPath = TestAssetsManager.CreateTestDirectory(identifier: $"{language}_{projectType}").Path;
string rootPath = TestAssets.CreateTestDirectory(identifier: $"{language}_{projectType}").FullName;
new TestCommand("dotnet") { WorkingDirectory = rootPath }
.Execute($"new {projectType} -lang {language} -o {rootPath} --debug:ephemeral-hive")
@ -38,7 +38,7 @@ namespace Microsoft.DotNet.New.Tests
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"));
}

View file

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

View file

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

View file

@ -46,27 +46,27 @@ Additional Arguments:
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
{
string newArgs = $"classlib -o \"{dir.Path}\"";
string newArgs = $"classlib -o \"{projDir.Path}\"";
new NewCommandShim()
.WithWorkingDirectory(dir.Path)
.WithWorkingDirectory(projDir.Path)
.ExecuteWithCapturedOutput(newArgs)
.Should().Pass();
}
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)
@ -76,9 +76,9 @@ Additional Arguments:
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);
return ret;
}
@ -205,8 +205,8 @@ Additional Arguments:
[Fact]
public void ItRemovesRefWithoutCondAndPrintsStatus()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = AddLibRef(setup, lib);
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
@ -215,7 +215,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"\"{libref.CsProjPath}\"");
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();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
@ -224,8 +224,8 @@ Additional Arguments:
[Fact]
public void ItRemovesRefWithCondAndPrintsStatus()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = AddLibRef(setup, lib, FrameworkNet451Arg);
int condBefore = lib.CsProj().NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451);
@ -234,7 +234,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{libref.CsProjPath}\"");
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();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condBefore - 1);
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(libref.Name, ConditionFrameworkNet451).Should().Be(0);
@ -243,8 +243,8 @@ Additional Arguments:
[Fact]
public void WhenTwoDifferentRefsArePresentItDoesNotRemoveBoth()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = AddLibRef(setup, lib);
var validref = AddValidRef(setup, lib);
@ -254,7 +254,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"\"{libref.CsProjPath}\"");
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();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
csproj.NumberOfProjectReferencesWithIncludeContaining(libref.Name).Should().Be(0);
@ -263,8 +263,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithoutCondIsNotThereItPrintsMessage()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = GetLibRef(setup);
string csprojContetntBefore = lib.CsProjContent();
@ -280,8 +280,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithCondIsNotThereItPrintsMessage()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = GetLibRef(setup);
string csprojContetntBefore = lib.CsProjContent();
@ -297,8 +297,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithAndWithoutCondArePresentAndRemovingNoCondItDoesNotRemoveOther()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var librefCond = AddLibRef(setup, lib, FrameworkNet451Arg);
var librefNoCond = AddLibRef(setup, lib);
@ -310,7 +310,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"\"{librefNoCond.CsProjPath}\"");
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();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore - 1);
csproj.NumberOfProjectReferencesWithIncludeContaining(librefNoCond.Name).Should().Be(0);
@ -322,8 +322,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithAndWithoutCondArePresentAndRemovingCondItDoesNotRemoveOther()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var librefCond = AddLibRef(setup, lib, FrameworkNet451Arg);
var librefNoCond = AddLibRef(setup, lib);
@ -335,7 +335,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{librefCond.CsProjPath}\"");
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();
csproj.NumberOfItemGroupsWithoutCondition().Should().Be(noCondBefore);
csproj.NumberOfProjectReferencesWithIncludeContaining(librefNoCond.Name).Should().Be(1);
@ -347,8 +347,8 @@ Additional Arguments:
[Fact]
public void WhenRefWithDifferentCondIsPresentItDoesNotRemoveIt()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var librefCondNet451 = AddLibRef(setup, lib, FrameworkNet451Arg);
var librefCondNetCoreApp10 = AddLibRef(setup, lib, FrameworkNetCoreApp10Arg);
@ -360,7 +360,7 @@ Additional Arguments:
.WithProject(lib.CsProjPath)
.Execute($"{FrameworkNet451Arg} \"{librefCondNet451.CsProjPath}\"");
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();
csproj.NumberOfItemGroupsWithConditionContaining(ConditionFrameworkNet451).Should().Be(condNet451Before - 1);
csproj.NumberOfProjectReferencesWithIncludeAndConditionContaining(librefCondNet451.Name, ConditionFrameworkNet451).Should().Be(0);
@ -452,13 +452,13 @@ Project reference `{setup.LibCsprojRelPath}` removed.";
[Fact]
public void WhenPassingMultipleReferencesItRemovesThemAll()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = AddLibRef(setup, lib);
var validref = AddValidRef(setup, lib);
string outputText = $@"Project reference `{Path.Combine(TestSetup.ProjectName, "Lib", setup.LibCsprojName)}` removed.
Project reference `{Path.Combine(TestSetup.ProjectName, setup.ValidRefCsprojRelPath)}` removed.";
string outputText = $@"Project reference `{Path.Combine("Lib", setup.LibCsprojName)}` removed.
Project reference `{Path.Combine(setup.ValidRefCsprojRelPath)}` removed.";
int noCondBefore = lib.CsProj().NumberOfItemGroupsWithoutCondition();
var cmd = new RemoveReferenceCommand()
@ -476,13 +476,13 @@ Project reference `{Path.Combine(TestSetup.ProjectName, setup.ValidRefCsprojRelP
[Fact]
public void WhenPassingMultipleReferencesAndOneOfThemDoesNotExistItRemovesOne()
{
var lib = NewLibWithFrameworks();
var setup = Setup();
var lib = NewLibWithFrameworks(setup.TestRoot);
var libref = GetLibRef(setup);
var validref = AddValidRef(setup, lib);
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();
var cmd = new RemoveReferenceCommand()

View file

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

View file

@ -13,10 +13,11 @@ namespace Microsoft.DotNet.Cli.Run.Tests
public void ItCanRunAMSBuildProject()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager
.CreateTestInstance(testAppName);
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.TestRoot;
var testProjectDirectory = testInstance.Root.FullName;
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
@ -39,10 +40,11 @@ namespace Microsoft.DotNet.Cli.Run.Tests
public void ItBuildsTheProjectBeforeRunning()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager
.CreateTestInstance(testAppName);
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.TestRoot;
var testProjectDirectory = testInstance.Root.FullName;
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
@ -60,10 +62,11 @@ namespace Microsoft.DotNet.Cli.Run.Tests
public void ItCanRunAMSBuildProjectWhenSpecifyingAFramework()
{
var testAppName = "MSBuildTestApp";
var testInstance = TestAssetsManager
.CreateTestInstance(testAppName);
var testInstance = TestAssets.Get(testAppName)
.CreateInstance()
.WithSourceFiles();
var testProjectDirectory = testInstance.TestRoot;
var testProjectDirectory = testInstance.Root.FullName;
new RestoreCommand()
.WithWorkingDirectory(testProjectDirectory)
@ -118,7 +121,7 @@ namespace Microsoft.DotNet.Cli.Run.Tests
[Fact]
public void ItRunsAppWhenRestoringToSpecificPackageDirectory()
{
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
var rootPath = TestAssets.CreateTestDirectory().FullName;
string dir = "pkgs";
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
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
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
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
new RestoreCommand()
@ -46,9 +48,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests
{
// Copy VSTestXunitDotNetCore project in output directory of project dotnet-vstest.Tests
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
new RestoreCommand()
@ -74,9 +78,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests
{
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
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
new RestoreCommand()
@ -104,9 +110,11 @@ namespace Microsoft.DotNet.Cli.Test.Tests
{
// Copy VSTestDotNetCore project in output directory of project dotnet-vstest.Tests
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
new RestoreCommand()
@ -118,7 +126,7 @@ namespace Microsoft.DotNet.Cli.Test.Tests
string trxLoggerDirectory = Path.Combine(testProjectDirectory, "TestResults");
// Delete trxLoggerDirectory if it exist
if(Directory.Exists(trxLoggerDirectory))
if (Directory.Exists(trxLoggerDirectory))
{
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
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
new RestoreCommand()

View file

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

View file

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

View file

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