From a030cf8585def125549ecf846c74950c88c6e494 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 f5631f8e..c4c6470f 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 d60e4fe2..4c37642b 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 7fd3e751f86bf2e63392169c7f18d02a4a35edac 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 2bcea9e4..4a5c377b 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 5eba0389..016a7570 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 dece3973..9227d603 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 6b3cdf0d..98b40ecf 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 97ef214b..8b8005d1 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 c2889fb4..a6689ae4 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 d92e2d7c..85adc99a 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 {