private void VerifyDnuInstall( string runtimeHomePath, string packageName, string packageVersion, string projectDir, string packagesDir, string workingDir) { var projectJsonPath = Path.Combine(projectDir ?? workingDir, Runtime.Project.ProjectFileName); var expectedProjectJson = $@"{{ ""dependencies"": {{ ""{packageName}"": ""{packageVersion}"" }} }}"; string stdOut, stdErr; var exitCode = DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "install", arguments: $"{packageName} {packageVersion} {projectDir} -s {_fixture.PackageSource} --packages {packagesDir}", stdOut: out stdOut, stdErr: out stdErr, environment: null, workingDir: workingDir); Assert.Equal(0, exitCode); Assert.Empty(stdErr); Assert.Contains($"Installing {packageName}.{packageVersion}", stdOut); Assert.Equal(expectedProjectJson, File.ReadAllText(projectJsonPath)); Assert.True(Directory.Exists(Path.Combine(packagesDir, packageName, packageVersion))); }
public void DnuPack_DoesNotExecutePostBuildScriptWhenBuildFails(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); var projectJson = @"{ ""scripts"": { ""postbuild"": ""echo POST_BUILD_SCRIPT_OUTPUT"", ""postpack"": ""echo POST_PACK_SCRIPT_OUTPUT"" }, }"; var sourceFileContents = @"Invalid source code that makes build fail"; using (var tempDir = new DisposableDir()) { var projectJsonPath = Path.Combine(tempDir, Runtime.Project.ProjectFileName); var sourceFilePath = Path.Combine(tempDir, "Program.cs"); File.WriteAllText(projectJsonPath, projectJson); File.WriteAllText(sourceFilePath, sourceFileContents); string stdOut, stdErr; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, "pack", projectJsonPath, out stdOut, out stdErr); Assert.NotEqual(0, exitCode); Assert.NotEmpty(stdErr); Assert.DoesNotContain("POST_BUILD_SCRIPT_OUTPUT", stdOut); Assert.DoesNotContain("POST_PACK_SCRIPT_OUTPUT", stdOut); } }
public void DnuPack_OutPathSpecified(string flavor, string os, string architecture) { string expectedNupkg = @"{0} -> {1}/CustomOutput/Debug/{0}.1.0.0.nupkg".Replace('/', Path.DirectorySeparatorChar); string expectedSymbol = @"{0} -> {1}/CustomOutput/Debug/{0}.1.0.0.symbols.nupkg".Replace('/', Path.DirectorySeparatorChar); string stdOut; string stdError; var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); int exitCode; using (var testEnv = new DnuTestEnvironment(runtimeHomeDir)) { File.WriteAllText($"{testEnv.RootDir}/project.json", @"{ ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { ""dependencies"": { ""System.Runtime"":""4.0.20-*"" } } } }"); DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", "", out stdOut, out stdError, environment: null, workingDir: testEnv.RootDir); exitCode = DnuTestUtils.ExecDnu(runtimeHomeDir, "pack", "--out CustomOutput", out stdOut, out stdError, environment: null, workingDir: testEnv.RootDir); Assert.Empty(stdError); Assert.Contains(string.Format(expectedNupkg, Path.GetFileName(testEnv.RootDir), testEnv.RootDir), stdOut); Assert.Contains(string.Format(expectedSymbol, Path.GetFileName(testEnv.RootDir), testEnv.RootDir), stdOut); Assert.Equal(0, exitCode); Assert.True(Directory.Exists($"{testEnv.RootDir}/CustomOutput")); } }
private static void BuildPackage(string sampleDir, string runtimeHomeDir) { var projectDir = Path.Combine(sampleDir, ProjectName); var buildOutpuDir = Path.Combine(sampleDir, OutputDirName); int exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, "pack", $"{projectDir} --out {buildOutpuDir} --configuration {Configuration}", environment: new Dictionary <string, string> { { "DNX_BUILD_VERSION", null } }); Assert.Equal(0, exitCode); }
private static int DnuPackagesAddOutputPackage(string sampleDir, string runtimeHomeDir, out string stdOut) { var packagePath = Path.Combine(sampleDir, OutputDirName, Configuration, $"{ProjectName}.{ProjectVersion}{NuGet.Constants.PackageExtension}"); var packagesDir = Path.Combine(sampleDir, PackagesDirName); string stdErr; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, "packages", $"add {packagePath} {packagesDir}", out stdOut, out stdErr); return(exitCode); }
public void DnuPack_NoArgs(string flavor, string os, string architecture) { string expectedDNX = @"Building {0} for DNX,Version=v4.5.1 Using Project dependency {0} 1.0.0 Source: {1}/project.json".Replace('/', Path.DirectorySeparatorChar); string expectedDNXCore = @"Building {0} for DNXCore,Version=v5.0 Using Project dependency {0} 1.0.0 Source: {1}/project.json".Replace('/', Path.DirectorySeparatorChar); string expectedNupkg = @"{0} -> {1}/bin/Debug/{0}.1.0.0.nupkg {0} -> {1}/bin/Debug/{0}.1.0.0.symbols.nupkg".Replace('/', Path.DirectorySeparatorChar); string stdOut; string stdError; var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); int exitCode; using (var testEnv = new DnuTestEnvironment(runtimeHomeDir)) { File.WriteAllText($"{testEnv.RootDir}/project.json", @"{ ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { ""dependencies"": { ""System.Runtime"":""4.0.20-*"" } } } }"); var environment = new Dictionary <string, string> { { "DNX_TRACE", "0" } }; DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", "", out stdOut, out stdError, environment: null, workingDir: testEnv.RootDir); exitCode = DnuTestUtils.ExecDnu(runtimeHomeDir, "pack", "", out stdOut, out stdError, environment, testEnv.RootDir); Assert.Empty(stdError); Assert.Contains(string.Format(expectedDNX, Path.GetFileName(testEnv.RootDir), testEnv.RootDir), stdOut); Assert.Contains(string.Format(expectedDNXCore, Path.GetFileName(testEnv.RootDir), testEnv.RootDir), stdOut); Assert.Contains(string.Format(expectedNupkg, Path.GetFileName(testEnv.RootDir), testEnv.RootDir), stdOut); Assert.Equal(0, exitCode); Assert.True(Directory.Exists($"{testEnv.RootDir}/bin")); } }
public void DnuRestore_ReinstallsPackageWithNormalizedVersion(string flavor, string os, string architecture) { var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var tempDir = new DisposableDir()) { var projectDir = Path.Combine(tempDir, "project"); var packagesDir = Path.Combine(tempDir, "packages"); var projectJson = Path.Combine(projectDir, Runtime.Project.ProjectFileName); Directory.CreateDirectory(projectDir); File.WriteAllText(projectJson, @" { ""dependencies"": { ""alpha"": ""0.1.0"" } }"); DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "restore", arguments: $"{projectDir} -s {_fixture.PackageSource} --packages {packagesDir}"); // rename package folder to an unnormalized string Directory.Move(Path.Combine(packagesDir, "alpha", "0.1.0"), Path.Combine(packagesDir, "alpha", "0.1.0.0")); // ensure the directory is renamed Assert.False(Directory.Exists(Path.Combine(packagesDir, "alpha", "0.1.0"))); string stdOut, stdErr; var exitCode = DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "restore", arguments: $"{projectDir} -s {_fixture.PackageSource} --packages {packagesDir}", stdOut: out stdOut, stdErr: out stdErr); Assert.Equal(0, exitCode); Assert.Empty(stdErr); Assert.Contains($"Installing alpha.0.1.0", stdOut); Assert.True(Directory.Exists(Path.Combine(packagesDir, "alpha", "0.1.0"))); Assert.True(File.Exists(Path.Combine(packagesDir, "alpha", "0.1.0", $"alpha{Constants.ManifestExtension}"))); } }
public void DnuRestore_ReinstallsCorruptedPackage(string flavor, string os, string architecture) { var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var tempDir = new DisposableDir()) { var projectDir = Path.Combine(tempDir, "project"); var packagesDir = Path.Combine(tempDir, "packages"); var projectJson = Path.Combine(projectDir, Runtime.Project.ProjectFileName); Directory.CreateDirectory(projectDir); File.WriteAllText(projectJson, @" { ""dependencies"": { ""alpha"": ""0.1.0"" } }"); DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "restore", arguments: $"{projectDir} -s {_fixture.PackageSource} --packages {packagesDir}"); // Corrupt the package by deleting nuspec from it var nuspecPath = Path.Combine(packagesDir, "alpha", "0.1.0", $"alpha{Constants.ManifestExtension}"); File.Delete(nuspecPath); string stdOut, stdErr; var exitCode = DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "restore", arguments: $"{projectDir} -s {_fixture.PackageSource} --packages {packagesDir}", stdOut: out stdOut, stdErr: out stdErr); Assert.Equal(0, exitCode); Assert.Empty(stdErr); Assert.Contains($"Installing alpha.0.1.0", stdOut); Assert.True(File.Exists(nuspecPath)); } }
public void DnuRestore_ExecutesScripts(string flavor, string os, string architecture) { bool isWindows = TestUtils.CurrentRuntimeEnvironment.OperatingSystem == "Windows"; var environment = new Dictionary <string, string> { { "DNX_TRACE", "0" }, }; var expectedPreContent = @"""one"" ""two"" "">three"" ""four"" "; var expectedPostContent = @"""five"" ""six"" ""argument seven"" ""argument eight"" "; string projectJsonContent; string scriptContent; string scriptName; if (isWindows) { projectJsonContent = @"{ ""frameworks"": { ""dnx451"": { } }, ""scripts"": { ""prerestore"": [ ""script.cmd one two > pre"", ""script.cmd ^>three >> pre && script.cmd ^ four >> pre"" ], ""postrestore"": [ ""\""%project:Directory%/script.cmd\"" five six > post"", ""\""%project:Directory%/script.cmd\"" \""argument seven\"" \""argument eight\"" >> post"" ] } }"; scriptContent = @"@echo off :argumentStart if ""%~1""=="""" goto argumentEnd echo ""%~1"" shift goto argumentStart :argumentEnd"; scriptName = "script.cmd"; } else { projectJsonContent = @"{ ""frameworks"": { ""dnx451"": { } }, ""scripts"": { ""prerestore"": [ ""script one two > pre"", ""script.sh \\>three >> pre; ./script.sh four >> pre"" ], ""postrestore"": [ ""\""%project:Directory%/script\"" five six > post"", ""\""%project:Directory%/script.sh\"" \""argument seven\"" \""argument eight\"" >> post"" ] } }"; scriptContent = @"#!/usr/bin/env bash set -o errexit for arg in ""$@""; do printf ""\""%s\""\n"" ""$arg"" done"; scriptName = "script.sh"; } var projectStructure = $@"{{ '.': ['project.json', '{ scriptName }'] }}"; var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name")) { var projectPath = testEnv.ProjectPath; DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", projectJsonContent) .WithFileContents(scriptName, scriptContent) .WriteTo(projectPath); FileOperationUtils.MarkExecutable(Path.Combine(projectPath, scriptName)); string output; string error; var exitCode = DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "restore", arguments: null, stdOut: out output, stdErr: out error, environment: environment, workingDir: projectPath); Assert.Equal(0, exitCode); Assert.Empty(error); Assert.Contains("Executing script 'prerestore' in project.json", output); Assert.Contains("Executing script 'postrestore' in project.json", output); var preContent = File.ReadAllText(Path.Combine(projectPath, "pre")); Assert.Equal(expectedPreContent, preContent); var postContent = File.ReadAllText(Path.Combine(projectPath, "post")); Assert.Equal(expectedPostContent, postContent); } }
public void DnuFeeds_ListsAllSources(string flavor, string os, string architecture) { var environment = new Dictionary <string, string> { { "DNX_TRACE", "0" }, }; var rootConfig = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <clear /> <!-- Remove the effects of any machine-level config --> <add key=""Source1"" value=""https://source1"" /> <add key=""Source2"" value=""https://source2"" /> </packageSources> </configuration>"; var subConfig = @"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <packageSources> <add key=""Source3"" value=""https://source3"" /> </packageSources> <disabledPackageSources> <add key=""Source1"" value=""https://source1"" /> </disabledPackageSources> </configuration>"; var projectStructure = @"{ 'root': { 'NuGet.Config': """", 'sub': { 'NuGet.Config': """" } } }"; var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name")) { var projectPath = testEnv.ProjectPath; DirTree.CreateFromJson(projectStructure) .WithFileContents("root/NuGet.Config", rootConfig) .WithFileContents("root/sub/NuGet.Config", subConfig) .WriteTo(projectPath); string output; string error; var exitCode = DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "feeds", arguments: "list root/sub", stdOut: out output, stdErr: out error, environment: environment, workingDir: projectPath); Assert.Equal(0, exitCode); Assert.Empty(error); // CI Machines and such have different sources in the user-global config // So we can't actually assert the exact content of the output. Assert.Contains($"https://source1 [Disabled]{Environment.NewLine} Origin: {Path.Combine(projectPath, "root", "NuGet.Config")}", output); Assert.Contains($"https://source2{Environment.NewLine} Origin: {Path.Combine(projectPath, "root", "NuGet.Config")}", output); Assert.Contains($"https://source3{Environment.NewLine} Origin: {Path.Combine(projectPath, "root", "sub", "NuGet.Config")}", output); } }
public void DnuWrapUpdatesExistingProjectJson(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); if (PlatformHelper.IsMono) { return; } var expectedProjectJson = @"{ ""version"": ""1.0.0-*"", ""dependencies"": {}, ""frameworks"": { ""net45+win+wpa81+wp80"": { ""wrappedProject"": ""../../LibraryBeta.PCL/LibraryBeta.PCL.csproj"", ""bin"": { ""assembly"": ""../../LibraryBeta.PCL/obj/{configuration}/LibraryBeta.dll"", ""pdb"": ""../../LibraryBeta.PCL/obj/{configuration}/LibraryBeta.pdb"" } }, ""net45"": { ""wrappedProject"": ""../../LibraryBeta.PCL.Desktop/LibraryBeta.PCL.Desktop.csproj"", ""bin"": { ""assembly"": ""../../LibraryBeta.PCL.Desktop/obj/{configuration}/LibraryBeta.dll"", ""pdb"": ""../../LibraryBeta.PCL.Desktop/obj/{configuration}/LibraryBeta.pdb"" } }, ""wpa81"": { ""wrappedProject"": ""../../LibraryBeta.PCL.Phone/LibraryBeta.PCL.Phone.csproj"", ""bin"": { ""assembly"": ""../../LibraryBeta.PCL.Phone/obj/{configuration}/LibraryBeta.dll"", ""pdb"": ""../../LibraryBeta.PCL.Phone/obj/{configuration}/LibraryBeta.pdb"" } } } }"; var expectedGlobalJson = @"{ ""projects"": [ ""src"", ""test"" ] }"; using (runtimeHomeDir) using (var testSolutionDir = TestUtils.GetTempTestSolution("ConsoleApp1")) { var libBetaPclCsprojPath = Path.Combine(testSolutionDir, "LibraryBeta.PCL", "LibraryBeta.PCL.csproj"); var libBetaPclDesktopCsprojPath = Path.Combine( testSolutionDir, "LibraryBeta.PCL.Desktop", "LibraryBeta.PCL.Desktop.csproj"); var libBetaPclPhoneCsprojPath = Path.Combine( testSolutionDir, "LibraryBeta.PCL.Phone", "LibraryBeta.PCL.Phone.csproj"); var libBetaJsonPath = Path.Combine(testSolutionDir, "src", "LibraryBeta", "project.json"); var globalJsonPath = Path.Combine(testSolutionDir, "global.json"); var betaPclExitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "wrap", arguments: string.Format("\"{0}\" --msbuild \"{1}\"", libBetaPclCsprojPath, _msbuildPath)); var betaDesktopExitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "wrap", arguments: string.Format("\"{0}\" --msbuild \"{1}\"", libBetaPclDesktopCsprojPath, _msbuildPath)); var betaPhoneExitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "wrap", arguments: string.Format("\"{0}\" --msbuild \"{1}\"", libBetaPclPhoneCsprojPath, _msbuildPath)); Assert.Equal(0, betaPclExitCode); Assert.Equal(0, betaDesktopExitCode); Assert.Equal(0, betaPhoneExitCode); Assert.Equal(expectedGlobalJson, File.ReadAllText(globalJsonPath)); Assert.False(Directory.Exists(Path.Combine(testSolutionDir, "wrap"))); Assert.Equal(expectedProjectJson, File.ReadAllText(libBetaJsonPath)); } }
public void DnuWrapInPlaceCreateCsprojWrappersInPlace(string flavor, string os, string architecture) { var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); if (PlatformHelper.IsMono) { return; } var expectedLibGammaProjectJson = @"{ ""version"": ""1.0.0-*"", ""frameworks"": { ""net45"": { ""wrappedProject"": ""LibraryGamma.csproj"", ""bin"": { ""assembly"": ""obj/{configuration}/LibraryGamma.dll"", ""pdb"": ""obj/{configuration}/LibraryGamma.pdb"" }, ""dependencies"": { ""EntityFramework"": ""6.1.2-beta1"", ""LibraryEpsilon"": ""1.0.0-*"", ""LibraryDelta"": ""1.0.0-*"" } } } }"; var expectedLibEpsilonProjectJson = @"{ ""version"": ""1.0.0-*"", ""frameworks"": { ""net45"": { ""wrappedProject"": ""LibraryEpsilon.csproj"", ""bin"": { ""assembly"": ""obj/{configuration}/LibraryEpsilon.dll"", ""pdb"": ""obj/{configuration}/LibraryEpsilon.pdb"" } } } }"; var expectedLibDeltaProjectJson = @"{ ""version"": ""1.0.0-*"", ""frameworks"": { ""net45"": { ""bin"": { ""assembly"": ""../../ExternalAssemblies/LibraryDelta.dll"" } } } }"; var expectedGlobalJson = @"{ ""projects"": [ ""src"", ""test"", ""wrap"", ""."" ] }"; using (runtimeHomeDir) using (var testSolutionDir = TestUtils.GetTempTestSolution("ConsoleApp1")) { var libGammaCsprojPath = Path.Combine(testSolutionDir, "LibraryGamma", "LibraryGamma.csproj"); var globalJsonPath = Path.Combine(testSolutionDir, "global.json"); var wrapFolderPath = Path.Combine(testSolutionDir, "wrap"); var libGammaJsonPath = Path.Combine(testSolutionDir, "LibraryGamma", "project.json"); var libEpsilonJsonPath = Path.Combine(testSolutionDir, "LibraryEpsilon", "project.json"); var libDeltaJsonPath = Path.Combine(wrapFolderPath, "LibraryDelta", "project.json"); var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "wrap", arguments: string.Format("\"{0}\" --in-place --msbuild \"{1}\"", libGammaCsprojPath, _msbuildPath)); Assert.Equal(0, exitCode); Assert.Equal(expectedGlobalJson, File.ReadAllText(globalJsonPath)); Assert.True(Directory.Exists(wrapFolderPath)); Assert.Equal(1, Directory.EnumerateDirectories(wrapFolderPath).Count()); Assert.Equal(expectedLibGammaProjectJson, File.ReadAllText(libGammaJsonPath)); Assert.Equal(expectedLibEpsilonProjectJson, File.ReadAllText(libEpsilonJsonPath)); Assert.Equal(expectedLibDeltaProjectJson, File.ReadAllText(libDeltaJsonPath)); } }