Enable xunit2015 analyzer (dotnet/corefx#39714)
authorViktor Hofer <viktor.hofer@microsoft.com>
Wed, 24 Jul 2019 11:25:58 +0000 (13:25 +0200)
committerStephen Toub <stoub@microsoft.com>
Wed, 24 Jul 2019 11:25:58 +0000 (07:25 -0400)
Commit migrated from https://github.com/dotnet/corefx/commit/a7fa4b58be0b266d8fe680de34f9b1a3dab8523a

src/libraries/CodeAnalysis.ruleset
src/libraries/System.Collections.Immutable/tests/ImmutableArrayBuilderTest.cs
src/libraries/System.ComponentModel.TypeConverter/tests/EventDescriptorTests.cs
src/libraries/System.IO.Ports/tests/SerialStream/SetLength.cs
src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs
src/libraries/System.Runtime.Loader/tests/DefaultContext/DefaultLoadContextTest.cs
src/libraries/System.ServiceModel.Syndication/tests/BasicScenarioTests.cs

index a4dc8ba..df36d7d 100644 (file)
@@ -95,7 +95,6 @@
     <Rule Id="xUnit2009" Action="None" />
     <Rule Id="xUnit2012" Action="None" />
     <Rule Id="xUnit2013" Action="None" />
-    <Rule Id="xUnit2015" Action="None" />
     <Rule Id="xUnit2017" Action="None" />
     <Rule Id="xUnit2018" Action="None" />
   </Rules>
index 7dc1c37..165396b 100644 (file)
@@ -691,7 +691,7 @@ namespace System.Collections.Immutable.Tests
             var builder = ImmutableArray.CreateBuilder<int>(initialCapacity: 10);
             builder.Add(1);
             builder.Add(1);
-            Assert.Throws(typeof(ArgumentException), () => builder.Capacity = 1);
+            Assert.Throws<ArgumentException>(() => builder.Capacity = 1);
         }
 
         [Fact]
index ee9bfb3..4a347fc 100644 (file)
@@ -35,7 +35,7 @@ namespace System.ComponentModel.Tests
             eventDescriptor.RemoveEventHandler(component, eventHandler);
 
             // component.Event should now have no handler => raising it should throw a NullReferenceException
-            Assert.Throws(typeof(NullReferenceException), () => component.RaiseEvent());
+            Assert.Throws<NullReferenceException>(() => component.RaiseEvent());
         }
 
         [Fact]
index 60aaed6..c959b04 100644 (file)
@@ -14,8 +14,6 @@ namespace System.IO.Ports.Tests
         private const int DEFAULT_VALUE = 0;
         private const int BAD_VALUE = -1;
 
-        #region Test Cases
-
         [ConditionalFact(nameof(HasOneSerialPort))]
         public void SetLength_Open_Close()
         {
@@ -27,7 +25,7 @@ namespace System.IO.Ports.Tests
 
                 Debug.WriteLine("Verifying SetLength property throws exception After Open() then Close()");
 
-                Assert.Throws(typeof(NotSupportedException), () => serialStream.SetLength(DEFAULT_VALUE));
+                Assert.Throws<NotSupportedException>(() => serialStream.SetLength(DEFAULT_VALUE));
             }
         }
 
@@ -42,7 +40,7 @@ namespace System.IO.Ports.Tests
 
                 Debug.WriteLine("Verifying SetLength property throws exception After Open() then BaseStream.Close()");
 
-                Assert.Throws(typeof(NotSupportedException), () => serialStream.SetLength(DEFAULT_VALUE));
+                Assert.Throws<NotSupportedException>(() => serialStream.SetLength(DEFAULT_VALUE));
             }
         }
 
@@ -54,7 +52,7 @@ namespace System.IO.Ports.Tests
                 com.Open();
                 Debug.WriteLine("Verifying SetLength method throws exception after a call to Open()");
 
-                Assert.Throws(typeof(NotSupportedException), () => com.BaseStream.SetLength(DEFAULT_VALUE));
+                Assert.Throws<NotSupportedException>(() => com.BaseStream.SetLength(DEFAULT_VALUE));
             }
         }
 
@@ -67,14 +65,8 @@ namespace System.IO.Ports.Tests
 
                 Debug.WriteLine("Verifying SetLength method throws exception with a bad value after a call to Open()");
 
-                Assert.Throws(typeof(NotSupportedException), () => com.BaseStream.SetLength(BAD_VALUE));
+                Assert.Throws<NotSupportedException>(() => com.BaseStream.SetLength(BAD_VALUE));
             }
         }
-
-        #endregion
-
-        #region Verification for Test Cases
-
-        #endregion
     }
 }
\ No newline at end of file
index c925ac6..9b642f6 100644 (file)
@@ -35,15 +35,13 @@ namespace System.Runtime.Loader.Tests
         [Fact]
         public static void GetAssemblyNameTest_AssemblyNotFound()
         {            
-            Assert.Throws(typeof(FileNotFoundException), 
-                () => AssemblyLoadContext.GetAssemblyName("Non.Existing.Assembly.dll"));
+            Assert.Throws<FileNotFoundException>(() => AssemblyLoadContext.GetAssemblyName("Non.Existing.Assembly.dll"));
         }
 
         [Fact]
         public static void GetAssemblyNameTest_NullParameter()
         {               
-            Assert.Throws(typeof(ArgumentNullException), 
-                () => AssemblyLoadContext.GetAssemblyName(null));
+            Assert.Throws<ArgumentNullException>(() => AssemblyLoadContext.GetAssemblyName(null));
         }
 
         [Fact]
@@ -79,8 +77,7 @@ namespace System.Runtime.Loader.Tests
             var loadContext = new ResourceAssemblyLoadContext();
             loadContext.LoadBy = LoadBy.Path;
 
-            Assert.Throws(typeof(FileNotFoundException), 
-                () => loadContext.LoadFromAssemblyName(asmName));
+            Assert.Throws<FileNotFoundException>(() => loadContext.LoadFromAssemblyName(asmName));
         }
 
         [Fact]
index 36a82f2..5853cb7 100644 (file)
@@ -90,7 +90,7 @@ namespace System.Runtime.Loader.Tests
             var assemblyName = new AssemblyName(TestAssemblyName);
 
             // By default, the assembly should not be found in DefaultContext at all
-            Assert.Throws(typeof(FileNotFoundException), () => Assembly.Load(assemblyName));
+            Assert.Throws<FileNotFoundException>(() => Assembly.Load(assemblyName));
 
             // Create a secondary load context and wireup its resolving event
             SecondaryLoadContext slc = new SecondaryLoadContext();
@@ -179,8 +179,7 @@ namespace System.Runtime.Loader.Tests
         public static void LoadNonExistentInDefaultContext()
         {
             // Now, try to load an assembly that does not exist
-            Assert.Throws(typeof(FileNotFoundException), 
-                () => AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName("System.Runtime.Loader.NonExistent.Assembly")));
+            Assert.Throws<FileNotFoundException>(() => AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName("System.Runtime.Loader.NonExistent.Assembly")));
         }
 
         private void DefaultContextFallback()
index a9e2c2e..0b61f12 100644 (file)
@@ -408,7 +408,7 @@ namespace System.ServiceModel.Syndication.Tests
             string file = "TestFeeds/FailureFeeds/diff_atom_ns.xml";
             using (XmlReader reader = XmlReader.Create(file))
             {
-                Assert.Throws(typeof(XmlException), () => { SyndicationItem.Load(reader); });
+                Assert.Throws<XmlException>(() => { SyndicationItem.Load(reader); });
             }
         }
 
@@ -418,7 +418,7 @@ namespace System.ServiceModel.Syndication.Tests
             string file = "TestFeeds/FailureFeeds/diff_rss_ns.xml";
             using (XmlReader reader = XmlReader.Create(file))
             {
-                Assert.Throws(typeof(XmlException), () => { SyndicationItem.Load(reader); });
+                Assert.Throws<XmlException>(() => { SyndicationItem.Load(reader); });
             }
         }
 
@@ -428,7 +428,7 @@ namespace System.ServiceModel.Syndication.Tests
             string file = "TestFeeds/FailureFeeds/diff_rss_version.xml";
             using (XmlReader reader = XmlReader.Create(file))
             {
-                Assert.Throws(typeof(XmlException), () => { SyndicationItem.Load(reader); });
+                Assert.Throws<XmlException>(() => { SyndicationItem.Load(reader); });
             }
         }
 
@@ -438,7 +438,7 @@ namespace System.ServiceModel.Syndication.Tests
             string file = "TestFeeds/FailureFeeds/no_rss_version.xml";
             using (XmlReader reader = XmlReader.Create(file))
             {
-                Assert.Throws(typeof(XmlException), () => { SyndicationItem.Load(reader); });
+                Assert.Throws<XmlException>(() => { SyndicationItem.Load(reader); });
             }
         }