TestFramework with support for managing test projects.

The CLI tool's tests are run against sample test projects for validation.
TestFramework provides an easy way to manage these sample test projects.

Converted the publish test to use the TestFramework.
This commit is contained in:
Sridhar Periyasamy 2016-02-10 00:16:40 -08:00
parent 5715d19922
commit d1d14283a1
20 changed files with 434 additions and 112 deletions

View file

@ -65,6 +65,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Cli.Utils.
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.Compiler.Common.Tests", "test\Microsoft.DotNet.Compiler.Common.Tests\Microsoft.DotNet.Compiler.Common.Tests.xproj", "{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.DotNet.TestFramework", "src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.xproj", "{0724ED7C-56E3-4604-9970-25E600611383}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -461,6 +463,22 @@ Global
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.Debug|x64.ActiveCfg = Debug|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.Debug|x64.Build.0 = Debug|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.MinSizeRel|Any CPU.ActiveCfg = Debug|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.MinSizeRel|Any CPU.Build.0 = Debug|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.Release|Any CPU.Build.0 = Release|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.Release|x64.ActiveCfg = Release|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.Release|x64.Build.0 = Release|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.RelWithDebInfo|Any CPU.Build.0 = Release|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU
{0724ED7C-56E3-4604-9970-25E600611383}.RelWithDebInfo|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -490,5 +508,6 @@ Global
{D521DD9F-0614-4929-93B4-D8FA5682C174} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
{09C52F96-EFDD-4448-95EC-6D362DD60BAA} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{44E7D1AC-DCF1-4A18-9C22-F09E6BB302B5} = {17735A9D-BFD9-4585-A7CB-3208CA6EA8A7}
{0724ED7C-56E3-4604-9970-25E600611383} = {ED2FE3E2-F7E7-4389-8231-B65123F2076F}
EndGlobalSection
EndGlobal

View file

@ -0,0 +1,3 @@
{
"projects": [ "."]
}

View file

@ -0,0 +1,24 @@
// 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;
namespace TestLibrary
{
public static class Helper
{
/// <summary>
/// Gets the message from the helper. This comment is here to help test XML documentation file generation, please do not remove it.
/// </summary>
/// <returns>A message</returns>
public static string GetMessage()
{
return "This string came from the test library!";
}
public static void SayHi()
{
Console.WriteLine("Hello there!");
}
}
}

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>947dd232-8d9b-4b78-9c6a-94f807d2dd58</ProjectGuid>
<RootNamespace>TestLibrary</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,15 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"nowarn": [ "CS1591" ],
"xmlDoc": true,
"additionalArguments": [ "-highentropyva+" ]
},
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23808"
},
"frameworks": {
"dnxcore50": { }
}
}

View file

@ -0,0 +1,3 @@
{
"projects": [ "."]
}

View file

@ -0,0 +1,116 @@
// 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;
namespace Microsoft.DotNet.TestFramework
{
public class TestInstance
{
private string _testDestination;
private TestScenario _testScenario;
internal TestInstance(TestScenario testScenario, string testDestination)
{
if (testScenario == null)
{
throw new ArgumentNullException("testScenario");
}
if (string.IsNullOrEmpty(testDestination))
{
throw new ArgumentException("testDestination");
}
_testScenario = testScenario;
_testDestination = testDestination;
if (Directory.Exists(testDestination))
{
Directory.Delete(testDestination, true);
}
Directory.CreateDirectory(testDestination);
CopySource();
}
private void CopySource()
{
var sourceDirs = Directory.GetDirectories(_testScenario.SourceRoot, "*", SearchOption.AllDirectories)
.Where(dir =>
{
dir = dir.ToLower();
return !dir.EndsWith("\\bin") && !dir.Contains("\\bin\\")
&& !dir.EndsWith("\\obj") && !dir.Contains("\\obj\\");
});
foreach (string sourceDir in sourceDirs)
{
Directory.CreateDirectory(sourceDir.Replace(_testScenario.SourceRoot, _testDestination));
}
var sourceFiles = Directory.GetFiles(_testScenario.SourceRoot, "*.*", SearchOption.AllDirectories)
.Where(file =>
{
file = file.ToLower();
return !file.EndsWith("project.lock.json")
&& !file.Contains("\\bin\\") && !file.Contains("\\obj\\");
});
foreach (string srcFile in sourceFiles)
{
File.Copy(srcFile, srcFile.Replace(_testScenario.SourceRoot, _testDestination), true);
}
}
public TestInstance WithLockFiles()
{
foreach (string lockFile in Directory.GetFiles(_testScenario.SourceRoot, "project.lock.json", SearchOption.AllDirectories))
{
string destinationLockFile = lockFile.Replace(_testScenario.SourceRoot, _testDestination);
File.Copy(lockFile, destinationLockFile, true);
}
return this;
}
public TestInstance WithBinaries()
{
var binDirs = Directory.GetDirectories(_testScenario.SourceRoot, "*", SearchOption.AllDirectories)
.Where(dir =>
{
dir = dir.ToLower();
return dir.EndsWith("\\bin") || dir.Contains("\\bin\\")
|| dir.EndsWith("\\obj") || dir.Contains("\\obj\\");
});
foreach (string dirPath in binDirs)
{
Directory.CreateDirectory(dirPath.Replace(_testScenario.SourceRoot, _testDestination));
}
var binFiles = Directory.GetFiles(_testScenario.SourceRoot, "*.*", SearchOption.AllDirectories)
.Where(file =>
{
file = file.ToLower();
return file.Contains("\\bin\\") || file.Contains("\\obj\\");
});
foreach (string binFile in binFiles)
{
File.Copy(binFile, binFile.Replace(_testScenario.SourceRoot, _testDestination), true);
}
return this;
}
public string TestRoot
{
get { return _testDestination; }
}
}
}

View file

@ -0,0 +1,115 @@
// 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 TestScenario
{
private static IDictionary<string, TestScenario> _scenarioCache = new Dictionary<string, TestScenario>();
private TestScenario(string testSourceRoot, bool skipRestore, bool skipBuild)
{
SourceRoot = testSourceRoot;
Projects = GetAllProjects(SourceRoot);
if (!skipRestore)
{
Restore();
}
if (!skipBuild)
{
Build();
}
}
private IEnumerable<string> Projects
{
get; set;
}
public string SourceRoot
{
get;
private set;
}
public static TestScenario Create(string testSourceRoot, bool skipRestore = false, bool skipBuild = false)
{
TestScenario testScenario;
lock (_scenarioCache)
{
if (!_scenarioCache.TryGetValue(testSourceRoot, out testScenario))
{
testScenario = new TestScenario(testSourceRoot, skipRestore, skipBuild);
_scenarioCache.Add(testSourceRoot, testScenario);
}
}
return testScenario;
}
public TestInstance CreateTestInstance([CallerMemberName] string callingMethod = "", string identifier = "")
{
string projectName = new DirectoryInfo(SourceRoot).Name;
string testDestination = Path.Combine(AppContext.BaseDirectory, callingMethod + identifier, projectName);
var testInstance = new TestInstance(this, testDestination);
return testInstance;
}
internal void Build()
{
foreach (var project in Projects)
{
string[] buildArgs = new string[] { "build", project };
var commandResult = Command.Create("dotnet", buildArgs)
.CaptureStdOut()
.CaptureStdErr()
.Execute();
Console.WriteLine(commandResult.StdOut);
Console.WriteLine(commandResult.StdErr);
int exitCode = commandResult.ExitCode;
if (exitCode != 0)
{
string message = string.Format("Command Failed - 'dotnet {0}' with exit code - {1}", string.Join(" ", buildArgs), exitCode);
throw new Exception(message);
}
}
}
private static IEnumerable<string> GetAllProjects(string sourceRoot)
{
return Directory.GetFiles(sourceRoot, "project.json", SearchOption.AllDirectories);
}
internal void Restore()
{
string[] restoreArgs = new string[] { "restore", SourceRoot };
var commandResult = Command.Create("dotnet", restoreArgs)
.CaptureStdOut()
.CaptureStdErr()
.Execute();
Console.WriteLine(commandResult.StdOut);
Console.WriteLine(commandResult.StdErr);
int exitCode = commandResult.ExitCode;
if (exitCode != 0)
{
string message = string.Format("Command Failed - 'dotnet {0}' with exit code - {1}", string.Join(" ", restoreArgs), exitCode);
throw new Exception(message);
}
}
}
}

View file

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>0724ed7c-56e3-4604-9970-25e600611383</ProjectGuid>
<RootNamespace>Microsoft.DotNet.TestFramework</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -0,0 +1,19 @@
{
"version": "1.0.0-*",
"description": "Microsoft.DotNet.TestFramework Class Library",
"authors": [ "sridhper" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"dependencies": {
"Microsoft.DotNet.Cli.Utils": "1.0.0-*",
"NETStandard.Library": "1.0.0-rc2-23728"
},
"frameworks": {
"dnxcore50": {
"imports": "portable-net45+win8"
}
}
}

View file

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Xunit;
@ -14,10 +15,37 @@ 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()
{
_testProjectsRoot = Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects");
_testProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "TestProjects");
}
public static IEnumerable<object[]> PublishOptions
@ -26,35 +54,30 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
{
return new[]
{
new object[] { "", "", "", "" },
new object[] { "dnxcore50", "", "", "" },
new object[] { "", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "", "" },
new object[] { "", "", "Release", "" },
new object[] { "", "", "", "some/dir"},
new object[] { "", "", "", "some/dir/with spaces" },
new object[] { "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "Debug", "some/dir" },
new object[] { "1", "", "", "", "" },
new object[] { "2", "dnxcore50", "", "", "" },
new object[] { "3", "", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "", "" },
new object[] { "4", "", "", "Release", "" },
new object[] { "5", "", "", "", "some/dir"},
new object[] { "6", "", "", "", "some/dir/with spaces" },
new object[] { "7", "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(), "Debug", "some/dir" },
};
}
}
[Theory]
[MemberData("PublishOptions")]
public void PublishOptionsTest(string framework, string runtime, string config, string outputDir)
public void PublishOptionsTest(string testIdentifier, string framework, string runtime, string config, string outputDir)
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithLibrary"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance(identifier: testIdentifier)
.WithLockFiles()
.WithBinaries();
var testAppDir = root.CreateDirectory("TestApp");
var testLibDir = root.CreateDirectory("TestLibrary");
string testRoot = Path.Combine(instance.TestRoot, "TestApp", "project.json");
//copy projects to the temp dir
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
// run publish
outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(root.Path, outputDir);
var testProject = GetProjectPath(testAppDir);
var publishCommand = new PublishCommand(testProject, output: outputDir);
outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(instance.TestRoot, outputDir);
var publishCommand = new PublishCommand(testRoot, output: outputDir);
publishCommand.Execute().Should().Pass();
// verify the output executable generated
@ -74,40 +97,25 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void ProjectWithContentsTest()
{
// create unique directories in the 'temp' folder
var testDir = Temp.CreateDirectory();
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithContents"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
.WithLockFiles()
.WithBinaries();
var testAppDir = Path.Combine(_testProjectsRoot, "TestAppWithContents");
// copy projects to the temp dir
CopyProjectToTempDir(testAppDir, testDir);
// run publish
var testProject = GetProjectPath(testDir);
var testProject = Path.Combine(instance.TestRoot, "project.json");
var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Pass();
// make sure that the output dir has the content files
publishCommand.Execute().Should().Pass();
publishCommand.GetOutputDirectory().Should().HaveFile("testcontentfile.txt");
}
[Fact]
public void FailWhenNoRestoreTest()
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithLibrary"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance();
var testAppDir = root.CreateDirectory("TestApp");
var testLibDir = root.CreateDirectory("TestLibrary");
// copy projects to the temp dir
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
File.Delete(Path.Combine(testAppDir.Path, "project.lock.json"));
File.Delete(Path.Combine(testLibDir.Path, "project.lock.json"));
var testProject = GetProjectPath(testAppDir);
string testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json");
var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Fail();
}
@ -115,15 +123,12 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void LibraryPublishTest()
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithLibrary", "TestLibrary"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
.WithLockFiles()
.WithBinaries();
var testLibDir = root.CreateDirectory("TestLibrary");
//copy projects to the temp dir
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
var testProject = GetProjectPath(testLibDir);
var testProject = Path.Combine(instance.TestRoot, "project.json");
var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Pass();
@ -137,13 +142,12 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[WindowsOnlyFact]
public void TestLibraryBindingRedirectGeneration()
{
// Set up Test Staging in Temporary Directory
var root = Temp.CreateDirectory();
root.CopyDirectory(Path.Combine(_testProjectsRoot, "TestBindingRedirectGeneration"));
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestBindingRedirectGeneration"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
.WithLockFiles()
.WithBinaries();
var testProjectsRootDir = Path.Combine(root.Path, "TestBindingRedirectGeneration");
var greaterTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryGreater");
var lesserTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryLesser");
var lesserTestLibDir = Path.Combine(instance.TestRoot, "TestLibraryLesser");
var lesserTestProject = Path.Combine(lesserTestLibDir, "project.json");
var publishCommand = new PublishCommand(lesserTestProject, "net451");
@ -152,7 +156,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll.config");
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.deps");
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.deps");
// dependencies should also be copied
publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll");
@ -164,7 +168,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb");
publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.dll.config");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.deps");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.deps");
// dependencies should also be copied
publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll");
@ -173,21 +177,16 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void RefsPublishTest()
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
.WithLockFiles()
.WithBinaries();
var testAppDir = root.CreateDirectory("TestAppCompilationContext");
var testLibDir = root.CreateDirectory("TestLibrary");
// copy projects to the temp dir
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), testAppDir);
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
var testProject = GetProjectPath(testAppDir);
var testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json");
var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Pass();
publishCommand.GetOutputDirectory().Should().HaveFile("TestAppCompilationContext.dll");
publishCommand.GetOutputDirectory().Should().HaveFile("TestApp.dll");
publishCommand.GetOutputDirectory().Should().HaveFile("TestLibrary.dll");
var refsDirectory = new DirectoryInfo(Path.Combine(publishCommand.GetOutputDirectory().FullName, "refs"));
@ -201,13 +200,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[Fact]
public void CompilationFailedTest()
{
var testDir = Temp.CreateDirectory();
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "CompileFail"), skipRestore: true, skipBuild: true);
TestInstance instance = scenario.CreateTestInstance()
.WithLockFiles();
var compileFailDir = Path.Combine(_testProjectsRoot, "CompileFail");
CopyProjectToTempDir(compileFailDir, testDir);
var testProject = GetProjectPath(testDir);
var testProject = Path.Combine(instance.TestRoot, "project.json");
var publishCommand = new PublishCommand(testProject);
publishCommand.Execute().Should().Fail();
@ -217,38 +214,18 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
[ActiveIssue(982)]
public void PublishScriptsRun()
{
// create unique directories in the 'temp' folder
var root = Temp.CreateDirectory();
TestScenario scenario = TestScenario.Create(Path.Combine(_testProjectsRoot, "TestAppWithLibrary"), skipRestore: true);
TestInstance instance = scenario.CreateTestInstance()
.WithLockFiles()
.WithBinaries();
var testAppDir = root.CreateDirectory("TestApp");
var testLibDir = root.CreateDirectory("TestLibrary");
var testProject = Path.Combine(instance.TestRoot, "TestApp", "project.json");
//copy projects to the temp dir
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir);
CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir);
// run publish
var testProject = GetProjectPath(testAppDir);
var publishCommand = new PublishCommand(testProject);
var result = publishCommand.ExecuteWithCapturedOutput();
result.Should().StdOutMatchPattern("\nprepublish_output( \\?[^%]+\\?){5}.+\npostpublish_output( \\?[^%]+\\?){5}", RegexOptions.Singleline);
result.Should().Pass();
}
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
{
// copy all the files to temp dir
foreach (var file in Directory.EnumerateFiles(projectDir))
{
tempDir.CopyFile(file);
}
}
private string GetProjectPath(TempDirectory projectDir)
{
return Path.Combine(projectDir.Path, "project.json");
}
}
}

View file

@ -4,6 +4,7 @@
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23808",
"Microsoft.DotNet.TestFramework": "1.0.0-*",
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
"Microsoft.DotNet.Cli.Utils": {
"target": "project",
@ -21,14 +22,5 @@
}
},
"content": [
"../../TestAssets/TestProjects/TestApp/**/*",
"../../TestAssets/TestProjects/TestLibrary/**/*",
"../../TestAssets/TestProjects/CompileFail/**/*",
"../../TestAssets/TestProjects/TestBindingRedirectGeneration/**/*",
"../../TestAssets/TestProjects/TestAppCompilationContext/**/*",
"../../TestAssets/TestProjects/TestAppWithContents/**/*"
],
"testRunner": "xunit"
}