Enable xunit2007 analyzer (dotnet/corefx#39740)
authorViktor Hofer <viktor.hofer@microsoft.com>
Thu, 25 Jul 2019 02:03:09 +0000 (04:03 +0200)
committerStephen Toub <stoub@microsoft.com>
Thu, 25 Jul 2019 02:03:09 +0000 (22:03 -0400)
Commit migrated from https://github.com/dotnet/corefx/commit/619f140e2f0e722a17f3797d532b21ace774ec2e

23 files changed:
src/libraries/CodeAnalysis.ruleset
src/libraries/System.Collections.Immutable/tests/ImmutableSortedDictionaryTest.cs
src/libraries/System.ComponentModel.TypeConverter/tests/TypeDescriptorTests.cs
src/libraries/System.Composition.TypedParts/tests/ContainerConfigurationTests.cs
src/libraries/System.Composition.TypedParts/tests/ReflectionTests.cs
src/libraries/System.Composition/tests/CircularityTests.cs
src/libraries/System.Composition/tests/DictionaryImportTests.cs
src/libraries/System.Composition/tests/DiscoveryTests.cs
src/libraries/System.Composition/tests/ExportFactoryTests.cs
src/libraries/System.Composition/tests/LazyTests.cs
src/libraries/System.Composition/tests/LightContainerTests.cs
src/libraries/System.Composition/tests/MetadataConstraintTests.cs
src/libraries/System.Composition/tests/OpenGenericsTests.cs
src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestUtilities.cs
src/libraries/System.Globalization/tests/CultureInfo/CultureInfoCalendar.cs
src/libraries/System.IO.Packaging/tests/Tests.cs
src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CurrentUserOnly.netcoreapp.Windows.cs
src/libraries/System.Runtime.CompilerServices.Unsafe/tests/UnsafeTests.cs
src/libraries/System.Runtime.Serialization.Formatters/tests/SerializationGuardTests.cs
src/libraries/System.Security.Cryptography.Algorithms/tests/CryptoConfigTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/PfxTests.cs
src/libraries/System.Security.Cryptography.X509Certificates/tests/PublicKeyTests.cs
src/libraries/System.Text.Json/tests/Serialization/SpanTests.cs

index f3c5d72..efd527f 100644 (file)
@@ -86,7 +86,6 @@
     <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="xUnit2007" Action="None" /> <!-- Do not use typeof expression to check the type -->
     <Rule Id="xUnit2009" Action="None" /> <!-- Do not use boolean check to check for substrings -->
     <Rule Id="xUnit2013" Action="None" /> <!-- Do not use equality check to check for collection size. -->
     <Rule Id="xUnit2017" Action="None" /> <!-- Do not use Contains() to check if a value exists in a collection -->
index 5991d82..e33c957 100644 (file)
@@ -107,7 +107,7 @@ namespace System.Collections.Immutable.Tests
         {
             var sortedMap = Empty<int, GenericParameterHelper>().AddRange(Enumerable.Range(1, 100).Select(n => new KeyValuePair<int, GenericParameterHelper>(n, new GenericParameterHelper(n))));
             var unsortedMap = sortedMap.ToImmutableDictionary();
-            Assert.IsAssignableFrom(typeof(ImmutableDictionary<int, GenericParameterHelper>), unsortedMap);
+            Assert.IsAssignableFrom<ImmutableDictionary<int, GenericParameterHelper>>(unsortedMap);
             Assert.Equal(sortedMap.Count, unsortedMap.Count);
             Assert.Equal<KeyValuePair<int, GenericParameterHelper>>(sortedMap.ToList(), unsortedMap.ToList());
         }
index 531e9a5..d372e24 100644 (file)
@@ -50,7 +50,7 @@ namespace System.ComponentModel.Tests
             var component = TypeDescriptor.CreateInstance(null, typeof(DescriptorTestComponent), new[] { expectedString.GetType() }, new[] { expectedString });
 
             Assert.NotNull(component);
-            Assert.IsType(typeof(DescriptorTestComponent), component);
+            Assert.IsType<DescriptorTestComponent>(component);
             Assert.Equal(expectedString, (component as DescriptorTestComponent).StringProperty);
         }
 
index d1581d0..b6c338d 100644 (file)
@@ -329,7 +329,7 @@ namespace System.Composition.Hosting.Tests
                 .CreateContainer();
 
             DerivedFromBaseWithImport export = container.GetExport<DerivedFromBaseWithImport>();
-            Assert.IsAssignableFrom(typeof(Imported), export.Imported);
+            Assert.IsAssignableFrom<Imported>(export.Imported);
         }
 
         public class Imported { }
index 054c877..ac8d08c 100644 (file)
@@ -76,12 +76,12 @@ namespace System.Composition.TypedParts.Tests
         {
             CompositionContext cc = CreateContainer(typeof(A), typeof(B), typeof(C), typeof(D));
             D d = cc.GetExport<D>();
-            Assert.IsAssignableFrom(typeof(A), d.A);
-            Assert.IsAssignableFrom(typeof(B), d.B);
-            Assert.IsAssignableFrom(typeof(A), d.B.A);
-            Assert.IsAssignableFrom(typeof(C), d.C);
-            Assert.IsAssignableFrom(typeof(A), d.C.A);
-            Assert.IsAssignableFrom(typeof(B), d.C.B);
+            Assert.IsAssignableFrom<A>(d.A);
+            Assert.IsAssignableFrom<B>(d.B);
+            Assert.IsAssignableFrom<A>(d.B.A);
+            Assert.IsAssignableFrom<C>(d.C);
+            Assert.IsAssignableFrom<A>(d.C.A);
+            Assert.IsAssignableFrom<B>(d.C.B);
         }
 
         private static CompositionContext CreateContainer(params Type[] types)
index 6b30491..616855e 100644 (file)
@@ -122,8 +122,8 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(ACircular), typeof(BLazy));
             var x = cc.GetExport<BLazy>();
-            Assert.IsAssignableFrom(typeof(ACircular), x.A.Value);
-            Assert.IsAssignableFrom(typeof(BLazy), ((ACircular)x.A.Value).B);
+            Assert.IsAssignableFrom<ACircular>(x.A.Value);
+            Assert.IsAssignableFrom<BLazy>(((ACircular)x.A.Value).B);
         }
 
         [Fact]
@@ -132,7 +132,7 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(ACircular), typeof(BLazy));
             var x = cc.GetExport<IA>();
-            Assert.IsAssignableFrom(typeof(BLazy), ((ACircular)((ACircular)x).B.A.Value).B);
+            Assert.IsAssignableFrom<BLazy>(((ACircular)((ACircular)x).B.A.Value).B);
         }
 
         [Fact]
index c6b0861..fa784e7 100644 (file)
@@ -76,8 +76,8 @@ namespace System.Composition.UnitTests
 
             var consumer = container.GetExport<Consumer>();
 
-            Assert.IsAssignableFrom(typeof(ValueA), consumer.Values["A"]);
-            Assert.IsAssignableFrom(typeof(ValueB), consumer.Values["B"]);
+            Assert.IsAssignableFrom<ValueA>(consumer.Values["A"]);
+            Assert.IsAssignableFrom<ValueB>(consumer.Values["B"]);
             Assert.Equal(2, consumer.Values.Count());
         }
 
index 05be7f5..dc22947 100644 (file)
@@ -46,7 +46,7 @@ namespace System.Composition.UnitTests
         {
             var container = CreateContainer(typeof(UnfairRule));
             var rule = container.GetExport<IRule>();
-            Assert.IsAssignableFrom(typeof(UnfairRule), rule);
+            Assert.IsAssignableFrom<UnfairRule>(rule);
         }
 
         [Fact]
@@ -55,7 +55,7 @@ namespace System.Composition.UnitTests
         {
             var container = CreateContainer(new ConventionBuilder(), typeof(UnfairRule));
             var rule = container.GetExport<IRule>();
-            Assert.IsAssignableFrom(typeof(UnfairRule), rule);
+            Assert.IsAssignableFrom<UnfairRule>(rule);
         }
 
         [Fact]
@@ -117,7 +117,7 @@ namespace System.Composition.UnitTests
         {
             var container = CreateContainer(typeof(HomeController), typeof(CloudBus));
             var hc = container.GetExport<HomeController>();
-            Assert.IsAssignableFrom(typeof(CloudBus), hc.Bus);
+            Assert.IsAssignableFrom<CloudBus>(hc.Bus);
         }
 
         private class CustomImportAttribute : ImportAttribute { }
index d8cf01c..9a6c420 100644 (file)
@@ -137,7 +137,7 @@ namespace System.Composition.UnitTests
             var cc = CreateContainer(typeof(A), typeof(UseExportFactory));
             var bef = cc.GetExport<UseExportFactory>();
             var a = bef.AFactory.CreateExport();
-            Assert.IsAssignableFrom(typeof(A), a.Value);
+            Assert.IsAssignableFrom<A>(a.Value);
             Assert.False(((A)a.Value).IsDisposed);
             a.Dispose();
             Assert.True(((A)a.Value).IsDisposed);
index 3004def..ccc2935 100644 (file)
@@ -41,7 +41,7 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(A), typeof(BLazy));
             var x = cc.GetExport<BLazy>();
-            Assert.IsAssignableFrom(typeof(A), x.A.Value);
+            Assert.IsAssignableFrom<A>(x.A.Value);
         }
 
         [Fact]
index c8a34c8..6cb9a74 100644 (file)
@@ -59,7 +59,7 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(A));
             var x = cc.GetExport<IA>();
-            Assert.IsAssignableFrom(typeof(A), x);
+            Assert.IsAssignableFrom<A>(x);
         }
 
         [Fact]
@@ -78,7 +78,7 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(A), typeof(B));
             var x = cc.GetExport<B>();
-            Assert.IsAssignableFrom(typeof(A), x.A);
+            Assert.IsAssignableFrom<A>(x.A);
         }
 
         [Fact]
@@ -112,7 +112,7 @@ namespace System.Composition.UnitTests
             rb.ForType<HasPropertyA>().ImportProperty(a => a.A).Export();
             var cc = CreateContainer(rb, typeof(HasPropertyA), typeof(A));
             var x = cc.GetExport<HasPropertyA>();
-            Assert.IsAssignableFrom(typeof(A), x.A);
+            Assert.IsAssignableFrom<A>(x.A);
         }
 
         [Fact]
index 915b034..43472cb 100644 (file)
@@ -92,7 +92,7 @@ namespace System.Composition.UnitTests
         {
             var c = CreateContainer(typeof(Presenter), typeof(Controller));
             var ctrl = c.GetExport<Controller>();
-            Assert.IsAssignableFrom(typeof(Presenter), ctrl.Presenter);
+            Assert.IsAssignableFrom<Presenter>(ctrl.Presenter);
         }
     }
 }
index 27babe5..dc9b60d 100644 (file)
@@ -70,7 +70,7 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(BasicRepository<>));
             var r = cc.GetExport<IRepository<string>>();
-            Assert.IsAssignableFrom(typeof(BasicRepository<string>), r);
+            Assert.IsAssignableFrom<BasicRepository<string>>(r);
         }
 
         [Fact]
@@ -80,7 +80,7 @@ namespace System.Composition.UnitTests
             var cc = CreateContainer(typeof(BasicRepository<>));
             var r = cc.GetExport<IRepository<string>>();
             var r2 = cc.GetExport<IRepository<int>>();
-            Assert.IsAssignableFrom(typeof(BasicRepository<int>), r2);
+            Assert.IsAssignableFrom<BasicRepository<int>>(r2);
         }
 
         [Fact]
@@ -89,7 +89,7 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(RepositoryProperty<>));
             var r = cc.GetExport<IRepository<string>>();
-            Assert.IsAssignableFrom(typeof(BasicRepository<string>), r);
+            Assert.IsAssignableFrom<BasicRepository<string>>(r);
         }
 
         [Fact]
@@ -124,7 +124,7 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(FirstAndSecond<>));
             var first = cc.GetExport<IFirst<string>>();
-            Assert.IsAssignableFrom(typeof(FirstAndSecond<string>), first);
+            Assert.IsAssignableFrom<FirstAndSecond<string>>(first);
         }
 
         // In future, the set of allowable generic type mappings will be expanded (see
@@ -151,7 +151,7 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(ExportSelf<>));
             var es = cc.GetExport<ExportSelf<string>>();
-            Assert.IsAssignableFrom(typeof(ExportSelf<string>), es);
+            Assert.IsAssignableFrom<ExportSelf<string>>(es);
         }
 
         [Fact]
@@ -160,7 +160,7 @@ namespace System.Composition.UnitTests
         {
             var cc = CreateContainer(typeof(ExportsBase<>));
             var es = cc.GetExport<SomeGenericType<string>>();
-            Assert.IsAssignableFrom(typeof(ExportsBase<string>), es);
+            Assert.IsAssignableFrom<ExportsBase<string>>(es);
         }
     }
 }
index 423f138..19ca727 100644 (file)
@@ -72,7 +72,7 @@ namespace BasicEventSourceTests
             // EventListener will return the boxed value of the nullable, which will either be a value or null object reference
             else if (wrappedValue != null)
             {
-                Assert.IsType(typeof(T), wrappedValue);
+                Assert.IsType<T>(wrappedValue);
                 return (T?)wrappedValue;
             }
 
index 8ffaad3..4161332 100644 (file)
@@ -12,7 +12,7 @@ namespace System.Globalization.Tests
         public void Calendar_Get_InvariantInfo()
         {
             CultureInfo cultureInfo = CultureInfo.InvariantCulture;
-            Assert.IsType(typeof(GregorianCalendar), cultureInfo.Calendar);
+            Assert.IsType<GregorianCalendar>(cultureInfo.Calendar);
             Assert.Same(cultureInfo.Calendar, cultureInfo.Calendar);
         }
         
@@ -21,7 +21,7 @@ namespace System.Globalization.Tests
         {
             CultureInfo cultureInfo = CultureInfo.InvariantCulture;
             Assert.Equal(1, cultureInfo.OptionalCalendars.Length);
-            Assert.IsType(typeof(GregorianCalendar), cultureInfo.OptionalCalendars[0]);
+            Assert.IsType<GregorianCalendar>(cultureInfo.OptionalCalendars[0]);
         }
     }
 }
index db84296..12f8156 100644 (file)
@@ -3771,7 +3771,7 @@ namespace System.IO.Packaging.Tests
 
             Assert.NotNull(part);
             Assert.Equal(part.Uri, partUri);
-            Assert.IsType(typeof(MockPackagePart), part);
+            Assert.IsType<MockPackagePart>(part);
 
             // Validate we get the same object back if we call GetPart again
             Assert.Same(part, mockPackage.GetPart(partUri));
index 175cbb3..2d86095 100644 (file)
@@ -161,7 +161,7 @@ namespace System.IO.Pipes.Tests
                 // Server is expected to not have received any request.
                 cts.Cancel();
                 AggregateException e = Assert.Throws<AggregateException>(() => serverTask.Wait(10_000));
-                Assert.IsType(typeof(TaskCanceledException), e.InnerException);
+                Assert.IsType<TaskCanceledException>(e.InnerException);
             }
         }
 
index 6a17003..2ef31ed 100644 (file)
@@ -376,7 +376,7 @@ namespace System.Runtime.CompilerServices
         {
             // Verify that As does not perform type checks
             object o = new object();
-            Assert.IsType(typeof(object), Unsafe.As<string>(o));
+            Assert.IsType<object>(Unsafe.As<string>(o));
         }
 
         [Fact]
index 5479765..d02d81f 100644 (file)
@@ -74,7 +74,7 @@ namespace System.Runtime.Serialization.Formatters.Tests
 
             BinaryFormatter reader = new BinaryFormatter();
             TargetInvocationException tie = Assert.Throws<TargetInvocationException>(() => reader.Deserialize(ms));
-            Assert.IsAssignableFrom(typeof(SerializationException), tie.InnerException);
+            Assert.IsAssignableFrom<SerializationException>(tie.InnerException);
         }
     }
 
index ac88fef..858d03d 100644 (file)
@@ -301,7 +301,7 @@ namespace System.Security.Cryptography.CryptoConfigTests
             // Valid case
             object obj = CryptoConfig.CreateFromName(className, "Hello");
             Assert.NotNull(obj);
-            Assert.IsType(typeof(ClassWithCtorArguments), obj);
+            Assert.IsType<ClassWithCtorArguments>(obj);
 
             ClassWithCtorArguments ctorObj = (ClassWithCtorArguments)obj;
             Assert.Equal("Hello", ctorObj.MyString);
@@ -374,7 +374,7 @@ namespace System.Security.Cryptography.CryptoConfigTests
         {
             object obj = CryptoConfig.CreateFromName(name);
             Assert.NotNull(obj);
-            Assert.IsType(typeof(TExpected), obj);
+            Assert.IsType<TExpected>(obj);
         }
 
         public class ClassWithCtorArguments
index 782f78e..3863664 100644 (file)
@@ -125,7 +125,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                 AsymmetricAlgorithm alg = c.PrivateKey;
                 Assert.NotNull(alg);
                 Assert.Same(alg, c.PrivateKey);
-                Assert.IsAssignableFrom(typeof(RSA), alg);
+                Assert.IsAssignableFrom<RSA>(alg);
                 VerifyPrivateKey((RSA)alg);
 
                 // Currently unable to set PrivateKey
index 3db6d14..a5dd0a2 100644 (file)
@@ -85,7 +85,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                 Assert.Same(alg, pk.Key);
                 Assert.Equal(2048, alg.KeySize);
 
-                Assert.IsAssignableFrom(typeof(RSA), alg);
+                Assert.IsAssignableFrom<RSA>(alg);
                 VerifyKey_RSA( /* cert */ null, (RSA)alg);
             }
         }
@@ -100,7 +100,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests
                 Assert.Same(alg, pk.Key);
                 Assert.Equal(1024, alg.KeySize);
 
-                Assert.IsAssignableFrom(typeof(DSA), alg);
+                Assert.IsAssignableFrom<DSA>(alg);
                 VerifyKey_DSA((DSA)alg);
             }
         }
index a36c8e6..6640ea5 100644 (file)
@@ -21,7 +21,7 @@ namespace System.Text.Json.Serialization.Tests
         public static void Read(Type classType, byte[] data)
         {
             object obj = JsonSerializer.Deserialize(data, classType);
-            Assert.IsAssignableFrom(typeof(ITestClass), obj);
+            Assert.IsAssignableFrom<ITestClass>(obj);
             ((ITestClass)obj).Verify();
         }
 
@@ -34,7 +34,7 @@ namespace System.Text.Json.Serialization.Tests
                 stream,
                 classType).Result;
 
-            Assert.IsAssignableFrom(typeof(ITestClass), obj);
+            Assert.IsAssignableFrom<ITestClass>(obj);
             ((ITestClass)obj).Verify();
 
             // Try again with a smaller initial buffer size to ensure we handle incomplete data
@@ -44,7 +44,7 @@ namespace System.Text.Json.Serialization.Tests
                 classType,
                 new JsonSerializerOptions { DefaultBufferSize = 5 }).Result;
 
-            Assert.IsAssignableFrom(typeof(ITestClass), obj);
+            Assert.IsAssignableFrom<ITestClass>(obj);
             ((ITestClass)obj).Verify();
         }