コード例 #1
0
        public void BuildPackageAndCheckServiceability(string projectName, bool expectedServiceability)
        {
            var          rootDir       = ProjectResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());
            var          projectSrcDir = Path.Combine(rootDir, "misc", "ServicingTestProjects", projectName);
            const string configuration = "Debug";

            var components   = TestUtils.GetRuntimeComponentsCombinations().First();
            var flavor       = (string)components[0];
            var os           = (string)components[1];
            var architecture = (string)components[2];

            using (var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture))
                using (var tempDir = new DisposableDir())
                {
                    var projectDir    = Path.Combine(tempDir, projectName);
                    var buildOutpuDir = Path.Combine(tempDir, "output");
                    TestUtils.CopyFolder(projectSrcDir, projectDir);

                    var exitCode = DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", projectDir);
                    Assert.Equal(0, exitCode);

                    exitCode = DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        "pack",
                        $"{projectDir} --out {buildOutpuDir} --configuration {configuration}");

                    Assert.Equal(0, exitCode);

                    var assemblyPath = Path.Combine(buildOutpuDir, configuration, "dnx451", $"{projectName}.dll");
                    Assert.Equal(expectedServiceability, LockFileUtils.IsAssemblyServiceable(assemblyPath));
                }
        }
コード例 #2
0
        public void DnuList_SingleDependencyProject(string flavor, string os, string architecture)
        {
            string stdOut, stdErr;
            var    runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            CreateProjectJson(new
            {
                dependencies = new
                {
                    alpha = "0.1.0"
                },
                frameworks = new
                {
                    dnx451    = new { },
                    dnxcore50 = new { }
                }
            });

            // restore the packages
            Assert.Equal(0, DnuTestUtils.ExecDnu(runtimeHomePath, "restore", "--source " + _fixture.PackageSource, workingDir: _workingDir.DirPath));

            // run dnu list
            Assert.Equal(0, DnuTestUtils.ExecDnu(runtimeHomePath, "list", "", out stdOut, out stdErr, environment: null, workingDir: _workingDir.DirPath));

            // there should be 2 and only 2 dependencies of alpha
            var resolvedHits = stdOut.Split('\n').Where(line => line.Contains("* alpha 0.1.0"))
                               .Where(line => !line.Contains("Unresolved"));
            var unresolvedHits = stdOut.Split('\n').Where(line => line.Contains("* alpha 0.1.0"))
                                 .Where(line => line.Contains("Unresolved"));

            Assert.Equal(1, resolvedHits.Count());
            Assert.Equal(1, unresolvedHits.Count());
        }
コード例 #3
0
        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"));
            }
        }
コード例 #4
0
        public static int CreateDisposableTestProject(string runtimeHomeDir,
                                                      string targetDir,
                                                      string projectDir)
        {
            // Find the misc project to copy
            var targetProjectDir = Path.Combine(targetDir, Path.GetFileName(projectDir));

            CopyFolder(projectDir, targetProjectDir);

            // Make sure package restore can be successful
            var currentDnxSolutionRootDir = ProjectRootResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());

            File.Copy(Path.Combine(currentDnxSolutionRootDir, "NuGet.config"),
                      Path.Combine(targetProjectDir, "NuGet.config"));

            // Use the newly built runtime to generate lock files for samples
            string stdOut, stdErr;

            return(DnuTestUtils.ExecDnu(
                       runtimeHomeDir,
                       subcommand: "restore",
                       arguments: targetProjectDir,
                       stdOut: out stdOut,
                       stdErr: out stdErr));
        }
コード例 #5
0
        public void DnuWrapCreatesGlobalJsonIfSolutionRootDoesNotHaveOne(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            if (RuntimeEnvironmentHelper.IsMono)
            {
                return;
            }

            var expectedGlobalJson = @"{
  ""projects"": [
    ""wrap""
  ]
}";

            using (runtimeHomeDir)
                using (var testSolutionDir = TestUtils.GetTempTestSolution("ConsoleApp1"))
                {
                    var libGammaCsprojPath = Path.Combine(testSolutionDir, "LibraryGamma", "LibraryGamma.csproj");
                    var globalJsonPath     = Path.Combine(testSolutionDir, "global.json");
                    File.Delete(globalJsonPath);

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

                    Assert.Equal(0, exitCode);
                    Assert.True(File.Exists(globalJsonPath));
                    Assert.Equal(expectedGlobalJson, File.ReadAllText(globalJsonPath));
                }
        }
コード例 #6
0
        private void CreateNewPackage(string name, string version)
        {
            var runtimeForPacking = TestUtils.GetClrRuntimeComponents().FirstOrDefault();

            if (runtimeForPacking == null)
            {
                throw new InvalidOperationException("Can't find a CLR runtime to pack test packages.");
            }

            var runtimeHomePath = base.GetRuntimeHomeDir((string)runtimeForPacking[0],
                                                         (string)runtimeForPacking[1],
                                                         (string)runtimeForPacking[2]);

            using (var tempdir = new DisposableDir())
            {
                var dir         = new DirectoryInfo(tempdir);
                var projectDir  = dir.CreateSubdirectory(name);
                var outputDir   = dir.CreateSubdirectory("output");
                var projectJson = Path.Combine(projectDir.FullName, "project.json");

                File.WriteAllText(projectJson, $@"{{
  ""version"": ""{version}"",
  ""frameworks"": {{ 
      ""dnx451"": {{ }}
  }}
}}");
                DnuTestUtils.ExecDnu(runtimeHomePath, "restore", projectJson);
                DnuTestUtils.ExecDnu(runtimeHomePath, "pack", projectJson + " --out " + outputDir.FullName, environment: null, workingDir: null);

                var packageName = string.Format("{0}.{1}.nupkg", name, version);
                var packageFile = Path.Combine(outputDir.FullName, "Debug", packageName);

                File.Copy(packageFile, Path.Combine(PackageSource, packageName), overwrite: true);
            }
        }
コード例 #7
0
        public void BootstrapperInvokesAssemblyWithInferredAppBaseAndLibPathOnCoreClr(string flavor, string os, string architecture)
        {
            using (var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture))
                using (var tempDir = TestUtils.CreateTempDir())
                {
                    var samplesPath   = TestUtils.GetSamplesFolder();
                    var sampleAppRoot = Path.Combine(samplesPath, "HelloWorld");

                    var exitCode = DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        subcommand: "build",
                        arguments: string.Format("{0} --configuration=Release --out {1}", sampleAppRoot, tempDir.DirPath));

                    Assert.Equal(0, exitCode);

                    string stdOut, stdErr;
                    exitCode = BootstrapperTestUtils.ExecBootstrapper(
                        runtimeHomeDir,
                        arguments: Path.Combine(tempDir, "Release", "dnxcore50", "HelloWorld.dll"),
                        stdOut: out stdOut,
                        stdErr: out stdErr,
                        environment: new Dictionary <string, string> {
                        { EnvironmentNames.Trace, null }
                    });

                    Assert.Equal(0, exitCode);
                    Assert.Equal(@"Hello World!
Hello, code!
", stdOut);
                }
        }
コード例 #8
0
        public void DnuList_Unresolved(string flavor, string os, string architecture)
        {
            string stdOut, stdErr;
            var    runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture);
            var    projectName     = Path.GetFileName(_workingDir.DirPath);

            CreateProjectJson(new
            {
                dependencies = new
                {
                    alpha = "0.1.0",
                    beta  = "0.2.0"
                },
                frameworks = new
                {
                    dnx451    = new { },
                    dnxcore50 = new { }
                }
            });

            // restore the packages, it should fail because missing package beta
            Assert.Equal(1, DnuTestUtils.ExecDnu(runtimeHomePath, "restore", "--source " + _fixture.PackageSource, workingDir: _workingDir.DirPath));

            // run dnu list
            Assert.Equal(0, DnuTestUtils.ExecDnu(runtimeHomePath, "list", "", out stdOut, out stdErr, environment: null, workingDir: _workingDir.DirPath));

            // the beta package is not resolved
            var hits = SplitLines(stdOut).Where(line => line.Contains("* beta 0.2.0 - Unresolved"));

            Assert.Equal(2, hits.Count());
        }
コード例 #9
0
        public void DnuRestore_UsesProjectAndCommandLineProvidedRuntimes(string flavor, string os, string architecture)
        {
            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);
                }

                // Modify the project
                AddRuntimeToProject(testDir, "win10-x86");

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

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

            AssertLockFileTarget(lockFile, "win10-x86", "win8-x86");
            AssertLockFileTarget(lockFile, "osx.10.10-x64", "osx.10.10-x64");
            AssertLockFileTarget(lockFile, "ubuntu.14.04-x64", "ubuntu.14.04-x64");
        }
コード例 #10
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"": {
      ""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""
      }
    }
  }
}";
            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 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));

                Assert.Equal(0, betaPclExitCode);
                Assert.Equal(0, betaDesktopExitCode);
                Assert.Equal(expectedGlobalJson, File.ReadAllText(globalJsonPath));
                Assert.False(Directory.Exists(Path.Combine(testSolutionDir, "wrap")));
                Assert.Equal(expectedProjectJson, File.ReadAllText(libBetaJsonPath));
            }
        }
コード例 #11
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.
            if (RuntimeEnvironmentHelper.RuntimeEnvironment.OperatingSystem.Equals("Darwin"))
            {
                var ver = Version.Parse(RuntimeEnvironmentHelper.RuntimeEnvironment.OperatingSystemVersion);
                if (ver < new Version(10, 10))
                {
                    // Not supported on this!
                    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 because by default it only uses the current OSes RIDs
            if (RuntimeEnvironmentHelper.IsWindows)
            {
                AssertLockFileTarget(lockFile, "win7-x86", "win7-x86");
                AssertLockFileTarget(lockFile, "win7-x64", "win7-x64");
            }
            else
            {
                var osName = RuntimeEnvironmentHelper.RuntimeEnvironment.GetDefaultRestoreRuntimes().First();
                osName = osName.Substring(0, osName.Length - 4);                    // Remove the -x86 suffix
                AssertLockFileTarget(lockFile, osName + "-x86", assemblyRid: null); // There is no ubuntu/osx-x86 in the test package
                AssertLockFileTarget(lockFile, osName + "-x64", osName + "-x64");
            }
        }
コード例 #12
0
        public void GitBuildGeneratesSourceInformation(string flavor, string os, string architecture)
        {
            const string fakeRepoName = "https://example.com/example.git";

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

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                var testProjectFolder = ScafoldEmptyProject(
                    testEnv.RootDir,
                    "TestPackage",
                    _ => @"{
                        ""frameworks"": {
                            ""dnx451"": { }
                        },
                        ""repository"": {
                            ""type"": ""git"",
                            ""url"": """ + fakeRepoName + @"""
                        }
                    }");

                InitGitRepoAndCommitAll(testEnv.RootDir);

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

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

                var repoInfoFile = Path.Combine(
                    outputFolder,
                    "Debug",
                    SourceControl.Constants.SnapshotInfoFileName);

                Assert.True(File.Exists(repoInfoFile));

                var repoInfo = JsonConvert.DeserializeObject <Dictionary <string, string> >(File.ReadAllText(repoInfoFile));

                Assert.Equal("git", repoInfo[SourceControl.Constants.RepoTypeKey]);
                Assert.Equal(fakeRepoName, repoInfo["url"]);
                Assert.False(string.IsNullOrEmpty(repoInfo["commit"]));
                Assert.Equal("src", repoInfo["path"]);
            }
        }
コード例 #13
0
        public void DnuPack_P2PDifferentFrameworks(string flavor, string os, string architecture)
        {
            string stdOut;
            string stdError;
            var    runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                var p1 = Path.Combine(testEnv.RootDir, "P1");
                var p2 = Path.Combine(testEnv.RootDir, "P2");

                Directory.CreateDirectory(p1);
                Directory.CreateDirectory(p2);

                File.WriteAllText($"{p1}/project.json",
                                  @"{
                    ""dependencies"": {
                        ""System.Runtime"":""4.0.20-*""
                    },
                    ""frameworks"": {
                        ""dotnet"": {}
                    }
                  }");

                File.WriteAllText($"{p1}/BaseClass.cs", @"
public class BaseClass {
    public virtual void Test() { }
}");

                File.WriteAllText($"{p2}/project.json",
                                  @"{
                    ""dependencies"": {
                        ""P1"":""""
                    },
                    ""frameworks"": {
                        ""dnxcore50"": {}
                    }
                  }");
                File.WriteAllText($"{p2}/TestClass.cs", @"
public class TestClass : BaseClass {
    public override void Test() { }
}");

                var environment = new Dictionary <string, string> {
                    { "DNX_TRACE", "0" }
                };
                DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", "", out stdOut, out stdError, environment: null, workingDir: testEnv.RootDir);
                var exitCode = DnuTestUtils.ExecDnu(runtimeHomeDir, "pack", "", out stdOut, out stdError, environment, p2);
                Assert.Equal(0, exitCode);
            }
        }
コード例 #14
0
        private void PackPackage(string app, string outpath)
        {
            var runtimeForPacking = TestUtils.GetClrRuntimeComponents().FirstOrDefault();

            if (runtimeForPacking == null)
            {
                throw new InvalidOperationException("Can't find a CLR runtime to pack test packages.");
            }

            var runtimeHomePath = base.GetRuntimeHomeDir((string)runtimeForPacking[0],
                                                         (string)runtimeForPacking[1],
                                                         (string)runtimeForPacking[2]);

            DnuTestUtils.ExecDnu(runtimeHomePath, "restore", "", environment: null, workingDir: app);
            DnuTestUtils.ExecDnu(runtimeHomePath, "pack", $"--out {outpath}", environment: null, workingDir: app);
        }
コード例 #15
0
        public void DnuPack_ShowUnresolvedDependencyWhenBuildFails(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);
            var projectJson    = @"{
  ""frameworks"": {
    ""dnx451"": {
      ""dependencies"": {
      ""NonexistentPackage"": ""1.0.0""
      }
    }
  }
}";

            using (var tempDir = new DisposableDir())
            {
                var projectPath    = Path.Combine(tempDir, "Project");
                var emptyLocalFeed = Path.Combine(tempDir, "EmptyLocalFeed");
                Directory.CreateDirectory(projectPath);
                Directory.CreateDirectory(emptyLocalFeed);
                var projectJsonPath = Path.Combine(projectPath, Runtime.Project.ProjectFileName);
                File.WriteAllText(projectJsonPath, projectJson);

                string stdOut, stdErr;
                var    exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    "restore",
                    $"{projectJsonPath} -s {emptyLocalFeed}",
                    out stdOut,
                    out stdErr);
                Assert.Equal(1, exitCode);

                exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    "pack",
                    projectJsonPath,
                    out stdOut,
                    out stdErr);

                Assert.Equal(1, exitCode);
                Assert.NotEmpty(stdErr);
                var unresolvedDependencyErrorCount = stdErr
                                                     .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
                                                     .Where(line => line.Contains("The dependency NonexistentPackage >= 1.0.0 could not be resolved"))
                                                     .Count();
                Assert.Equal(1, unresolvedDependencyErrorCount);
            }
        }
コード例 #16
0
        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"));
            }
        }
コード例 #17
0
        private void RunAdditionalFilesTest(string flavor, string os, string architecture, string dirTree, string projectJson, string[] expectedOutput, bool shouldFail = false)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                int    exitCode;
                string stdOut;
                string stdErr;

                DirTree.CreateFromJson(dirTree)
                .WithFileContents("project.json", projectJson)
                .WriteTo(testEnv.ProjectPath);

                DnuTestUtils.ExecDnu(runtimeHomeDir, "restore", "", workingDir: testEnv.RootDir);
                exitCode = DnuTestUtils.ExecDnu(runtimeHomeDir, "pack", $"{testEnv.ProjectPath} --out {testEnv.PublishOutputDirPath}", out stdOut, out stdErr, workingDir: testEnv.RootDir);

                var packageOutputPath = Path.Combine(testEnv.PublishOutputDirPath, "Debug", $"{testEnv.ProjectName}.1.0.0.nupkg");

                // Check it
                if (shouldFail)
                {
                    Assert.NotEqual(0, exitCode);
                    foreach (var message in expectedOutput)
                    {
                        Assert.Contains(
                            message.Replace("PROJECTJSONPATH", Path.Combine(testEnv.ProjectPath, "project.json")),
                            stdErr.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
                    }
                    Assert.False(File.Exists(packageOutputPath));
                }
                else
                {
                    Assert.True(File.Exists(packageOutputPath));

                    string[] entries;
                    using (var archive = ZipFile.OpenRead(packageOutputPath))
                    {
                        entries = archive.Entries.Select(e => e.FullName).Where(IsNotOpcMetadata).ToArray();
                    }

                    Assert.Equal(0, exitCode);
                    Assert.Equal(expectedOutput, entries);
                }
            }
        }
コード例 #18
0
        public void DnuList_EmptyProject_Details(string flavor, string os, string architecture)
        {
            string stdOut, stdErr;
            var    runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture);
            var    expectedTitle   = string.Format(
                @"Listing dependencies for {0} ({1})",
                Path.GetFileName(_workingDir.DirPath),
                Path.Combine(_workingDir, "project.json"));

            CreateProjectJson(@"{}");

            // run dnu list
            Assert.Equal(0, DnuTestUtils.ExecDnu(runtimeHomePath, "list", "--details", out stdOut, out stdErr, environment: null, workingDir: _workingDir.DirPath));

            // assert
            Assert.True(string.IsNullOrEmpty(stdErr));
            Assert.True(stdOut.Contains(expectedTitle));
        }
コード例 #19
0
        public void DnuPack_PortablePdbsGeneratedWhenEnvVariableSet(string flavor, string os, string architecture)
        {
            string stdOut;
            string stdError;
            var    runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);
            int    exitCode;

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                var appName = PathUtility.GetDirectoryName(testEnv.RootDir);
                File.WriteAllText($"{testEnv.RootDir}/project.json",
                                  @"{
                    ""frameworks"": {
                        ""dnx451"": {
                        }
                    }
                  }");

                var environment = new Dictionary <string, string> {
                    { "DNX_TRACE", "0" }, { "DNX_BUILD_PORTABLE_PDB", "1" }
                };
                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);

                var outputDir = Path.Combine(testEnv.RootDir, "bin", "Debug", "dnx451");
                Assert.Equal(0, exitCode);
                Assert.True(Directory.Exists(outputDir));
                Assert.True(File.Exists(Path.Combine(outputDir, appName + ".dll")));
                Assert.True(File.Exists(Path.Combine(outputDir, appName + ".pdb")));
            }
        }
コード例 #20
0
        public void DnuCommands_Install_InstallsWorkingCommand(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                var environment = new Dictionary <string, string>();
                environment.Add("USERPROFILE", testEnv.RootDir);

                string stdOut, stdErr;
                var    exitCode = DnuTestUtils.ExecDnu(runtimeHomeDir, "commands",
                                                       $"install {_fixture.PackageSource}/Debug/CommandsProject.1.0.0.nupkg --source https://nuget.org/api/v2/",
                                                       out stdOut, out stdErr, environment, workingDir: testEnv.RootDir);

                var  commandFilePath = "hello.cmd";
                bool isWindows       = TestUtils.CurrentRuntimeEnvironment.OperatingSystem == "Windows";
                if (!isWindows)
                {
                    commandFilePath = "hello";
                }
                commandFilePath = Path.Combine(testEnv.RootDir, ".dnx/bin", commandFilePath);

                Assert.Equal(0, exitCode);
                Assert.True(string.IsNullOrEmpty(stdErr));
                Assert.True(File.Exists(commandFilePath));

                environment = new Dictionary <string, string>();
                environment.Add("DNX_PACKAGES", null);

                if (!isWindows)
                {
                    exitCode = TestUtils.Exec("bash", commandFilePath, out stdOut, out stdErr, environment);
                }
                else
                {
                    exitCode = TestUtils.Exec("cmd", $"/C {commandFilePath}", out stdOut, out stdErr, environment);
                }
                Assert.Equal(0, exitCode);
                Assert.True(string.IsNullOrEmpty(stdErr));
                Assert.Contains("Write text", stdOut);
            }
        }
コード例 #21
0
        public void DnuPack_ResourcesNoArgs_WarningAsErrorsCompilationOption(string flavor, string os, string architecture)
        {
            string stdOut;
            string stdError;
            var    runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);
            int    exitCode;

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                using (var tempDir = new DisposableDir())
                {
                    var appPath = Path.Combine(tempDir, "ResourcesTestProjects", "ReadFromResources");
                    TestUtils.CopyFolder(Path.Combine(TestUtils.GetMiscProjectsFolder(), "ResourcesTestProjects", "ReadFromResources"), appPath);
                    var workingDir = Path.Combine(appPath, "src", "ResourcesLibrary");

                    var environment = new Dictionary <string, string> {
                        { "DNX_TRACE", "0" }
                    };
                    DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        "restore", "",
                        out stdOut,
                        out stdError,
                        environment: null,
                        workingDir: workingDir);
                    exitCode = DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        "pack",
                        "",
                        out stdOut,
                        out stdError,
                        environment,
                        workingDir);

                    Assert.Empty(stdError);
                    Assert.Equal(0, exitCode);
                    Assert.True(Directory.Exists(Path.Combine(workingDir, "bin")));
                    Assert.True(File.Exists(Path.Combine(workingDir, "bin", "Debug", "dnx451", "fr-FR", "ResourcesLibrary.resources.dll")));
                    Assert.True(File.Exists(Path.Combine(workingDir, "bin", "Debug", "dnxcore50", "fr-FR", "ResourcesLibrary.resources.dll")));
                }
            }
        }
コード例 #22
0
        public void GitBuildInNonGitRepoDoesntGenerateSourceInformation(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                var testProjectFolder = ScafoldEmptyProject(
                    testEnv.RootDir,
                    "TestPackage",
                    _ => @"{
                        ""frameworks"": {
                            ""dnx451"": { }
                        },
                        ""repository"": {
                            ""type"": ""git"",
                            ""url"": ""https://example.com/example.git""
                        }
                    }");

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

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

                var repoInfoFile = Path.Combine(
                    outputFolder,
                    "Debug",
                    SourceControl.Constants.SnapshotInfoFileName);

                Assert.False(File.Exists(repoInfoFile));
            }
        }
コード例 #23
0
ファイル: LockFileUtilsFacts.cs プロジェクト: voloda/dnx
        public void BuildPackageAndCheckServiceability(string projectName, bool expectedServiceability)
        {
            var          rootDir       = ProjectResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());
            var          projectDir    = Path.Combine(rootDir, "misc", "ServicingTestProjects", projectName);
            const string configuration = "Debug";

            using (var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor: "clr", os: "win", architecture: "x86"))
                using (var tempDir = new DisposableDir())
                {
                    var buildOutpuDir = Path.Combine(tempDir, "output");

                    DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        "pack",
                        $"{projectDir} --out {buildOutpuDir} --configuration {configuration}");

                    var assemblyPath = Path.Combine(buildOutpuDir, configuration, "dnx451", $"{projectName}.dll");
                    Assert.Equal(expectedServiceability, LockFileUtils.IsAssemblyServiceable(assemblyPath));
                }
        }
コード例 #24
0
        public static DisposableDir PrepareTemporarySamplesFolder(string runtimeHomeDir)
        {
            var tempDir = new DisposableDir();

            TestUtils.CopyFolder(TestUtils.GetSamplesFolder(), tempDir);

            // Make sure sample projects depend on runtime components from newly built dnx
            var currentDnxSolutionRootDir = ProjectRootResolver.ResolveRootDirectory(Directory.GetCurrentDirectory());
            var currentDnxSolutionSrcPath = Path.Combine(currentDnxSolutionRootDir, "src").Replace("\\", "\\\\");
            var samplesGlobalJson         = new JObject();

            samplesGlobalJson["projects"] = new JArray(new[] { currentDnxSolutionSrcPath });
            File.WriteAllText(Path.Combine(tempDir, GlobalSettings.GlobalFileName), samplesGlobalJson.ToString());

            // Make sure package restore can be successful
            const string nugetConfigName = "NuGet.config";

            File.Copy(Path.Combine(currentDnxSolutionRootDir, nugetConfigName), Path.Combine(tempDir, nugetConfigName));

            // Use the newly built runtime to generate lock files for samples
            string stdOut, stdErr;
            int    exitCode;

            foreach (var projectDir in Directory.EnumerateDirectories(tempDir))
            {
                exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomeDir,
                    subcommand: "restore",
                    arguments: projectDir,
                    stdOut: out stdOut,
                    stdErr: out stdErr);

                if (exitCode != 0)
                {
                    Console.WriteLine(stdOut);
                    Console.WriteLine(stdErr);
                }
            }

            return(tempDir);
        }
コード例 #25
0
        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));
            }
        }
コード例 #26
0
        public void DnuList_SingleDependencyProject_Detailed(string flavor, string os, string architecture)
        {
            string stdOut, stdErr;
            var    runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture);
            var    projectName     = Path.GetFileName(_workingDir.DirPath);

            CreateProjectJson(new
            {
                dependencies = new
                {
                    alpha = "0.1.0"
                },
                frameworks = new
                {
                    dnx451 = new { }
                }
            });

            // restore the packages
            Assert.Equal(0, DnuTestUtils.ExecDnu(runtimeHomePath, "restore", "--source " + _fixture.PackageSource, workingDir: _workingDir.DirPath));

            // run dnu list
            Assert.Equal(0, DnuTestUtils.ExecDnu(runtimeHomePath, "list", "--details", out stdOut, out stdErr, environment: null, workingDir: _workingDir.DirPath));

            // assert - in the output of the dnu list, alpha 0.1.0 is listed as resolved, its source is listed on the second line.
            string[] outputLines = stdOut.Split(Environment.NewLine[0]);
            Assert.True(outputLines.Length > 0);
            for (int i = 0; i < outputLines.Length; ++i)
            {
                if (outputLines[i].Contains("* alpha 0.1.0"))
                {
                    Assert.False(outputLines[i].Contains("Unresolved"), "Dnu list reports unresolved package");

                    // the following line should list the dependency's source
                    Assert.True(++i < outputLines.Length);
                    Assert.True(outputLines[i].Contains(projectName));
                }
            }
        }
コード例 #27
0
        public void DnuCommands_Uninstall_PreservesPackagesUsedByOtherInstalledApps(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                var directory = Path.Combine(testEnv.RootDir, Runtime.Constants.DefaultLocalRuntimeHomeDir, "bin");
                InstallFakeApp(directory, "pack1", "0.0.0");
                InstallFakeApp(directory, "pack2", "0.0.0");
                WriteLockFile($"{directory}/packages/pack2/0.0.0/app", "pack2", "0.0.0");

                var environment = new Dictionary <string, string> {
                    { "USERPROFILE", testEnv.RootDir }
                };
                DnuTestUtils.ExecDnu(runtimeHomeDir, "commands", "uninstall pack1", environment);

                // Pack2 is in use by the pack2 app so should not be removed
                Assert.True(Directory.Exists($"{directory}/packages/pack2"));
                // Pack1 only used by pack1 app so should be removed
                Assert.False(Directory.Exists($"{directory}/packages/pack1"));
            }
        }
コード例 #28
0
        public void DnuCommands_Uninstall_NoPurge_DoesNotRemoveUnusedPackageNotUsedByApp(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir))
            {
                var directory = Path.Combine(testEnv.RootDir, Runtime.Constants.DefaultLocalRuntimeHomeDir, "bin");
                InstallFakeApp(directory, "pack1", "0.0.0");
                Directory.CreateDirectory($"{directory}/packages/pack2/0.0.0/");
                WriteLockFile($"{directory}/packages/pack1/0.0.0/app", "pack1", "0.0.0");

                var environment = new Dictionary <string, string> {
                    { "USERPROFILE", testEnv.RootDir }
                };
                DnuTestUtils.ExecDnu(runtimeHomeDir, "commands", "uninstall pack1 --no-purge", environment);

                // Pack1 only used by pack1 app but --no-purge should not remove it
                Assert.True(Directory.Exists($"{directory}/packages/pack1"));
                // Pack2 was unused but --no-purge should not remove it
                Assert.True(Directory.Exists($"{directory}/packages/pack2"));
            }
        }
コード例 #29
0
ファイル: BootstrapperTests.cs プロジェクト: cemoses/aspnet
        public void BootstrapperInvokesAssemblyWithInferredAppBaseAndLibPathOnClr(string flavor, string os, string architecture)
        {
            var outputFolder   = flavor == "coreclr" ? "dnxcore50" : "dnx451";
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            using (var tempSamplesDir = TestUtils.PrepareTemporarySamplesFolder(runtimeHomeDir))
                using (var tempDir = TestUtils.CreateTempDir())
                {
                    var sampleAppRoot = Path.Combine(tempSamplesDir, "HelloWorld");

                    string stdOut, stdErr;
                    var    exitCode = DnuTestUtils.ExecDnu(
                        runtimeHomeDir,
                        subcommand: "build",
                        arguments: string.Format("{0} --configuration=Release --out {1}", sampleAppRoot, tempDir),
                        stdOut: out stdOut,
                        stdErr: out stdErr);

                    if (exitCode != 0)
                    {
                        Console.WriteLine(stdOut);
                        Console.WriteLine(stdErr);
                    }

                    exitCode = TestUtils.ExecBootstrapper(
                        runtimeHomeDir,
                        arguments: Path.Combine(tempDir, "Release", outputFolder, "HelloWorld.dll"),
                        stdOut: out stdOut,
                        stdErr: out stdErr,
                        environment: new Dictionary <string, string> {
                        { EnvironmentNames.Trace, null }
                    });

                    Assert.Equal(0, exitCode);
                    Assert.Equal(@"Hello World!
Hello, code!
", stdOut);
                }
        }
コード例 #30
0
        public void DnuPack_NormalizesVersionNumberWithNoBuildNumber(string flavor, string os, string architecture)
        {
            int exitCode;
            var projectName      = "TestProject";
            var projectStructure = @"{
  '.': ['project.json']
}";
            var runtimeHomeDir   = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);

            using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, projectName))
            {
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("project.json", @"{
  ""version"": ""1.0-beta"",
  ""frameworks"": {
    ""dnx451"": {}
  }
}")
                .WriteTo(testEnv.ProjectPath);

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

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

                Assert.True(File.Exists(Path.Combine(testEnv.ProjectPath, "bin", "Debug", $"{projectName}.1.0.0-beta.nupkg")));
                Assert.True(File.Exists(Path.Combine(testEnv.ProjectPath, "bin", "Debug", $"{projectName}.1.0.0-beta.symbols.nupkg")));
            }
        }