Exemplo n.º 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");

                Runtime.Project project;
                Assert.True(new ProjectResolver(resolutionRoot).TryResolveProject("ProjectB", out project));
                Assert.NotNull(project);
            }
        }
Exemplo n.º 2
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);

                Runtime.Project project;
                Assert.False(new ProjectResolver(projectPath).TryResolveProject(projectName, out project));
                Assert.Null(project);
            }
        }
Exemplo n.º 3
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);

                Runtime.Project project;
                Assert.True(new ProjectResolver(unambiguousProjectPath).TryResolveProject(unambiguousName, out project));
                Assert.NotNull(project);
            }
        }
Exemplo n.º 4
0
 public DnuTestEnvironment(string runtimePath, string projectName = null, string outputDirName = null)
 {
     _projectName   = projectName ?? "ProjectName";
     _outputDirName = outputDirName ?? "OutputDirName";
     _runtimePath   = runtimePath;
     RootDir        = new DisposableDir();
 }
Exemplo n.º 5
0
        public void ReadResourcesFromProjectNugetPackageAndClassLibrary(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            using (var tempDir = new DisposableDir())
            {
                var appPath = Path.Combine(tempDir, "ResourcesTestProjects", "ReadFromResources");
                TestUtils.CreateDisposableTestProject(runtimeHomeDir, Path.Combine(tempDir, "ResourcesTestProjects"), Path.Combine(TestUtils.GetMiscProjectsFolder(), "ResourcesTestProjects", "ReadFromResources"));

                string stdOut;
                string stdErr;
                var    exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: "-p . run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary <string, string> {
                    { EnvironmentNames.Trace, null }
                },
                    workingDir: Path.Combine(appPath, "src", "ReadFromResources"));

                Assert.Equal(0, exitCode);
                Assert.Contains(@"Hello World!
Bonjour Monde!
Hallo Welt
Bienvenue
The name '{0}' is ambiguous.
Le nom '{0}' est ambigu.
", stdOut);
            }
        }
Exemplo n.º 6
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");
        }
Exemplo n.º 7
0
        public void DthNegative_BrokenProjectPathInLockFile_V2(DnxSdk sdk)
        {
            var testProject = _fixture.GetTestProjectPath("BrokenProjectPathSample");

            using (var disposableDir = new DisposableDir())
                using (var server = DthTestServer.Create(sdk))
                    using (var client = server.CreateClient())
                    {
                        // copy the project to difference location so that the project path in its lock file is invalid
                        var targetPath = Path.Combine(disposableDir, "BrokenProjectPathSample");
                        Testing.TestUtils.CopyFolder(testProject, targetPath);

                        client.Initialize(targetPath, protocolVersion: 2);
                        var messages = client.DrainAllMessages()
                                       .AssertDoesNotContain("Error");

                        messages.RetrieveSingleMessage("DependencyDiagnostics")
                        .RetrieveDependencyDiagnosticsCollection()
                        .RetrieveDependencyDiagnosticsErrorAt(0)
                        .AssertProperty <string>("FormattedMessage", message => message.Contains("error NU1001: The dependency EmptyLibrary  could not be resolved."))
                        .RetrievePropertyAs <JObject>("Source")
                        .AssertProperty("Name", "EmptyLibrary");

                        messages.RetrieveSingleMessage("Dependencies")
                        .RetrieveDependency("EmptyLibrary")
                        .AssertProperty <JArray>("Errors", errorsArray => errorsArray.Count == 1)
                        .AssertProperty <JArray>("Warnings", warningsArray => warningsArray.Count == 0)
                        .AssertProperty("Name", "EmptyLibrary")
                        .AssertProperty("Resolved", false);
                    }
        }
Exemplo n.º 8
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);
            }
        }
Exemplo n.º 9
0
        public void KCommandShowsErrorWhenGivenSubcommandWasNotFoundInProjectJson(DisposableDir runtimeHomeDir)
        {
            var projectStructure = @"{
  'project.json': '{ }'
}";

            using (runtimeHomeDir)
                using (var projectPath = TestUtils.CreateTempDir())
                {
                    DirTree.CreateFromJson(projectStructure).WriteTo(projectPath);

                    string stdOut, stdErr;
                    var    exitCode = KCommandTestUtils.ExecKCommand(
                        runtimeHomeDir,
                        subcommand: "invalid",
                        arguments: string.Empty,
                        stdOut: out stdOut,
                        stdErr: out stdErr,
                        environment: new Dictionary <string, string> {
                        { EnvironmentNames.AppBase, projectPath }
                    });

                    Assert.NotEqual(0, exitCode);
                    Assert.Contains("Unable to load application or execute command 'invalid'.", stdErr);
                }
        }
Exemplo n.º 10
0
        public void DnuInstall_OverwriteOldVersion(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"": {
    ""alpha"": ""0.0.0""
  }
}");

                VerifyDnuInstall(
                    runtimeHomePath,
                    packageName: "alpha",
                    packageVersion: "0.1.0",
                    projectDir: projectDir,
                    packagesDir: packagesDir,
                    workingDir: projectDir);
            }
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
0
        public void AppHostShowsErrorWhenGivenSubcommandWasNotFoundInProjectJson(string flavor, string os, string architecture)
        {
            var runtimeHomeDir   = _fixture.GetRuntimeHomeDir(flavor, os, architecture);
            var projectStructure = @"{
  ""project.json"": ""{ }""
}";

            using (var projectPath = new DisposableDir())
            {
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("project.json", @"
{
    ""frameworks"": {
        ""dnx451"": { },
        ""dnxcore50"": { }
    }
}").WriteTo(projectPath);

                string stdOut, stdErr;
                var    exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: "invalid",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary <string, string> {
                },
                    workingDir: projectPath);

                Assert.Equal(1, exitCode);
                Assert.Contains("Unable to load application or execute command 'invalid'.", stdErr);
            }
        }
Exemplo n.º 13
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);

                Runtime.Project project;
                Assert.True(new ProjectResolver(projectPath).TryResolveProject(projectName, out project));
                Assert.NotNull(project);
            }
        }
Exemplo n.º 14
0
        public void ReadEmbeddedResourcesFromProject(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            using (var tempDir = new DisposableDir())
            {
                var appPath = Path.Combine(tempDir, "ResourcesTestProjects", "EmbeddedResources");
                TestUtils.CreateDisposableTestProject(runtimeHomeDir, Path.Combine(tempDir, "ResourcesTestProjects"), Path.Combine(TestUtils.GetMiscProjectsFolder(), "ResourcesTestProjects", "EmbeddedResources"));

                string stdOut;
                string stdErr;
                var    exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: "-p . run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary <string, string> {
                    { EnvironmentNames.Trace, null }
                },
                    workingDir: appPath);

                Assert.Equal(0, exitCode);
                Assert.Contains(@"Hello
<html>
Basic Test
</html>
", stdOut);
            }
        }
Exemplo n.º 15
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));
                }
        }
Exemplo n.º 16
0
        public void BootstrapperLaunchesRequestedFramworkVersionIfOptionProvided(string flavor, string os, string architecture, string requestedFramework, string expectedOutput)
        {
            const string projectStructure = @"{
    ""project.json"": {},
    ""project.lock.json"": {},
    ""Program.cs"": {}
}";

            const string projectJson = @"{
    ""dependencies"": {
    },
    ""frameworks"": {
        ""dnx46"": {},
        ""dnx452"": {},
        ""dnx451"": {}
    }
}";
            const string lockFile    = @"{
  ""locked"": false,
  ""version"": 2,
  ""targets"": {
    ""DNX,Version=v4.5.1"": {},
    ""DNX,Version=v4.5.2"": {},
    ""DNX,Version=v4.6"": {}
  },
  ""libraries"": {},
  ""projectFileDependencyGroups"": {
    """": [],
    ""DNX,Version=v4.5.1"": [],
    ""DNX,Version=v4.5.2"": [],
    ""DNX,Version=v4.6"": []
  }
}";

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

            using (var tempDir = new DisposableDir())
            {
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("project.json", projectJson)
                .WithFileContents("project.lock.json", lockFile)
                .WithFileContents("Program.cs", ClrVersionTestProgram)
                .WriteTo(tempDir);

                string stdOut;
                string stdErr;
                var    exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: $"--framework {requestedFramework} run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary <string, string> {
                    { EnvironmentNames.Trace, null }
                },
                    workingDir: tempDir);
                Assert.Equal(0, exitCode);
                Assert.Contains(expectedOutput, stdOut.Trim());
            }
        }
Exemplo n.º 17
0
 public void Dispose()
 {
     if (Root != null)
     {
         Root.Dispose();
         Root = null;
     }
 }
Exemplo n.º 18
0
        public void KpmBundleConsoleApp(DisposableDir runtimeHomeDir)
        {
            var projectStructure        = @"{
  '.': ['project.json', 'Config.json', 'Program.cs'],
  'Data': {
    'Input': ['data1.dat', 'data2.dat'],
    'Backup': ['backup1.dat', 'backup2.dat']
  },
  'packages': {}
}";
            var expectedOutputStructure = @"{
  'approot': {
    'global.json': '',
    'src': {
      'PROJECT_NAME': {
        '.': ['project.json', 'Config.json', 'Program.cs'],
          'Data': {
            'Input': ['data1.dat', 'data2.dat']
          }
        }
      }
    }
  }".Replace("PROJECT_NAME", _projectName);

            using (var testEnv = new KpmTestEnvironment(runtimeHomeDir, _projectName, _outputDirName))
            {
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("project.json", @"{
  ""bundleExclude"": ""Data/Backup/**""
}")
                .WriteTo(testEnv.ProjectPath);

                var environment = new Dictionary <string, string>()
                {
                    { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") }
                };

                var exitCode = KpmTestUtils.ExecKpm(
                    runtimeHomeDir,
                    subcommand: "bundle",
                    arguments: string.Format("--out {0}",
                                             testEnv.BundleOutputDirPath),
                    environment: environment,
                    workingDir: testEnv.ProjectPath);
                Assert.Equal(0, exitCode);

                var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure)
                                        .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{
  ""bundleExclude"": ""Data/Backup/**""
}")
                                        .WithFileContents(Path.Combine("approot", "global.json"), @"{
  ""dependencies"": {},
  ""packages"": ""packages""
}");
                Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.BundleOutputDirPath,
                                                                   compareFileContents: true));
            }
        }
Exemplo n.º 19
0
        public PackageManagerFunctionalTestFixture() : base()
        {
            _contextDir   = new DisposableDir();
            PackageSource = Path.Combine(_contextDir.DirPath, "packages");
            Directory.CreateDirectory(PackageSource);

            CreateNewPackage("alpha", "0.1.0");

            PackPackage(Path.Combine(TestUtils.GetMiscProjectsFolder(), "XreTestApps/CommandsProject"), PackageSource);
        }
Exemplo n.º 20
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");
            }
        }
Exemplo n.º 21
0
        public void BootstrapperConfiguresAppConfigFile(string flavor, string os, string architecture)
        {
            const string projectStructure = @"{
    ""project.json"": {},
    ""project.lock.json"": {},
    ""app.config"": {},
    ""Program.cs"": {}
}";

            const string projectJson = @" {
    ""frameworks"": {
        ""dnx451"": {
            ""frameworkAssemblies"": {
                ""System.Configuration"": """"
            }
        }
    }
}";
            const string appConfig   = @"<configuration>
  <appSettings>
    <add key=""TheSetting"" value=""TheValue"" />
  </appSettings>
</configuration>";

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

            using (var tempDir = new DisposableDir())
            {
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("project.json", projectJson)
                .WithFileContents("app.config", appConfig)
                .WithFileContents("Program.cs", AppSettingTestProgram)
                .WriteTo(tempDir);

                string stdOut;
                string stdErr;
                var    exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: $"run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    environment: new Dictionary <string, string> {
                    { EnvironmentNames.Trace, null }
                },
                    workingDir: tempDir);
                Assert.Equal(0, exitCode);
                Assert.Contains("TheSetting=TheValue", stdOut.Trim());
            }
        }
Exemplo n.º 22
0
        public void KCommandReturnsNonZeroExitCodeWhenNoArgumentWasGiven(DisposableDir kreHomeDir)
        {
            using (kreHomeDir)
            {
                string stdOut, stdErr;
                var    exitCode = KCommandTestUtils.ExecKCommand(
                    kreHomeDir,
                    subcommand: string.Empty,
                    arguments: string.Empty,
                    stdOut: out stdOut,
                    stdErr: out stdErr);

                Assert.NotEqual(0, exitCode);
            }
        }
Exemplo n.º 23
0
        public void KCommandReturnsZeroExitCodeWhenHelpOptionWasGiven(DisposableDir runtimeHomeDir)
        {
            using (runtimeHomeDir)
            {
                string stdOut, stdErr;
                var    exitCode = KCommandTestUtils.ExecKCommand(
                    runtimeHomeDir,
                    subcommand: string.Empty,
                    arguments: "--help",
                    stdOut: out stdOut,
                    stdErr: out stdErr);

                Assert.Equal(0, exitCode);
            }
        }
Exemplo n.º 24
0
        public IDisposable CreateDisposableTestProject(string projectName, DnxSdk sdk, out string testProjectDir)
        {
            var source = Path.Combine(TestUtils.GetTestSolutionsDirectory(), "DthTestProjects", projectName);

            if (!Directory.Exists(source))
            {
                throw new ArgumentException($"Test project {source} doesn't exist.", nameof(projectName));
            }

            var disposableDir = new DisposableDir();

            CreateDisposableTestProject(sdk, disposableDir, source);

            testProjectDir = Path.Combine(disposableDir, projectName);
            return(disposableDir);
        }
Exemplo n.º 25
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.NotEqual(0, exitCode);

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

                Assert.NotEqual(0, 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);
            }
        }
Exemplo n.º 26
0
        public void AppHostShowsErrorWhenNoProjectJsonWasFound(string flavor, string os, string architecture)
        {
            var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture);

            using (var emptyFolder = new DisposableDir())
            {
                string stdOut, stdErr;
                var    exitCode = TestUtils.ExecBootstrapper(
                    runtimeHomeDir,
                    arguments: "run",
                    stdOut: out stdOut,
                    stdErr: out stdErr,
                    workingDir: emptyFolder);

                Assert.Equal(1, exitCode);
                Assert.Contains("Unable to resolve project", stdErr);
            }
        }
Exemplo n.º 27
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}")));
            }
        }
Exemplo n.º 28
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}";

                Runtime.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);
            }
        }
Exemplo n.º 29
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);
                }
        }
Exemplo n.º 30
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")));
                }
            }
        }