Skip to content

Commit dae03c7

Browse files
committed
Annotate test code.
1 parent 6b45a47 commit dae03c7

5 files changed

Lines changed: 22 additions & 21 deletions

File tree

PropertyChangedAnalyzers.Test/INPC007MissingInvoker/CodeFix.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public sealed class C : INotifyPropertyChanged
6565
public event PropertyChangedEventHandler? PropertyChanged;
6666
}
6767
}";
68-
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Seal class.");
68+
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Seal class.", settings: Settings.Default.WithAllowedCompilerDiagnostics(AllowedCompilerDiagnostics.Warnings));
6969
}
7070

7171
[Test]
@@ -312,7 +312,7 @@ public C(int p1)
312312
}
313313
}";
314314

315-
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Seal class.");
315+
RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after, fixTitle: "Seal class.", settings: Settings.Default.WithAllowedCompilerDiagnostics(AllowedCompilerDiagnostics.Warnings));
316316
}
317317

318318
[Test]
@@ -405,11 +405,11 @@ namespace N.Client
405405
406406
public class C : INotifyPropertyChanged
407407
{
408-
private string p;
408+
private string? p;
409409
410410
↓public event PropertyChangedEventHandler? PropertyChanged;
411411
412-
public string P
412+
public string? P
413413
{
414414
get { return this.p; }
415415
set { this.TrySet(ref this.p, value); }
@@ -438,11 +438,11 @@ namespace N.Client
438438
439439
public class C : INotifyPropertyChanged
440440
{
441-
private string p;
441+
private string? p;
442442
443443
public event PropertyChangedEventHandler? PropertyChanged;
444444
445-
public string P
445+
public string? P
446446
{
447447
get { return this.p; }
448448
set { this.TrySet(ref this.p, value); }

PropertyChangedAnalyzers.Test/INPC007MissingInvoker/Valid.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace PropertyChangedAnalyzers.Test.INPC007MissingInvoker
22
{
33
using Gu.Roslyn.Asserts;
4+
45
using NUnit.Framework;
56

67
public static class Valid
@@ -18,11 +19,11 @@ namespace N
1819
1920
public class C : INotifyPropertyChanged
2021
{
21-
private string p;
22+
private string? p;
2223
2324
public event PropertyChangedEventHandler? PropertyChanged;
2425
25-
public string P
26+
public string? P
2627
{
2728
get
2829
{
@@ -62,11 +63,11 @@ namespace N
6263
6364
public sealed class C : INotifyPropertyChanged
6465
{
65-
private string p;
66+
private string? p;
6667
6768
public event PropertyChangedEventHandler? PropertyChanged;
6869
69-
public string P
70+
public string? P
7071
{
7172
get
7273
{
@@ -126,7 +127,7 @@ public class C : N.Core.ViewModelBase
126127
}
127128
}";
128129

129-
RoslynAssert.Valid(Analyzer, viewModelBaseCode, code);
130+
RoslynAssert.Valid(Analyzer, new[] { viewModelBaseCode, code }, settings: Settings.Default.WithAllowedCompilerDiagnostics(AllowedCompilerDiagnostics.Warnings));
130131
}
131132

132133
[Test]
@@ -208,7 +209,7 @@ public C(int p1)
208209
}
209210
}";
210211

211-
RoslynAssert.Valid(Analyzer, code);
212+
RoslynAssert.Valid(Analyzer, code, settings: Settings.Default.WithAllowedCompilerDiagnostics(AllowedCompilerDiagnostics.Warnings));
212213
}
213214

214215
[Test]
@@ -380,7 +381,7 @@ public class CachingInConcurrentDictionary : INotifyPropertyChanged
380381
381382
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
382383
{
383-
this.PropertyChanged?.Invoke(this, Cache.GetOrAdd(propertyName, name => new PropertyChangedEventArgs(name)));
384+
this.PropertyChanged?.Invoke(this, Cache.GetOrAdd(propertyName ?? string.Empty, name => new PropertyChangedEventArgs(name)));
384385
}
385386
}
386387
}";
@@ -406,7 +407,7 @@ public class CachingInConcurrentDictionary : INotifyPropertyChanged
406407
407408
protected void OnPropertyChanged([CallerMemberName]string? propertyName = null)
408409
{
409-
var args = _propertyChangedCache.GetOrAdd(propertyName, name => new PropertyChangedEventArgs(propertyName));
410+
var args = _propertyChangedCache.GetOrAdd(propertyName ?? string.Empty, name => new PropertyChangedEventArgs(propertyName));
410411
411412
PropertyChanged?.Invoke(this, args);
412413
}

PropertyChangedAnalyzers.Test/INPC008StructMustNotNotify/Diagnostics.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace PropertyChangedAnalyzers.Test.INPC008StructMustNotNotify
1+
namespace PropertyChangedAnalyzers.Test.INPC008StructMustNotNotify
22
{
33
using Gu.Roslyn.Asserts;
44
using NUnit.Framework;
@@ -11,6 +11,7 @@ public static class Diagnostics
1111
public static void WhenNotifying()
1212
{
1313
var code = @"
14+
#pragma warning disable CS0067
1415
namespace N
1516
{
1617
using System.ComponentModel;
@@ -27,6 +28,7 @@ public struct S : ↓INotifyPropertyChanged
2728
public static void WhenNotifyingFullyQualified()
2829
{
2930
var code = @"
31+
#pragma warning disable CS0067
3032
namespace N
3133
{
3234
public struct S : ↓System.ComponentModel.INotifyPropertyChanged

PropertyChangedAnalyzers.Test/INPC009NotifiesForMissingProperty/Diagnostics.Argument.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ public static void InvokesSimple()
152152
namespace N
153153
{
154154
using System.ComponentModel;
155-
using System.Runtime.CompilerServices;
156155
157156
public class C : INotifyPropertyChanged
158157
{
@@ -290,7 +289,6 @@ public static void CallsOnPropertyChangedWithCachedEventArgs(string cached)
290289
namespace N
291290
{
292291
using System.ComponentModel;
293-
using System.Runtime.CompilerServices;
294292
295293
public class C : INotifyPropertyChanged
296294
{

PropertyChangedAnalyzers.Test/INPC009NotifiesForMissingProperty/Valid{T}.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace PropertyChangedAnalyzers.Test.INPC009NotifiesForMissingProperty
1+
namespace PropertyChangedAnalyzers.Test.INPC009NotifiesForMissingProperty
22
{
33
using Gu.Roslyn.Asserts;
44
using Microsoft.CodeAnalysis;
@@ -26,7 +26,6 @@ public static void OnPropertyChangedWithEventArgs(string propertyName)
2626
namespace N
2727
{
2828
using System.ComponentModel;
29-
using System.Runtime.CompilerServices;
3029
3130
public class C : INotifyPropertyChanged
3231
{
@@ -380,7 +379,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName
380379
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
381380
}
382381
383-
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
382+
private void OnPropertyChanged(object? sender, PropertyChangedEventArgs e)
384383
{
385384
if (e.HasPropertyChanged(""SomeProperty""))
386385
{
@@ -557,6 +556,7 @@ public void M()
557556
public static void WhenNotAnInvoker()
558557
{
559558
var code = @"
559+
#pragma warning disable CS0067
560560
namespace N
561561
{
562562
using System.ComponentModel;
@@ -604,7 +604,7 @@ namespace N
604604
using System.ComponentModel;
605605
public class C : INotifyPropertyChanged
606606
{
607-
private Dictionary<int, int> map;
607+
private Dictionary<int, int> map = new();
608608
609609
public event PropertyChangedEventHandler? PropertyChanged;
610610

0 commit comments

Comments
 (0)