Refactor 'publish' and 'build' tests to use the TestFramework

This commit is contained in:
Sridhar Periyasamy 2016-02-11 14:17:20 -08:00
parent b239c548a4
commit 9695fbfeda
12 changed files with 267 additions and 180 deletions

View file

@ -5,6 +5,8 @@
. "$PSScriptRoot\..\..\common\_common.ps1"
function buildTestPackages
{
mkdir -Force $TestPackageDir
loadTestPackageList | foreach {
@ -15,3 +17,29 @@ loadTestPackageList | foreach {
Exit 1
}
}
}
function buildTestProjects
{
$testProjectsRoot = "$RepoRoot\TestAssets\TestProjects"
$exclusionList = @("$testProjectsRoot\CompileFail\project.json")
$testProjectsList = (Get-ChildItem "$testProjectsRoot" -rec -filter "project.json").FullName
$testProjectsList | foreach {
if ($exclusionList -notcontains $_) {
Write-Host "$_"
dotnet build "$_"
if (!$?) {
error "Command failed: dotnet build"
Exit 1
}
}
}
}
buildTestPackages
buildTestProjects

View file

@ -7,6 +7,7 @@ using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.TestFramework;
namespace Microsoft.DotNet.Tools.Test.Utilities
{
@ -18,6 +19,48 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
{
protected const string DefaultFramework = "dnxcore50";
private TempRoot _temp;
private static TestAssetsManager s_testsAssetsMgr;
private static string s_repoRoot;
protected static string RepoRoot
{
get
{
if (!string.IsNullOrEmpty(s_repoRoot))
{
return s_repoRoot;
}
string directory = AppContext.BaseDirectory;
while (!Directory.Exists(Path.Combine(directory, ".git")) && directory != null)
{
directory = Directory.GetParent(directory).FullName;
}
if (directory == null)
{
throw new Exception("Cannot find the git repository root");
}
s_repoRoot = directory;
return s_repoRoot;
}
}
protected static TestAssetsManager TestAssetsManager
{
get
{
if (s_testsAssetsMgr == null)
{
string assetsRoot = Path.Combine(RepoRoot, "TestAssets", "TestProjects");
s_testsAssetsMgr = new TestAssetsManager(assetsRoot);
}
return s_testsAssetsMgr;
}
}
protected TestBase()
{

View file

@ -3,11 +3,12 @@
"description": "Microsoft.DotNet.Tools.Tests.Utilities Class Library",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23808",
"System.Collections.Immutable": "1.2.0-rc2-23808",
"NETStandard.Library": "1.0.0-rc2-23811",
"System.Collections.Immutable": "1.2.0-rc2-23811",
"FluentAssertions": "4.0.0",
"xunit": "2.1.0",
"Microsoft.DotNet.TestFramework": "1.0.0-*",
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-16537"
},

View file

@ -16,7 +16,12 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class BuildOutputTests : TestBase
{
private readonly string _testProjectsRoot;
private string _testProjectsRoot;
private string _runtime;
private DirectoryInfo _rootDirInfo;
private DirectoryInfo _testAppDirDirInfo;
private DirectoryInfo _testLibDirInfo;
private readonly string[] _runtimeFiles =
{
"TestApp" + FileNameSuffixes.DotNet.DynamicLib,
@ -37,28 +42,18 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
"TestLibrary" + FileNameSuffixes.DotNet.ProgramDatabase,
};
public BuildOutputTests()
private void GetProjectInfo(string testRoot)
{
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
}
private void PrepareProject(out TempDirectory root, out TempDirectory testAppDir, out TempDirectory testLibDir, out string runtime)
{
root = Temp.CreateDirectory();
var src = root.CreateDirectory("src");
testAppDir = src.CreateDirectory("TestApp");
testLibDir = src.CreateDirectory("TestLibrary");
// copy projects to the temp dir
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
_testProjectsRoot = testRoot;
_rootDirInfo = new DirectoryInfo(_testProjectsRoot);
_testAppDirDirInfo = new DirectoryInfo(Path.Combine(_testProjectsRoot, "TestApp"));
_testLibDirInfo = new DirectoryInfo(Path.Combine(_testProjectsRoot, "TestLibrary"));
var contexts = ProjectContext.CreateContextForEachFramework(
testLibDir.Path,
_testAppDirDirInfo.FullName,
null,
PlatformServices.Default.Runtime.GetAllCandidateRuntimeIdentifiers());
runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier;
_runtime = contexts.FirstOrDefault(c => !string.IsNullOrEmpty(c.RuntimeIdentifier))?.RuntimeIdentifier;
}
private string FormatPath(string input, string framework, string runtime)
@ -68,37 +63,30 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
[Theory]
// global.json exists
[InlineData(true, null, null, "src/TestLibrary/bin/Debug/{fw}", "src/TestApp/bin/Debug/{fw}", "src/TestApp/bin/Debug/{fw}/{rid}")]
[InlineData(true, "out", null, "src/TestLibrary/bin/Debug/{fw}", "src/TestApp/bin/Debug/{fw}", "out")]
[InlineData(true, null, "build", "build/src/TestLibrary/bin/Debug/{fw}", "build/src/TestApp/bin/Debug/{fw}", "build/src/TestApp/bin/Debug/{fw}/{rid}")]
[InlineData(true, "out", "build", "build/src/TestLibrary/bin/Debug/{fw}", "build/src/TestApp/bin/Debug/{fw}", "out")]
[InlineData(true, null, null, "TestLibrary/bin/Debug/{fw}", "TestApp/bin/Debug/{fw}", "TestApp/bin/Debug/{fw}/{rid}")]
[InlineData(true, "out", null, "TestLibrary/bin/Debug/{fw}", "TestApp/bin/Debug/{fw}", "out")]
[InlineData(true, null, "build", "build/TestLibrary/bin/Debug/{fw}", "build/TestApp/bin/Debug/{fw}", "build/TestApp/bin/Debug/{fw}/{rid}")]
[InlineData(true, "out", "build", "build/TestLibrary/bin/Debug/{fw}", "build/TestApp/bin/Debug/{fw}", "out")]
//no global.json
//[InlineData(false, null, null, "src/TestLibrary/bin/debug/{fw}", "src/TestApp/bin/debug/{fw}", "src/TestApp/bin/debug/{fw}/{rid}")]
//[InlineData(false, "out", null, "src/TestLibrary/bin/debug/{fw}", "src/TestApp/bin/debug/{fw}", "out")]
//[InlineData(false, null, null, "TestLibrary/bin/debug/{fw}", "TestApp/bin/debug/{fw}", "TestApp/bin/debug/{fw}/{rid}")]
//[InlineData(false, "out", null, "TestLibrary/bin/debug/{fw}", "TestApp/bin/debug/{fw}", "out")]
//[InlineData(false, null, "build", "build/TestLibrary/bin/debug/{fw}", "build/TestApp/bin/debug/{fw}", "build/TestApp/bin/debug/{fw}/{rid}")]
//[InlineData(false, "out", "build", "build/TestLibrary/bin/debug/{fw}", "build/TestApp/bin/debug/{fw}", "out")]
public void DefaultPaths(bool global, string outputValue, string baseValue, string expectedLibCompile, string expectedAppCompile, string expectedAppRuntime)
{
TempDirectory root;
TempDirectory testAppDir;
TempDirectory testLibDir;
string runtime;
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary", callingMethod: )
.WithLockFiles();
GetProjectInfo(testInstance.TestRoot);
PrepareProject(out root, out testAppDir, out testLibDir, out runtime);
if (global)
{
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
}
new BuildCommand(GetProjectPath(testAppDir),
output: outputValue != null ? Path.Combine(root.Path, outputValue) : string.Empty,
buidBasePath: baseValue != null ? Path.Combine(root.Path, baseValue) : string.Empty,
new BuildCommand(GetProjectPath(_testAppDirDirInfo),
output: outputValue != null ? Path.Combine(_testProjectsRoot, outputValue) : string.Empty,
buidBasePath: baseValue != null ? Path.Combine(_testProjectsRoot, baseValue) : string.Empty,
framework: DefaultFramework)
.ExecuteWithCapturedOutput().Should().Pass();
var libdebug = root.DirectoryInfo.Sub(FormatPath(expectedLibCompile, DefaultFramework, runtime));
var appdebug = root.DirectoryInfo.Sub(FormatPath(expectedAppCompile, DefaultFramework, runtime));
var appruntime = root.DirectoryInfo.Sub(FormatPath(expectedAppRuntime, DefaultFramework, runtime));
var libdebug = _rootDirInfo.Sub(FormatPath(expectedLibCompile, DefaultFramework, _runtime));
var appdebug = _rootDirInfo.Sub(FormatPath(expectedAppCompile, DefaultFramework, _runtime));
var appruntime = _rootDirInfo.Sub(FormatPath(expectedAppRuntime, DefaultFramework, _runtime));
libdebug.Should().Exist().And.HaveFiles(_libCompileFiles);
appdebug.Should().Exist().And.HaveFiles(_appCompileFiles);
@ -108,32 +96,27 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
[Fact]
public void ResourceTest()
{
TempDirectory root;
TempDirectory testAppDir;
TempDirectory testLibDir;
string runtime;
PrepareProject(out root, out testAppDir, out testLibDir, out runtime);
var names = new[]
{
"uk-UA",
"en",
"en-US"
};
foreach (var folder in new [] { testAppDir, testLibDir })
foreach (var folder in new[] { _testAppDirDirInfo, _testLibDirInfo })
{
foreach (var name in names)
{
folder.CreateFile($"Resource.{name}.resx").WriteAllText("<root></root>");
var resourceFile = Path.Combine(folder.FullName, $"Resource.{name}.resx");
File.WriteAllText(resourceFile, "<root></root>");
}
}
new BuildCommand(GetProjectPath(testAppDir), framework: DefaultFramework)
new BuildCommand(GetProjectPath(_testAppDirDirInfo), framework: DefaultFramework)
.ExecuteWithCapturedOutput().Should().Pass();
var libdebug = testLibDir.DirectoryInfo.Sub("bin/Debug").Sub(DefaultFramework);
var appdebug = testAppDir.DirectoryInfo.Sub("bin/Debug").Sub(DefaultFramework);
var appruntime = appdebug.Sub(runtime);
var libdebug = _testLibDirInfo.Sub("bin/Debug").Sub(DefaultFramework);
var appdebug = _testAppDirDirInfo.Sub("bin/Debug").Sub(DefaultFramework);
var appruntime = appdebug.Sub(_runtime);
foreach (var name in names)
{
@ -152,9 +135,9 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
}
}
private string GetProjectPath(TempDirectory projectDir)
private string GetProjectPath(DirectoryInfo projectDir)
{
return Path.Combine(projectDir.Path, "project.json");
return Path.Combine(projectDir.FullName, "project.json");
}
}
}

View file

@ -8,6 +8,7 @@ using System.Linq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
using System.Runtime.InteropServices;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
@ -15,26 +16,35 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
{
private string[] _projects = new[] { "L0", "L11", "L12", "L21", "L22" };
public ProjectToProjectDependenciesIncrementalTest() : base(
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestProjectToProjectDependencies"),
"L0",
"L0 L11 L12 L22 L21 L12 L22 " + Environment.NewLine)
private string MainProjectExe
{
get
{
return MainProject + (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "");
}
}
public ProjectToProjectDependenciesIncrementalTest()
{
MainProject = "L0";
ExpectedOutput = "L0 L11 L12 L22 L21 L12 L22 " + Environment.NewLine;
}
[Theory,
InlineData("L0", new[] { "L0" }),
InlineData("L11", new[] { "L0", "L11" }),
InlineData("L12", new[] { "L0", "L11", "L12" }),
InlineData("L22", new[] { "L0", "L11", "L12", "L22" }),
InlineData("L21", new[] { "L0", "L11", "L21" })
InlineData("1", "L0", new[] { "L0" }),
InlineData("2", "L11", new[] { "L0", "L11" }),
InlineData("3", "L12", new[] { "L0", "L11", "L12" }),
InlineData("4", "L22", new[] { "L0", "L11", "L12", "L22" }),
InlineData("5", "L21", new[] { "L0", "L11", "L21" })
]
public void TestIncrementalBuildOfDependencyGraph(string projectToTouch, string[] expectedRebuiltProjects)
public void TestIncrementalBuildOfDependencyGraph(string testIdentifer, string projectToTouch, string[] expectedRebuiltProjects)
{
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectToProjectDependencies", identifier: testIdentifer)
.WithLockFiles()
.WithBuildArtifacts();
// first clean build; all projects required compilation
var result1 = BuildProject();
AssertRebuilt(result1, _projects);
TestProjectRoot = testInstance.TestRoot;
// second build; nothing changed; no project required compilation
var result2 = BuildProject();
@ -71,7 +81,25 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
protected override string GetProjectDirectory(string projectName)
{
return Path.Combine(TempProjectRoot.Path, "src", projectName);
return Path.Combine(TestProjectRoot, "src", projectName);
}
protected override string GetOutputDir()
{
return "";
}
protected override string GetOutputExePath()
{
var outputExe = Directory.GetFiles(TestProjectRoot, MainProjectExe, SearchOption.AllDirectories)
.FirstOrDefault();
if (string.IsNullOrEmpty(outputExe))
{
throw new FileNotFoundException($"Unable to find {outputExe} in {TestProjectRoot} or its subdirectories");
}
return Path.GetDirectoryName(outputExe);
}
}
}

View file

@ -12,19 +12,31 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTestBase : TestBase
{
protected readonly TempDirectory TempProjectRoot;
protected virtual string MainProject
{
get; set;
}
protected readonly string MainProject;
protected readonly string ExpectedOutput;
protected virtual string ExpectedOutput
{
get; set;
}
protected virtual string TestProjectRoot
{
get; set;
}
protected IncrementalTestBase()
{
}
public IncrementalTestBase(string testProjectsRoot, string mainProject, string expectedOutput)
{
MainProject = mainProject;
ExpectedOutput = expectedOutput;
var root = Temp.CreateDirectory();
TempProjectRoot = root.CopyDirectory(testProjectsRoot);
TestProjectRoot = testProjectsRoot;
}
protected void TouchSourcesOfProject()
@ -45,17 +57,21 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
File.SetLastWriteTimeUtc(file, DateTime.UtcNow);
}
protected CommandResult BuildProject(bool noIncremental = false, bool expectBuildFailure = false)
protected CommandResult BuildProject(bool defaultOutput = false, bool noIncremental = false, bool expectBuildFailure = false)
{
var mainProjectFile = GetProjectFile(MainProject);
return BuildProject(mainProjectFile, noIncremental, expectBuildFailure);
}
var buildCommand = new BuildCommand(mainProjectFile, output: GetBinRoot(), framework: "dnxcore50", noIncremental : noIncremental);
protected CommandResult BuildProject(string projectFile, bool noIncremental = false, bool expectBuildFailure = false)
{
var buildCommand = new BuildCommand(projectFile, output: GetOutputDir(), framework: "dnxcore50", noIncremental: noIncremental);
var result = buildCommand.ExecuteWithCapturedOutput();
if (!expectBuildFailure)
{
result.Should().Pass();
TestOutputExecutable(GetBinRoot(), buildCommand.GetOutputExecutableName(), ExpectedOutput);
TestOutputExecutable(GetOutputExePath(), buildCommand.GetOutputExecutableName(), ExpectedOutput);
}
else
{
@ -65,14 +81,24 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
return result;
}
protected virtual string GetOutputExePath()
{
return GetBinRoot();
}
protected virtual string GetOutputDir()
{
return GetBinRoot();
}
protected string GetBinRoot()
{
return Path.Combine(TempProjectRoot.Path, "bin");
return Path.Combine(TestProjectRoot, "bin");
}
protected virtual string GetProjectDirectory(string projectName)
{
return Path.Combine(TempProjectRoot.Path);
return Path.Combine(TestProjectRoot);
}
protected string GetProjectFile(string projectName)

View file

@ -7,22 +7,33 @@ using System.Linq;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
using Microsoft.DotNet.TestFramework;
namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTests : IncrementalTestBase
{
public IncrementalTests() : base(
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestSimpleIncrementalApp"),
"TestSimpleIncrementalApp",
"Hello World!" + Environment.NewLine)
public IncrementalTests()
{
MainProject = "TestSimpleIncrementalApp";
ExpectedOutput = "Hello World!" + Environment.NewLine;
}
private TestInstance _testInstance;
private void CreateTestInstance()
{
_testInstance = TestAssetsManager.CreateTestInstance("TestSimpleIncrementalApp")
.WithLockFiles();
TestProjectRoot = _testInstance.TestRoot;
}
[Fact]
public void TestNoIncrementalFlag()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject);
@ -33,29 +44,32 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
[Fact]
public void TestRebuildMissingPdb()
{
CreateTestInstance();
TestDeleteOutputWithExtension("pdb");
}
[Fact]
public void TestRebuildMissingDll()
{
CreateTestInstance();
TestDeleteOutputWithExtension("dll");
}
[Fact]
public void TestRebuildMissingXml()
{
CreateTestInstance();
TestDeleteOutputWithExtension("xml");
}
[Fact]
public void TestNoLockFile()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject);
var lockFile = Path.Combine(TempProjectRoot.Path, "project.lock.json");
var lockFile = Path.Combine(TestProjectRoot, "project.lock.json");
Assert.True(File.Exists(lockFile));
File.Delete(lockFile);
@ -68,11 +82,11 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
[Fact]
public void TestRebuildChangedLockFile()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject);
var lockFile = Path.Combine(TempProjectRoot.Path, "project.lock.json");
var lockFile = Path.Combine(TestProjectRoot, "project.lock.json");
TouchFile(lockFile);
buildResult = BuildProject();
@ -82,7 +96,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
[Fact]
public void TestRebuildChangedProjectFile()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject);
@ -96,6 +110,7 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
[Fact]
public void TestInputWithSameTimeAsOutputCausesProjectToCompile()
{
CreateTestInstance();
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject);

View file

@ -10,16 +10,20 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTestsOnCultureSpecificResource : IncrementalTestBase
{
public IncrementalTestsOnCultureSpecificResource() : base(
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestProjectWithCultureSpecificResource"),
"TestProjectWithCultureSpecificResource",
"Hello World!" + Environment.NewLine + "Bonjour!" + Environment.NewLine)
public IncrementalTestsOnCultureSpecificResource()
{
MainProject = "TestProjectWithCultureSpecificResource";
ExpectedOutput = "Hello World!" + Environment.NewLine + "Bonjour!" + Environment.NewLine;
}
[Fact]
public void TestRebuildSkipsCompilationOnNonCultureResource()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectWithCultureSpecificResource")
.WithLockFiles();
TestProjectRoot = testInstance.TestRoot;
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject);

View file

@ -10,16 +10,20 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
{
public class IncrementalTestsOnResources : IncrementalTestBase
{
public IncrementalTestsOnResources() : base(
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestProjectWithResource"),
"TestProjectWithResource",
"Hello World!" + Environment.NewLine)
public IncrementalTestsOnResources()
{
MainProject = "TestProjectWithResource";
ExpectedOutput = "Hello World!" + Environment.NewLine;
}
[Fact]
public void TestRebuildSkipsCompilationOnNonCultureResource()
{
var testInstance = TestAssetsManager.CreateTestInstance("TestProjectWithResource")
.WithLockFiles();
TestProjectRoot = testInstance.TestRoot;
var buildResult = BuildProject();
buildResult.Should().HaveCompiledProject(MainProject);

View file

@ -2,7 +2,7 @@
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23808",
"NETStandard.Library": "1.0.0-rc2-23811",
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
"Microsoft.DotNet.Cli.Utils": {
@ -20,15 +20,5 @@
}
},
"content": [
"../../TestAssets/TestProjects/TestApp/**/*",
"../../TestAssets/TestProjects/TestLibrary/**/*",
"../../TestAssets/TestProjects/TestSimpleIncrementalApp/*",
"../../TestAssets/TestProjects/TestProjectToProjectDependencies/**/*",
"../../TestAssets/TestProjects/TestProjectWithCultureSpecificResource/**/*",
"../../TestAssets/TestProjects/TestProjectWithResource/**/*",
"../../TestAssets/TestProjects/global.json"
],
"testRunner": "xunit"
}

View file

@ -25,7 +25,7 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
root.CopyFile(Path.Combine(_testProjectsRoot, "global.json"));
var testLibDir = root.CreateDirectory("TestLibrary");
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibrary");
var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestAppWithLibrary", "TestLibrary");
CopyProjectToTempDir(sourceTestLibDir, testLibDir);

View file

@ -15,33 +15,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
public class PublishTests : TestBase
{
private readonly string _testProjectsRoot;
private string _repoRoot;
private string RepoRoot
{
get
{
if (!string.IsNullOrEmpty(_repoRoot))
{
return _repoRoot;
}
string directory = AppContext.BaseDirectory;
while (!Directory.Exists(Path.Combine(directory, ".git")) && directory != null)
{
directory = Directory.GetParent(directory).FullName;
}
if (directory == null)
{
throw new Exception("Cannot find the git repository root");
}
_repoRoot = directory;
return _repoRoot;
}
}
public PublishTests()
{
@ -69,10 +42,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[MemberData("PublishOptions")]
public void PublishOptionsTest(string testIdentifier, string framework, string runtime, string config, string outputDir)
{
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithLibrary"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance(identifier: testIdentifier)
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary", identifier: testIdentifier)
.WithLockFiles()
.WithBinaries();
.WithBuildArtifacts();
string testRoot = Path.Combine(instance.TestRoot, "TestApp", "project.json");
@ -97,10 +69,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void ProjectWithContentsTest()
{
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithContents"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithContents")
.WithLockFiles()
.WithBinaries();
.WithBuildArtifacts();
var testProject = Path.Combine(instance.TestRoot, "project.json");
var publishCommand = new PublishCommand(testProject);
@ -112,8 +83,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void FailWhenNoRestoreTest()
{
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithLibrary"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance();
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary");
string testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json");
var publishCommand = new PublishCommand(testProject);
@ -123,10 +93,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void LibraryPublishTest()
{
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithLibrary", "TestLibrary"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine("TestAppWithLibrary", "TestLibrary"))
.WithLockFiles()
.WithBinaries();
.WithBuildArtifacts();
var testProject = Path.Combine(instance.TestRoot, "project.json");
var publishCommand = new PublishCommand(testProject);
@ -142,10 +111,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[WindowsOnlyFact]
public void TestLibraryBindingRedirectGeneration()
{
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestBindingRedirectGeneration"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
TestInstance instance = TestAssetsManager.CreateTestInstance("TestBindingRedirectGeneration")
.WithLockFiles()
.WithBinaries();
.WithBuildArtifacts();
var lesserTestLibDir = Path.Combine(instance.TestRoot, "TestLibraryLesser");
@ -177,10 +145,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void RefsPublishTest()
{
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppCompilationContext")
.WithLockFiles()
.WithBinaries();
.WithBuildArtifacts();
var testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json");
var publishCommand = new PublishCommand(testProject);
@ -200,8 +167,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void CompilationFailedTest()
{
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "CompileFail"), skipRestore: true, skipBuild: true);
TestInstance instance = scenario.CreateTestInstance()
TestInstance instance = TestAssetsManager.CreateTestInstance("CompileFail")
.WithLockFiles();
var testProject = Path.Combine(instance.TestRoot, "project.json");
@ -214,10 +180,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[ActiveIssue(982)]
public void PublishScriptsRun()
{
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithLibrary"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary")
.WithLockFiles()
.WithBinaries();
.WithBuildArtifacts();
var testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json");