Skip to content

Commit 7ed6d4c

Browse files
committed
Fix tests.
1 parent 365e965 commit 7ed6d4c

4 files changed

Lines changed: 144 additions & 15 deletions

File tree

PropertyChangedAnalyzers.Test/Helpers/LibrarySettings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ public static class LibrarySettings
99
{
1010
private static readonly DirectoryInfo ProjectDirectory = ProjectFile.Find("PropertyChangedAnalyzers.Test.csproj").Directory;
1111

12-
internal static Settings CaliburnMicro { get; } = Settings.Default.WithMetadataReferences(MetadataReferences.Transitive(typeof(Caliburn.Micro.PropertyChangedBase)));
12+
internal static Settings CaliburnMicro { get; } = Settings.Default
13+
.WithCompilationOptions(x => x.WithSuppressedDiagnostics("CS1701"))
14+
.WithMetadataReferences(MetadataReferences.Transitive(typeof(Caliburn.Micro.PropertyChangedBase)));
1315

1416
internal static Settings Stylet { get; } = Settings.Default.WithMetadataReferences(MetadataReferences.Transitive(LoadUnsigned("Stylet.dll")));
1517

PropertyChangedAnalyzers.Test/INPC001ImplementINotifyPropertyChanged/CodeFix.CS0246.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
namespace PropertyChangedAnalyzers.Test.INPC001ImplementINotifyPropertyChanged
22
{
33
using Gu.Roslyn.Asserts;
4-
using Microsoft.CodeAnalysis;
5-
using Microsoft.CodeAnalysis.CSharp;
64
using NUnit.Framework;
75

86
public static partial class CodeFix
@@ -11,12 +9,12 @@ public static class CS0246
119
{
1210
// ReSharper disable once MemberHidesStaticFromOuterClass
1311
private static readonly ExpectedDiagnostic ExpectedDiagnostic = ExpectedDiagnostic.Create("CS0246");
14-
private static readonly CSharpCompilationOptions NullableEnabled = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, nullableContextOptions: NullableContextOptions.Enable);
1512

1613
[Test]
17-
public static void WhenInterfaceOnlyAddUsings()
14+
public static void WhenInterfaceOnlyAddUsingsNullableDisable()
1815
{
1916
var before = @"
17+
#nullable disable
2018
namespace N
2119
{
2220
public class C : ↓INotifyPropertyChanged
@@ -25,6 +23,7 @@ public class C : ↓INotifyPropertyChanged
2523
}";
2624

2725
var after = @"
26+
#nullable disable
2827
namespace N
2928
{
3029
using System.ComponentModel;
@@ -44,7 +43,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
4443
}
4544

4645
[Test]
47-
public static void WhenInterfaceOnlyAddUsingsNullable()
46+
public static void WhenInterfaceOnlyAddUsings()
4847
{
4948
var before = @"
5049
namespace N
@@ -89,9 +88,9 @@ namespace N
8988
{
9089
public class C : System.ComponentModel.INotifyPropertyChanged
9190
{
92-
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
91+
public event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;
9392
94-
protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
93+
protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
9594
{
9695
this.PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
9796
}
@@ -119,9 +118,9 @@ namespace N
119118
120119
public sealed class C : INotifyPropertyChanged
121120
{
122-
public event PropertyChangedEventHandler PropertyChanged;
121+
public event PropertyChangedEventHandler? PropertyChanged;
123122
124-
private void OnPropertyChanged([CallerMemberName] string propertyName = null)
123+
private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
125124
{
126125
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
127126
}
@@ -146,9 +145,9 @@ namespace N
146145
{
147146
public sealed class C : System.ComponentModel.INotifyPropertyChanged
148147
{
149-
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
148+
public event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;
150149
151-
private void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
150+
private void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
152151
{
153152
this.PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
154153
}

PropertyChangedAnalyzers.Test/INPC001ImplementINotifyPropertyChanged/CodeFix.CaliburnMicro.cs

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,33 @@ public static class CaliburnMicro
1414
public static void SubclassPropertyChangedBaseAddUsing()
1515
{
1616
var before = @"
17+
#nullable disable
18+
namespace N
19+
{
20+
public class ↓C
21+
{
22+
public int P { get; set; }
23+
}
24+
}";
25+
26+
var after = @"
27+
#nullable disable
28+
namespace N
29+
{
30+
using Caliburn.Micro;
31+
32+
public class C : PropertyChangedBase
33+
{
34+
public int P { get; set; }
35+
}
36+
}";
37+
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Subclass Caliburn.Micro.PropertyChangedBase and add using.", settings: Settings);
38+
}
39+
40+
[Test]
41+
public static void SubclassPropertyChangedBaseAddUsingNullableDisabled()
42+
{
43+
var before = @"
1744
namespace N
1845
{
1946
public class ↓C
@@ -59,9 +86,10 @@ public class C : Caliburn.Micro.PropertyChangedBase
5986
}
6087

6188
[Test]
62-
public static void ImplementINotifyPropertyChangedAddUsings()
89+
public static void ImplementINotifyPropertyChangedAddUsingsNullableDisabled()
6390
{
6491
var before = @"
92+
#nullable disable
6593
namespace N
6694
{
6795
public class ↓C
@@ -71,6 +99,7 @@ public class ↓C
7199
}";
72100

73101
var after = @"
102+
#nullable disable
74103
namespace N
75104
{
76105
using System.ComponentModel;
@@ -92,7 +121,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName
92121
}
93122

94123
[Test]
95-
public static void ImplementINotifyPropertyChangedFullyQualified()
124+
public static void ImplementINotifyPropertyChangedAddUsings()
96125
{
97126
var before = @"
98127
namespace N
@@ -105,6 +134,41 @@ public class ↓C
105134

106135
var after = @"
107136
namespace N
137+
{
138+
using System.ComponentModel;
139+
using System.Runtime.CompilerServices;
140+
141+
public class C : INotifyPropertyChanged
142+
{
143+
public event PropertyChangedEventHandler? PropertyChanged;
144+
145+
public int P { get; set; }
146+
147+
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
148+
{
149+
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
150+
}
151+
}
152+
}";
153+
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Implement INotifyPropertyChanged and add usings.", settings: Settings);
154+
}
155+
156+
[Test]
157+
public static void ImplementINotifyPropertyChangedFullyQualifiedNullableDisabled()
158+
{
159+
var before = @"
160+
#nullable disable
161+
namespace N
162+
{
163+
public class ↓C
164+
{
165+
public int P { get; set; }
166+
}
167+
}";
168+
169+
var after = @"
170+
#nullable disable
171+
namespace N
108172
{
109173
public class C : System.ComponentModel.INotifyPropertyChanged
110174
{
@@ -117,6 +181,36 @@ protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.Caller
117181
this.PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
118182
}
119183
}
184+
}";
185+
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Implement INotifyPropertyChanged fully qualified.", settings: Settings);
186+
}
187+
188+
[Test]
189+
public static void ImplementINotifyPropertyChangedFullyQualified()
190+
{
191+
var before = @"
192+
namespace N
193+
{
194+
public class ↓C
195+
{
196+
public int P { get; set; }
197+
}
198+
}";
199+
200+
var after = @"
201+
namespace N
202+
{
203+
public class C : System.ComponentModel.INotifyPropertyChanged
204+
{
205+
public event System.ComponentModel.PropertyChangedEventHandler? PropertyChanged;
206+
207+
public int P { get; set; }
208+
209+
protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
210+
{
211+
this.PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
212+
}
213+
}
120214
}";
121215
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Implement INotifyPropertyChanged fully qualified.", settings: Settings);
122216
}

PropertyChangedAnalyzers.Test/INPC001ImplementINotifyPropertyChanged/CodeFix.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.Caller
262262
}
263263

264264
[Test]
265-
public static void WhenEventOnly()
265+
public static void WhenEventOnlyNullableDisabled()
266266
{
267267
var before = @"
268+
#nullable disable
268269
namespace N
269270
{
270271
using System.ComponentModel;
@@ -276,6 +277,7 @@ public class ↓C
276277
}";
277278

278279
var after = @"
280+
#nullable disable
279281
namespace N
280282
{
281283
using System.ComponentModel;
@@ -293,6 +295,38 @@ protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.Caller
293295
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Implement INotifyPropertyChanged fully qualified.");
294296
}
295297

298+
[Test]
299+
public static void WhenEventOnly()
300+
{
301+
var before = @"
302+
namespace N
303+
{
304+
using System.ComponentModel;
305+
306+
public class ↓C
307+
{
308+
public event PropertyChangedEventHandler? PropertyChanged;
309+
}
310+
}";
311+
312+
var after = @"
313+
namespace N
314+
{
315+
using System.ComponentModel;
316+
317+
public class C : INotifyPropertyChanged
318+
{
319+
public event PropertyChangedEventHandler? PropertyChanged;
320+
321+
protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string? propertyName = null)
322+
{
323+
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
324+
}
325+
}
326+
}";
327+
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Implement INotifyPropertyChanged fully qualified.");
328+
}
329+
296330
[Test]
297331
public static void WhenEventAndInvokerOnly()
298332
{

0 commit comments

Comments
 (0)