Example #1
0
    public async Task <Project> GetOrCreateProject(string projectKey, ITestOutputHelper output)
    {
        await TemplatePackageInstaller.EnsureTemplatingEngineInitializedAsync(output);

        // Different tests may have different output helpers, so need to fix up the output to write to the correct log
        if (_projects.TryGetValue(projectKey, out var project))
        {
            project.Output = output;
            return(project);
        }
        return(_projects.GetOrAdd(
                   projectKey,
                   (key, outputHelper) =>
        {
            var project = new Project
            {
                Output = outputHelper,
                DiagnosticsMessageSink = DiagnosticsMessageSink,
                ProjectGuid = Path.GetRandomFileName().Replace(".", string.Empty)
            };
            project.ProjectName = $"AspNet.{project.ProjectGuid}";

            var assemblyPath = GetType().Assembly;
            var basePath = GetTemplateFolderBasePath(assemblyPath);
            project.TemplateOutputDir = Path.Combine(basePath, project.ProjectName);
            return project;
        },
                   output));
    }
Example #2
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 #3
0
    public async Task <Project> CreateProject(ITestOutputHelper output)
    {
        await TemplatePackageInstaller.EnsureTemplatingEngineInitializedAsync(output);

        var project = CreateProjectImpl(output);

        var projectKey = Guid.NewGuid().ToString().Substring(0, 10).ToLowerInvariant();

        if (!_projects.TryAdd(projectKey, project))
        {
            throw new InvalidOperationException($"Project key collision in {nameof(ProjectFactoryFixture)}.{nameof(CreateProject)}!");
        }

        return(project);
    }
Example #4
0
        public Project CreateProject(ITestOutputHelper output)
        {
            TemplatePackageInstaller.EnsureTemplatingEngineInitialized(output);
            var project = new Project
            {
                DotNetNewLock = DotNetNewLock,
                Output        = output,
                ProjectGuid   = Guid.NewGuid().ToString("N").Substring(0, 6)
            };

            project.ProjectName = $"AspNet.Template.{project.ProjectGuid}";

            _projects.Add(project);

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

            project.TemplateOutputDir = Path.Combine(basePath, "TestTemplates", project.ProjectName);
            Directory.CreateDirectory(project.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=""Directory.Build.After.props"" Condition=""Exists('Directory.Build.After.props')"" />
</Project>";

            File.WriteAllText(Path.Combine(project.TemplateOutputDir, "Directory.Build.props"), directoryBuildPropsContent);

            // TODO: remove this once we get a newer version of the SDK which supports an implicit FrameworkReference
            // cref https://github.com/aspnet/websdk/issues/424
            var directoryBuildTargetsContent =
                $@"<Project>
    <Import Project=""{templatesTestsPropsFilePath}"" />
</Project>";

            File.WriteAllText(Path.Combine(project.TemplateOutputDir, "Directory.Build.targets"), directoryBuildTargetsContent);

            return(project);
        }
Example #5
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 />");
        }
        public TemplateTestBase(ITestOutputHelper output)
        {
            _output.Value = output;
            TemplatePackageInstaller.EnsureTemplatingEngineInitialized(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=""Directory.Build.After.props"" Condition=""Exists('Directory.Build.After.props')"" />
</Project>";

            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.props"), directoryBuildPropsContent);

            // TODO: remove this once we get a newer version of the SDK which supports an implicit FrameworkReference
            // cref https://github.com/aspnet/websdk/issues/424
            var directoryBuildTargetsContent =
                $@"<Project>
    <Import Project=""{templatesTestsPropsFilePath}"" />

    <ItemGroup>
       <FrameworkReference Remove=""Microsoft.AspNetCore.App"" />
       <PackageReference Include=""Microsoft.AspNetCore.App"" Version=""$(BundledAspNetCoreAppPackageVersion)"" IsImplicitlyDefined=""true"" />
    </ItemGroup>
</Project>";

            File.WriteAllText(Path.Combine(TemplateOutputDir, "Directory.Build.targets"), directoryBuildTargetsContent);
        }
 static TemplateTestBase()
 {
     TemplatePackageInstaller.ReinstallTemplatePackages();
 }