public async Task LoadConfigurationForGivenProjectShouldReturnDefinedConfig()
        {
            AnalyzerManager  manager   = new AnalyzerManager();
            IProjectAnalyzer analyzer  = manager.GetProject(@"..\..\..\..\Tests.Assets.WebApi2022\Tests.Assets.WebApi2022.csproj");
            AdhocWorkspace   workspace = analyzer.GetWorkspace(false);
            var project = workspace.CurrentSolution.Projects.Where(x => x.Name == "Tests.Assets.WebApi2022").First();
            var output  = new IOutputMock();
            var loader  = new UserCodeLoader(output, new IFileSearcherMock());

            var userCode = await loader.LoadUserCodeForGivenProject(workspace.CurrentSolution, project.FilePath);

            var config = userCode.Config;

            Assert.AreEqual(false, config.AddGeneratedFilesToVSProject);
            config.ProjectsToBeSearched.ShouldBe(new[] { "Tests.Assets.WebApi2022" });
        }
Esempio n. 2
0
        public async Task Execute(Solution solution, IList <TemplateToRender> templates)
        {
            await status.Update("Rendering", 0, templates.Count);

            for (int i = 0; i < templates.Count; ++i)
            {
                var template = templates[i];

                output.Info(new String('-', 69));
                output.Info("Rendering started : " + System.IO.Path.GetFileName(template.FilePath));
                await status.Update("Rendering", i + 1, templates.Count);

                var userCodeLoader = new UserCodeLoader(output, fileSearcher);
                var userCode       = await userCodeLoader.LoadUserCodeForGivenProject(solution, template.ProjectPath).ConfigureAwait(false);

                var editorConfig = new EditorConfig(userCode.Config);

                var codeModelBuilder = new CodeModelBuilder();
                var codeModel        = new LazyCodeModel(() => codeModelBuilder.Build(solution, editorConfig));

                output.Info($"Loading template : {template.FilePath}");
                var templateContent = template.Content ?? await fileReaderWriter.Read(template.FilePath).ConfigureAwait(false);

                var templateRenderer = new TemplateRenderer(errorList, output);
                var renderedItems    = await templateRenderer.RenderAsync(template.FilePath, templateContent, codeModel, userCode.TypesThatMayContainCustomFunctions, editorConfig).ConfigureAwait(false);

                var fileSaver = new FileSaver(output, sourceControl, fileReaderWriter);
                await fileSaver.Save(renderedItems).ConfigureAwait(false);

                if (editorConfig.AddGeneratedFilesToVSProject)
                {
                    output.Info("Updating VisualStudio solution");
                    await solutionItemsManager.UpdateSolution(template.FilePath, renderedItems.Select(x => x.FilePath)).ConfigureAwait(false);

                    output.Info("VisualStudio solution updated successfully");
                }

                await status.Update("Rendering succeed");
            }
        }