Esempio n. 1
0
        internal async Task TestAsync(string testCode, string expected, OptionsCollection?options = null, ParseOptions?parseOptions = null)
        {
            using var workspace = CreateTestWorkspace(testCode, parseOptions);
            options?.SetGlobalOptions(workspace.GlobalOptions);

            var solution = workspace.CurrentSolution;

            var document         = workspace.CurrentSolution.Projects.First().Documents.First();
            var languageServices = document.Project.LanguageServices;

            var cleanupOptions =
                options?.ToAnalyzerConfigOptions(languageServices).GetCodeCleanupOptions(allowImportsInHiddenRegions: false, fallbackOptions: null, languageServices) ??
                CodeCleanupOptions.GetDefault(languageServices);

            var formattingService = document.GetRequiredLanguageService <INewDocumentFormattingService>();
            var formattedDocument = await formattingService.FormatNewDocumentAsync(document, hintDocument : null, cleanupOptions, CancellationToken.None);

            var actual = await formattedDocument.GetTextAsync();

            AssertEx.EqualOrDiff(expected, actual.ToString());
        }