Fix null reference exceptions in TypeConverter
authorHugh Bellamy <hughbellars@gmail.com>
Mon, 4 Feb 2019 19:51:38 +0000 (19:51 +0000)
committerDan Moseley <danmose@microsoft.com>
Sat, 2 Mar 2019 21:29:07 +0000 (13:29 -0800)
Commit migrated from https://github.com/dotnet/corefx/commit/a7d0e7b048a549fbce55831d60e19e0e36f33851

28 files changed:
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/AttributeCollection.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesignerCollection.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/DesigntimeLicenseContext.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/MenuCommand.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/Serialization/DesignerSerializerAttribute.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/Design/Serialization/RootDesignerSerializerAttribute.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/DesignerAttribute.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/EditorAttribute.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ExtenderProvidedPropertyAttribute.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/InstallerTypeAttribute.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/LicenseException.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ProvidePropertyAttribute.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/RefreshEventArgs.cs
src/libraries/System.ComponentModel.TypeConverter/src/System/ComponentModel/ToolboxItemAttribute.cs
src/libraries/System.ComponentModel.TypeConverter/tests/AttributeCollectionTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/Design/DesignerCollectionTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/Design/DesigntimeLicenseContextTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/Design/MenuCommandTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/Design/Serialization/DesignerSerializerAttributeTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/Design/Serialization/RootDesignerSerializerAttributeTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/DesignerAttributeTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/EditorAttributeTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/ExtenderProvidedPropertyAttributeTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/InstallerTypeAttributeTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/LicenseExceptionTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/ProvidePropertyAttributeTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/RefreshEventArgsTests.cs
src/libraries/System.ComponentModel.TypeConverter/tests/ToolboxItemAttributeTests.cs

index 377ed7d..135ec19 100644 (file)
@@ -54,7 +54,7 @@ namespace System.ComponentModel
             }
         }
 
-        protected AttributeCollection()
+        protected AttributeCollection() : this(Array.Empty<Attribute>())
         {
         }
 
index 88cf368..6ed3607 100644 (file)
@@ -37,7 +37,7 @@ namespace System.ComponentModel.Design
         /// </summary>
         public DesignerCollection(IList designers)
         {
-            _designers = designers;
+            _designers = designers ?? new ArrayList();
         }
 
         /// <summary>
index 1867975..7c9b959 100644 (file)
@@ -32,6 +32,11 @@ namespace System.ComponentModel.Design
         /// </summary>
         public override void SetSavedLicenseKey(Type type, string key)
         {
+            if (type == null)
+            {
+                throw new ArgumentNullException(nameof(type));
+            }
+
             _savedLicenseKeys[type.AssemblyQualifiedName] = key;
         }
     }
index 0f5d33d..193a336 100644 (file)
@@ -165,7 +165,7 @@ namespace System.ComponentModel.Design
         /// </summary>
         public override string ToString()
         {
-            string str = CommandID.ToString() + " : ";
+            string str = (CommandID?.ToString() ?? "") + " : ";
             if ((_status & SUPPORTED) != 0)
             {
                 str += "Supported";
index 2b86e5d..ab3d5ca 100644 (file)
@@ -19,6 +19,15 @@ namespace System.ComponentModel.Design.Serialization
         /// </summary>
         public DesignerSerializerAttribute(Type serializerType, Type baseSerializerType)
         {
+            if (serializerType == null)
+            {
+                throw new ArgumentNullException(nameof(serializerType));
+            }
+            if (baseSerializerType == null)
+            {
+                throw new ArgumentNullException(nameof(baseSerializerType));
+            }
+
             SerializerTypeName = serializerType.AssemblyQualifiedName;
             SerializerBaseTypeName = baseSerializerType.AssemblyQualifiedName;
         }
@@ -28,6 +37,11 @@ namespace System.ComponentModel.Design.Serialization
         /// </summary>
         public DesignerSerializerAttribute(string serializerTypeName, Type baseSerializerType)
         {
+            if (baseSerializerType == null)
+            {
+                throw new ArgumentNullException(nameof(baseSerializerType));
+            }
+
             SerializerTypeName = serializerTypeName;
             SerializerBaseTypeName = baseSerializerType.AssemblyQualifiedName;
         }
@@ -64,7 +78,7 @@ namespace System.ComponentModel.Design.Serialization
             {
                 if (_typeId == null)
                 {
-                    string baseType = SerializerBaseTypeName;
+                    string baseType = SerializerBaseTypeName ?? string.Empty;
                     int comma = baseType.IndexOf(',');
                     if (comma != -1)
                     {
index 4766508..560471b 100644 (file)
@@ -20,6 +20,15 @@ namespace System.ComponentModel.Design.Serialization
         /// </summary>
         public RootDesignerSerializerAttribute(Type serializerType, Type baseSerializerType, bool reloadable)
         {
+            if (serializerType == null)
+            {
+                throw new ArgumentNullException(nameof(serializerType));
+            }
+            if (baseSerializerType == null)
+            {
+                throw new ArgumentNullException(nameof(baseSerializerType));
+            }
+
             SerializerTypeName = serializerType.AssemblyQualifiedName;
             SerializerBaseTypeName = baseSerializerType.AssemblyQualifiedName;
             Reloadable = reloadable;
@@ -30,6 +39,11 @@ namespace System.ComponentModel.Design.Serialization
         /// </summary>
         public RootDesignerSerializerAttribute(string serializerTypeName, Type baseSerializerType, bool reloadable)
         {
+            if (baseSerializerType == null)
+            {
+                throw new ArgumentNullException(nameof(baseSerializerType));
+            }
+
             SerializerTypeName = serializerTypeName;
             SerializerBaseTypeName = baseSerializerType.AssemblyQualifiedName;
             Reloadable = reloadable;
@@ -75,7 +89,7 @@ namespace System.ComponentModel.Design.Serialization
             {
                 if (_typeId == null)
                 {
-                    string baseType = SerializerBaseTypeName;
+                    string baseType = SerializerBaseTypeName ?? string.Empty;
                     int comma = baseType.IndexOf(',');
                     if (comma != -1)
                     {
index bd9c5f6..b9e4fb2 100644 (file)
@@ -30,6 +30,11 @@ namespace System.ComponentModel
         /// </summary>
         public DesignerAttribute(Type designerType)
         {
+            if (designerType == null)
+            {
+                throw new ArgumentNullException(nameof(designerType));
+            }
+
             DesignerTypeName = designerType.AssemblyQualifiedName;
             DesignerBaseTypeName = typeof(IDesigner).FullName;
         }
@@ -50,7 +55,16 @@ namespace System.ComponentModel
         /// </summary>
         public DesignerAttribute(string designerTypeName, Type designerBaseType)
         {
-            DesignerTypeName = designerTypeName ?? throw new ArgumentNullException(nameof(designerTypeName));
+            if (designerTypeName == null)
+            {
+                throw new ArgumentNullException(nameof(designerTypeName));
+            }
+            if (designerBaseType == null)
+            {
+                throw new ArgumentNullException(nameof(designerBaseType));
+            }
+
+            DesignerTypeName = designerTypeName;
             DesignerBaseTypeName = designerBaseType.AssemblyQualifiedName;
         }
 
@@ -60,6 +74,15 @@ namespace System.ComponentModel
         /// </summary>
         public DesignerAttribute(Type designerType, Type designerBaseType)
         {
+            if (designerType == null)
+            {
+                throw new ArgumentNullException(nameof(designerType));
+            }
+            if (designerBaseType == null)
+            {
+                throw new ArgumentNullException(nameof(designerBaseType));
+            }
+
             DesignerTypeName = designerType.AssemblyQualifiedName;
             DesignerBaseTypeName = designerBaseType.AssemblyQualifiedName;
         }
@@ -87,7 +110,7 @@ namespace System.ComponentModel
             {
                 if (_typeId == null)
                 {
-                    string baseType = DesignerBaseTypeName;
+                    string baseType = DesignerBaseTypeName ?? string.Empty;
                     int comma = baseType.IndexOf(',');
                     if (comma != -1)
                     {
index ee0473c..370665e 100644 (file)
@@ -37,7 +37,16 @@ namespace System.ComponentModel
         /// </summary>
         public EditorAttribute(string typeName, Type baseType)
         {
-            EditorTypeName = typeName ?? throw new ArgumentNullException(nameof(typeName));
+            if (typeName == null)
+            {
+                throw new ArgumentNullException(nameof(typeName));
+            }
+            if (baseType == null)
+            {
+                throw new ArgumentNullException(nameof(baseType));
+            }
+
+            EditorTypeName = typeName;
             EditorBaseTypeName = baseType.AssemblyQualifiedName;
         }
 
@@ -46,6 +55,15 @@ namespace System.ComponentModel
         /// </summary>
         public EditorAttribute(Type type, Type baseType)
         {
+            if (type == null)
+            {
+                throw new ArgumentNullException(nameof(type));
+            }
+            if (baseType == null)
+            {
+                throw new ArgumentNullException(nameof(baseType));
+            }
+
             EditorTypeName = type.AssemblyQualifiedName;
             EditorBaseTypeName = baseType.AssemblyQualifiedName;
         }
@@ -73,7 +91,7 @@ namespace System.ComponentModel
             {
                 if (_typeId == null)
                 {
-                    string baseType = EditorBaseTypeName;
+                    string baseType = EditorBaseTypeName ?? string.Empty;
                     int comma = baseType.IndexOf(',');
                     if (comma != -1)
                     {
index 935c370..5559269 100644 (file)
@@ -52,9 +52,17 @@ namespace System.ComponentModel
             {
                 return true;
             }
+            if (!(obj is ExtenderProvidedPropertyAttribute other))
+            {
+                return false;
+            }
+
+            if (other.IsDefaultAttribute())
+            {
+                return IsDefaultAttribute();
+            }
 
-            return obj is ExtenderProvidedPropertyAttribute other
-                && other.ExtenderProperty.Equals(ExtenderProperty)
+            return other.ExtenderProperty.Equals(ExtenderProperty)
                 && other.Provider.Equals(Provider)
                 && other.ReceiverType.Equals(ReceiverType);
         }
index bae14b5..3469a94 100644 (file)
@@ -21,6 +21,11 @@ namespace System.ComponentModel
         /// </summary>
         public InstallerTypeAttribute(Type installerType)
         {
+            if (installerType == null)
+            {
+                throw new ArgumentNullException(nameof(installerType));
+            }
+
             _typeName = installerType.AssemblyQualifiedName;
         }
 
index 9eace10..a06eb5e 100644 (file)
@@ -24,14 +24,14 @@ namespace System.ComponentModel
         /// Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the 
         /// specified type.
         /// </summary>
-        public LicenseException(Type type) : this(type, null, SR.Format(SR.LicExceptionTypeOnly, type.FullName))
+        public LicenseException(Type type) : this(type, null, SR.Format(SR.LicExceptionTypeOnly, type?.FullName))
         {
         }
         /// <summary>
         /// Initializes a new instance of the <see cref='System.ComponentModel.LicenseException'/> class for the 
         /// specified type and instance.
         /// </summary>
-        public LicenseException(Type type, object instance) : this(type, null, SR.Format(SR.LicExceptionTypeAndInstance, type.FullName, instance.GetType().FullName))
+        public LicenseException(Type type, object instance) : this(type, null, SR.Format(SR.LicExceptionTypeAndInstance, type?.FullName, instance?.GetType().FullName))
         {
         }
         /// <summary>
index 871293e..ba9e553 100644 (file)
@@ -15,6 +15,11 @@ namespace System.ComponentModel
         /// </summary>
         public ProvidePropertyAttribute(string propertyName, Type receiverType)
         {
+            if (receiverType == null)
+            {
+                throw new ArgumentNullException(nameof(receiverType));
+            }
+
             PropertyName = propertyName;
             ReceiverTypeName = receiverType.AssemblyQualifiedName;
         }
@@ -50,7 +55,10 @@ namespace System.ComponentModel
                 && other.ReceiverTypeName == ReceiverTypeName;
         }
 
-        public override int GetHashCode() => PropertyName.GetHashCode() ^ ReceiverTypeName.GetHashCode();
+        public override int GetHashCode()
+        {
+            return (PropertyName?.GetHashCode() ?? 0) ^ (ReceiverTypeName?.GetHashCode() ?? 0);
+        }
 
         public override object TypeId => GetType().FullName + PropertyName;
     }
index 0095dc9..24a738f 100644 (file)
@@ -16,7 +16,7 @@ namespace System.ComponentModel
         public RefreshEventArgs(object componentChanged)
         {
             ComponentChanged = componentChanged;
-            TypeChanged = componentChanged.GetType();
+            TypeChanged = componentChanged?.GetType();
         }
 
         /// <summary>
index 81bd5c3..3fb6a90 100644 (file)
@@ -57,6 +57,11 @@ namespace System.ComponentModel
         /// </summary>
         public ToolboxItemAttribute(Type toolboxItemType)
         {
+            if (toolboxItemType == null)
+            {
+                throw new ArgumentNullException(nameof(toolboxItemType));
+            }
+
             _toolboxItemType = toolboxItemType;
             _toolboxItemTypeName = toolboxItemType.AssemblyQualifiedName;
         }
index b24b353..593c648 100644 (file)
@@ -15,26 +15,33 @@ namespace System.ComponentModel.Tests
         public void Ctor_Default()
         {
             var subAttributeCollection = new SubAttributeCollection();
-            Assert.Throws<NullReferenceException>(() => subAttributeCollection.Count);
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.Equal(0, subAttributeCollection.Count);
+                Assert.Empty(subAttributeCollection);
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => subAttributeCollection.Count);
+                Assert.Throws<NullReferenceException>(() => subAttributeCollection.GetEnumerator());
+            }
         }
 
-        [Theory]
-        [InlineData(20)]
-        [InlineData(1000)]
-        [InlineData(1)]
-        [InlineData(0)]
-        public void Ctor_Attributes(int count)
+        public static IEnumerable<object[]> Ctor_Attributes_TestData()
         {
-            Attribute[] attributes = GetAttributes().Take(count).ToArray();
-            var attributeCollection = new AttributeCollection(attributes);
-            Assert.Equal(attributes, attributeCollection.Cast<Attribute>());
+            yield return new object[] { GetAttributes().Take(20).ToArray() };
+            yield return new object[] { GetAttributes().Take(1).ToArray() };
+            yield return new object[] { new Attribute[0] };
+            yield return new object[] { null };
         }
 
-        [Fact]
-        public void Ctor_NullAttributes_ReturnsEmpty()
+        [Theory]
+        [MemberData(nameof(Ctor_Attributes_TestData))]
+        public void Ctor_Attributes(Attribute[] attributes)
         {
-            var collection = new AttributeCollection(null);
-            Assert.Equal(0, collection.Count);
+            var attributeCollection = new AttributeCollection(attributes);
+            Assert.Equal(attributes?.Length ?? 0, attributeCollection.Count);
+            Assert.Equal(attributes ?? new Attribute[0], attributeCollection.Cast<Attribute>());
         }
 
         [Fact]
@@ -71,6 +78,22 @@ namespace System.ComponentModel.Tests
             Assert.Equal(attributeCollection.Cast<Attribute>(), array.Cast<Attribute>().Skip(index));
         }
 
+        [Fact]
+        public void CopyTo_Default_Nop()
+        {
+            var attributeCollection = new SubAttributeCollection();
+            var array = new object[] { 1, 2, 3 };
+            if (!PlatformDetection.IsFullFramework)
+            {
+                attributeCollection.CopyTo(array, 1);
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attributeCollection.CopyTo(array, 1));
+            }
+            Assert.Equal(new object[] { 1, 2, 3}, array);
+        }
+
         [Theory]
         [InlineData(20)]
         [InlineData(1000)]
@@ -99,6 +122,22 @@ namespace System.ComponentModel.Tests
             Assert.False(attributeCollection.Contains(new Attribute[] { new ReadOnlyAttribute(true) }));
         }
 
+        [Fact]
+        public void Contains_Default_ReturnsFalse()
+        {
+            var attributeCollection = new SubAttributeCollection();
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.False(attributeCollection.Contains(new ReadOnlyAttribute(true)));
+                Assert.False(attributeCollection.Contains(new Attribute[] { new ReadOnlyAttribute(true) }));
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attributeCollection.Contains(new ReadOnlyAttribute(true)));
+                Assert.Throws<NullReferenceException>(() => attributeCollection.Contains(new Attribute[] { new ReadOnlyAttribute(true) }));
+            }
+        }
+
         [Theory]
         [InlineData(20)]
         [InlineData(1000)]
@@ -293,12 +332,28 @@ namespace System.ComponentModel.Tests
             };
 
             var collection = new AttributeCollection(attributes);
-
+            
             Assert.True(collection.Matches(attributes));
             Assert.False(collection.Matches(notInCollection));
         }
 
-        private IEnumerable<Attribute> GetAttributes()
+        [Fact]
+        public void Matches_Default_ReturnsFalse()
+        {
+            var attributeCollection = new SubAttributeCollection();
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.False(attributeCollection.Matches(new ReadOnlyAttribute(true)));
+                Assert.False(attributeCollection.Matches(new Attribute[] { new ReadOnlyAttribute(true) }));
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attributeCollection.Matches(new ReadOnlyAttribute(true)));
+                Assert.Throws<NullReferenceException>(() => attributeCollection.Matches(new Attribute[] { new ReadOnlyAttribute(true) }));
+            }
+        }
+
+        private static IEnumerable<Attribute> GetAttributes()
         {
             while (true)
             {
index a428955..5659e71 100644 (file)
@@ -13,11 +13,16 @@ namespace System.ComponentModel.Design.Tests
     {
         public static IEnumerable<object[]> Ctor_TestData()
         {
+            // [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Core fixed a NRE bug.")]
+            if (!PlatformDetection.IsFullFramework)
+            {
+                yield return new object[] { null };
+            }
+
             yield return new object[] { new IDesignerHost[] { new TestDesignerHost(), null, new TestDesignerHost() } };
         }
 
         [Theory]
-        [InlineData(null)]
         [MemberData(nameof(Ctor_TestData))]
         public void Ctor_DesignersArray(IDesignerHost[] designers)
         {
@@ -31,17 +36,8 @@ namespace System.ComponentModel.Design.Tests
         public void Ctor_DesignersIList(IDesignerHost[] designers)
         {
             var collection = new DesignerCollection((IList)designers);
-            Assert.Equal(designers.Length, collection.Count);
-            Assert.Equal(designers, collection.Cast<IDesignerHost>());
-        }
-
-        [Fact]
-        public void Ctor_NullDesignersIList_Success()
-        {
-            var collection = new DesignerCollection((IList)null);
-            Assert.Throws<NullReferenceException>(() => collection.Count);
-            Assert.Throws<NullReferenceException>(() => collection.GetEnumerator());
-            Assert.Throws<NullReferenceException>(() => collection[0]);
+            Assert.Equal(designers?.Length ?? 0, collection.Count);
+            Assert.Equal(designers ?? Enumerable.Empty<IDesignerHost>(), collection.Cast<IDesignerHost>());
         }
 
         [Fact]
@@ -74,5 +70,15 @@ namespace System.ComponentModel.Design.Tests
 
             Assert.Equal(new IDesignerHost[] { null, designers[0], designers[1], null }, destination);
         }
+
+        [Fact]
+        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Core fixed a NRE bug.")]
+        public void CopyTo_NullIList_Nop()
+        {
+            ICollection collection = new DesignerCollection((IList)null);
+            var array = new object[] { 1, 2, 3 };
+            collection.CopyTo(array, 1);
+            Assert.Equal(new object[] { 1, 2, 3}, array);
+        }
     }
 }
index e657798..34e041f 100644 (file)
@@ -42,7 +42,7 @@ namespace System.ComponentModel.Design.Tests
         public void SetSavedLicenseKey_NullType_ThrowsNullReferenceException()
         {
             var context = new DesigntimeLicenseContext();
-            Assert.Throws<NullReferenceException>(() => context.SetSavedLicenseKey(null, "Key"));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("type", () => context.SetSavedLicenseKey(null, "Key"));
         }
     }
 }
index 71ded22..15e9f61 100644 (file)
@@ -108,10 +108,17 @@ namespace System.ComponentModel.Design.Tests
         }
 
         [Fact]
-        public void ToString_NullCommandId_ThrowsNullReferenceException()
+        public void ToString_NullCommandI_ReturnsExpected()
         {
             var command = new MenuCommand(new EventHandler(EventHandler), null);
-            Assert.Throws<NullReferenceException>(() => command.ToString());
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.Equal(" : Supported|Enabled|Visible", command.ToString());
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => command.ToString());
+            }
         }
 
         [Fact]
index d732e6f..5d8f1b2 100644 (file)
@@ -19,16 +19,16 @@ namespace System.ComponentModel.Design.Serialization.Tests
         }
 
         [Fact]
-        public void Ctor_NullSerializerType_ThrowsNullReferenceException()
+        public void Ctor_NullSerializerType_ThrowsArgumentNullException()
         {
-            Assert.Throws<NullReferenceException>(() => new DesignerSerializerAttribute((Type)null, typeof(int)));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>(() => new DesignerSerializerAttribute((Type)null, typeof(int)));
         }
 
         [Fact]
-        public void Ctor_NullBaseSerializerType_ThrowsNullReferenceException()
+        public void Ctor_NullBaseSerializerType_ThrowsArgumentNullException()
         {
-            Assert.Throws<NullReferenceException>(() => new DesignerSerializerAttribute(typeof(int), (Type)null));
-            Assert.Throws<NullReferenceException>(() => new DesignerSerializerAttribute("int", (Type)null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("baseSerializerType", () => new DesignerSerializerAttribute(typeof(int), (Type)null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("baseSerializerType", () => new DesignerSerializerAttribute("int", (Type)null));
         }
 
         [Theory]
@@ -65,7 +65,14 @@ namespace System.ComponentModel.Design.Serialization.Tests
         public void TypeId_NullBaseSerializerTypeName_ThrowsNullReferenceException()
         {
             var attribute = new DesignerSerializerAttribute("SerializerType", (string)null);
-            Assert.Throws<NullReferenceException>(() => attribute.TypeId);
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.Equal("System.ComponentModel.Design.Serialization.DesignerSerializerAttribute", attribute.TypeId);
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attribute.TypeId);
+            }
         }
     }
 }
index 3754e28..51f1553 100644 (file)
@@ -23,14 +23,14 @@ namespace System.ComponentModel.Design.Serialization.Tests
         [Fact]
         public void Ctor_NullSerializerType_ThrowsNullReferenceException()
         {
-            Assert.Throws<NullReferenceException>(() => new RootDesignerSerializerAttribute((Type)null, typeof(int), false));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("serializerType", () => new RootDesignerSerializerAttribute((Type)null, typeof(int), false));
         }
 
         [Fact]
         public void Ctor_NullBaseSerializerType_ThrowsNullReferenceException()
         {
-            Assert.Throws<NullReferenceException>(() => new RootDesignerSerializerAttribute(typeof(int), (Type)null, false));
-            Assert.Throws<NullReferenceException>(() => new RootDesignerSerializerAttribute("int", (Type)null, false));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("baseSerializerType", () => new RootDesignerSerializerAttribute(typeof(int), (Type)null, false));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("baseSerializerType", () => new RootDesignerSerializerAttribute("int", (Type)null, false));
         }
 
         [Theory]
@@ -66,10 +66,17 @@ namespace System.ComponentModel.Design.Serialization.Tests
         }
 
         [Fact]
-        public void TypeId_NullBaseSerializerTypeName_ThrowsNullReferenceException()
+        public void TypeId_NullBaseSerializerTypeName_ReturnsExpected()
         {
             var attribute = new RootDesignerSerializerAttribute("SerializerType", (string)null, reloadable: true);
-            Assert.Throws<NullReferenceException>(() => attribute.TypeId);
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.Equal("System.ComponentModel.Design.Serialization.RootDesignerSerializerAttribute", attribute.TypeId);
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attribute.TypeId);
+            }
         }
     }
 #pragma warning restore 0618
index a7aa8e8..95f0814 100644 (file)
@@ -66,7 +66,7 @@ namespace System.ComponentModel.Tests
         }
 
         [Fact]
-        public void Ctor_NullDesignerTypeName_ThrowsArgumentNullExceptionException()
+        public void Ctor_NullDesignerTypeName_ThrowsArgumentNullException()
         {
             AssertExtensions.Throws<ArgumentNullException, NullReferenceException>(() => new DesignerAttribute((string)null));
             AssertExtensions.Throws<ArgumentNullException, NullReferenceException>(() => new DesignerAttribute(null, "designerBaseTypeName"));
@@ -74,17 +74,17 @@ namespace System.ComponentModel.Tests
         }
 
         [Fact]
-        public void Ctor_NullDesignerType_ThrowsNullReferenceException()
+        public void Ctor_NullDesignerType_ThrowsArgumentNullException()
         {
-            Assert.Throws<NullReferenceException>(() => new DesignerAttribute((Type)null));
-            Assert.Throws<NullReferenceException>(() => new DesignerAttribute((Type)null, typeof(int)));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("designerType", () => new DesignerAttribute((Type)null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("designerType", () => new DesignerAttribute((Type)null, typeof(int)));
         }
 
         [Fact]
-        public void Ctor_NullDesignerBaseType_ThrowsNullReferenceException()
+        public void Ctor_NullDesignerBaseType_ThrowsArgumentNullException()
         {
-            Assert.Throws<NullReferenceException>(() => new DesignerAttribute("designerTypeName", (Type)null));
-            Assert.Throws<NullReferenceException>(() => new DesignerAttribute(typeof(int), null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("designerBaseType", () => new DesignerAttribute("designerTypeName", (Type)null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("designerBaseType", () => new DesignerAttribute(typeof(int), null));
         }
 
         [Theory]
@@ -101,7 +101,14 @@ namespace System.ComponentModel.Tests
         public void TypeId_NullDesignerDesignerTypeName_ThrowsNullReferenceException()
         {
             var attribute = new DesignerAttribute("DesignerType", (string)null);
-            Assert.Throws<NullReferenceException>(() => attribute.TypeId);
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.Equal("System.ComponentModel.DesignerAttribute", attribute.TypeId);
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attribute.TypeId);
+            }
         }
 
         public static IEnumerable<object[]> Equals_TestData()
index e3cab87..9da0172 100644 (file)
@@ -52,23 +52,23 @@ namespace System.ComponentModel.Tests
         }
 
         [Fact]
-        public void Ctor_NullEditorTypeName_ThrowsArgumentNullException()
+        public void Ctor_NullTypeName_ThrowsArgumentNullException()
         {
-            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>(() => new EditorAttribute(null, "baseTypeName"));
-            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>(() => new EditorAttribute((string)null, typeof(int)));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("typeName", () => new EditorAttribute(null, "baseTypeName"));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("typeName", () => new EditorAttribute((string)null, typeof(int)));
         }
 
         [Fact]
-        public void Ctor_NullType_ThrowsNullReferenceException()
+        public void Ctor_NullType_ThrowsArgumentNullException()
         {
-            Assert.Throws<NullReferenceException>(() => new EditorAttribute((Type)null, typeof(int)));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("type", () => new EditorAttribute((Type)null, typeof(int)));
         }
 
         [Fact]
-        public void Ctor_NullEditorBaseType_ThrowsNullReferenceException()
+        public void Ctor_NullBaseType_ThrowsArgumentNullException()
         {
-            Assert.Throws<NullReferenceException>(() => new EditorAttribute("typeName", (Type)null));
-            Assert.Throws<NullReferenceException>(() => new EditorAttribute(typeof(int), null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("baseType", () => new EditorAttribute("typeName", (Type)null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("baseType", () => new EditorAttribute(typeof(int), null));
         }
 
         [Theory]
@@ -82,10 +82,17 @@ namespace System.ComponentModel.Tests
         }
 
         [Fact]
-        public void TypeId_NullBaseTypeName_ThrowsNullReferenceException()
+        public void TypeId_NullBaseTypeName_ReturnsExpected()
         {
             var attribute = new EditorAttribute("Type", (string)null);
-            Assert.Throws<NullReferenceException>(() => attribute.TypeId);
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.Equal("System.ComponentModel.EditorAttribute", attribute.TypeId);
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attribute.TypeId);
+            }
         }
 
         public static IEnumerable<object[]> Equals_TestData()
index f996d3e..d04fddd 100644 (file)
@@ -43,7 +43,14 @@ namespace System.ComponentModel.Tests
         public void Equals_NullProperties_ThrowsNullReferenceException()
         {
             var attribute = new ExtenderProvidedPropertyAttribute();
-            Assert.Throws<NullReferenceException>(() => attribute.Equals(new ExtenderProvidedPropertyAttribute()));
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.True(attribute.Equals(new ExtenderProvidedPropertyAttribute()));
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attribute.Equals(new ExtenderProvidedPropertyAttribute()));
+            }
         }
     }
 }
index 3cf410a..ed2f67a 100644 (file)
@@ -12,16 +12,16 @@ namespace System.ComponentModel.Tests
         [Theory]
         [InlineData(typeof(int))]
         [InlineData(typeof(InstallerTypeAttribute))]
-        public void Ctor_InheritanceLevel(Type installerType)
+        public void Ctor_Type(Type installerType)
         {
             var attribute = new InstallerTypeAttribute(installerType);
             Assert.Equal(installerType, attribute.InstallerType);
         }
 
         [Fact]
-        public void Ctor_NullInstallerType_ThrowsNullReferenceException()
+        public void Ctor_NullInstallerType_ThrowsArgumentNullException()
         {
-            Assert.Throws<NullReferenceException>(() => new InstallerTypeAttribute((Type)null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("installerType", () => new InstallerTypeAttribute((Type)null));
         }
 
         [Theory]
index 076f3f4..00b6923 100644 (file)
@@ -11,8 +11,18 @@ namespace System.ComponentModel.Tests
 {
     public class LicenseExceptionTests
     {
+        public static IEnumerable<object[]> Ctor_Type_TestData()
+        {
+            if (!PlatformDetection.IsFullFramework)
+            {
+                yield return new object[] { null };
+            }
+
+            yield return new object[] { typeof(int) };
+        }
+
         [Theory]
-        [InlineData(typeof(int))]
+        [MemberData(nameof(Ctor_Type_TestData))]
         public void Ctor_Type(Type type)
         {
             var exception = new LicenseException(type);
@@ -22,8 +32,18 @@ namespace System.ComponentModel.Tests
             Assert.NotEmpty(exception.Message);
         }
 
+        public static IEnumerable<object[]> Ctor_Type_Object_TestData()
+        {
+            if (!PlatformDetection.IsFullFramework)
+            {
+                yield return new object[] { null, null };
+            }
+
+            yield return new object[] { typeof(int), "instance" };
+        }
+
         [Theory]
-        [InlineData(typeof(int), "instance")]
+        [MemberData(nameof(Ctor_Type_Object_TestData))]
         public void Ctor_Type_Object(Type type, object instance)
         {
             var exception = new LicenseException(type, instance);
@@ -63,19 +83,6 @@ namespace System.ComponentModel.Tests
         }
 
         [Fact]
-        public void Ctor_NullType_ThrowsNullReferenceException()
-        {
-            Assert.Throws<NullReferenceException>(() => new LicenseException(null));
-            Assert.Throws<NullReferenceException>(() => new LicenseException(null, new object()));
-        }
-
-        [Fact]
-        public void Ctor_NullInstance_ThrowsNullReferenceException()
-        {
-            Assert.Throws<NullReferenceException>(() => new LicenseException(typeof(int), null));
-        }
-
-        [Fact]
         public void Ctor_SerializationInfo_StreamingContext()
         {
             using (var stream = new MemoryStream())
index 50a1ebb..dee66ea 100644 (file)
@@ -35,7 +35,7 @@ namespace System.ComponentModel
         [Fact]
         public void Ctor_NullReceiverType_ThrowsNullReferenceException()
         {
-            Assert.Throws<NullReferenceException>(() => new ProvidePropertyAttribute("propertyName", (Type)null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("receiverType", () => new ProvidePropertyAttribute("propertyName", (Type)null));
         }
 
         public static IEnumerable<object[]> Equals_TestData()
@@ -72,17 +72,32 @@ namespace System.ComponentModel
         }
 
         [Fact]
-        public void GetHashCode_NullPropertyName_ThrowsNullReferenceException()
+        public void GetHashCode_NullPropertyName_ReturnsEqual()
         {
             var attribute = new ProvidePropertyAttribute(null, "receiverTypeName");
-            Assert.Throws<NullReferenceException>(() => attribute.GetHashCode());
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.Equal(attribute.GetHashCode(), attribute.GetHashCode());
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attribute.GetHashCode());
+            }
         }
 
         [Fact]
-        public void GetHashCode_NullReceiverTypeName_ThrowsNullReferenceException()
+        public void GetHashCode_NullReceiverTypeName_ReturnsEqual()
         {
             var attribute = new ProvidePropertyAttribute("propertyName", (string)null);
-            Assert.Throws<NullReferenceException>(() => attribute.GetHashCode());
+
+            if (!PlatformDetection.IsFullFramework)
+            {
+                Assert.Equal(attribute.GetHashCode(), attribute.GetHashCode());
+            }
+            else
+            {
+                Assert.Throws<NullReferenceException>(() => attribute.GetHashCode());
+            }
         }
     }
 }
index 19c6efb..f8172e9 100644 (file)
@@ -2,6 +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.
 
+using System.Collections.Generic;
 using Xunit;
 
 namespace System.ComponentModel.Tests
@@ -18,19 +19,23 @@ namespace System.ComponentModel.Tests
             Assert.Same(typeChanged, args.TypeChanged);
         }
 
-        [Fact]
-        public void Ctor_Object()
+        public static IEnumerable<object[]> Ctor_Object_TestData()
         {
-            object componentChanged = "componentChanged";
-            var args = new RefreshEventArgs(componentChanged);
-            Assert.Same(componentChanged, args.ComponentChanged);
-            Assert.Equal(typeof(string), args.TypeChanged);
+            if (!PlatformDetection.IsFullFramework)
+            {
+                yield return new object[] { null, null };
+            }
+
+                yield return new object[] { "componentChanged", typeof(string) };
         }
 
-        [Fact]
-        public void Ctor_NullComponentChanged_ThrowsNullReferenceException()
+        [Theory]
+        [MemberData(nameof(Ctor_Object_TestData))]
+        public void Ctor_Object(object componentChanged, Type expectedTypeChanged)
         {
-            Assert.Throws<NullReferenceException>(() => new RefreshEventArgs((object)null));
+            var args = new RefreshEventArgs(componentChanged);
+            Assert.Same(componentChanged, args.ComponentChanged);
+            Assert.Equal(expectedTypeChanged, args.TypeChanged);
         }
     }
 }
index a2e7424..573d29c 100644 (file)
@@ -80,7 +80,7 @@ namespace System.ComponentModel
         [Fact]
         public void Ctor_NullToolboxItemType_ThrowsNullReferenceException()
         {
-            Assert.Throws<NullReferenceException>(() => new ToolboxItemAttribute((Type)null));
+            AssertExtensions.Throws<ArgumentNullException, NullReferenceException>("toolboxItemType", () => new ToolboxItemAttribute((Type)null));
         }
 
         [Fact]