Example #1
0
        public TemplateTestBase(ITestOutputHelper output)
        {
            TemplatePackageInstaller.EnsureTemplatePackagesWereReinstalled(output);

            Output      = output;
            ProjectGuid = Guid.NewGuid().ToString("N");
            ProjectName = $"AspNet.Template.{ProjectGuid}";

            var assemblyPath = GetType().GetTypeInfo().Assembly.CodeBase;
            var assemblyUri  = new Uri(assemblyPath, UriKind.Absolute);
            var basePath     = Path.GetDirectoryName(assemblyUri.LocalPath);

            TemplateOutputDir = Path.Combine(basePath, "TestTemplates", ProjectName);
            Directory.CreateDirectory(TemplateOutputDir);

            // We don't want any of the host repo's build config interfering with
            // how the test project is built, so disconnect it from the
            // Directory.Build.props/targets context

            var templatesTestsPropsFilePath = Path.Combine(basePath, "TemplateTests.props");
            var directoryBuildPropsContent  =
                $@"<Project>
    <Import Project=""{templatesTestsPropsFilePath}"" />
    <Import Project=""Directory.Build.After.props"" Condition=""Exists('Directory.Build.After.props')"" />
</Project>";

            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.props"), directoryBuildPropsContent);
            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.targets"), "<Project />");
        }
Example #2
0
        public TemplateTestBase(ITestOutputHelper output)
        {
            TemplatePackageInstaller.EnsureTemplatePackagesWereReinstalled(output);

            Output      = output;
            ProjectName = Guid.NewGuid().ToString().Replace("-", "");

            var assemblyPath = GetType().GetTypeInfo().Assembly.CodeBase;
            var assemblyUri  = new Uri(assemblyPath, UriKind.Absolute);
            var basePath     = Path.GetDirectoryName(assemblyUri.LocalPath);

            TemplateOutputDir = Path.Combine(basePath, "TestTemplates", ProjectName);
            Directory.CreateDirectory(TemplateOutputDir);

            // We don't want any of the host repo's build config interfering with
            // how the test project is built, so disconnect it from the
            // Directory.Build.props/targets context
            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.props"), "<Project />");
            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.targets"), "<Project />");
        }