예제 #1
0
        public void CanSpecifyProjectDirectoryInGlobalJson()
        {
            var solutionStructure = @"{
              'global.json': '',
              'src': {
            'ProjectA': {
              'project.json': '{}'
            }
              },
              'ProjectB': {
            'project.json': '{}'
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src"", ""ProjectB""]
            }")
                    .WriteTo(solutionPath);

                var resolutionRoot = Path.Combine(solutionPath, "src", "ProjectA");

                Project project;
                Assert.True(new ProjectResolver(resolutionRoot).TryResolveProject("ProjectB", out project));
                Assert.NotNull(project);
            }
        }
예제 #2
0
        public void ProjectResolverChecksProjectFileForDisambiguation()
        {
            const string projectName = "ProjectA";
            var solutionStructure = @"{
              'global.json': '',
              'src1': {
            'ProjectA': {
              'project.json': '{}'
            }
              },
              'src2': {
            'ProjectA': {
              'file.txt': 'Not a project.json'
            }
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src1"", ""src2""]
            }")
                    .WriteTo(solutionPath);

                var projectPath = Path.Combine(solutionPath, "src1", projectName);

                Project project;
                Assert.True(new ProjectResolver(projectPath).TryResolveProject(projectName, out project));
                Assert.NotNull(project);
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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";

            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 buildOutpuDir = Path.Combine(tempDir, "output");

                int 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));
            }
        }
예제 #5
0
 public void Dispose()
 {
     if (Root != null)
     {
         Root.Dispose();
         Root = null;
     }
 }
        public PackageManagerFunctionalTestFixture()
            : base()
        {
            _contextDir = TestUtils.CreateTempDir();
            PackageSource = Path.Combine(_contextDir.DirPath, "packages");
            Directory.CreateDirectory(PackageSource);

            CreateNewPackage("alpha", "0.1.0");

            PackPackage(Path.Combine(TestUtils.GetMiscProjectsFolder(), "XreTestApps/CommandsProject"), PackageSource);
        }
예제 #7
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 = ProjectResolver.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);
        }
예제 #8
0
        public void ApplicationScriptsHaveTheCorrectContent()
        {
            using (DisposableDir tempDir = new DisposableDir())
            {
                string testDir = Path.Combine(tempDir, "TestApp");
                Directory.CreateDirectory(testDir);

                string projectFilePath = Path.Combine(testDir, "project.json");
                string projectFileContent =
                @"{
                    ""commands"" : {
                        ""cmd1"":""demo1"",
                        ""cmd2"":""demo2""
                    }
                }";
                File.WriteAllText(projectFilePath, projectFileContent);

                Runtime.Project project;
                Runtime.Project.TryGetProject(projectFilePath, out project);

                var packageManager = new MockPackageManager();
                var infoReport = new MockReport();

                var builder = new InstallBuilder(
                    project,
                    packageManager,
                    new Reports()
                    {
                        Information = infoReport,
                        Verbose = new MockReport()
                    });

                Assert.True(builder.Build(testDir));

                ValidateProjectFile(Path.Combine(testDir, "app", "project.json"));
                ValidateScriptFile(Path.Combine(testDir, "app", "cmd1.cmd"));
                ValidateScriptFile(Path.Combine(testDir, "app", "cmd2.cmd"));
            }
        }
예제 #9
0
        public void DnuInstall_WithoutProjectPathArgument(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: null,
                    packagesDir: packagesDir,
                    workingDir: projectDir);
            }
        }
예제 #10
0
        public void ProjectResolverDoesNotThrowWhenAmbiguousNameIsNotUsed()
        {
            const string ambiguousName = "ProjectA";
            const string unambiguousName = "ProjectB";
            var solutionStructure = @"{
              'global.json': '',
              'src1': {
            'ProjectA': {
              'project.json': '{}'
            },
            'ProjectB': {
              'project.json': '{}'
            }
              },
              'src2': {
            'ProjectA': {
              'project.json': '{}'
            }
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src1"", ""src2""]
            }")
                    .WriteTo(solutionPath);

                var ambiguousProjectPath = Path.Combine(solutionPath, "src1", ambiguousName);
                var unambiguousProjectPath = Path.Combine(solutionPath, "src1", unambiguousName);

                Project project;
                Assert.True(new ProjectResolver(ambiguousProjectPath).TryResolveProject(unambiguousName, out project));
                Assert.NotNull(project);

                project = null;
                Assert.True(new ProjectResolver(unambiguousProjectPath).TryResolveProject(unambiguousName, out project));
                Assert.NotNull(project);
            }
        }
예제 #11
0
        public void ProjectResolverWorksWithMultipleNonProjectFoldersThatHaveSameName()
        {
            const string projectName = "ProjectA";
            var solutionStructure = @"{
              'global.json': '',
              'src1': {
            'ProjectA': {
              'file.txt': 'Not a project.json'
            }
              },
              'src2': {
            'ProjectA': {
              'file.txt': 'Not a project.json'
            }
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src1"", ""src2""]
            }")
                    .WriteTo(solutionPath);

                var projectPath = Path.Combine(solutionPath, "src1", projectName);

                Project project;
                Assert.False(new ProjectResolver(projectPath).TryResolveProject(projectName, out project));
                Assert.Null(project);
            }
        }
예제 #12
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));
            }
        }
예제 #13
0
 public DnuListTests(PackageManagerFunctionalTestFixture fixture)
 {
     _fixture = fixture;
     _workingDir = TestUtils.CreateTempDir();
 }
예제 #14
0
 public FileGlobbingTestBase()
 {
     Root = new DisposableDir();
     CreateContext();
 }
예제 #15
0
파일: TestUtils.cs 프로젝트: noahfalk/dnx
        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 = ProjectResolver.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;
        }
예제 #16
0
        public void AppHostShowsErrorWhenCurrentTargetFrameworkWasNotFoundInProjectJson(string flavor, string os, string architecture)
        {
            var runtimeTargetFrameworkString = flavor == "coreclr" ? FrameworkNames.LongNames.DnxCore50 : FrameworkNames.LongNames.Dnx451;
            var runtimeTargetFramework = new FrameworkName(runtimeTargetFrameworkString);
            var runtimeTargetFrameworkShortName = VersionUtility.GetShortFrameworkName(runtimeTargetFramework);
            var runtimeType = flavor == "coreclr" ? "CoreCLR" : "CLR";
            runtimeType = RuntimeEnvironmentHelper.IsMono ? "Mono" : runtimeType;
            var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture);
            var projectJsonContents = @"{
              ""frameworks"": {
            ""FRAMEWORK_NAME"": { }
              }
            }".Replace("FRAMEWORK_NAME", flavor == "coreclr" ? "dnx451" : "dnxcore50");

            using (runtimeHomeDir)
            using (var projectPath = new DisposableDir())
            {
                var projectName = new DirectoryInfo(projectPath).Name;
                var projectJsonPath = Path.Combine(projectPath, Project.ProjectFileName);
                File.WriteAllText(projectJsonPath, projectJsonContents);

                string stdOut, stdErr;
                var exitCode = BootstrapperTestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: $"{projectPath} run",
                    stdOut: out stdOut,
                    stdErr: out stdErr);

                var expectedErrorMsg =$@"The current runtime target framework is not compatible with '{projectName}'.

            Current runtime Target Framework: '{runtimeTargetFramework} ({runtimeTargetFrameworkShortName})'
              Type: {runtimeType}
              Architecture: {architecture ?? TestUtils.CurrentRuntimeEnvironment.RuntimeArchitecture}
              Version: {TestUtils.GetRuntimeVersion()}

            Please make sure the runtime matches a framework specified in {Project.ProjectFileName}";

                Assert.NotEqual(0, exitCode);
                Assert.Contains(expectedErrorMsg, stdErr);
            }
        }
예제 #17
0
        public void ProjectResolverDoesNotThrowWhenThereAreDuplicatedEntriesInGlobalJson()
        {
            const string unambiguousName = "ProjectA";
            var solutionStructure = @"{
              'global.json': '',
              'src': {
            'ProjectA': {
              'project.json': '{}'
            }
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src"", ""src/../src"", ""somedir\\somesubdir\\..\\..\\src""]
            }")
                    .WriteTo(solutionPath);

                var unambiguousProjectPath = Path.Combine(solutionPath, "src", unambiguousName);

                Project project;
                Assert.True(new ProjectResolver(unambiguousProjectPath).TryResolveProject(unambiguousName, out project));
                Assert.NotNull(project);
            }
        }
예제 #18
0
        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}")));
            }
        }
예제 #19
0
        public void ProjectResolverThrowsWhenResolvingAmbiguousName()
        {
            const string ambiguousName = "ProjectA";
            var solutionStructure = @"{
              'global.json': '',
              'src1': {
            'ProjectA': {
              'project.json': '{}'
            }
              },
              'src2': {
            'ProjectA': {
              'project.json': '{}'
            }
              }
            }";

            using (var solutionPath = new DisposableDir())
            {
                DirTree.CreateFromJson(solutionStructure)
                    .WithFileContents("global.json", @"{
              ""projects"": [""src1"", ""src2""]
            }")
                    .WriteTo(solutionPath);

                var src1ProjectPath = Path.Combine(solutionPath, "src1", ambiguousName);
                var src2ProjectPath = Path.Combine(solutionPath, "src2", ambiguousName);
                var expectedMessage = $@"The project name '{ambiguousName}' is ambiguous between the following projects:
            {src1ProjectPath}
            {src2ProjectPath}";

                Project project = null;
                var resolver1 = new ProjectResolver(src1ProjectPath);
                var exception = Assert.Throws<InvalidOperationException>(() => resolver1.TryResolveProject(ambiguousName, out project));
                Assert.Contains(expectedMessage, exception.Message);
                Assert.Null(project);

                var resolver2 = new ProjectResolver(src2ProjectPath);
                exception = Assert.Throws<InvalidOperationException>(() => resolver2.TryResolveProject(ambiguousName, out project));
                Assert.Contains(expectedMessage, exception.Message);
                Assert.Null(project);
            }
        }