Skip to content

Commit 16218eb

Browse files
committed
Fixed warnings in Mvvm unit tests
1 parent 9df270b commit 16218eb

File tree

7 files changed

+18
-5
lines changed

7 files changed

+18
-5
lines changed

UnitTests/UnitTests.NetCore/Mvvm/Test_ICommandAttribute.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#pragma warning disable CS0618
6-
5+
using System.Diagnostics.CodeAnalysis;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using Microsoft.Toolkit.Mvvm.Input;
109
using Microsoft.VisualStudio.TestTools.UnitTesting;
1110

1211
namespace UnitTests.Mvvm
1312
{
13+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")]
1414
[TestClass]
1515
public partial class Test_ICommandAttribute
1616
{

UnitTests/UnitTests.NetCore/Mvvm/Test_INotifyPropertyChangedAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.ComponentModel;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Reflection;
78
using Microsoft.Toolkit.Mvvm.ComponentModel;
89
using Microsoft.VisualStudio.TestTools.UnitTesting;
910

1011
namespace UnitTests.Mvvm
1112
{
13+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")]
1214
[TestClass]
1315
public partial class Test_INotifyPropertyChangedAttribute
1416
{

UnitTests/UnitTests.NetCore/Mvvm/Test_IRecipientGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
#pragma warning disable CS0618
66

77
using System;
8+
using System.Diagnostics.CodeAnalysis;
89
using Microsoft.Toolkit.Mvvm.Messaging;
910
using Microsoft.VisualStudio.TestTools.UnitTesting;
1011

1112
namespace UnitTests.Mvvm
1213
{
14+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")]
1315
[TestClass]
1416
public partial class Test_IRecipientGenerator
1517
{

UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableObjectAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System.ComponentModel;
6+
using System.Diagnostics.CodeAnalysis;
67
using Microsoft.Toolkit.Mvvm.ComponentModel;
78
using Microsoft.VisualStudio.TestTools.UnitTesting;
89

910
namespace UnitTests.Mvvm
1011
{
12+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")]
1113
[TestClass]
1214
public partial class Test_ObservableObjectAttribute
1315
{

UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using System.ComponentModel;
88
using System.ComponentModel.DataAnnotations;
9+
using System.Diagnostics.CodeAnalysis;
910
using System.Reflection;
1011
using Microsoft.Toolkit.Mvvm.ComponentModel;
1112
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -14,6 +15,7 @@
1415

1516
namespace UnitTests.Mvvm
1617
{
18+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")]
1719
[TestClass]
1820
public partial class Test_ObservablePropertyAttribute
1921
{
@@ -105,9 +107,10 @@ public void Test_ValidationAttributes()
105107
Assert.AreEqual(testAttribute.D, 6.28);
106108
CollectionAssert.AreEqual(testAttribute.Names, new[] { "Bob", "Ross" });
107109

108-
object[] nestedArray = (object[])testAttribute.NestedArray;
110+
object[]? nestedArray = (object[]?)testAttribute.NestedArray;
109111

110-
Assert.AreEqual(nestedArray.Length, 3);
112+
Assert.IsNotNull(nestedArray);
113+
Assert.AreEqual(nestedArray!.Length, 3);
111114
Assert.AreEqual(nestedArray[0], 1);
112115
Assert.AreEqual(nestedArray[1], "Hello");
113116
Assert.IsTrue(nestedArray[2] is int[]);
@@ -181,7 +184,7 @@ public TestValidationAttribute(object? o, Type t, bool flag, double d, string[]
181184

182185
public string[] Names { get; }
183186

184-
public object NestedArray { get; set; }
187+
public object? NestedArray { get; set; }
185188

186189
public Animal Animal { get; set; }
187190
}

UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableRecipientAttribute.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.ComponentModel;
77
using System.ComponentModel.DataAnnotations;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.Linq;
910
using System.Reflection;
1011
using Microsoft.Toolkit.Mvvm.ComponentModel;
@@ -13,6 +14,7 @@
1314

1415
namespace UnitTests.Mvvm
1516
{
17+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")]
1618
[TestClass]
1719
public partial class Test_ObservableRecipientAttribute
1820
{

UnitTests/UnitTests.Shared/Mvvm/Test_Messenger.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Linq;
78
using System.Reflection;
89
using Microsoft.Toolkit.Mvvm.Messaging;
910
using Microsoft.VisualStudio.TestTools.UnitTesting;
1011

1112
namespace UnitTests.Mvvm
1213
{
14+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")]
1315
[TestClass]
1416
public partial class Test_Messenger
1517
{

0 commit comments

Comments
 (0)