From 240f0774f16144651a01ab97ca6d332e2387a768 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 29 Jul 2021 11:52:27 +0200 Subject: [PATCH 1/2] Fixed warnings in HighPerformance unit tests --- .../Enumerables/Test_ReadOnlyRefEnumerable{T}.cs | 2 ++ .../Enumerables/Test_RefEnumerable{T}.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs b/UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs index f5631f8e3d4..c4c6470fdb3 100644 --- a/UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs +++ b/UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_ReadOnlyRefEnumerable{T}.cs @@ -5,6 +5,7 @@ #if !WINDOWS_UWP using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.HighPerformance.Enumerables; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -12,6 +13,7 @@ namespace UnitTests.HighPerformance.Enumerables { [TestClass] + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649", Justification = "Test class for generic type")] public class Test_ReadOnlyRefEnumerable { [TestCategory("ReadOnlyRefEnumerable")] diff --git a/UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_RefEnumerable{T}.cs b/UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_RefEnumerable{T}.cs index d60e4fe2c48..4c37642b515 100644 --- a/UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_RefEnumerable{T}.cs +++ b/UnitTests/UnitTests.HighPerformance.Shared/Enumerables/Test_RefEnumerable{T}.cs @@ -5,6 +5,7 @@ #if !WINDOWS_UWP using System; +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using Microsoft.Toolkit.HighPerformance.Enumerables; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -12,6 +13,7 @@ namespace UnitTests.HighPerformance.Enumerables { [TestClass] + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1649", Justification = "Test class for generic type")] public class Test_RefEnumerable { [TestCategory("RefEnumerable")] From 6b03f8a608b3caed9b26412233fff823b190c3ab Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Thu, 29 Jul 2021 12:14:50 +0200 Subject: [PATCH 2/2] Fixed warnings in Mvvm unit tests --- .../UnitTests.NetCore/Mvvm/Test_ICommandAttribute.cs | 4 ++-- .../Mvvm/Test_INotifyPropertyChangedAttribute.cs | 2 ++ .../UnitTests.NetCore/Mvvm/Test_IRecipientGenerator.cs | 2 ++ .../Mvvm/Test_ObservableObjectAttribute.cs | 2 ++ .../Mvvm/Test_ObservablePropertyAttribute.cs | 9 ++++++--- .../Mvvm/Test_ObservableRecipientAttribute.cs | 2 ++ UnitTests/UnitTests.Shared/Mvvm/Test_Messenger.cs | 2 ++ 7 files changed, 18 insertions(+), 5 deletions(-) diff --git a/UnitTests/UnitTests.NetCore/Mvvm/Test_ICommandAttribute.cs b/UnitTests/UnitTests.NetCore/Mvvm/Test_ICommandAttribute.cs index 2bcea9e41dd..4a5c377b613 100644 --- a/UnitTests/UnitTests.NetCore/Mvvm/Test_ICommandAttribute.cs +++ b/UnitTests/UnitTests.NetCore/Mvvm/Test_ICommandAttribute.cs @@ -2,8 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#pragma warning disable CS0618 - +using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using Microsoft.Toolkit.Mvvm.Input; @@ -11,6 +10,7 @@ namespace UnitTests.Mvvm { + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")] [TestClass] public partial class Test_ICommandAttribute { diff --git a/UnitTests/UnitTests.NetCore/Mvvm/Test_INotifyPropertyChangedAttribute.cs b/UnitTests/UnitTests.NetCore/Mvvm/Test_INotifyPropertyChangedAttribute.cs index 5eba0389465..016a75702c2 100644 --- a/UnitTests/UnitTests.NetCore/Mvvm/Test_INotifyPropertyChangedAttribute.cs +++ b/UnitTests/UnitTests.NetCore/Mvvm/Test_INotifyPropertyChangedAttribute.cs @@ -3,12 +3,14 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTests.Mvvm { + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")] [TestClass] public partial class Test_INotifyPropertyChangedAttribute { diff --git a/UnitTests/UnitTests.NetCore/Mvvm/Test_IRecipientGenerator.cs b/UnitTests/UnitTests.NetCore/Mvvm/Test_IRecipientGenerator.cs index dece3973370..9227d603619 100644 --- a/UnitTests/UnitTests.NetCore/Mvvm/Test_IRecipientGenerator.cs +++ b/UnitTests/UnitTests.NetCore/Mvvm/Test_IRecipientGenerator.cs @@ -5,11 +5,13 @@ #pragma warning disable CS0618 using System; +using System.Diagnostics.CodeAnalysis; using Microsoft.Toolkit.Mvvm.Messaging; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTests.Mvvm { + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")] [TestClass] public partial class Test_IRecipientGenerator { diff --git a/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableObjectAttribute.cs b/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableObjectAttribute.cs index 6b3cdf0dbe3..98b40ecf6ec 100644 --- a/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableObjectAttribute.cs +++ b/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableObjectAttribute.cs @@ -3,11 +3,13 @@ // See the LICENSE file in the project root for more information. using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace UnitTests.Mvvm { + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")] [TestClass] public partial class Test_ObservableObjectAttribute { diff --git a/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs b/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs index 97ef214b38c..8b8005d15c9 100644 --- a/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs +++ b/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservablePropertyAttribute.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using Microsoft.Toolkit.Mvvm.ComponentModel; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -14,6 +15,7 @@ namespace UnitTests.Mvvm { + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")] [TestClass] public partial class Test_ObservablePropertyAttribute { @@ -105,9 +107,10 @@ public void Test_ValidationAttributes() Assert.AreEqual(testAttribute.D, 6.28); CollectionAssert.AreEqual(testAttribute.Names, new[] { "Bob", "Ross" }); - object[] nestedArray = (object[])testAttribute.NestedArray; + object[]? nestedArray = (object[]?)testAttribute.NestedArray; - Assert.AreEqual(nestedArray.Length, 3); + Assert.IsNotNull(nestedArray); + Assert.AreEqual(nestedArray!.Length, 3); Assert.AreEqual(nestedArray[0], 1); Assert.AreEqual(nestedArray[1], "Hello"); Assert.IsTrue(nestedArray[2] is int[]); @@ -181,7 +184,7 @@ public TestValidationAttribute(object? o, Type t, bool flag, double d, string[] public string[] Names { get; } - public object NestedArray { get; set; } + public object? NestedArray { get; set; } public Animal Animal { get; set; } } diff --git a/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableRecipientAttribute.cs b/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableRecipientAttribute.cs index c2889fb4795..a6689ae4869 100644 --- a/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableRecipientAttribute.cs +++ b/UnitTests/UnitTests.NetCore/Mvvm/Test_ObservableRecipientAttribute.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using Microsoft.Toolkit.Mvvm.ComponentModel; @@ -13,6 +14,7 @@ namespace UnitTests.Mvvm { + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")] [TestClass] public partial class Test_ObservableRecipientAttribute { diff --git a/UnitTests/UnitTests.Shared/Mvvm/Test_Messenger.cs b/UnitTests/UnitTests.Shared/Mvvm/Test_Messenger.cs index d92e2d7cb6c..85adc99af92 100644 --- a/UnitTests/UnitTests.Shared/Mvvm/Test_Messenger.cs +++ b/UnitTests/UnitTests.Shared/Mvvm/Test_Messenger.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using Microsoft.Toolkit.Mvvm.Messaging; @@ -10,6 +11,7 @@ namespace UnitTests.Mvvm { + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1601", Justification = "Type only used for testing")] [TestClass] public partial class Test_Messenger {