Beispiel #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));
    }
Beispiel #2
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);
    }