private static async Task <bool> IsGeneratedAsync(string content, GeneratedCodeRecognizer generatedCodeRecognizer) { using (var workspace = new AdhocWorkspace()) { var document = workspace.CurrentSolution.AddProject("foo", "foo.dll", LanguageNames.CSharp) .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("mscorlib.dll"))) .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.dll"))) .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.Core.dll"))) .AddDocument("Foo.cs", content); var compilation = document.Project.GetCompilationAsync().Result; var tree = await document.GetSyntaxTreeAsync(); return(tree.IsGenerated(generatedCodeRecognizer, compilation)); } }
private static void VerifyEmpty(string name, string content, DiagnosticAnalyzer diagnosticAnalyzer) { using (var workspace = new AdhocWorkspace()) { var document = workspace.CurrentSolution.AddProject("foo", "foo.dll", LanguageNames.CSharp) .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("mscorlib.dll"))) .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.dll"))) .AddMetadataReference(AssemblyReferenceService.GetMetadataReference(AssemblyReference.FromFramework("System.Core.dll"))) .AddDocument(name, content); var compilation = document.Project.GetCompilationAsync().Result; var diagnostics = Verifier.GetDiagnostics(compilation, diagnosticAnalyzer); diagnostics.Should().HaveCount(0); } }