Skip to content

Commit 16d2886

Browse files
author
msftbot[bot]
authored
Fix warnings in HighPerformance/Mvvm unit tests (#4142)
## Fixes #4102 (comment) <!-- Add the relevant issue number after the "#" mentioned above (for ex: "## Fixes #1234") which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more options below that apply to this PR. --> - Maintenance <!-- - Bugfix --> <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Some HighPerformance/Mvvm unit tests produce warnings when the projects are built. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> No more warnings 🙌 ## PR Checklist Please check if your PR fulfills the following requirements: - [X] Tested code with current [supported SDKs](../readme.md#supported) - [X] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link --> - [X] Sample in sample app has been added / updated (for bug fixes / features) - [X] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/CommunityToolkit/WindowsCommunityToolkit-design-assets) - [X] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/CommunityToolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc... - [X] Tests for the changes have been added (for bug fixes / features) (if applicable) - [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [X] Contains **NO** breaking changes
2 parents 9476299 + 6b03f8a commit 16d2886

File tree

9 files changed

+22
-5
lines changed

9 files changed

+22
-5
lines changed

UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
#if !WINDOWS_UWP
66

77
using System;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.Runtime.CompilerServices;
910
using Microsoft.Toolkit.HighPerformance.Enumerables;
1011
using Microsoft.VisualStudio.TestTools.UnitTesting;
1112

1213
namespace UnitTests.HighPerformance.Enumerables
1314
{
1415
[TestClass]
16+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649", Justification = "Test class for generic type")]
1517
public class Test_ReadOnlyRefEnumerable
1618
{
1719
[TestCategory("ReadOnlyRefEnumerable")]

UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_RefEnumerable{T}.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
#if !WINDOWS_UWP
66

77
using System;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.Runtime.CompilerServices;
910
using Microsoft.Toolkit.HighPerformance.Enumerables;
1011
using Microsoft.VisualStudio.TestTools.UnitTesting;
1112

1213
namespace UnitTests.HighPerformance.Enumerables
1314
{
1415
[TestClass]
16+
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649", Justification = "Test class for generic type")]
1517
public class Test_RefEnumerable
1618
{
1719
[TestCategory("RefEnumerable")]

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)