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"]); } }
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); } }
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")); } }
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); } }
public void GenerateBatchFilesAndBashScriptsWithPublishedRuntime(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); // Each runtime home only contains one runtime package, which is the one we are currently testing against var runtimeRoot = Directory.EnumerateDirectories(Path.Combine(runtimeHomeDir, "runtimes"), Constants.RuntimeNamePrefix + "*").First(); var runtimeName = new DirectoryInfo(runtimeRoot).Name; var projectStructure = @"{ '.': ['project.json'], 'packages': {} }"; var expectedOutputStructure = @"{ '.': ['run.cmd', 'run', 'kestrel.cmd', 'kestrel'], 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json'] } }, 'packages': {}, 'runtimes': { 'RUNTIME_PACKAGE_NAME': {} } } }".Replace("PROJECT_NAME", _projectName).Replace("RUNTIME_PACKAGE_NAME", runtimeName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""commands"": { ""run"": ""run server.urls=http://localhost:5003"", ""kestrel"": ""Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"" }, ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { } } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") }, { EnvironmentNames.Home, runtimeHomeDir }, { EnvironmentNames.Trace, "1" } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0} --runtime {1}", testEnv.PublishOutputDirPath, runtimeName), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var runtimeSubDir = DirTree.CreateFromDirectory(runtimeRoot) .RemoveFile(Path.Combine("bin", "lib", "Microsoft.Framework.PackageManager", "bin", "profile", "startup.prof")); var batchFileBinPath = string.Format(@"%~dp0approot\runtimes\{0}\bin\", runtimeName); var bashScriptBinPath = string.Format("$DIR/approot/runtimes/{0}/bin/", runtimeName); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""commands"": { ""run"": ""run server.urls=http://localhost:5003"", ""kestrel"": ""Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"" }, ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { } } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), @"{ ""locked"": false, ""version"": LOCKFILEFORMAT_VERSION, ""targets"": { ""RUNTIME_TARGET"": {} }, ""libraries"": {}, ""projectFileDependencyGroups"": { """": [], ""DNX,Version=v4.5.1"": [], ""DNXCore,Version=v5.0"": [] } }".Replace("LOCKFILEFORMAT_VERSION", Constants.LockFileVersion.ToString()) .Replace("RUNTIME_TARGET", flavor == "coreclr" ? "DNXCore,Version=v5.0" : "DNX,Version=v4.5.1")) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }") .WithFileContents("run.cmd", BatchFileTemplate, batchFileBinPath, Constants.BootstrapperExeName, testEnv.ProjectName, "run") .WithFileContents("kestrel.cmd", BatchFileTemplate, batchFileBinPath, Constants.BootstrapperExeName, testEnv.ProjectName, "kestrel") .WithFileContents("run", BashScriptTemplate, EnvironmentNames.AppBase, testEnv.ProjectName, bashScriptBinPath, Constants.BootstrapperExeName, "run") .WithFileContents("kestrel", BashScriptTemplate, EnvironmentNames.AppBase, testEnv.ProjectName, bashScriptBinPath, Constants.BootstrapperExeName, "kestrel") .WithSubDir(Path.Combine("approot", "runtimes", runtimeName), runtimeSubDir); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void ProjectWithIncompatibleFrameworks(string flavor, string os, string architecture) { // Because we're testing cases where the framework in the project is INcompatible with the runtime, // this looks backwards. When we're testing against coreclr, we want to write dnx451 into the project and vice versa string frameworkInProject = flavor == "coreclr" ? "dnx451" : "dnxcore50"; var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json'] }"; using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""frameworks"": {""" + frameworkInProject + @""":{}} }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; string stdOut; string stdErr; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0} --runtime {1}", testEnv.PublishOutputDirPath, runtimeHomeDir), stdOut: out stdOut, stdErr: out stdErr, environment: environment, workingDir: testEnv.ProjectPath); Assert.NotEqual(0, exitCode); Assert.Contains($"The project being published does not support the runtime '{runtimeHomeDir}'", stdErr); } }
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")); } }
public void DnuRestore_ExecutesScripts(string flavor, string os, string architecture) { bool isWindows = TestUtils.CurrentRuntimeEnvironment.OperatingSystem == "Windows"; var environment = new Dictionary <string, string> { { "DNX_TRACE", "0" }, }; var expectedPreContent = @"""one"" ""two"" "">three"" ""four"" "; var expectedPostContent = @"""five"" ""six"" ""argument seven"" ""argument eight"" "; string projectJsonContent; string scriptContent; string scriptName; if (isWindows) { projectJsonContent = @"{ ""frameworks"": { ""dnx451"": { } }, ""scripts"": { ""prerestore"": [ ""script.cmd one two > pre"", ""script.cmd ^>three >> pre && script.cmd ^ four >> pre"" ], ""postrestore"": [ ""\""%project:Directory%/script.cmd\"" five six > post"", ""\""%project:Directory%/script.cmd\"" \""argument seven\"" \""argument eight\"" >> post"" ] } }"; scriptContent = @"@echo off :argumentStart if ""%~1""=="""" goto argumentEnd echo ""%~1"" shift goto argumentStart :argumentEnd"; scriptName = "script.cmd"; } else { projectJsonContent = @"{ ""frameworks"": { ""dnx451"": { } }, ""scripts"": { ""prerestore"": [ ""script one two > pre"", ""script.sh \\>three >> pre; ./script.sh four >> pre"" ], ""postrestore"": [ ""\""%project:Directory%/script\"" five six > post"", ""\""%project:Directory%/script.sh\"" \""argument seven\"" \""argument eight\"" >> post"" ] } }"; scriptContent = @"#!/usr/bin/env bash set -o errexit for arg in ""$@""; do printf ""\""%s\""\n"" ""$arg"" done"; scriptName = "script.sh"; } var projectStructure = $@"{{ '.': ['project.json', '{ scriptName }'] }}"; var runtimeHomePath = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name")) { var projectPath = testEnv.ProjectPath; DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", projectJsonContent) .WithFileContents(scriptName, scriptContent) .WriteTo(projectPath); FileOperationUtils.MarkExecutable(Path.Combine(projectPath, scriptName)); string output; string error; var exitCode = DnuTestUtils.ExecDnu( runtimeHomePath, subcommand: "restore", arguments: null, stdOut: out output, stdErr: out error, environment: environment, workingDir: projectPath); Assert.Equal(0, exitCode); Assert.Empty(error); Assert.Contains("Executing script 'prerestore' in project.json", output); Assert.Contains("Executing script 'postrestore' in project.json", output); var preContent = File.ReadAllText(Path.Combine(projectPath, "pre")); Assert.Equal(expectedPreContent, preContent); var postContent = File.ReadAllText(Path.Combine(projectPath, "post")); Assert.Equal(expectedPostContent, postContent); } }
public void PublishMultipleProjectsWithDifferentTargetFrameworks(string flavor, string os, string architecture) { string projectStructure = @"{ 'App': [ 'project.json' ], 'Lib': [ 'project.json' ], '.': [ 'global.json' ] }"; var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("global.json", @"{ ""projects"": [ ""."" ] }") .WithFileContents("App/project.json", @"{ ""dependencies"": { ""Lib"": """" }, ""frameworks"": { ""dnx46"": {} } }") .WithFileContents("Lib/project.json", @"{ ""frameworks"": { ""dnx451"": {} } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "restore", arguments: "", environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: Path.Combine(testEnv.ProjectPath, "App")); Assert.Equal(0, exitCode); // App lock file has DNX 4.6 target referring to lib with DNX 4.5.1 target var appLockFile = new LockFileReader().Read(Path.Combine(testEnv.PublishOutputDirPath, "approot", "src", "App", "project.lock.json")); foreach(var target in appLockFile.Targets) { // Rid will differ Assert.Equal(Dnx46, target.TargetFramework); var lib = target.Libraries.FirstOrDefault(l => l.Name.Equals("Lib")); Assert.NotNull(lib); Assert.Equal("project", lib.Type); Assert.Equal(Dnx451, lib.TargetFramework); } // Lib lock file has DNX 4.5.1 target AssertDefaultTargets(Path.Combine(testEnv.PublishOutputDirPath, "approot", "src", "Lib", "project.lock.json"), Dnx451); } }
public void GenerateBatchFilesAndBashScriptsWithoutPublishedRuntime(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json'], 'packages': {} }"; var expectedOutputStructure = @"{ '.': ['run.cmd', 'run', 'kestrel.cmd', 'kestrel'], 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json'] } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""commands"": { ""run"": ""run server.urls=http://localhost:5003"", ""kestrel"": ""Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"" }, ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { } } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""commands"": { ""run"": ""run server.urls=http://localhost:5003"", ""kestrel"": ""Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"" }, ""frameworks"": { ""dnx451"": { }, ""dnxcore50"": { } } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), @"{ ""locked"": false, ""version"": LOCKFILEFORMAT_VERSION, ""targets"": { ""DNX,Version=v4.5.1"": {}, ""DNXCore,Version=v5.0"": {} }, ""libraries"": {}, ""projectFileDependencyGroups"": { """": [], ""DNX,Version=v4.5.1"": [], ""DNXCore,Version=v5.0"": [] } }".Replace("LOCKFILEFORMAT_VERSION", Constants.LockFileVersion.ToString())) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }") .WithFileContents("run.cmd", BatchFileTemplate, string.Empty, Constants.BootstrapperExeName, testEnv.ProjectName, "run") .WithFileContents("kestrel.cmd", BatchFileTemplate, string.Empty, Constants.BootstrapperExeName, testEnv.ProjectName, "kestrel") .WithFileContents("run", BashScriptTemplate, EnvironmentNames.AppBase, testEnv.ProjectName, string.Empty, Constants.BootstrapperExeName, "run") .WithFileContents("kestrel", BashScriptTemplate, EnvironmentNames.AppBase, testEnv.ProjectName, string.Empty, Constants.BootstrapperExeName, "kestrel"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
private void DnuPublishWebApp_SpecificFramework(string flavor, string os, string architecture, string framework) { var fx = NuGet.VersionUtility.ParseFrameworkName(framework); var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'Program.cs'], 'public': ['index.html'], }"; var expectedOutputStructure = @"{ 'wwwroot': ['web.config', 'index.html'], 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json', 'Program.cs'] } } } }".Replace("PROJECT_NAME", _projectName); var outputWebConfigTemplate = $@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <appSettings> <add key=""{Constants.WebConfigBootstrapperVersion}"" value="""" /> <add key=""{Constants.WebConfigRuntimePath}"" value=""..\approot\runtimes"" /> <add key=""{Constants.WebConfigRuntimeVersion}"" value="""" /> <add key=""{Constants.WebConfigRuntimeFlavor}"" value="""" /> <add key=""{Constants.WebConfigRuntimeAppBase}"" value=""..\approot\src\{{0}}"" /> </appSettings> <system.web> <httpRuntime targetFramework=""{fx.Version}"" /> </system.web> </configuration>"; using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""webroot"": ""public"", ""frameworks"": { """ + framework + @""": {} } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0} --wwwroot-out wwwroot", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""webroot"": ""../../../wwwroot"", ""frameworks"": { """ + framework + @""": {} } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFileTemplate.Replace("FRAMEWORK_NAME", fx.ToString())) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }") .WithFileContents(Path.Combine("wwwroot", "web.config"), outputWebConfigTemplate, testEnv.ProjectName); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void VerifyDefaultPublishExcludePatterns(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'File', '.FileStartingWithDot'], 'bin': { 'AspNet.Loader.dll': '', 'Debug': ['test.exe', 'test.dll'] }, 'obj': { 'test.obj': '', 'References': ['ref1.dll', 'ref2.dll'] }, '.git': ['index', 'HEAD', 'log'], 'Folder': { '.svn': ['index', 'HEAD', 'log'], 'File': '', '.FileStartingWithDot': '' }, 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json', 'File', '.FileStartingWithDot'], 'Folder': ['File', '.FileStartingWithDot'] } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""frameworks"": { ""dnx451"": {} } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""frameworks"": { ""dnx451"": {} } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
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"))); } }
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")); } }
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)); } }
public void GitCanInstallPackageWithSourceInformation(string flavor, string os, string architecture) { using (var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture)) using (var testEnv = new DnuTestEnvironment(runtimeHomeDir)) { var testPackageFolder = ScafoldEmptyProject( testEnv.RootDir, "TestPackage", _ => @"{ ""frameworks"": { ""dnx451"": { } }, ""repository"": { ""type"": ""git"", ""url"": """ + testEnv.RootDir.Replace('\\', '/') + @""" } }"); InitGitRepoAndCommitAll(testEnv.RootDir); var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, "restore", arguments: null, workingDir: testPackageFolder); Assert.Equal(0, exitCode); var outputFolder = Path.Combine(testPackageFolder, "bin"); exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, $"pack --out {outputFolder}", arguments: null, workingDir: testPackageFolder); Assert.Equal(0, exitCode); outputFolder = Path.Combine(outputFolder, "Debug").Replace('\\', '/'); using (var installEnv = new DnuTestEnvironment(runtimeHomeDir)) { var testFolderName = Path.Combine(installEnv.RootDir, "project"); Directory.CreateDirectory(testFolderName); var consumerProjectFolder = ScafoldEmptyProject( testFolderName, "Client", _ => @"{ ""dependencies"": { ""TestPackage"": ""1.0.0"" }, ""frameworks"": { ""dnx451"": { } }, }"); var packagesDestinationFolder = Path.Combine(installEnv.RootDir, "packages"); exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, $"restore --fallbacksource \"{ outputFolder }\" --packages \"{ packagesDestinationFolder }\"", arguments: null, workingDir: consumerProjectFolder); Assert.Equal(0, exitCode); var sourcesDestinationFolder = Path.Combine(installEnv.RootDir, "sources"); exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, $"sources get TestPackage --packages \"{ packagesDestinationFolder }\" --output \"{ sourcesDestinationFolder }\"", arguments: null, workingDir: consumerProjectFolder); Assert.Equal(0, exitCode); var installProjectGlobalFile = Path.Combine(testFolderName, GlobalSettings.GlobalFileName); var globalFile = JsonConvert.DeserializeObject(File.ReadAllText(installProjectGlobalFile)) as JObject; var projects = globalFile["projects"] as JArray; Assert.Equal(2, projects.Count); var sourceFolder = projects .First(prj => prj.ToString().StartsWith(sourcesDestinationFolder, StringComparison.Ordinal)) .ToString(); Assert.True(Directory.Exists(sourceFolder)); } } }
public void ProjectWithNoFrameworks(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json'] }"; using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""frameworks"": {} }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; string stdOut; string stdErr; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), stdOut: out stdOut, stdErr: out stdErr, environment: environment, workingDir: testEnv.ProjectPath); Assert.NotEqual(0, exitCode); Assert.Contains("The project being published has no frameworks listed in the 'frameworks' section.", stdErr); } }
public void DnuPublishWebApp_NonexistentFolderAsPublicFolder(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json'], }"; var expectedOutputStructure = @"{ 'wwwroot': { 'web.config': '' }, 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json'], } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""webroot"": ""wwwroot"", ""frameworks"": { ""dnx451"": {} } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: $"--out {testEnv.PublishOutputDirPath}", environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: false)); } }
public void PublishMultipleProjectsWithDifferentTargetFrameworks(string flavor, string os, string architecture) { string projectStructure = @"{ 'App': [ 'project.json' ], 'Lib': [ 'project.json' ], '.': [ 'global.json' ] }"; string expectedAppLockFile = @"{ ""locked"": false, ""version"": LOCKFILEFORMAT_VERSION, ""targets"": { ""DNX,Version=v4.6"": {} }, ""libraries"": {}, ""projectFileDependencyGroups"": { """": [ ""Lib "" ], ""DNX,Version=v4.6"": [] } }".Replace("LOCKFILEFORMAT_VERSION", Constants.LockFileVersion.ToString()); string expectedLibLockFile = BasicLockFileTemplate.Replace("FRAMEWORK_NAME", "DNX,Version=v4.5.1"); var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("global.json", @"{ ""projects"": [ ""."" ] }") .WithFileContents("App/project.json", @"{ ""dependencies"": { ""Lib"": """" }, ""frameworks"": { ""dnx46"": {} } }") .WithFileContents("Lib/project.json", @"{ ""frameworks"": { ""dnx451"": {} } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: Path.Combine(testEnv.ProjectPath, "App")); Assert.Equal(0, exitCode); // Check the lock files Assert.Equal(expectedAppLockFile, File.ReadAllText(Path.Combine(testEnv.PublishOutputDirPath, "approot", "src", "App", "project.lock.json"))); Assert.Equal(expectedLibLockFile, File.ReadAllText(Path.Combine(testEnv.PublishOutputDirPath, "approot", "src", "Lib", "project.lock.json"))); } }
public void DnuPublishWebApp_UpdateExistingWebConfig(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json'], 'public': ['index.html', 'web.config'], 'packages': {} }"; var expectedOutputStructure = @"{ 'wwwroot': ['web.config', 'index.html'], 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': ['project.json', 'project.lock.json'] } } }".Replace("PROJECT_NAME", _projectName); var originalWebConfigContents = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <nonRelatedElement> <add key=""non-related-key"" value=""OLD_VALUE"" /> </nonRelatedElement> <appSettings> <add key=""non-related-key"" value=""OLD_VALUE"" /> <add key=""{0}"" value=""OLD_VALUE"" /> <add key=""{1}"" value=""OLD_VALUE"" /> <add key=""{2}"" value=""OLD_VALUE"" /> <add key=""{3}"" value=""OLD_VALUE"" /> <add key=""{4}"" value=""OLD_VALUE"" /> </appSettings> </configuration>", Constants.WebConfigBootstrapperVersion, Constants.WebConfigRuntimePath, Constants.WebConfigRuntimeVersion, Constants.WebConfigRuntimeFlavor, Constants.WebConfigRuntimeAppBase); var outputWebConfigContents = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <nonRelatedElement> <add key=""non-related-key"" value=""OLD_VALUE"" /> </nonRelatedElement> <appSettings> <add key=""non-related-key"" value=""OLD_VALUE"" /> <add key=""{0}"" value="""" /> <add key=""{1}"" value=""..\approot\runtimes"" /> <add key=""{2}"" value="""" /> <add key=""{3}"" value="""" /> <add key=""{4}"" value=""..\approot\src\{{0}}"" /> </appSettings> <system.web> <httpRuntime targetFramework=""4.5.1"" /> </system.web> </configuration>", Constants.WebConfigBootstrapperVersion, Constants.WebConfigRuntimePath, Constants.WebConfigRuntimeVersion, Constants.WebConfigRuntimeFlavor, Constants.WebConfigRuntimeAppBase); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""webroot"": ""../../../wwwroot"", ""frameworks"": { ""dnx451"": {} } }") .WithFileContents(Path.Combine("public", "web.config"), originalWebConfigContents) .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0} --wwwroot public --wwwroot-out wwwroot", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""webroot"": ""../../../wwwroot"", ""frameworks"": { ""dnx451"": {} } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }") .WithFileContents(Path.Combine("wwwroot", "web.config"), outputWebConfigContents, testEnv.ProjectName); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void WildcardMatchingFacts(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json'], 'UselessFolder1': { '.': ['uselessfile1.txt', 'uselessfile2'], 'SubFolder': ['uselessfile3.js', 'uselessfile4'] }, 'UselessFolder2': { '.': ['uselessfile1.txt', 'uselessfile2'], 'SubFolder': ['uselessfile3.js', 'uselessfile4'] }, 'UselessFolder3': { '.': ['uselessfile1.txt', 'uselessfile2'], 'SubFolder': ['uselessfile3.js', 'uselessfile4'] }, 'MixFolder1': { '.': ['uselessfile1.txt', 'uselessfile2'], 'UsefulSub': ['useful.txt', 'useful'] }, 'MixFolder2': { '.': ['uselessfile1.txt', 'uselessfile2'], 'UsefulSub': ['useful.txt', 'useful'] }, 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json'], 'MixFolder1': { '.': ['uselessfile1.txt', 'uselessfile2'], 'UsefulSub': ['useful.txt', 'useful'] }, 'MixFolder2': { '.': ['uselessfile1.txt', 'uselessfile2'], 'UsefulSub': ['useful.txt', 'useful'] } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""frameworks"": { ""dnx451"": {} }, ""publishExclude"": [ ""UselessFolder1\\**"", ""UselessFolder2/**/*"", ""UselessFolder3\\**/*.*"" ] }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""frameworks"": { ""dnx451"": {} }, ""publishExclude"": [ ""UselessFolder1\\**"", ""UselessFolder2/**/*"", ""UselessFolder3\\**/*.*"" ] }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void DnuPublishConsoleAppWithNoSourceOptionNormalizesVersionNumberWithNoBuildNumber(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'Config.json', 'Program.cs'], 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'packages': { 'PROJECT_NAME': { '1.0.0-beta': { '.': ['PROJECT_NAME.1.0.0-beta.nupkg', 'PROJECT_NAME.1.0.0-beta.nupkg.sha512', 'PROJECT_NAME.nuspec'], 'root': ['Config.json', 'project.json', 'project.lock.json'], 'lib': { 'dnx451': ['PROJECT_NAME.dll', 'PROJECT_NAME.xml'] } } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""version"": ""1.0-beta"", ""frameworks"": { ""dnx451"": {} } }") .WriteTo(testEnv.ProjectPath); var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "restore", arguments: string.Empty, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: $"--no-source --out {testEnv.PublishOutputDirPath}", workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: false)); } }
public void DnuPublishConsoleApp(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); 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', 'project.lock.json', 'Config.json', 'Program.cs'], 'Data': { 'Input': ['data1.dat', 'data2.dat'] } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""publishExclude"": ""Data/Backup/**"", ""frameworks"": { ""dnx451"": {} } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""publishExclude"": ""Data/Backup/**"", ""frameworks"": { ""dnx451"": {} } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
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"))); } }
public void DnuPublishWebApp_SubfolderAsPublicFolder(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'Config.json', 'Program.cs'], 'public': { 'Scripts': ['bootstrap.js', 'jquery.js'], 'Images': ['logo.png'], 'UselessFolder': ['file.useless'] }, 'Views': { 'Home': ['index.cshtml'], 'Shared': ['_Layout.cshtml'] }, 'Controllers': ['HomeController.cs'], 'UselessFolder': ['file.useless'], 'packages': {} }"; var expectedOutputStructure = @"{ 'wwwroot': { 'web.config': '', 'Scripts': ['bootstrap.js', 'jquery.js'], 'Images': ['logo.png'], 'UselessFolder': ['file.useless'] }, 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json', 'Config.json', 'Program.cs'], 'Views': { 'Home': ['index.cshtml'], 'Shared': ['_Layout.cshtml'] }, 'Controllers': ['HomeController.cs'], } } } }".Replace("PROJECT_NAME", _projectName); var outputWebConfigTemplate = string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <appSettings> <add key=""{0}"" value="""" /> <add key=""{1}"" value=""..\approot\runtimes"" /> <add key=""{2}"" value="""" /> <add key=""{3}"" value="""" /> <add key=""{4}"" value=""..\approot\src\{{0}}"" /> </appSettings> <system.web> <httpRuntime targetFramework=""4.5.1"" /> </system.web> </configuration>", Constants.WebConfigBootstrapperVersion, Constants.WebConfigRuntimePath, Constants.WebConfigRuntimeVersion, Constants.WebConfigRuntimeFlavor, Constants.WebConfigRuntimeAppBase); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""publishExclude"": ""**.useless"", ""webroot"": ""public"", ""frameworks"": { ""dnx451"": {} } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0} --wwwroot-out wwwroot", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""publishExclude"": ""**.useless"", ""webroot"": ""../../../wwwroot"", ""frameworks"": { ""dnx451"": {} } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }") .WithFileContents(Path.Combine("wwwroot", "web.config"), outputWebConfigTemplate, testEnv.ProjectName); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
public void DnuPack_ExecutesScriptsForEachConfigurationAndTargetFramework(string flavor, string os, string architecture) { var projectStructure = @"{ '.': ['project.json'] }"; var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, "TestProject")) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""version"": ""1.0-beta"", ""frameworks"": { ""dnx451"": {}, ""dnxcore50"": { ""dependencies"": { ""System.Runtime"":""4.0.20-*"" } } }, ""scripts"": { ""prebuild"": ""echo PREBUILD_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"", ""prepack"": ""echo PREPACK_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"", ""postbuild"": ""echo POSTBUILD_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"", ""postpack"": ""echo POSTPACK_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"" } }") .WriteTo(testEnv.ProjectPath); string stdOut, stdErr; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "restore", arguments: string.Empty, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, "pack", testEnv.ProjectPath + " --configuration Debug --configuration Release", out stdOut, out stdErr); Assert.Equal(0, exitCode); Assert.Empty(stdErr); var idx = 0; foreach (var configuration in new[] { "Debug", "Release"}) { // note that %TargetFramework% is not defined outside build idx = stdOut.IndexOf($"PREPACK_SCRIPT_OUTPUT {configuration} %build:TargetFramework%", 0); Assert.True(idx >= 0); foreach (var framework in new[] { "dnx451", "dnxcore50" }) { idx = stdOut.IndexOf($"PREBUILD_SCRIPT_OUTPUT {configuration} {framework}", idx); Assert.True(idx >= 0); idx = stdOut.IndexOf($"POSTBUILD_SCRIPT_OUTPUT {configuration} {framework}", idx); Assert.True(idx >= 0); } idx = stdOut.IndexOf($"POSTPACK_SCRIPT_OUTPUT {configuration} %build:TargetFramework%", 0); Assert.True(idx >= 0); } Assert.Equal(-1, stdOut.IndexOf("PREPACK_SCRIPT_OUTPUT", idx + 1)); Assert.Equal(-1, stdOut.IndexOf("PREBUILD_SCRIPT_OUTPUT", idx + 1)); Assert.Equal(-1, stdOut.IndexOf("POSTBUILD_SCRIPT_OUTPUT", idx + 1)); Assert.Equal(-1, stdOut.IndexOf("POSTPACK_SCRIPT_OUTPUT", idx + 1)); } }
public void FoldersAsFilePatternsAutoGlob(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'FileWithoutExtension'], 'UselessFolder1': { '.': ['file1.txt', 'file2.css', 'file_without_extension'], 'SubFolder': ['file3.js', 'file4.html', 'file_without_extension'] }, 'UselessFolder2': { '.': ['file1.txt', 'file2.css', 'file_without_extension'], 'SubFolder': ['file3.js', 'file4.html', 'file_without_extension'] }, 'UselessFolder3': { '.': ['file1.txt', 'file2.css', 'file_without_extension'], 'SubFolder': ['file3.js', 'file4.html', 'file_without_extension'] }, 'MixFolder': { 'UsefulSub': ['useful.txt', 'useful.css', 'file_without_extension'], 'UselessSub1': ['file1.js', 'file2.html', 'file_without_extension'], 'UselessSub2': ['file1.js', 'file2.html', 'file_without_extension'], 'UselessSub3': ['file1.js', 'file2.html', 'file_without_extension'], 'UselessSub4': ['file1.js', 'file2.html', 'file_without_extension'], 'UselessSub5': ['file1.js', 'file2.html', 'file_without_extension'] }, '.git': ['index', 'HEAD', 'log'], 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json'], 'MixFolder': { 'UsefulSub': ['useful.txt', 'useful.css', 'file_without_extension'] } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { // REVIEW: Paths with \ don't work on *nix so we put both in here for now // We need a good strategy to test \\ and / on windows and / on *nix and osx DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""frameworks"": { ""dnx451"": {} }, ""publishExclude"": [ ""FileWithoutExtension"", ""UselessFolder1"", ""UselessFolder2/"", ""UselessFolder3\\"", ""UselessFolder3/"", ""MixFolder/UselessSub1/"", ""MixFolder\\UselessSub2\\"", ""MixFolder/UselessSub2/"", ""MixFolder/UselessSub3\\"", ""MixFolder/UselessSub3/"", ""MixFolder/UselessSub4"", ""MixFolder\\UselessSub5"", ""MixFolder/UselessSub5"", "".git"" ] }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""frameworks"": { ""dnx451"": {} }, ""publishExclude"": [ ""FileWithoutExtension"", ""UselessFolder1"", ""UselessFolder2/"", ""UselessFolder3\\"", ""UselessFolder3/"", ""MixFolder/UselessSub1/"", ""MixFolder\\UselessSub2\\"", ""MixFolder/UselessSub2/"", ""MixFolder/UselessSub3\\"", ""MixFolder/UselessSub3/"", ""MixFolder/UselessSub4"", ""MixFolder\\UselessSub5"", ""MixFolder/UselessSub5"", "".git"" ] }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
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"))); } } }
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")); } }
public void CorrectlyExcludeFoldersStartingWithDots(string flavor, string os, string architecture) { var runtimeHomeDir = _fixture.GetRuntimeHomeDir(flavor, os, architecture); var projectStructure = @"{ '.': ['project.json', 'File', '.FileStartingWithDot', 'File.Having.Dots'], '.FolderStaringWithDot': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], '.SubFolderStartingWithDot': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' }, 'Folder': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], '.SubFolderStartingWithDot': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' }, 'Folder.Having.Dots': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], '.SubFolderStartingWithDot': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' }, 'packages': {} }"; var expectedOutputStructure = @"{ 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json', 'project.lock.json', 'File', '.FileStartingWithDot', 'File.Having.Dots'], 'Folder': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' }, 'Folder.Having.Dots': { 'SubFolder': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'SubFolder.Having.Dots': ['File', '.FileStartingWithDot', 'File.Having.Dots'], 'File': '', '.FileStartingWithDot': '', 'File.Having.Dots': '' } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""frameworks"": { ""dnx451"": {} } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") } }; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "publish", arguments: string.Format("--out {0}", testEnv.PublishOutputDirPath), environment: environment, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure) .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{ ""frameworks"": { ""dnx451"": {} } }") .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.lock.json"), BasicLockFile) .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PublishOutputDirPath, compareFileContents: true)); } }
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); } } }
public void DnuPack_ExecutesScriptsForEachConfigurationAndTargetFramework(string flavor, string os, string architecture) { var projectStructure = @"{ '.': ['project.json'] }"; var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor, os, architecture); using (var testEnv = new DnuTestEnvironment(runtimeHomeDir, "TestProject")) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""version"": ""1.0-beta"", ""frameworks"": { ""dnx451"": {}, ""dnxcore50"": { ""dependencies"": { ""System.Runtime"":""4.0.20-*"" } } }, ""scripts"": { ""prebuild"": ""echo PREBUILD_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"", ""prepack"": ""echo PREPACK_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"", ""postbuild"": ""echo POSTBUILD_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"", ""postpack"": ""echo POSTPACK_SCRIPT_OUTPUT %build:Configuration% %build:TargetFramework%"" } }") .WriteTo(testEnv.ProjectPath); string stdOut, stdErr; var exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, subcommand: "restore", arguments: string.Empty, workingDir: testEnv.ProjectPath); Assert.Equal(0, exitCode); exitCode = DnuTestUtils.ExecDnu( runtimeHomeDir, "pack", testEnv.ProjectPath + " --configuration Debug --configuration Release", out stdOut, out stdErr); Assert.Equal(0, exitCode); Assert.Empty(stdErr); var idx = 0; foreach (var configuration in new[] { "Debug", "Release" }) { // note that %TargetFramework% is not defined outside build idx = stdOut.IndexOf($"PREPACK_SCRIPT_OUTPUT {configuration} %build:TargetFramework%", 0); Assert.True(idx >= 0); foreach (var framework in new[] { "dnx451", "dnxcore50" }) { idx = stdOut.IndexOf($"PREBUILD_SCRIPT_OUTPUT {configuration} {framework}", idx); Assert.True(idx >= 0); idx = stdOut.IndexOf($"POSTBUILD_SCRIPT_OUTPUT {configuration} {framework}", idx); Assert.True(idx >= 0); } idx = stdOut.IndexOf($"POSTPACK_SCRIPT_OUTPUT {configuration} %build:TargetFramework%", 0); Assert.True(idx >= 0); } Assert.Equal(-1, stdOut.IndexOf("PREPACK_SCRIPT_OUTPUT", idx + 1)); Assert.Equal(-1, stdOut.IndexOf("PREBUILD_SCRIPT_OUTPUT", idx + 1)); Assert.Equal(-1, stdOut.IndexOf("POSTBUILD_SCRIPT_OUTPUT", idx + 1)); Assert.Equal(-1, stdOut.IndexOf("POSTPACK_SCRIPT_OUTPUT", idx + 1)); } }