public static void FixAllInDocumentTwoErrors() { var before = @" namespace N { class C { private readonly int ↓_value1; private readonly int ↓_value2; } }"; var after = @" namespace N { class C { private readonly int value1; private readonly int value2; } }"; var analyzer = new FieldNameMustNotBeginWithUnderscore(); var fix = new DoNotUseUnderscoreFix(); RoslynAssert.FixAllInDocument(analyzer, fix, before, after); }
public static void AddAfterOtherFieldAssignment(string expression) { var before = @" namespace N { using System.ComponentModel; using System.Runtime.CompilerServices; public class C : INotifyPropertyChanged { private int p3; private int f; public event PropertyChangedEventHandler PropertyChanged; public int P1 => 2 * this.p3; public int P2 => 3 * this.p3; public int P3 { get => this.p3; set { if (value == this.p3) { return; } ↓this.p3 = value; this.f = value * 2; this.OnPropertyChanged(); this.OnPropertyChanged(nameof(this.P1)); } } protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }".AssertReplace("this.OnPropertyChanged(nameof(this.P1))", expression); var after = @" namespace N { using System.ComponentModel; using System.Runtime.CompilerServices; public class C : INotifyPropertyChanged { private int p3; private int f; public event PropertyChangedEventHandler PropertyChanged; public int P1 => 2 * this.p3; public int P2 => 3 * this.p3; public int P3 { get => this.p3; set { if (value == this.p3) { return; } this.p3 = value; this.f = value * 2; this.OnPropertyChanged(); this.OnPropertyChanged(nameof(this.P1)); this.OnPropertyChanged(nameof(this.P2)); } } protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }"; RoslynAssert.FixAll(Analyzer, Fix, ExpectedDiagnostic, before, after); RoslynAssert.FixAllInDocument(Analyzer, Fix, ExpectedDiagnostic, before, after); }