コード例 #1
0
ファイル: ProjectResolverTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: ProjectResolverTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: DnuPackTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: LockFileUtilsFacts.cs プロジェクト: noahfalk/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";

            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
ファイル: FileGlobbingTestBase.cs プロジェクト: noahfalk/dnx
 public void Dispose()
 {
     if (Root != null)
     {
         Root.Dispose();
         Root = null;
     }
 }
コード例 #6
0
        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
ファイル: TestUtils.cs プロジェクト: shawnwildermuth/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);
        }
コード例 #8
0
ファイル: InstallBuilderTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: DnuInstallTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: ProjectResolverTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: ProjectResolverTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: DnuRestoreTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: DnuListTests.cs プロジェクト: noahfalk/dnx
 public DnuListTests(PackageManagerFunctionalTestFixture fixture)
 {
     _fixture = fixture;
     _workingDir = TestUtils.CreateTempDir();
 }
コード例 #14
0
ファイル: FileGlobbingTestBase.cs プロジェクト: noahfalk/dnx
 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
ファイル: AppHostTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: ProjectResolverTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: DnuRestoreTests.cs プロジェクト: noahfalk/dnx
        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
ファイル: ProjectResolverTests.cs プロジェクト: noahfalk/dnx
        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);
            }
        }