C# Class TestHelper.CodeFixVerifier

Superclass of all Unit tests made for diagnostics with codefixes. Contains methods used to verify correctness of codefixes
Inheritance: DiagnosticVerifier
ファイルを表示 Open project: signumsoftware/framework

Public Methods

Method Description
VerifyFix ( string oldSource, string newSource, int codeFixIndex = null, bool allowNewCompilerDiagnostics = false ) : void

General verifier for codefixes. Creates a Document from the source string, then gets diagnostics on it and applies the relevant codefixes. Then gets the string after the codefix is applied and compares it with the expected result. Note: If any codefix causes new diagnostics to show up, the test fails unless allowNewCompilerDiagnostics is set to true.

Protected Methods

Method Description
GetCSharpCodeFixProvider ( ) : Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider

Returns the codefix being tested (C#) - to be implemented in non-abstract class

Private Methods

Method Description
ApplyFix ( Microsoft.CodeAnalysis.Document document, CodeAction codeAction ) : Microsoft.CodeAnalysis.Document

Apply the inputted CodeAction to the inputted document. Meant to be used to apply codefixes.

GetCompilerDiagnostics ( Microsoft.CodeAnalysis.Document document ) : IEnumerable

Get the existing compiler diagnostics on the inputted document.

GetNewDiagnostics ( IEnumerable diagnostics, IEnumerable newDiagnostics ) : IEnumerable

Compare two collections of Diagnostics,and return a list of any new diagnostics that appear only in the second collection. Note: Considers Diagnostics to be the same if they have the same Ids. In the case of multiple diagnostics with the same Id in a row, this method may not necessarily return the new one.

GetStringFromDocument ( Microsoft.CodeAnalysis.Document document ) : string

Given a document, turn it into a string based on the syntax root

Method Details

GetCSharpCodeFixProvider() protected method

Returns the codefix being tested (C#) - to be implemented in non-abstract class
protected GetCSharpCodeFixProvider ( ) : Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider
return Microsoft.CodeAnalysis.CodeFixes.CodeFixProvider

VerifyFix() public method

General verifier for codefixes. Creates a Document from the source string, then gets diagnostics on it and applies the relevant codefixes. Then gets the string after the codefix is applied and compares it with the expected result. Note: If any codefix causes new diagnostics to show up, the test fails unless allowNewCompilerDiagnostics is set to true.
public VerifyFix ( string oldSource, string newSource, int codeFixIndex = null, bool allowNewCompilerDiagnostics = false ) : void
oldSource string A class in the form of a string before the CodeFix was applied to it
newSource string A class in the form of a string after the CodeFix was applied to it
codeFixIndex int Index determining which codefix to apply if there are multiple
allowNewCompilerDiagnostics bool A bool controlling whether or not the test will fail if the CodeFix introduces other warnings after being applied
return void