diff --git a/test/E2E/EndToEndTest.cs b/test/E2E/EndToEndTest.cs index c5fa7617a..910b42cc8 100644 --- a/test/E2E/EndToEndTest.cs +++ b/test/E2E/EndToEndTest.cs @@ -21,11 +21,18 @@ namespace Microsoft.DotNet.Tests.EndToEnd private static readonly string s_testdirName = "e2etestroot"; private static readonly string s_outputdirName = "test space/bin"; + private static string RestoredTestProjectDirectory { get; set; } + private string Rid { get; set; } private string TestDirectory { get; set; } private string TestProject { get; set; } private string OutputDirectory { get; set; } + static EndToEndTest() + { + EndToEndTest.SetupStaticTestProject(); + } + public static void Main() { Console.WriteLine("Dummy Entrypoint."); @@ -33,9 +40,7 @@ namespace Microsoft.DotNet.Tests.EndToEnd public EndToEndTest() { - TestSetup(); - - Rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); + TestInstanceSetup(); } [Fact] @@ -169,21 +174,34 @@ namespace Microsoft.DotNet.Tests.EndToEnd TestExecutable(OutputDirectory, publishCommand.GetOutputExecutable(), s_expectedOutput); } - private void TestSetup() + private void TestInstanceSetup() { var root = Temp.CreateDirectory(); - TestDirectory = root.CreateDirectory(s_testdirName).Path; + var testInstanceDir = root.CopyDirectory(RestoredTestProjectDirectory); + + TestDirectory = testInstanceDir.Path; TestProject = Path.Combine(TestDirectory, "project.json"); OutputDirectory = Path.Combine(TestDirectory, s_outputdirName); - InitializeTestDirectory(); + Rid = PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier(); } - private void InitializeTestDirectory() + private static void SetupStaticTestProject() { + RestoredTestProjectDirectory = Path.Combine(AppContext.BaseDirectory, "bin", s_testdirName); + + // Ignore Delete Failure + try + { + Directory.Delete(RestoredTestProjectDirectory, true); + } + catch(Exception e) {} + + Directory.CreateDirectory(RestoredTestProjectDirectory); + var currentDirectory = Directory.GetCurrentDirectory(); - Directory.SetCurrentDirectory(TestDirectory); + Directory.SetCurrentDirectory(RestoredTestProjectDirectory); new NewCommand().Execute().Should().Pass(); new RestoreCommand().Execute("--quiet").Should().Pass(); diff --git a/test/TestProjects/TestLibraryWithRunner/NuGet.Config b/test/TestProjects/TestBindingRedirectGeneration/NuGet.Config similarity index 100% rename from test/TestProjects/TestLibraryWithRunner/NuGet.Config rename to test/TestProjects/TestBindingRedirectGeneration/NuGet.Config diff --git a/test/TestProjects/TestBindingRedirectGeneration/TestLibraryGreater/Program.cs b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryGreater/Program.cs new file mode 100644 index 000000000..e2e651793 --- /dev/null +++ b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryGreater/Program.cs @@ -0,0 +1,4 @@ + +public class P{ + public static void Main() { var t = typeof(Newtonsoft.Json.JsonConvert); } +} \ No newline at end of file diff --git a/test/TestProjects/TestBindingRedirectGeneration/TestLibraryGreater/TestLibraryGreater.xproj b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryGreater/TestLibraryGreater.xproj new file mode 100644 index 000000000..e69de29bb diff --git a/test/TestProjects/TestBindingRedirectGeneration/TestLibraryGreater/project.json b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryGreater/project.json new file mode 100644 index 000000000..ba8c579fa --- /dev/null +++ b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryGreater/project.json @@ -0,0 +1,17 @@ +{ + "version": "1.0.0-*", + "testRunner": "xunit", + "dependencies": { + "Newtonsoft.Json": "7.0.1" + }, + + "frameworks": { + "net451": { }, + "dnxcore50": { + "imports" : "portable-net45+wp80+win8", + "dependencies": { + "NETStandard.Library": "1.0.0-rc2-23704" + } + } + } +} diff --git a/test/TestProjects/TestBindingRedirectGeneration/TestLibraryLesser/Program.cs b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryLesser/Program.cs new file mode 100644 index 000000000..e2e651793 --- /dev/null +++ b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryLesser/Program.cs @@ -0,0 +1,4 @@ + +public class P{ + public static void Main() { var t = typeof(Newtonsoft.Json.JsonConvert); } +} \ No newline at end of file diff --git a/test/TestProjects/TestBindingRedirectGeneration/TestLibraryLesser/TestLibraryLesser.xproj b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryLesser/TestLibraryLesser.xproj new file mode 100644 index 000000000..e69de29bb diff --git a/test/TestProjects/TestLibraryWithRunner/project.json b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryLesser/project.json similarity index 77% rename from test/TestProjects/TestLibraryWithRunner/project.json rename to test/TestProjects/TestBindingRedirectGeneration/TestLibraryLesser/project.json index 25f611ed3..6dd717ad9 100644 --- a/test/TestProjects/TestLibraryWithRunner/project.json +++ b/test/TestProjects/TestBindingRedirectGeneration/TestLibraryLesser/project.json @@ -2,8 +2,8 @@ "version": "1.0.0-*", "testRunner": "xunit", "dependencies": { - "Microsoft.Extensions.DependencyModel": "1.0.0-*", - "Newtonsoft.Json": "6.0.0" + "Newtonsoft.Json": "6.0.0", + "TestLibraryGreater": {"target":"project"} }, "frameworks": { diff --git a/test/TestProjects/TestBindingRedirectGeneration/global.json b/test/TestProjects/TestBindingRedirectGeneration/global.json new file mode 100644 index 000000000..3a4684c26 --- /dev/null +++ b/test/TestProjects/TestBindingRedirectGeneration/global.json @@ -0,0 +1,3 @@ +{ + "projects": [ "."] +} \ No newline at end of file diff --git a/test/TestProjects/TestLibraryWithRunner/TestLibraryWithRunner.xproj b/test/TestProjects/TestLibraryWithRunner/TestLibraryWithRunner.xproj deleted file mode 100644 index ea90d3d7e..000000000 --- a/test/TestProjects/TestLibraryWithRunner/TestLibraryWithRunner.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0.24720 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - b76591d6-d105-441d-ab40-ac7e78eaf84d - TestLibraryWithRunner - ..\..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\..\artifacts\bin\$(MSBuildProjectName)\ - - - - 2.0 - - - \ No newline at end of file diff --git a/test/dotnet-build.Tests/IncrementalTestBase.cs b/test/dotnet-build.Tests/IncrementalTestBase.cs index 0fc08829f..0fdb0b01d 100644 --- a/test/dotnet-build.Tests/IncrementalTestBase.cs +++ b/test/dotnet-build.Tests/IncrementalTestBase.cs @@ -25,12 +25,9 @@ namespace Microsoft.DotNet.Tools.Builder.Tests _mainProject = mainProject; _expectedOutput = expectedOutput; - // create unique directories in the 'temp' folder var root = Temp.CreateDirectory(); - // recursively copy projects to the temp dir and restore them _tempProjectRoot = root.CopyDirectory(testProjectsRoot); - RunRestore(_tempProjectRoot.Path); } protected void TouchSourcesOfProject() @@ -115,11 +112,5 @@ namespace Microsoft.DotNet.Tools.Builder.Tests return executablePath; } - - private void RunRestore(string args) - { - var restoreCommand = new RestoreCommand(); - restoreCommand.Execute($"--quiet {args}").Should().Pass(); - } } } \ No newline at end of file diff --git a/test/dotnet-compile.Tests/CompilerTests.cs b/test/dotnet-compile.Tests/CompilerTests.cs index 961e074a1..82da693ed 100644 --- a/test/dotnet-compile.Tests/CompilerTests.cs +++ b/test/dotnet-compile.Tests/CompilerTests.cs @@ -21,9 +21,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests var testLibDir = root.CreateDirectory("TestLibrary"); - // copy projects to the temp dir and restore them CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir); - RunRestore(testLibDir.Path); // run compile var outputDir = Path.Combine(testLibDir.Path, "bin"); @@ -46,7 +44,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests var testLibDir = root.CreateDirectory("TestLibraryWithAnalyzer"); CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibraryWithAnalyzer"), testLibDir); - RunRestore(testLibDir.Path); // run compile var outputDir = Path.Combine(testLibDir.Path, "bin"); @@ -62,12 +59,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests // copy all the files to temp dir foreach (var file in Directory.EnumerateFiles(projectDir)) { - // never copy project.lock.json. All the tests are expected to call 'dotnet restore' - if (file.ToLower().EndsWith("project.lock.json")) - { - continue; - } - tempDir.CopyFile(file); } } @@ -76,11 +67,5 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { return Path.Combine(projectDir.Path, "project.json"); } - - private void RunRestore(string args) - { - var restoreCommand = new RestoreCommand(); - restoreCommand.Execute($"--quiet {args}").Should().Pass(); - } } } diff --git a/test/dotnet-publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs b/test/dotnet-publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs index 2d7444248..3a5af1d39 100644 --- a/test/dotnet-publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs +++ b/test/dotnet-publish.Tests/Microsoft.DotNet.Tools.Publish.Tests.cs @@ -7,6 +7,8 @@ using System.Text.RegularExpressions; using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.Extensions.PlatformAbstractions; using Xunit; +using System; +using System.Text; namespace Microsoft.DotNet.Tools.Publish.Tests { @@ -37,7 +39,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { // create unique directories in the 'temp' folder var root = Temp.CreateDirectory(); - root.CopyFile(Path.Combine(_testProjectsRoot, "global.json")); + var testAppDir = root.CreateDirectory("TestApp"); var testLibDir = root.CreateDirectory("TestLibrary"); @@ -45,9 +47,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir); CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir); - RunRestore(testAppDir.Path); - RunRestore(testLibDir.Path); - // run publish outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(root.Path, outputDir); var testProject = GetProjectPath(testAppDir); @@ -74,14 +73,12 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { // create unique directories in the 'temp' folder var testDir = Temp.CreateDirectory(); - testDir.CopyFile(Path.Combine(_testProjectsRoot, "global.json")); + var testAppDir = Path.Combine(_testProjectsRoot, "TestAppWithContents"); // copy projects to the temp dir CopyProjectToTempDir(testAppDir, testDir); - RunRestore(testDir.Path); - // run publish var testProject = GetProjectPath(testDir); var publishCommand = new PublishCommand(testProject); @@ -92,11 +89,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests } [Fact] - public void BeforeRestoreTest() + public void FailWhenNoRestoreTest() { // create unique directories in the 'temp' folder var root = Temp.CreateDirectory(); - root.CopyFile(Path.Combine(_testProjectsRoot, "global.json")); + var testAppDir = root.CreateDirectory("TestApp"); var testLibDir = root.CreateDirectory("TestLibrary"); @@ -104,6 +101,9 @@ namespace Microsoft.DotNet.Tools.Publish.Tests 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); var publishCommand = new PublishCommand(testProject); publishCommand.Execute().Should().Fail(); @@ -114,14 +114,12 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { // create unique directories in the 'temp' folder var root = Temp.CreateDirectory(); - root.CopyFile(Path.Combine(_testProjectsRoot, "global.json")); + var testLibDir = root.CreateDirectory("TestLibrary"); //copy projects to the temp dir CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir); - RunRestore(testLibDir.Path); - var testProject = GetProjectPath(testLibDir); var publishCommand = new PublishCommand(testProject); publishCommand.Execute().Should().Pass(); @@ -134,37 +132,34 @@ namespace Microsoft.DotNet.Tools.Publish.Tests } [WindowsOnlyFact] - public void TestLibraryPublishTest() + public void TestLibraryBindingRedirectGeneration() { - // create unique directories in the 'temp' folder + // Set up Test Staging in Temporary Directory var root = Temp.CreateDirectory(); - root.CopyFile(Path.Combine(_testProjectsRoot, "global.json")); - var testLibDir = root.CreateDirectory("TestLibraryWithRunner"); + root.CopyDirectory(Path.Combine(_testProjectsRoot, "TestBindingRedirectGeneration")); - //copy projects to the temp dir - CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibraryWithRunner"), testLibDir); + var testProjectsRootDir = Path.Combine(root.Path, "TestBindingRedirectGeneration"); + var greaterTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryGreater"); + var lesserTestLibDir = Path.Combine(testProjectsRootDir, "TestLibraryLesser"); - RunRestore(testLibDir.Path); - - var testProject = GetProjectPath(testLibDir); - var publishCommand = new PublishCommand(testProject, "net451"); + var lesserTestProject = Path.Combine(lesserTestLibDir, "project.json"); + var publishCommand = new PublishCommand(lesserTestProject, "net451"); publishCommand.Execute().Should().Pass(); - publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.dll"); - publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.pdb"); - publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryWithRunner.deps"); - publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.dll.config"); + publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll"); + publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb"); + publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll.config"); + // dependencies should also be copied publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll"); publishCommand.GetOutputDirectory().Delete(true); - publishCommand = new PublishCommand(testProject, "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier()); + publishCommand = new PublishCommand(lesserTestProject, "dnxcore50", PlatformServices.Default.Runtime.GetLegacyRestoreRuntimeIdentifier()); publishCommand.Execute().Should().Pass(); - publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.dll"); - publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.pdb"); - publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryWithRunner.deps"); - publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryWithRunner.dll.config"); + publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll"); + publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb"); + publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.dll.config"); // dependencies should also be copied publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll"); } @@ -174,7 +169,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { // create unique directories in the 'temp' folder var root = Temp.CreateDirectory(); - root.CopyFile(Path.Combine(_testProjectsRoot, "global.json")); + var testAppDir = root.CreateDirectory("TestAppCompilationContext"); var testLibDir = root.CreateDirectory("TestLibrary"); @@ -182,9 +177,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestAppCompilationContext"), testAppDir); CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir); - RunRestore(testAppDir.Path); - RunRestore(testLibDir.Path); - var testProject = GetProjectPath(testAppDir); var publishCommand = new PublishCommand(testProject); publishCommand.Execute().Should().Pass(); @@ -204,13 +196,11 @@ namespace Microsoft.DotNet.Tools.Publish.Tests public void CompilationFailedTest() { var testDir = Temp.CreateDirectory(); - testDir.CopyFile(Path.Combine(_testProjectsRoot, "global.json")); + var compileFailDir = Path.Combine(_testProjectsRoot, "CompileFail"); CopyProjectToTempDir(compileFailDir, testDir); - RunRestore(testDir.Path); - var testProject = GetProjectPath(testDir); var publishCommand = new PublishCommand(testProject); @@ -223,7 +213,7 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { // create unique directories in the 'temp' folder var root = Temp.CreateDirectory(); - root.CopyFile(Path.Combine(_testProjectsRoot, "global.json")); + var testAppDir = root.CreateDirectory("TestApp"); var testLibDir = root.CreateDirectory("TestLibrary"); @@ -231,9 +221,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir); CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir); - RunRestore(testAppDir.Path); - RunRestore(testLibDir.Path); - // run publish var testProject = GetProjectPath(testAppDir); var publishCommand = new PublishCommand(testProject); @@ -249,12 +236,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests // copy all the files to temp dir foreach (var file in Directory.EnumerateFiles(projectDir)) { - // never copy project.lock.json. All the tests are expected to call 'dotnet restore' - if (file.ToLower().EndsWith("project.lock.json")) - { - continue; - } - tempDir.CopyFile(file); } } @@ -263,11 +244,5 @@ namespace Microsoft.DotNet.Tools.Publish.Tests { return Path.Combine(projectDir.Path, "project.json"); } - - private void RunRestore(string args) - { - var restoreCommand = new RestoreCommand(); - restoreCommand.Execute($"--quiet {args}").Should().Pass(); - } } }