Re-enable xunit warning 2002 dotnet/corefx#39696 (dotnet/corefx#39706)
authorZoey McCullough <zoey.c.mccullough@gmail.com>
Fri, 26 Jul 2019 13:58:06 +0000 (06:58 -0700)
committerStephen Toub <stoub@microsoft.com>
Fri, 26 Jul 2019 13:58:06 +0000 (09:58 -0400)
* Removed null checks on value types and enabled xunit 2002

* Updated Fill_OpenDataReader_Throws to use range check

Updated Fill_OpenDataReader_Throws to use range check for passing path

* Removed uneeded asserts and updated others

- Removed any assert for a valuetype where it was succeeded by a value type assertion (e.g. Assert.Equal(1, 1))
- Updated reflection tests to check flags for the specified scenario

* Update src/Microsoft.VisualBasic.Core/tests/FileSystemTests.cs

Co-Authored-By: Jeremy Barton <jbarton@microsoft.com>
* Update src/System.Reflection/tests/AssemblyNameTests.cs

Co-Authored-By: Jeremy Barton <jbarton@microsoft.com>
* Fixed failing reflection tests and removed Assert.NotNull for enum

* Pulled ruleset up from master to merge

* Cleaned up assert ordering for TestGuid

* Updated TestResponseWithoutContentEvents

- Asserted for 200 OK based on response from DefaultAzureServer + EmptyContentHandler

Commit migrated from https://github.com/dotnet/corefx/commit/c96e389f803b043753558878fefb575f3f85c934

19 files changed:
src/libraries/CodeAnalysis.ruleset
src/libraries/Microsoft.VisualBasic.Core/tests/FileSystemTests.cs
src/libraries/System.Collections.Specialized/tests/BitVector32Tests.cs
src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/SettingElementTests.cs
src/libraries/System.Data.OleDb/tests/OleDbDataAdapterTests.cs
src/libraries/System.Diagnostics.DiagnosticSource/tests/HttpHandlerDiagnosticListenerTests.cs
src/libraries/System.Diagnostics.EventLog/tests/System/Diagnostics/Reader/ProviderMetadataTests.cs
src/libraries/System.IO.Pipelines/tests/PipePoolTests.nonnetstandard.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/UdpClientTest.cs
src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.RuntimeOnly.cs
src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs
src/libraries/System.Reflection.MetadataLoadContext/tests/src/Tests/TypeInfoFromProjectN/TypeInfo_PropertyTests.cs
src/libraries/System.Reflection/tests/AssemblyNameTests.cs
src/libraries/System.Reflection/tests/MethodInfoTests.cs
src/libraries/System.Runtime.Extensions/tests/System/Environment.GetEnvironmentVariable.cs
src/libraries/System.Runtime.Serialization.Formatters/tests/BinaryFormatterTests.cs
src/libraries/System.Runtime.Serialization.Json/tests/DataContractJsonSerializer.cs
src/libraries/System.Text.Json/tests/Serialization/ExtensionDataTests.cs

index 8494e21..b74e574 100644 (file)
@@ -80,7 +80,6 @@
     <Rule Id="xUnit1024" Action="None" /> <!-- Test methods cannot have overloads -->
     <Rule Id="xUnit1026" Action="None" /> <!-- Theory methods should use all of their parameters -->
     <Rule Id="xUnit2000" Action="None" /> <!-- Constants and literals should be the expected argument -->
-    <Rule Id="xUnit2002" Action="None" /> <!-- Do not use null check on value type -->
     <Rule Id="xUnit2005" Action="None" /> <!-- Do not use identity check on value type -->
     <Rule Id="xUnit2006" Action="None" /> <!-- Do not use invalid string equality check -->
     <Rule Id="xUnit2009" Action="None" /> <!-- Do not use boolean check to check for substrings -->
index d011d79..774137f 100644 (file)
@@ -6,6 +6,7 @@ using System;
 using System.Linq;
 using Microsoft.DotNet.RemoteExecutor;
 using Xunit;
+using Xunit.Sdk;
 
 namespace Microsoft.VisualBasic.Tests
 {
@@ -723,7 +724,15 @@ namespace Microsoft.VisualBasic.Tests
             {
                 ex = e;
             }
-            Assert.NotNull(ex?.GetType() == typeof(TException));
+            if (ex == null)
+            {
+                throw new ThrowsException(typeof(TException));
+            }
+            
+            if (ex.GetType() != typeof(TException))
+            {
+                throw new ThrowsException(typeof(TException), ex);
+            }
         }
     }
 }
index 9b00139..af687cb 100644 (file)
@@ -133,12 +133,10 @@ namespace System.Collections.Specialized.Tests
         public static void Constructor_DefaultTest()
         {
             BitVector32 bv = new BitVector32();
-            Assert.NotNull(bv);
             Assert.Equal(0, bv.Data);
 
             // Copy constructor results in item with same data.
             BitVector32 copied = new BitVector32(bv);
-            Assert.NotNull(bv);
             Assert.Equal(0, copied.Data);
         }
 
@@ -163,12 +161,10 @@ namespace System.Collections.Specialized.Tests
         public static void Constructor_DataTest(int data)
         {
             BitVector32 bv = new BitVector32(data);
-            Assert.NotNull(bv);
             Assert.Equal(data, bv.Data);
 
             // Copy constructor results in item with same data.
             BitVector32 copied = new BitVector32(bv);
-            Assert.NotNull(bv);
             Assert.Equal(data, copied.Data);
         }
 
index f34e19f..96df31b 100644 (file)
@@ -74,7 +74,6 @@ namespace System.Configuration.Tests
                     }
                 }
             };
-            Assert.NotNull(Element.GetHashCode());
         }
     }
 }
index 469dbb2..335fb6e 100644 (file)
@@ -144,7 +144,7 @@ namespace System.Data.OleDb.Tests
                         }
                         else
                         {
-                            Assert.NotNull(adapter.Fill(ds, tableName));
+                            Assert.InRange(adapter.Fill(ds, tableName), 0, int.MaxValue);
                         }
                     }
                 };
index c199912..0783db3 100644 (file)
@@ -315,7 +315,7 @@ namespace System.Diagnostics.Tests
                 HttpWebRequest stopRequest = ReadPublicProperty<HttpWebRequest>(stopEvent.Value, "Request");
                 Assert.Equal(startRequest, stopRequest);
                 HttpStatusCode status = ReadPublicProperty<HttpStatusCode>(stopEvent.Value, "StatusCode");
-                Assert.NotNull(status);
+                Assert.Equal(HttpStatusCode.OK, status);
 
                 WebHeaderCollection headers = ReadPublicProperty<WebHeaderCollection>(stopEvent.Value, "Headers");
                 Assert.NotNull(headers);
index d99c383..c027828 100644 (file)
@@ -99,7 +99,6 @@ namespace System.Diagnostics.Tests
                             foreach (var keyword in providerMetadata.Keywords)
                             {
                                 Assert.NotEmpty(keyword.Name);
-                                Assert.NotNull(keyword.Value);
                             }
                             foreach (var logLink in providerMetadata.LogLinks)
                             {
index fd4a81e..946bfc5 100644 (file)
@@ -36,7 +36,6 @@ namespace System.IO.Pipelines.Tests
             var endSegment = (BufferSegment)end;
 
             Assert.Same(startSegment, endSegment);
-            Assert.NotNull(startSegment.Memory);
             Assert.IsType<byte[]>(startSegment.MemoryOwner);
 
             pipe.Reader.AdvanceTo(result.Buffer.End);
index 5268baa..e7d3257 100644 (file)
@@ -2001,7 +2001,6 @@ namespace System.Net.Sockets.Tests
                 Assert.Equal(connectTo.MapToIPv6(), remoteEndPoint.Address);
 
                 Assert.Equal(SocketFlags.None, socketFlags);
-                Assert.NotNull(ipPacketInformation);
 
                 Assert.Equal(connectTo, ipPacketInformation.Address);
             }
@@ -2173,7 +2172,6 @@ namespace System.Net.Sockets.Tests
                 Assert.Equal(connectTo.MapToIPv6(), remoteEndPoint.Address);
 
                 Assert.Equal(SocketFlags.None, socketFlags);
-                Assert.NotNull(ipPacketInformation);
                 Assert.Equal(connectTo, ipPacketInformation.Address);
             }
         }
@@ -2345,7 +2343,6 @@ namespace System.Net.Sockets.Tests
                 Assert.Equal(connectTo.MapToIPv6(), remoteEndPoint.Address);
 
                 Assert.Equal(SocketFlags.None, args.SocketFlags);
-                Assert.NotNull(args.ReceiveMessageFromPacketInfo);
                 Assert.Equal(connectTo, args.ReceiveMessageFromPacketInfo.Address);
             }
         }
index c0d53e7..bcbe5a7 100644 (file)
@@ -618,7 +618,6 @@ namespace System.Net.Sockets.Tests
                 }
 
                 UdpReceiveResult result = await receiver.ReceiveAsync();
-                Assert.NotNull(result);
                 Assert.NotNull(result.RemoteEndPoint);
                 Assert.NotNull(result.Buffer);
                 Assert.InRange(result.Buffer.Length, 1, int.MaxValue);
@@ -639,7 +638,6 @@ namespace System.Net.Sockets.Tests
                 }
 
                 UdpReceiveResult result = await receiver.ReceiveAsync();
-                Assert.NotNull(result);
                 Assert.NotNull(result.RemoteEndPoint);
                 Assert.NotNull(result.Buffer);
                 Assert.InRange(result.Buffer.Length, 1, int.MaxValue);
index 4bdfe4e..c2d960d 100644 (file)
@@ -1994,7 +1994,6 @@ public static partial class XmlSerializerTests
         var getDataRequestBodyValue = 3;
         var getDataRequestBodyActual = RoundTripWithXmlMembersMapping<int>(getDataRequestBodyValue, memberName, "<?xml version=\"1.0\"?>\r\n<value xmlns=\"http://tempuri.org/\">3</value>");
 
-        Assert.NotNull(getDataRequestBodyActual);
         Assert.Equal(getDataRequestBodyValue, getDataRequestBodyActual);
     }
 
@@ -2434,7 +2433,6 @@ public static partial class XmlSerializerTests
         var getDataRequestBodyValue = 3;
         var getDataRequestBodyActual = RoundTripWithXmlMembersMappingSoap<int>(getDataRequestBodyValue, memberName, "<?xml version=\"1.0\"?>\r\n<int d1p1:type=\"int\" xmlns:d1p1=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.w3.org/2001/XMLSchema\">3</int>");
 
-        Assert.NotNull(getDataRequestBodyActual);
         Assert.Equal(getDataRequestBodyValue, getDataRequestBodyActual);
     }
 
@@ -2473,7 +2471,6 @@ public static partial class XmlSerializerTests
             "<?xml version=\"1.0\"?>\r\n<q1:wrapper xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:q1=\"http://tempuri.org/\">\r\n  <value xsi:type=\"xsd:int\">3</value>\r\n</q1:wrapper>",
             wrapperName: "wrapper");
 
-        Assert.NotNull(getDataRequestBodyActual);
         Assert.Equal(getDataRequestBodyValue, getDataRequestBodyActual);
     }
 
@@ -2488,7 +2485,6 @@ public static partial class XmlSerializerTests
             wrapperName: "wrapper",
             validate: true);
 
-        Assert.NotNull(getDataRequestBodyActual);
         Assert.Equal(getDataRequestBodyValue, getDataRequestBodyActual);
     }
 
index 44d530c..bbe1df4 100644 (file)
@@ -712,7 +712,6 @@ string.Format(@"<?xml version=""1.0"" encoding=""utf-8""?>
         using (StringReader reader = new StringReader(xml))
         {
             TimeSpan deserializedObj = (TimeSpan)serializer.Deserialize(reader);
-            Assert.NotNull(deserializedObj);
             Assert.Equal(default(TimeSpan), deserializedObj);
         }
     }
index a6dce92..00cb546 100644 (file)
@@ -81,7 +81,7 @@ namespace System.Reflection.Tests
             TypeInfo ti = t.GetTypeInfo();
 
             Guid myguid = ti.GUID;
-            Assert.NotNull(myguid);
+            Assert.NotEqual(Guid.Empty, myguid);
         }
 
         // Verify HasElementType
index 3b8d3d8..def1072 100644 (file)
@@ -292,7 +292,7 @@ namespace System.Reflection.Tests
         public void Flags_CurrentlyExecutingAssembly()
         {
             AssemblyName assemblyName = Helpers.ExecutingAssembly.GetName();
-            Assert.NotNull(assemblyName.Flags);
+            Assert.NotEqual(AssemblyNameFlags.None, assemblyName.Flags);
         }
 
         [Theory]
index ec8c728..99f19e9 100644 (file)
@@ -384,7 +384,7 @@ namespace System.Reflection.Tests
         {
             MethodInfo methodInfo = GetMethod(typeof(MI_SubClass), "ReturnVoidMethod");
             MethodAttributes attributes = methodInfo.Attributes;
-            Assert.NotNull(attributes);
+            Assert.True(attributes.HasFlag(MethodAttributes.Public));
         }
 
         [Fact]
@@ -392,7 +392,7 @@ namespace System.Reflection.Tests
         {
             MethodInfo methodInfo = GetMethod(typeof(MI_SubClass), "ReturnVoidMethod");
             CallingConventions callingConvention = methodInfo.CallingConvention;
-            Assert.NotNull(callingConvention);
+            Assert.True(callingConvention.HasFlag(CallingConventions.HasThis));
         }
 
         [Theory]
index 0d12a32..39ede89 100644 (file)
@@ -237,7 +237,7 @@ namespace System.Tests
                 IDictionaryEnumerator enumerator = results.GetEnumerator();
                 while (enumerator.MoveNext())
                 {
-                    Assert.NotNull(enumerator.Entry);
+                    Assert.NotNull(enumerator.Entry.Key);
                 }
 
                 if (lookForSetValue)
index bc59e17..ffe0ea8 100644 (file)
@@ -339,7 +339,6 @@ namespace System.Runtime.Serialization.Formatters.Tests
             f.Binder = binder;
             Assert.Same(binder, f.Binder);
 
-            Assert.NotNull(f.Context);
             Assert.Null(f.Context.Context);
             Assert.Equal(StreamingContextStates.All, f.Context.State);
             var context = new StreamingContext(StreamingContextStates.Clone);
index 5d925d9..e98760a 100644 (file)
@@ -1016,7 +1016,6 @@ public static partial class DataContractJsonSerializerTests
         var x = new KeyValuePair<string, object>("key1", "key1value");
 
         var y = SerializeAndDeserialize<KeyValuePair<string, object>>(x, @"{""key"":""key1"",""value"":""key1value""}");
-        Assert.NotNull(y);
         Assert.StrictEqual(y.Key, "key1");
         Assert.StrictEqual(y.Value, "key1value");
     }
@@ -2468,7 +2467,6 @@ public static partial class DataContractJsonSerializerTests
                 },
             };
             var actual = SerializeAndDeserialize(original, null, dcjsSettings, null, true);
-            Assert.NotNull(actual);
             Assert.Equal(original, actual);
         }
     }
@@ -2512,7 +2510,6 @@ public static partial class DataContractJsonSerializerTests
             };
             var original = DateTime.Now;
             var actual = SerializeAndDeserialize(original, null, dcjsSettings, null, true);
-            Assert.NotNull(actual);
             Assert.Equal(original, actual);
         }
     }
@@ -2593,7 +2590,6 @@ public static partial class DataContractJsonSerializerTests
         var graph = new DateTimeOffset(2008, 5, 1, 8, 6, 32, new TimeSpan(1, 0, 0));
         dcjsSettings = new DataContractJsonSerializerSettings() { DateTimeFormat = jsonTypes.DTF_DMMMM };
         var actual3 = SerializeAndDeserialize(graph, "{\"DateTime\":\"1, mayo\",\"OffsetMinutes\":60}", dcjsSettings);
-        Assert.NotNull(actual3);
         var expected3 = new DateTimeOffset(DateTime.Now.Year, 5, 1, 0, 0, 0, new TimeSpan(1, 0, 0));
         Assert.True(actual3 == expected3, 
             $"{nameof(actual3)} was not as expected.\r\nExpected: {expected3} \r\n Actual: {actual3}");
@@ -2621,7 +2617,6 @@ public static partial class DataContractJsonSerializerTests
         expectedOutput = string.Format("\"{0}\"", expectedOutput);
         dcjsSettings = new DataContractJsonSerializerSettings() { DateTimeFormat = jsonTypes.DTF_DefaultFormatProviderIsDateTimeFormatInfoDotCurrentInfo };
         var actual6 = SerializeAndDeserialize(dateTime, expectedOutput, dcjsSettings);
-        Assert.NotNull(actual6);
         Assert.True(actual6 == dateTime);
     }
 
@@ -2639,7 +2634,6 @@ public static partial class DataContractJsonSerializerTests
             KnownTypes = new List<Type>()
         };
         var actual = SerializeAndDeserialize(dateTime, expectedString, dcjsSettings);
-        Assert.NotNull(actual);
         Assert.True(actual == dateTime);
 
         dcjsSettings = new DataContractJsonSerializerSettings()
@@ -2652,7 +2646,6 @@ public static partial class DataContractJsonSerializerTests
         string actualam = GetAmString(jsonTypes.DTF_hmsFt);
         string baseline = $"\"03:58:32.00 {actualam}\"";
         var actual2 = SerializeAndDeserialize(new DateTime(1, 1, 1, 3, 58, 32), baseline, dcjsSettings);
-        Assert.NotNull(actual2);
         Assert.True(actual2 == new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 3, 58, 32));
 
         dcjsSettings = new DataContractJsonSerializerSettings()
@@ -2664,7 +2657,6 @@ public static partial class DataContractJsonSerializerTests
         };
         var value3 = new DateTime(DateTime.Now.Year, 12, 20);
         var actual3 = SerializeAndDeserialize(value3, "\"20, diciembre\"", dcjsSettings);
-        Assert.NotNull(actual3);
         Assert.Equal(value3, actual3);
 
         dcjsSettings = new DataContractJsonSerializerSettings()
@@ -2676,7 +2668,6 @@ public static partial class DataContractJsonSerializerTests
         };
         var value4 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 32);
         var actual4 = SerializeAndDeserialize(value4, "\"32\"", dcjsSettings);
-        Assert.NotNull(actual4);
         Assert.Equal(value4, actual4);
 
         dcjsSettings = new DataContractJsonSerializerSettings()
@@ -2688,7 +2679,6 @@ public static partial class DataContractJsonSerializerTests
         };
         var value5 = new DateTime(1998, 1, 1);
         var actual5 = SerializeAndDeserialize(value5, "\"1998 A.D.\"", dcjsSettings);
-        Assert.NotNull(actual5);
         Assert.Equal(value5, actual5);
 
         dcjsSettings = new DataContractJsonSerializerSettings()
@@ -2700,7 +2690,6 @@ public static partial class DataContractJsonSerializerTests
         };
         var value6 = new DateTime(1998, 1, 1, 8, 25, 32, DateTimeKind.Utc);
         var actual6 = SerializeAndDeserialize(value6, "\"1998-01-01T08:25:32.000Z\"", dcjsSettings);
-        Assert.NotNull(actual6);
         Assert.Equal(value6, actual6);
     }
 
index d78d3f0..cd847c5 100644 (file)
@@ -42,7 +42,6 @@ namespace System.Text.Json.Serialization.Tests
             void Verify()
             {
                 Assert.NotNull(obj.MyOverflow);
-                Assert.NotNull(obj.MyOverflow["MyIntMissing"]);
                 Assert.Equal(1, obj.MyInt);
                 Assert.Equal(2, obj.MyOverflow["MyIntMissing"].GetInt32());