Ejemplo n.º 1
0
        public void KpmBundleConsoleApp(DisposableDir runtimeHomeDir)
        {
            var projectStructure        = @"{
  '.': ['project.json', 'Config.json', 'Program.cs'],
  'Data': {
    'Input': ['data1.dat', 'data2.dat'],
    'Backup': ['backup1.dat', 'backup2.dat']
  },
  'packages': {}
}";
            var expectedOutputStructure = @"{
  'approot': {
    'global.json': '',
    'src': {
      'PROJECT_NAME': {
        '.': ['project.json', 'Config.json', 'Program.cs'],
          'Data': {
            'Input': ['data1.dat', 'data2.dat']
          }
        }
      }
    }
  }".Replace("PROJECT_NAME", _projectName);

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

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

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

                var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure)
                                        .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{
  ""bundleExclude"": ""Data/Backup/**""
}")
                                        .WithFileContents(Path.Combine("approot", "global.json"), @"{
  ""dependencies"": {},
  ""packages"": ""packages""
}");
                Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.BundleOutputDirPath,
                                                                   compareFileContents: true));
            }
        }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 3
0
        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));
            }
        }
Ejemplo n.º 4
0
        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));
            }
        }
Ejemplo n.º 5
0
        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));
            }
        }
Ejemplo n.º 6
0
        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));
            }
        }
Ejemplo n.º 7
0
        public void KpmBundleWebApp_RootAsPublicFolder(DisposableDir runtimeHomeDir)
        {
            var projectStructure        = @"{
  '.': ['project.json', 'Config.json', 'Program.cs', 'build_config1.bconfig'],
  'Views': {
    'Home': ['index.cshtml'],
    'Shared': ['_Layout.cshtml']
  },
  'Controllers': ['HomeController.cs'],
  'Models': ['User.cs', 'build_config2.bconfig'],
  'Build': ['build_config3.bconfig'],
  'packages': {}
}";
            var expectedOutputStructure = @"{
  'wwwroot': {
    '.': ['project.json', 'Config.json', 'Program.cs', 'build_config1.bconfig', 'web.config'],
      'Views': {
        'Home': ['index.cshtml'],
        'Shared': ['_Layout.cshtml']
    },
    'Controllers': ['HomeController.cs'],
    'Models': ['User.cs', 'build_config2.bconfig'],
    'Build': ['build_config3.bconfig']
  },
  'approot': {
    'global.json': '',
    'src': {
      'PROJECT_NAME': {
        '.': ['project.json', 'Config.json', 'Program.cs'],
          'Views': {
            'Home': ['index.cshtml'],
            'Shared': ['_Layout.cshtml']
        },
        'Controllers': ['HomeController.cs'],
        'Models': ['User.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"": ""**.bconfig"",
  ""webroot"": ""to_be_overridden""
}")
                .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 . --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"": ""**.bconfig"",
  ""webroot"": ""../../../wwwroot""
}")
                                        .WithFileContents(Path.Combine("wwwroot", "project.json"), @"{
  ""bundleExclude"": ""**.bconfig"",
  ""webroot"": ""to_be_overridden""
}")
                                        .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));
            }
        }
Ejemplo n.º 8
0
        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));
            }
        }
Ejemplo n.º 9
0
        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));
            }
        }
Ejemplo n.º 10
0
        public void GenerateBatchFilesAndBashScriptsWithPackedRuntime(DisposableDir kreHomeDir)
        {
            // Each KRE home only contains one KRE package, which is the one we are currently testing against
            var kreRoot = Directory.EnumerateDirectories(Path.Combine(kreHomeDir, "packages"), "KRE-*").First();
            var kreName = new DirectoryInfo(kreRoot).Name;

            var projectStructure        = @"{
  '.': ['project.json'],
  'packages': {}
}";
            var expectedOutputStructure = @"{
  '.': ['run.cmd', 'run', 'kestrel.cmd', 'kestrel'],
  'approot': {
    'global.json': '',
    'src': {
      'PROJECT_NAME': {
        '.': ['project.json']
      }
    },
    'packages': {
      'KRE_PACKAGE_NAME': {}
    }
  }
}".Replace("PROJECT_NAME", _projectName).Replace("KRE_PACKAGE_NAME", kreName);

            using (var testEnv = new KpmTestEnvironment(kreHomeDir, _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>()
                {
                    { "KRE_PACKAGES", Path.Combine(testEnv.ProjectPath, "packages") },
                    { "KRE_HOME", kreHomeDir },
                    { "KRE_TRACE", "1" }
                };

                var exitCode = KpmTestUtils.ExecKpm(
                    kreHomeDir,
                    subcommand: "pack",
                    arguments: string.Format("--out {0} --runtime {1}",
                                             testEnv.PackOutputDirPath, kreName),
                    environment: environment,
                    workingDir: testEnv.ProjectPath);
                Assert.Equal(0, exitCode);

                var kreNupkgSHA   = TestUtils.ComputeSHA(Path.Combine(kreRoot, kreName + ".nupkg"));
                var runtimeSubDir = DirTree.CreateFromDirectory(kreRoot)
                                    .WithFileContents(kreName + ".nupkg.sha512", kreNupkgSHA)
                                    .RemoveFile("[Content_Types].xml")
                                    .RemoveFile(Path.Combine("_rels", ".rels"))
                                    .RemoveSubDir("package");

                var batchFileBinPath  = string.Format(@"%~dp0approot\packages\{0}\bin\", kreName);
                var bashScriptBinPath = string.Format("$DIR/approot/packages/{0}/bin/", kreName);

                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, testEnv.ProjectName, "run")
                                        .WithFileContents("kestrel.cmd", BatchFileTemplate, batchFileBinPath, testEnv.ProjectName, "kestrel")
                                        .WithFileContents("run",
                                                          BashScriptTemplate, testEnv.ProjectName, bashScriptBinPath, "run")
                                        .WithFileContents("kestrel",
                                                          BashScriptTemplate, testEnv.ProjectName, bashScriptBinPath, "kestrel")
                                        .WithSubDir(Path.Combine("approot", "packages", kreName), runtimeSubDir);

                Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PackOutputDirPath,
                                                                   compareFileContents: true));
            }
        }
Ejemplo n.º 11
0
        public void KpmPackWebApp_UpdateExistingWebConfig(DisposableDir kreHomeDir)
        {
            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 webConfigContents       = @"<?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=""kpm-package-path"" value=""OLD_VALUE"" />
    <add key=""bootstrapper-version"" value=""OLD_VALUE"" />
    <add key=""kre-package-path"" value=""OLD_VALUE"" />
    <add key=""kre-version"" value=""OLD_VALUE"" />
    <add key=""kre-clr"" value=""OLD_VALUE"" />
    <add key=""kre-app-base"" value=""OLD_VALUE"" />
  </appSettings>
</configuration>";

            using (var testEnv = new KpmTestEnvironment(kreHomeDir, _projectName, _outputDirName))
            {
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("project.json", @"{
  ""webroot"": ""../../../wwwroot""
}")
                .WithFileContents(Path.Combine("public", "web.config"), webConfigContents)
                .WriteTo(testEnv.ProjectPath);

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

                var exitCode = KpmTestUtils.ExecKpm(
                    kreHomeDir,
                    subcommand: "pack",
                    arguments: string.Format("--out {0} --wwwroot public --wwwroot-out wwwroot",
                                             testEnv.PackOutputDirPath),
                    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"), @"<?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=""kpm-package-path"" value=""..\approot\packages"" />
    <add key=""bootstrapper-version"" value="""" />
    <add key=""kre-package-path"" value=""..\approot\packages"" />
    <add key=""kre-version"" value="""" />
    <add key=""kre-clr"" value="""" />
    <add key=""kre-app-base"" value=""..\approot\src\{0}"" />
  </appSettings>
</configuration>", testEnv.ProjectName);
                Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PackOutputDirPath,
                                                                   compareFileContents: true));
            }
        }
Ejemplo n.º 12
0
        public void KpmPackWebApp_SubfolderAsPublicFolder(DisposableDir kreHomeDir)
        {
            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);

            using (var testEnv = new KpmTestEnvironment(kreHomeDir, _projectName, _outputDirName))
            {
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("project.json", @"{
  ""packExclude"": ""**.useless"",
  ""webroot"": ""public""
}")
                .WriteTo(testEnv.ProjectPath);

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

                var exitCode = KpmTestUtils.ExecKpm(
                    kreHomeDir,
                    subcommand: "pack",
                    arguments: string.Format("--out {0} --wwwroot-out wwwroot",
                                             testEnv.PackOutputDirPath),
                    environment: environment,
                    workingDir: testEnv.ProjectPath);
                Assert.Equal(0, exitCode);

                var expectedOutputDir = DirTree.CreateFromJson(expectedOutputStructure)
                                        .WithFileContents(Path.Combine("approot", "src", testEnv.ProjectName, "project.json"), @"{
  ""packExclude"": ""**.useless"",
  ""webroot"": ""../../../wwwroot""
}")
                                        .WithFileContents(Path.Combine("approot", "global.json"), @"{
  ""dependencies"": {},
  ""packages"": ""packages""
}")
                                        .WithFileContents(Path.Combine("wwwroot", "web.config"), @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <appSettings>
    <add key=""kpm-package-path"" value=""..\approot\packages"" />
    <add key=""bootstrapper-version"" value="""" />
    <add key=""kre-package-path"" value=""..\approot\packages"" />
    <add key=""kre-version"" value="""" />
    <add key=""kre-clr"" value="""" />
    <add key=""kre-app-base"" value=""..\approot\src\{0}"" />
  </appSettings>
</configuration>", testEnv.ProjectName);
                Assert.True(expectedOutputDir.MatchDirectoryOnDisk(testEnv.PackOutputDirPath,
                                                                   compareFileContents: true));
            }
        }
Ejemplo n.º 13
0
        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);
            }
        }
Ejemplo n.º 14
0
        public void DnuFeeds_ListsAllSources(string flavor, string os, string architecture)
        {
            var environment = new Dictionary <string, string>
            {
                { "DNX_TRACE", "0" },
            };

            var rootConfig =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <packageSources>
    <clear /> <!-- Remove the effects of any machine-level config -->
    <add key=""Source1"" value=""https://source1"" />
    <add key=""Source2"" value=""https://source2"" />
  </packageSources>
</configuration>";

            var subConfig =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
  <packageSources>
    <add key=""Source3"" value=""https://source3"" />
  </packageSources>
  <disabledPackageSources>
    <add key=""Source1"" value=""https://source1"" />
  </disabledPackageSources>
</configuration>";

            var projectStructure =
                @"{
    'root': {
        'NuGet.Config': """",
        'sub': {
            'NuGet.Config': """"
        }
    }
}";

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

            using (var testEnv = new DnuTestEnvironment(runtimeHomePath, projectName: "Project Name"))
            {
                var projectPath = testEnv.ProjectPath;
                DirTree.CreateFromJson(projectStructure)
                .WithFileContents("root/NuGet.Config", rootConfig)
                .WithFileContents("root/sub/NuGet.Config", subConfig)
                .WriteTo(projectPath);

                string output;
                string error;
                var    exitCode = DnuTestUtils.ExecDnu(
                    runtimeHomePath,
                    subcommand: "feeds",
                    arguments: "list root/sub",
                    stdOut: out output,
                    stdErr: out error,
                    environment: environment,
                    workingDir: projectPath);

                Assert.Equal(0, exitCode);
                Assert.Empty(error);

                // CI Machines and such have different sources in the user-global config
                // So we can't actually assert the exact content of the output.
                Assert.Contains($"https://source1 [Disabled]{Environment.NewLine}      Origin: {Path.Combine(projectPath, "root", "NuGet.Config")}", output);
                Assert.Contains($"https://source2{Environment.NewLine}      Origin: {Path.Combine(projectPath, "root", "NuGet.Config")}", output);
                Assert.Contains($"https://source3{Environment.NewLine}      Origin: {Path.Combine(projectPath, "root", "sub", "NuGet.Config")}", output);
            }
        }