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); } }
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); } }
public void BuildPackageAndCheckServiceability(string projectName, bool expectedServiceability) { var rootDir = ProjectResolver.ResolveRootDirectory(Directory.GetCurrentDirectory()); var projectDir = Path.Combine(rootDir, "misc", "ServicingTestProjects", projectName); const string configuration = "Debug"; using (var runtimeHomeDir = TestUtils.GetRuntimeHomeDir(flavor: "clr", os: "win", architecture: "x86")) using (var tempDir = new DisposableDir()) { var buildOutpuDir = Path.Combine(tempDir, "output"); DnuTestUtils.ExecDnu( runtimeHomeDir, "pack", $"{projectDir} --out {buildOutpuDir} --configuration {configuration}"); var assemblyPath = Path.Combine(buildOutpuDir, configuration, "dnx451", $"{projectName}.dll"); Assert.Equal(expectedServiceability, LockFileUtils.IsAssemblyServiceable(assemblyPath)); } }
public void ApplicationScriptsHaveTheCorrectContent() { using (DisposableDir tempDir = new DisposableDir()) { string testDir = Path.Combine(tempDir, "TestApp"); Directory.CreateDirectory(testDir); string projectFilePath = Path.Combine(testDir, "project.json"); string projectFileContent = @"{ ""commands"" : { ""cmd1"":""demo1"", ""cmd2"":""demo2"" } }"; File.WriteAllText(projectFilePath, projectFileContent); Runtime.Project project; Runtime.Project.TryGetProject(projectFilePath, out project); var packageManager = new MockPackageManager(); var infoReport = new MockReport(); var builder = new InstallBuilder( project, packageManager, new Reports() { Information = infoReport, Verbose = new MockReport() }); Assert.True(builder.Build(testDir)); ValidateProjectFile(Path.Combine(testDir, "app", "project.json")); ValidateScriptFile(Path.Combine(testDir, "app", "cmd1.cmd")); ValidateScriptFile(Path.Combine(testDir, "app", "cmd2.cmd")); } }
public void KCommandShowsVersionAndReturnsZeroExitCodeWhenVersionOptionWasGiven(DisposableDir runtimeHomeDir) { using (runtimeHomeDir) { string stdOut, stdErr; var exitCode = KCommandTestUtils.ExecKCommand( runtimeHomeDir, subcommand: string.Empty, arguments: "--version", stdOut: out stdOut, stdErr: out stdErr); Assert.Equal(0, exitCode); Assert.Contains(TestUtils.GetRuntimeVersion(), stdOut); } }
public void KCommandShowsErrorWhenNoProjectJsonWasFound(DisposableDir runtimeHomeDir) { using (runtimeHomeDir) using (var emptyFolder = TestUtils.CreateTempDir()) { string stdOut, stdErr; var exitCode = KCommandTestUtils.ExecKCommand( runtimeHomeDir, subcommand: "run", arguments: string.Empty, stdOut: out stdOut, stdErr: out stdErr, environment: new Dictionary<string, string> { { EnvironmentNames.AppBase, emptyFolder } }); Assert.NotEqual(0, exitCode); Assert.Contains("Unable to locate project.json", stdErr); } }
public void WildcardMatchingFacts(DisposableDir runtimeHomeDir) { 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'], 'MixFolder1': { 'UsefulSub': ['useful.txt', 'useful'] }, 'MixFolder2': { 'UsefulSub': ['useful.txt', 'useful'] } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new KpmTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""bundleExclude"": [ ""UselessFolder1\\**"", ""UselessFolder2/**/*"", ""UselessFolder3\\**/*.*"", ""MixFolder1\\*"", ""MixFolder2/*.*"" ] }") .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"": [ ""UselessFolder1\\**"", ""UselessFolder2/**/*"", ""UselessFolder3\\**/*.*"", ""MixFolder1\\*"", ""MixFolder2/*.*"" ] }") .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""dependencies"": {}, ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.BundleOutputDirPath, compareFileContents: true)); } }
public void VerifyDefaultBundleExcludePatterns(DisposableDir runtimeHomeDir) { 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', 'File', '.FileStartingWithDot'], 'Folder': ['File', '.FileStartingWithDot'] } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new KpmTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ }") .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"), @"{ }") .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""dependencies"": {}, ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.BundleOutputDirPath, compareFileContents: true)); } }
public void KpmWrapInPlaceCreateCsprojWrappersInPlace(DisposableDir runtimeHomeDir) { if (PlatformHelper.IsMono) { return; } var expectedLibGammaProjectJson = @"{ ""version"": ""1.0.0-*"", ""frameworks"": { ""net45"": { ""wrappedProject"": ""LibraryGamma.csproj"", ""bin"": { ""assembly"": ""obj/{configuration}/LibraryGamma.dll"", ""pdb"": ""obj/{configuration}/LibraryGamma.pdb"" }, ""dependencies"": { ""EntityFramework"": ""6.1.2-beta1"", ""LibraryEpsilon"": ""1.0.0-*"", ""LibraryDelta"": ""1.0.0-*"" } } } }"; var expectedLibEpsilonProjectJson = @"{ ""version"": ""1.0.0-*"", ""frameworks"": { ""net45"": { ""wrappedProject"": ""LibraryEpsilon.csproj"", ""bin"": { ""assembly"": ""obj/{configuration}/LibraryEpsilon.dll"", ""pdb"": ""obj/{configuration}/LibraryEpsilon.pdb"" } } } }"; var expectedLibDeltaProjectJson = @"{ ""version"": ""1.0.0-*"", ""frameworks"": { ""net45"": { ""bin"": { ""assembly"": ""../../ExternalAssemblies/LibraryDelta.dll"" } } } }"; var expectedGlobalJson = @"{ ""sources"": [ ""src"", ""test"", ""wrap"", ""."" ] }"; using (runtimeHomeDir) using (var testSolutionDir = TestUtils.GetTempTestSolution("ConsoleApp1")) { var libGammaCsprojPath = Path.Combine(testSolutionDir, "LibraryGamma", "LibraryGamma.csproj"); var globalJsonPath = Path.Combine(testSolutionDir, "global.json"); var wrapFolderPath = Path.Combine(testSolutionDir, "wrap"); var libGammaJsonPath = Path.Combine(testSolutionDir, "LibraryGamma", "project.json"); var libEpsilonJsonPath = Path.Combine(testSolutionDir, "LibraryEpsilon", "project.json"); var libDeltaJsonPath = Path.Combine(wrapFolderPath, "LibraryDelta", "project.json"); var exitCode = KpmTestUtils.ExecKpm( runtimeHomeDir, subcommand: "wrap", arguments: string.Format("\"{0}\" --in-place --msbuild \"{1}\"", libGammaCsprojPath, _msbuildPath)); Assert.Equal(0, exitCode); Assert.Equal(expectedGlobalJson, File.ReadAllText(globalJsonPath)); Assert.True(Directory.Exists(wrapFolderPath)); Assert.Equal(1, Directory.EnumerateDirectories(wrapFolderPath).Count()); Assert.Equal(expectedLibGammaProjectJson, File.ReadAllText(libGammaJsonPath)); Assert.Equal(expectedLibEpsilonProjectJson, File.ReadAllText(libEpsilonJsonPath)); Assert.Equal(expectedLibDeltaProjectJson, File.ReadAllText(libDeltaJsonPath)); } }
public void KpmBundleWebApp_SubfolderAsPublicFolder(DisposableDir runtimeHomeDir) { 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', '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=""..\approot\packages"" /> <add key=""{1}"" value="""" /> <add key=""{2}"" value=""..\approot\packages"" /> <add key=""{3}"" value="""" /> <add key=""{4}"" value="""" /> <add key=""{5}"" value=""..\approot\src\{{0}}"" /> </appSettings> </configuration>", Constants.WebConfigKpmPackagePath, Constants.WebConfigBootstrapperVersion, Constants.WebConfigRuntimePath, Constants.WebConfigRuntimeVersion, Constants.WebConfigRuntimeFlavor, Constants.WebConfigRuntimeAppBase); using (var testEnv = new KpmTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""bundleExclude"": ""**.useless"", ""webroot"": ""public"" }") .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} --wwwroot-out wwwroot", 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"": ""**.useless"", ""webroot"": ""../../../wwwroot"" }") .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""dependencies"": {}, ""packages"": ""packages"" }") .WithFileContents(Path.Combine("wwwroot", "web.config"), outputWebConfigTemplate, testEnv.ProjectName); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.BundleOutputDirPath, compareFileContents: true)); } }
public void CorrectlyExcludeFoldersStartingWithDots(DisposableDir runtimeHomeDir) { 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', '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 KpmTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ }") .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"), @"{ }") .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""dependencies"": {}, ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.BundleOutputDirPath, compareFileContents: true)); } }
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)); } }
public void GenerateBatchFilesAndBashScriptsWithoutBundledRuntime(DisposableDir runtimeHomeDir) { var projectStructure = @"{ '.': ['project.json'], 'packages': {} }"; var expectedOutputStructure = @"{ '.': ['run.cmd', 'run', 'kestrel.cmd', 'kestrel'], 'approot': { 'global.json': '', 'src': { 'PROJECT_NAME': { '.': ['project.json'] } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new KpmTestEnvironment(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"": { ""aspnet50"": { }, ""aspnetcore50"": { } } }") .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"), @"{ ""commands"": { ""run"": ""run server.urls=http://localhost:5003"", ""kestrel"": ""Microsoft.AspNet.Hosting --server Kestrel --server.urls http://localhost:5004"" }, ""frameworks"": { ""aspnet50"": { }, ""aspnetcore50"": { } } }") .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""dependencies"": {}, ""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.BundleOutputDirPath, compareFileContents: true)); } }
public void GenerateBatchFilesAndBashScriptsWithBundledRuntime(DisposableDir runtimeHomeDir) { // 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'] } }, 'packages': { 'RUNTIME_PACKAGE_NAME': {} } } }".Replace("PROJECT_NAME", _projectName).Replace("RUNTIME_PACKAGE_NAME", runtimeName); using (var testEnv = new KpmTestEnvironment(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"": { ""aspnet50"": { }, ""aspnetcore50"": { } } }") .WriteTo(testEnv.ProjectPath); var environment = new Dictionary<string, string>() { { EnvironmentNames.Packages, Path.Combine(testEnv.ProjectPath, "packages") }, { EnvironmentNames.Home, runtimeHomeDir }, { EnvironmentNames.Trace, "1" } }; var exitCode = KpmTestUtils.ExecKpm( runtimeHomeDir, subcommand: "bundle", arguments: string.Format("--out {0} --runtime {1}", testEnv.BundleOutputDirPath, 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\packages\{0}\bin\", runtimeName); var bashScriptBinPath = string.Format("$DIR/approot/packages/{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"": { ""aspnet50"": { }, ""aspnetcore50"": { } } }") .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""dependencies"": {}, ""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", "packages", runtimeName), runtimeSubDir); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.BundleOutputDirPath, compareFileContents: true)); } }
public void FoldersAsFilePatternsAutoGlob(DisposableDir runtimeHomeDir) { 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'], 'MixFolder': { 'UsefulSub': ['useful.txt', 'useful.css', 'file_without_extension'] } } } } }".Replace("PROJECT_NAME", _projectName); using (var testEnv = new KpmTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""bundleExclude"": [ ""FileWithoutExtension"", ""UselessFolder1"", ""UselessFolder2/"", ""UselessFolder3\\"", ""MixFolder/UselessSub1/"", ""MixFolder\\UselessSub2\\"", ""MixFolder/UselessSub3\\"", ""MixFolder/UselessSub4"", ""MixFolder\\UselessSub5"", "".git"" ] }") .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"": [ ""FileWithoutExtension"", ""UselessFolder1"", ""UselessFolder2/"", ""UselessFolder3\\"", ""MixFolder/UselessSub1/"", ""MixFolder\\UselessSub2\\"", ""MixFolder/UselessSub3\\"", ""MixFolder/UselessSub4"", ""MixFolder\\UselessSub5"", "".git"" ] }") .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""dependencies"": {}, ""packages"": ""packages"" }"); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.BundleOutputDirPath, compareFileContents: true)); } }
public void KpmBundleWebApp_UpdateExistingWebConfig(DisposableDir runtimeHomeDir) { 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'] } } }".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"" /> <add key=""{5}"" value=""OLD_VALUE"" /> </appSettings> </configuration>", Constants.WebConfigKpmPackagePath, 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=""..\approot\packages"" /> <add key=""{1}"" value="""" /> <add key=""{2}"" value=""..\approot\packages"" /> <add key=""{3}"" value="""" /> <add key=""{4}"" value="""" /> <add key=""{5}"" value=""..\approot\src\{{0}}"" /> </appSettings> </configuration>", Constants.WebConfigKpmPackagePath, Constants.WebConfigBootstrapperVersion, Constants.WebConfigRuntimePath, Constants.WebConfigRuntimeVersion, Constants.WebConfigRuntimeFlavor, Constants.WebConfigRuntimeAppBase); using (var testEnv = new KpmTestEnvironment(runtimeHomeDir, _projectName, _outputDirName)) { DirTree.CreateFromJson(projectStructure) .WithFileContents("project.json", @"{ ""webroot"": ""../../../wwwroot"" }") .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 = KpmTestUtils.ExecKpm( runtimeHomeDir, subcommand: "bundle", arguments: string.Format("--out {0} --wwwroot public --wwwroot-out wwwroot", 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"), @"{ ""webroot"": ""../../../wwwroot"" }") .WithFileContents(Path.Combine("approot", "global.json"), @"{ ""dependencies"": {}, ""packages"": ""packages"" }") .WithFileContents(Path.Combine("wwwroot", "web.config"), outputWebConfigContents, testEnv.ProjectName); Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.BundleOutputDirPath, compareFileContents: true)); } }
public void KpmWrapUpdatesExistingProjectJson(DisposableDir runtimeHomeDir) { if (PlatformHelper.IsMono) { return; } var expectedProjectJson = @"{ ""version"": ""1.0.0-*"", ""dependencies"": {}, ""frameworks"": { ""net45+win+wpa81+wp80"": { ""wrappedProject"": ""../../LibraryBeta.PCL/LibraryBeta.PCL.csproj"", ""bin"": { ""assembly"": ""../../LibraryBeta.PCL/obj/{configuration}/LibraryBeta.dll"", ""pdb"": ""../../LibraryBeta.PCL/obj/{configuration}/LibraryBeta.pdb"" } }, ""net45"": { ""wrappedProject"": ""../../LibraryBeta.PCL.Desktop/LibraryBeta.PCL.Desktop.csproj"", ""bin"": { ""assembly"": ""../../LibraryBeta.PCL.Desktop/obj/{configuration}/LibraryBeta.dll"", ""pdb"": ""../../LibraryBeta.PCL.Desktop/obj/{configuration}/LibraryBeta.pdb"" } }, ""wpa81"": { ""wrappedProject"": ""../../LibraryBeta.PCL.Phone/LibraryBeta.PCL.Phone.csproj"", ""bin"": { ""assembly"": ""../../LibraryBeta.PCL.Phone/obj/{configuration}/LibraryBeta.dll"", ""pdb"": ""../../LibraryBeta.PCL.Phone/obj/{configuration}/LibraryBeta.pdb"" } } } }"; var expectedGlobalJson = @"{ ""sources"": [ ""src"", ""test"" ] }"; using (runtimeHomeDir) using (var testSolutionDir = TestUtils.GetTempTestSolution("ConsoleApp1")) { var libBetaPclCsprojPath = Path.Combine(testSolutionDir, "LibraryBeta.PCL", "LibraryBeta.PCL.csproj"); var libBetaPclDesktopCsprojPath = Path.Combine( testSolutionDir, "LibraryBeta.PCL.Desktop", "LibraryBeta.PCL.Desktop.csproj"); var libBetaPclPhoneCsprojPath = Path.Combine( testSolutionDir, "LibraryBeta.PCL.Phone", "LibraryBeta.PCL.Phone.csproj"); var libBetaJsonPath = Path.Combine(testSolutionDir, "src", "LibraryBeta", "project.json"); var globalJsonPath = Path.Combine(testSolutionDir, "global.json"); var betaPclExitCode = KpmTestUtils.ExecKpm( runtimeHomeDir, subcommand: "wrap", arguments: string.Format("\"{0}\" --msbuild \"{1}\"", libBetaPclCsprojPath, _msbuildPath)); var betaDesktopExitCode = KpmTestUtils.ExecKpm( runtimeHomeDir, subcommand: "wrap", arguments: string.Format("\"{0}\" --msbuild \"{1}\"", libBetaPclDesktopCsprojPath, _msbuildPath)); var betaPhoneExitCode = KpmTestUtils.ExecKpm( runtimeHomeDir, subcommand: "wrap", arguments: string.Format("\"{0}\" --msbuild \"{1}\"", libBetaPclPhoneCsprojPath, _msbuildPath)); Assert.Equal(0, betaPclExitCode); Assert.Equal(0, betaDesktopExitCode); Assert.Equal(0, betaPhoneExitCode); Assert.Equal(expectedGlobalJson, File.ReadAllText(globalJsonPath)); Assert.False(Directory.Exists(Path.Combine(testSolutionDir, "wrap"))); Assert.Equal(expectedProjectJson, File.ReadAllText(libBetaJsonPath)); } }