public void DnuInstall_WithProjectPathArgument(string flavor, string os, string architecture) { var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var tempDir = new DisposableDir()) { var packagesDir = Path.Combine(tempDir, "packages"); var projectDir = Path.Combine(tempDir, "project"); Directory.CreateDirectory(projectDir); var projectJsonPath = Path.Combine(projectDir, Runtime.Project.ProjectFileName); File.WriteAllText(projectJsonPath, @"{ ""dependencies"": { } }"); VerifyDnuInstall( runtimeHomePath, packageName: "alpha", packageVersion: "0.1.0", projectDir: projectDir, packagesDir: packagesDir, workingDir: null); } }
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); } }