private async Task AssertFormattingAsync(string code, string formatted) { var project = DiagnosticProject.Create(typeof(CodeFileBuilderTests).Assembly, LanguageVersion.Latest, new[] { code }); project = project.WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); var compilation = await project.GetCompilationAsync(); Assert.Empty(compilation.GetDiagnostics().Where(d => d.Severity > DiagnosticSeverity.Warning)); var memoryStream = new MemoryStream(); compilation.Emit(memoryStream); memoryStream.Position = 0; var compilationFromDll = CompilationFactory.GetCompilation(memoryStream, null); var codeModel = new CodeFileBuilder() { SymbolOrderProvider = new NameSymbolOrderProvider() }.Build(compilationFromDll, false, null); var formattedModel = new CodeFileRenderer().Render(codeModel); var formattedString = string.Join(Environment.NewLine, formattedModel.Select(l => l.DisplayString)); _testOutputHelper.WriteLine(formattedString); Assert.Equal(formatted, formattedString); }
private async Task AssertFormattingAsync(string code, string formatted) { var project = DiagnosticProject.Create(typeof(CodeFileBuilderTests).Assembly, new[] { code }); project = project.WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); var compilation = await project.GetCompilationAsync(); Assert.Empty(compilation.GetDiagnostics().Where(d => d.Severity > DiagnosticSeverity.Warning)); var codeModel = new CodeFileBuilder() { SymbolOrderProvider = new NameSymbolOrderProvider() }.Build(compilation.Assembly, false); var formattedModel = new CodeFileRenderer().Render(codeModel); var formattedString = formattedModel.ToString(); _testOutputHelper.WriteLine(formattedString); Assert.Equal(formatted, formattedString); }