Esempio n. 1
0
        public void DnuRestore_GeneratesDefaultRuntimeTargets(string flavor, string os, string architecture)
        {
            // TODO(anurse): Maybe this could be a condition? This is the only place we need it right now so it
            // didn't seem worth the refactor.
            // Travis has old versions of OSes and our test package doesn't work there
            var isTravisEnvironment = Environment.GetEnvironmentVariable("TRAVIS") ?? "false";

            if (isTravisEnvironment.Equals("true"))
            {
                return;
            }

            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            LockFile lockFile;

            using (var testDir = new DisposableDir())
            {
                var misc = TestUtils.GetMiscProjectsFolder();
                DirTree.CreateFromDirectory(Path.Combine(misc, "RuntimeRestore", "TestProject"))
                .WriteTo(testDir);

                // Clean up the lock file if it ended up there during the copy
                var lockFilePath = Path.Combine(testDir, "project.lock.json");
                if (File.Exists(lockFilePath))
                {
                    File.Delete(lockFilePath);
                }

                // Restore the project!
                var source = Path.Combine(misc, "RuntimeRestore", "RuntimeRestoreTestPackage", "feed");
                DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", $"--source {source}", workingDir: testDir);

                // Check the lock file
                lockFile = (new LockFileFormat()).Read(Path.Combine(testDir, "project.lock.json"));
            }

            // We can use the runtime environment to determine the expected RIDs
            var osName = RuntimeEnvironmentHelper.RuntimeEnvironment.GetDefaultRestoreRuntimes().First();

            if (osName.StartsWith("win"))
            {
                AssertLockFileTarget(lockFile, "win7-x86", "win7-x86");
                AssertLockFileTarget(lockFile, "win7-x64", "win7-x64");
            }
            else if (osName.StartsWith("ubuntu"))
            {
                // There is only ubuntu 14.04 in the package
                AssertLockFileTarget(lockFile, osName + "-x86", assemblyRid: null); // There is no ubuntu/osx-x86 in the test package
                AssertLockFileTarget(lockFile, osName + "-x64", "ubuntu.14.04-x64");
            }
            else if (osName.StartsWith("osx"))
            {
                // There is only osx 10.10 in the package
                AssertLockFileTarget(lockFile, osName + "-x86", assemblyRid: null); // There is no ubuntu/osx-x86 in the test package
                AssertLockFileTarget(lockFile, osName + "-x64", "osx.10.10-x64");
            }
            else
            {
                Assert.True(false, $"Unknown OS Name: {osName}");
            }
        }
Esempio n. 2
0
        public void AppHost_ExecutesCommands(
            string flavor,
            string os,
            string architecture,
            string command,
            string expectedOutput)
        {
            var environment = new Dictionary <string, string>
            {
                { "DNX_TRACE", "0" },
            };

            var projectName      = "Project Name";
            var projectStructure =
                $@"{{
  '.': ['Program.cs', '{ Project.ProjectFileName }']
}}";
            var programContents =
                @"using System;

namespace Project_Name
{
    public class Program
    {
        public void Main(string[] arguments)
        {
            for (var i = 0; i < arguments.Length; i++)
            {
                var argument = arguments[i];
                if (!string.IsNullOrWhiteSpace(argument))
                {
                    Console.WriteLine($""{ i }: '{ argument }'"");
                }
            }
        }
    }
}";
            var projectJsonContents =
                $@"{{
  ""commands"": {{
    ""one"": ""\""{ projectName }\"" one two"",
    ""two"": ""\""{ projectName }\"" ^>three &&>>^\"""",
    ""three"": ""\""{ projectName }\"" four \""argument five\""""
  }},
  ""frameworks"" : {{
    ""dnx451"": {{ }}
  }}
}}";

            using (var applicationRoot = new DisposableDir())
            {
                var projectPath = Path.Combine(applicationRoot, projectName);
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("Program.cs", programContents)
                .WithFileContents(Project.ProjectFileName, projectJsonContents)
                .WriteTo(projectPath);
                var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

                var exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomePath,
                    subcommand: "restore",
                    arguments: null,
                    environment: environment,
                    workingDir: projectPath);
                Assert.Equal(0, exitCode); // Guard

                string output;
                string error;
                exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomePath,
                    arguments: $@" { command } extra",
                    stdOut: out output,
                    stdErr: out error,
                    environment: environment,
                    workingDir: projectPath);

                Assert.Equal(0, exitCode);
                Assert.Empty(error);
                Assert.Contains(expectedOutput, output);
            }
        }
Esempio n. 3
0
        public void DnuWrapMaintainsAllKindsOfReferences(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            if (RuntimeEnvironmentHelper.IsMono)
            {
                return;
            }

            var expectedLibGammaProjectJson   = @"{
  ""version"": ""1.0.0-*"",
  ""frameworks"": {
    ""net45"": {
      ""wrappedProject"": ""../../LibraryGamma/LibraryGamma.csproj"",
      ""bin"": {
        ""assembly"": ""../../LibraryGamma/obj/{configuration}/LibraryGamma.dll"",
        ""pdb"": ""../../LibraryGamma/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/LibraryEpsilon.csproj"",
      ""bin"": {
        ""assembly"": ""../../LibraryEpsilon/obj/{configuration}/LibraryEpsilon.dll"",
        ""pdb"": ""../../LibraryEpsilon/obj/{configuration}/LibraryEpsilon.pdb""
      }
    }
  }
}";
            var expectedLibDeltaProjectJson   = @"{
  ""version"": ""1.0.0-*"",
  ""frameworks"": {
    ""net45"": {
      ""bin"": {
        ""assembly"": ""../../ExternalAssemblies/LibraryDelta.dll""
      }
    }
  }
}";
            var expectedGlobalJson            = @"{
  ""projects"": [
    ""src"",
    ""test"",
    ""wrap""
  ]
}";

            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(wrapFolderPath, "LibraryGamma", "project.json");
                var libEpsilonJsonPath = Path.Combine(wrapFolderPath, "LibraryEpsilon", "project.json");
                var libDeltaJsonPath   = Path.Combine(wrapFolderPath, "LibraryDelta", "project.json");

                var exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    subcommand: "wrap",
                    arguments: string.Format("\"{0}\" --msbuild \"{1}\"", libGammaCsprojPath, _msbuildPath));

                Assert.Equal(0, exitCode);
                Assert.Equal(expectedGlobalJson, File.ReadAllText(globalJsonPath));
                Assert.Equal(3, Directory.EnumerateDirectories(wrapFolderPath).Count());
                Assert.Equal(expectedLibGammaProjectJson, File.ReadAllText(libGammaJsonPath));
                Assert.Equal(expectedLibEpsilonProjectJson, File.ReadAllText(libEpsilonJsonPath));
                Assert.Equal(expectedLibDeltaProjectJson, File.ReadAllText(libDeltaJsonPath));
            }
        }
Esempio n. 4
0
        public void DnuWrapUpdatesExistingProjectJson(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            if (RuntimeEnvironmentHelper.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 (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));
            }
        }
Esempio n. 5
0
        public void GitCanInstallPackageWithSourceInformation(string flavor, string os, string architecture)
        {
            using (var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture))
                using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
                {
                    var testPackageFolder = ScafoldEmptyProject(
                        testEnv.RootDir,
                        "TestPackage",
                        _ => @"{
                        ""frameworks"": {
                            ""dnx451"": { }
                        },
                        ""repository"": {
                            ""type"": ""git"",
                            ""url"": """ + testEnv.RootDir.Replace('\\', '/') + @"""
                        }
                    }");

                    InitGitRepoAndCommitAll(testEnv.RootDir);

                    var exitCode = DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        "restore",
                        arguments: null,
                        workingDir: testPackageFolder);
                    Assert.Equal(0, exitCode);

                    var outputFolder = Path.Combine(testPackageFolder, "bin");
                    exitCode = DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        $"pack --out {outputFolder}",
                        arguments: null,
                        workingDir: testPackageFolder);
                    Assert.Equal(0, exitCode);

                    outputFolder = Path.Combine(outputFolder, "Debug").Replace('\\', '/');

                    using (var installEnv = new DnuTestEnvironment(runtimeHomeDir))
                    {
                        var testFolderName = Path.Combine(installEnv.RootDir, "project");
                        Directory.CreateDirectory(testFolderName);

                        var consumerProjectFolder = ScafoldEmptyProject(
                            testFolderName,
                            "Client",
                            _ => @"{
                            ""dependencies"": {
                                ""TestPackage"": ""1.0.0""
                            },
                            ""frameworks"": {
                                ""dnx451"": {
                                }
                            },
                        }");

                        var packagesDestinationFolder = Path.Combine(installEnv.RootDir, "packages");
                        exitCode = DnuTestUtils.ExecDnu(
                            runtimeHomeDir,
                            $"restore --fallbacksource \"{ outputFolder }\" --packages \"{ packagesDestinationFolder }\"",
                            arguments: null,
                            workingDir: consumerProjectFolder);
                        Assert.Equal(0, exitCode);

                        var sourcesDestinationFolder = Path.Combine(installEnv.RootDir, "sources");
                        exitCode = DnuTestUtils.ExecDnu(
                            runtimeHomeDir,
                            $"sources get TestPackage --packages \"{ packagesDestinationFolder }\"  --output \"{ sourcesDestinationFolder }\"",
                            arguments: null,
                            workingDir: consumerProjectFolder);
                        Assert.Equal(0, exitCode);

                        var installProjectGlobalFile = Path.Combine(testFolderName, GlobalSettings.GlobalFileName);
                        var globalFile = JsonConvert.DeserializeObject(File.ReadAllText(installProjectGlobalFile)) as JObject;
                        var projects   = globalFile["projects"] as JArray;

                        Assert.Equal(2, projects.Count);
                        var sourceFolder = projects
                                           .First(prj => prj.ToString().StartsWith(sourcesDestinationFolder, StringComparison.Ordinal))
                                           .ToString();

                        Assert.True(Directory.Exists(sourceFolder));
                    }
                }
        }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
        public void DnuPack_ExecutesScriptsForEachConfigurationAndTargetFramework(string flavor, string os, string architecture)
        {
            var projectStructure = @"{
  '.': ['project.json']
}";
            var runtimeHomeDir   = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, "TestProject"))
            {
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("project.json", @"{
  ""version"": ""1.0-beta"",
  ""frameworks"": {
    ""dnx451"": {},
    ""dnxcore50"": {
        ""dependencies"": {
            ""System.Runtime"":""4.0.20-*""
        }
      }
  },
  ""scripts"": {
    ""prebuild"": ""echo PREBUILD_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"",
    ""prepack"": ""echo PREPACK_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"",
    ""postbuild"": ""echo POSTBUILD_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"",
    ""postpack"": ""echo POSTPACK_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%""
  }
}")
                .WriteTo(testEnv.ProjectPath);

                string stdOut, stdErr;
                var    exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    subcommand: "restore",
                    arguments: string.Empty,
                    workingDir: testEnv.ProjectPath);
                Assert.Equal(0, exitCode);

                exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    "pack",
                    testEnv.ProjectPath + " --configuration Debug --configuration Release",
                    out stdOut,
                    out stdErr);

                Assert.Equal(0, exitCode);
                Assert.Empty(stdErr);

                var idx = 0;
                foreach (var configuration in new[] { "Debug", "Release" })
                {
                    // note that %TargetFramework% is not defined outside build
                    idx = stdOut.IndexOf($"PREPACK_SCRIPT_OUTPUT {configuration} %build:TargetFramework%", 0);
                    Assert.True(idx >= 0);
                    foreach (var framework in new[] { "dnx451", "dnxcore50" })
                    {
                        idx = stdOut.IndexOf($"PREBUILD_SCRIPT_OUTPUT {configuration} {framework}", idx);
                        Assert.True(idx >= 0);
                        idx = stdOut.IndexOf($"POSTBUILD_SCRIPT_OUTPUT {configuration} {framework}", idx);
                        Assert.True(idx >= 0);
                    }
                    idx = stdOut.IndexOf($"POSTPACK_SCRIPT_OUTPUT {configuration} %build:TargetFramework%", 0);
                    Assert.True(idx >= 0);
                }

                Assert.Equal(-1, stdOut.IndexOf("PREPACK_SCRIPT_OUTPUT", idx + 1));
                Assert.Equal(-1, stdOut.IndexOf("PREBUILD_SCRIPT_OUTPUT", idx + 1));
                Assert.Equal(-1, stdOut.IndexOf("POSTBUILD_SCRIPT_OUTPUT", idx + 1));
                Assert.Equal(-1, stdOut.IndexOf("POSTPACK_SCRIPT_OUTPUT", idx + 1));
            }
        }