C# Class TestHelper.DiagnosticVerifier

Superclass of all Unit Tests for DiagnosticAnalyzers
ファイルを表示 Open project: signumsoftware/framework Class Usage Examples

Protected Methods

Method Description
CreateDocument ( string source ) : Microsoft.CodeAnalysis.Document

Create a Document from a string through creating a project that contains it.

GetCSharpDiagnosticAnalyzer ( ) : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer
GetSortedDiagnosticsFromDocuments ( Microsoft.CodeAnalysis.Document documents ) : Diagnostic[]
VerifyDiagnostic ( string source ) : void

Called to test a C# DiagnosticAnalyzer when applied on the single inputted string as a source Note: input a DiagnosticResult for each Diagnostic expected

Private Methods

Method Description
CreateProject ( string sources ) : Microsoft.CodeAnalysis.Project

Create a project using the inputted strings as sources.

FormatDiagnostics ( Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer analyzer ) : string

Helper method to format a Diagnostic into an easily readable string

GetDocuments ( string sources ) : Microsoft.CodeAnalysis.Document[]

Given an array of strings as sources and a language, turn them into a project and return the documents and spans of it.

VerifyDiagnosticResults ( IEnumerable actualResults ) : void

Checks each of the actual Diagnostics found and compares them with the corresponding DiagnosticResult in the array of expected results. Diagnostics are considered equal only if the DiagnosticResultLocation, Id, Severity, and Message of the DiagnosticResult match the actual diagnostic.

Method Details

CreateDocument() protected static method

Create a Document from a string through creating a project that contains it.
protected static CreateDocument ( string source ) : Microsoft.CodeAnalysis.Document
source string Classes in the form of a string
return Microsoft.CodeAnalysis.Document

GetCSharpDiagnosticAnalyzer() protected method

protected GetCSharpDiagnosticAnalyzer ( ) : Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer
return Microsoft.CodeAnalysis.Diagnostics.DiagnosticAnalyzer

GetSortedDiagnosticsFromDocuments() protected method

protected GetSortedDiagnosticsFromDocuments ( Microsoft.CodeAnalysis.Document documents ) : Diagnostic[]
documents Microsoft.CodeAnalysis.Document
return Diagnostic[]

VerifyDiagnostic() protected method

Called to test a C# DiagnosticAnalyzer when applied on the single inputted string as a source Note: input a DiagnosticResult for each Diagnostic expected
protected VerifyDiagnostic ( string source ) : void
source string A class in the form of a string to run the analyzer on
return void