diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DES/DesTests.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DES/DesTests.cs index 7b3b444b436..9108cea39a3 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DES/DesTests.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DES/DesTests.cs @@ -42,7 +42,7 @@ namespace System.Security.Cryptography.Encryption.Des.Tests using (DES des = DESFactory.Create()) { - Assert.Throws(() => des.Key = KnownShortKey); + AssertExtensions.Throws(null, () => des.Key = KnownShortKey); Assert.Throws(() => des.Key = KnownSemiWeakKey); AssertExtensions.Throws("value", () => des.Key = null); diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaImportExport.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaImportExport.cs index d06e22e9299..2742746b078 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaImportExport.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaImportExport.cs @@ -133,12 +133,12 @@ namespace System.Security.Cryptography.EcDsa.Tests { Assert.Throws(() => ECCurve.CreateFromFriendlyName(null)); Assert.Throws(() => ECCurve.CreateFromValue(null)); - Assert.Throws(() => ECCurve.CreateFromFriendlyName("")); + AssertExtensions.Throws(null, () => ECCurve.CreateFromFriendlyName("")); Assert.Throws(() => ECDsaFactory.Create(ECCurve.CreateFromFriendlyName("Invalid")).ExportExplicitParameters(false)); - Assert.Throws(() => ECCurve.CreateFromValue("")); + AssertExtensions.Throws(null, () => ECCurve.CreateFromValue("")); Assert.Throws(() => ECDsaFactory.Create(ECCurve.CreateFromValue("Invalid")).ExportExplicitParameters(false)); - Assert.Throws(() => ECCurve.CreateFromOid(new Oid(null, null))); - Assert.Throws(() => ECCurve.CreateFromOid(new Oid("", ""))); + AssertExtensions.Throws(null, () => ECCurve.CreateFromOid(new Oid(null, null))); + AssertExtensions.Throws(null, () => ECCurve.CreateFromOid(new Oid("", ""))); } [Fact] diff --git a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs index 4ca5d2ca5fe..954c1a3420c 100644 --- a/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs +++ b/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/ImportExport.cs @@ -255,7 +255,7 @@ namespace System.Security.Cryptography.Rsa.Tests using (RSA rsa = RSAFactory.Create()) { if (rsa is RSACng && PlatformDetection.IsFullFramework) - Assert.Throws(() => rsa.ImportParameters(imported)); + AssertExtensions.Throws(null, () => rsa.ImportParameters(imported)); else Assert.ThrowsAny(() => rsa.ImportParameters(imported)); } @@ -272,7 +272,7 @@ namespace System.Security.Cryptography.Rsa.Tests using (RSA rsa = RSAFactory.Create()) { if (rsa is RSACng && PlatformDetection.IsFullFramework) - Assert.Throws(() => rsa.ImportParameters(imported)); + AssertExtensions.Throws(null, () => rsa.ImportParameters(imported)); else Assert.ThrowsAny(() => rsa.ImportParameters(imported)); } diff --git a/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_Getvalue_str_str_obj.cs b/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_Getvalue_str_str_obj.cs index 61ac9d16a02..5b2665a57bf 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_Getvalue_str_str_obj.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_Getvalue_str_str_obj.cs @@ -14,7 +14,7 @@ namespace Microsoft.Win32.RegistryTests [Fact] public static void NullKeyName_ThrowsArgumentNullException() { - AssertExtensions.Throws("keyName", () => Registry.GetValue(null, null, null)); + AssertExtensions.Throws("keyName", null, () => Registry.GetValue(null, null, null)); } public static readonly object[][] ArgumentExceptionTestData = @@ -34,7 +34,7 @@ namespace Microsoft.Win32.RegistryTests [MemberData(nameof(ArgumentExceptionTestData))] public static void InvalidKeyName_ThrowsArgumentException(string keyName) { - Assert.Throws(() => Registry.GetValue(keyName, null, null)); + AssertExtensions.Throws("keyName", null, () => Registry.GetValue(keyName, null, null)); } [Fact] diff --git a/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_SetValue_str_str_obj.cs b/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_SetValue_str_str_obj.cs index e578d33ffae..b40786b9895 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_SetValue_str_str_obj.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_SetValue_str_str_obj.cs @@ -30,21 +30,21 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => Registry.SetValue(keyName: null, valueName: "test", value: "test")); // Should throw if passed string does NOT start with one of the valid base key names - Assert.Throws(() => Registry.SetValue("HHHH_MMMM", "test", "test")); + AssertExtensions.Throws("keyName", null, () => Registry.SetValue("HHHH_MMMM", "test", "test")); // Should throw if passed string which only starts with one of the valid base key names but actually it isn't valid. - Assert.Throws(() => Registry.SetValue("HKEY_LOCAL_MACHINE_FOOBAR", "test", "test")); + AssertExtensions.Throws("keyName", null, () => Registry.SetValue("HKEY_LOCAL_MACHINE_FOOBAR", "test", "test")); // Should throw if key length above 255 characters but prior to V4, the limit is 16383 const int maxValueNameLength = 16383; - Assert.Throws(() => Registry.SetValue(TestRegistryKey.Name, new string('a', maxValueNameLength + 1), 5)); + AssertExtensions.Throws("name", null, () => Registry.SetValue(TestRegistryKey.Name, new string('a', maxValueNameLength + 1), 5)); // Should throw if passed value is array with uninitialized elements - Assert.Throws(() => Registry.SetValue(TestRegistryKey.Name, "StringArr", value: new string[1])); + AssertExtensions.Throws(null, () => Registry.SetValue(TestRegistryKey.Name, "StringArr", value: new string[1])); // Should throw because only String[] (REG_MULTI_SZ) and byte[] (REG_BINARY) are supported. // RegistryKey.SetValue does not support arrays of type UInt32[]. - Assert.Throws(() => Registry.SetValue(TestRegistryKey.Name, "IntArray", new[] { 1, 2, 3 })); + AssertExtensions.Throws(null, () => Registry.SetValue(TestRegistryKey.Name, "IntArray", new[] { 1, 2, 3 })); } public static IEnumerable TestValueTypes { get { return TestData.TestValueTypes; } } diff --git a/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_SetValue_str_str_obj_valuekind.cs b/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_SetValue_str_str_obj_valuekind.cs index db20faa609f..eae7dd6ca0d 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_SetValue_str_str_obj_valuekind.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/Registry/Registry_SetValue_str_str_obj_valuekind.cs @@ -172,25 +172,25 @@ namespace Microsoft.Win32.RegistryTests // Should throw if key length above 255 characters but prior to V4 the limit is 16383 const int maxValueNameLength = 16383; var valueName = new string('a', maxValueNameLength + 1); - Assert.Throws(() => Registry.SetValue(TestRegistryKey.Name, valueName, ulong.MaxValue, RegistryValueKind.String)); + AssertExtensions.Throws("name", null, () => Registry.SetValue(TestRegistryKey.Name, valueName, ulong.MaxValue, RegistryValueKind.String)); valueName = "FooBar"; // Should throw if passed value is null Assert.Throws(() => Registry.SetValue(TestRegistryKey.Name, valueName, null, RegistryValueKind.QWord)); // Should throw because valueKind is equal to -2 which is not an acceptable value - Assert.Throws(() => Registry.SetValue(TestRegistryKey.Name, valueName, int.MinValue, (RegistryValueKind)(-2))); + AssertExtensions.Throws("valueKind", () => Registry.SetValue(TestRegistryKey.Name, valueName, int.MinValue, (RegistryValueKind)(-2))); // Should throw because passed array contains null string[] strArr = { "one", "two", null, "three" }; - Assert.Throws(() => Registry.SetValue(TestRegistryKey.Name, valueName, strArr, RegistryValueKind.MultiString)); + AssertExtensions.Throws(null, () => Registry.SetValue(TestRegistryKey.Name, valueName, strArr, RegistryValueKind.MultiString)); // Should throw because passed array has wrong type - Assert.Throws(() => Registry.SetValue(TestRegistryKey.Name, valueName, new[] { new object() }, RegistryValueKind.MultiString)); + AssertExtensions.Throws(null, () => Registry.SetValue(TestRegistryKey.Name, valueName, new[] { new object() }, RegistryValueKind.MultiString)); // Should throw because passed array has wrong type object[] objTemp = { "my string", "your string", "Any once string" }; - Assert.Throws(() => Registry.SetValue(TestRegistryKey.Name, valueName, objTemp, RegistryValueKind.Unknown)); + AssertExtensions.Throws(null, () => Registry.SetValue(TestRegistryKey.Name, valueName, objTemp, RegistryValueKind.Unknown)); } } } diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKeyDeleteSubKeyTestsBase.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKeyDeleteSubKeyTestsBase.cs index 9ed116f3ce7..fb7b8d313d2 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKeyDeleteSubKeyTestsBase.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKeyDeleteSubKeyTestsBase.cs @@ -22,7 +22,7 @@ namespace Microsoft.Win32.RegistryTests Assert.Null(TestRegistryKey.OpenSubKey(expected)); Assert.Equal(0, TestRegistryKey.SubKeyCount); - Assert.Throws(() => deleteSubKey()); + AssertExtensions.Throws(null, () => deleteSubKey()); } protected void Verify_DeleteSubKey_KeyDoesNotExists_DoesNotThrow(string expected, Action deleteSubKey) diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKeyDeleteSubKeyTreeTestsBase.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKeyDeleteSubKeyTreeTestsBase.cs index 5741ea1febc..ac695eaa061 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKeyDeleteSubKeyTreeTestsBase.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKeyDeleteSubKeyTreeTestsBase.cs @@ -22,7 +22,7 @@ namespace Microsoft.Win32.RegistryTests Assert.Null(TestRegistryKey.OpenSubKey(expected)); Assert.Equal(0, TestRegistryKey.SubKeyCount); - Assert.Throws(() => deleteSubKeyTree()); + AssertExtensions.Throws(null, () => deleteSubKeyTree()); } protected void Verify_DeleteSubKeyTree_KeyDoesNotExists_DoesNotThrow(string expected, Action deleteSubKeyTree) diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_CreateSubKey_str.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_CreateSubKey_str.cs index 3564bcfbd60..5b61d90b405 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_CreateSubKey_str.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_CreateSubKey_str.cs @@ -19,7 +19,7 @@ namespace Microsoft.Win32.RegistryTests // Should throw if key length above 255 characters const int maxValueNameLength = 255; - Assert.Throws(() => TestRegistryKey.CreateSubKey(new string('a', maxValueNameLength + 1))); + AssertExtensions.Throws("name", null, () => TestRegistryKey.CreateSubKey(new string('a', maxValueNameLength + 1))); // Should throw if RegistryKey is readonly const string name = "FooBar"; diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_CreateSubKey_str_rkpc.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_CreateSubKey_str_rkpc.cs index 6fb01e69e76..1af96057406 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_CreateSubKey_str_rkpc.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_CreateSubKey_str_rkpc.cs @@ -18,7 +18,7 @@ namespace Microsoft.Win32.RegistryTests // [] Vanilla; create a new subkey in read/write mode and write to it const string testValueName = "TestValue"; const string testStringValueName = "TestString"; - const string testStringValue = "Hello World!†þ"; + const string testStringValue = "Hello World!\u2020\u00FE"; const int testValue = 42; using (var rk = TestRegistryKey.CreateSubKey(TestRegistryKeyName, writable: true)) @@ -42,7 +42,7 @@ namespace Microsoft.Win32.RegistryTests // [] Vanilla; create a new subkey in read/write mode and write to it const string testValueName = "TestValue"; const string testStringValueName = "TestString"; - const string testStringValue = "Hello World!†þ"; + const string testStringValue = "Hello World!\u2020\u00FE"; const int testValue = 42; using (var rk = TestRegistryKey.CreateSubKey(TestRegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree)) @@ -71,16 +71,16 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.CreateSubKey(null, RegistryKeyPermissionCheck.ReadWriteSubTree, new RegistryOptions(), new RegistrySecurity())); // Should throw if passed option is invalid - Assert.Throws(() => TestRegistryKey.CreateSubKey(TestRegistryKeyName, true, options: (RegistryOptions)(-1))); - Assert.Throws(() => TestRegistryKey.CreateSubKey(TestRegistryKeyName, true, options: (RegistryOptions)3)); - Assert.Throws(() => TestRegistryKey.CreateSubKey(TestRegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, (RegistryOptions)(-1))); - Assert.Throws(() => TestRegistryKey.CreateSubKey(TestRegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, (RegistryOptions)3)); - Assert.Throws(() => TestRegistryKey.CreateSubKey(TestRegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, (RegistryOptions)(-1), new RegistrySecurity())); - Assert.Throws(() => TestRegistryKey.CreateSubKey(TestRegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, (RegistryOptions)3, new RegistrySecurity())); + AssertExtensions.Throws("options", () => TestRegistryKey.CreateSubKey(TestRegistryKeyName, true, options: (RegistryOptions)(-1))); + AssertExtensions.Throws("options", () => TestRegistryKey.CreateSubKey(TestRegistryKeyName, true, options: (RegistryOptions)3)); + AssertExtensions.Throws("options", () => TestRegistryKey.CreateSubKey(TestRegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, (RegistryOptions)(-1))); + AssertExtensions.Throws("options", () => TestRegistryKey.CreateSubKey(TestRegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, (RegistryOptions)3)); + AssertExtensions.Throws("options", () => TestRegistryKey.CreateSubKey(TestRegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, (RegistryOptions)(-1), new RegistrySecurity())); + AssertExtensions.Throws("options", () => TestRegistryKey.CreateSubKey(TestRegistryKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree, (RegistryOptions)3, new RegistrySecurity())); // Should throw if key length above 255 characters const int maxValueNameLength = 255; - Assert.Throws(() => TestRegistryKey.CreateSubKey(new string('a', maxValueNameLength + 1))); + AssertExtensions.Throws("name", null, () => TestRegistryKey.CreateSubKey(new string('a', maxValueNameLength + 1))); // Should throw if RegistryKey is readonly const string name = "FooBar"; diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKeyTree.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKeyTree.cs index 70880552c46..cf307e1f454 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKeyTree.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKeyTree.cs @@ -19,10 +19,10 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.DeleteSubKeyTree(null, throwOnMissingSubKey: false)); // Should throw if target subkey is system subkey and name is empty - Assert.Throws(() => Registry.CurrentUser.DeleteSubKeyTree(string.Empty, throwOnMissingSubKey: false)); + AssertExtensions.Throws(null, () => Registry.CurrentUser.DeleteSubKeyTree(string.Empty, throwOnMissingSubKey: false)); // Should throw because subkey doesn't exists - Assert.Throws(() => TestRegistryKey.DeleteSubKeyTree(name, throwOnMissingSubKey: true)); + AssertExtensions.Throws(null, () => TestRegistryKey.DeleteSubKeyTree(name, throwOnMissingSubKey: true)); // Should throw because RegistryKey is readonly using (var rk = TestRegistryKey.OpenSubKey(string.Empty, false)) diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKeyTree_str.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKeyTree_str.cs index 292a3271086..c2ccf6dd1e7 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKeyTree_str.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKeyTree_str.cs @@ -20,10 +20,10 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.DeleteSubKeyTree(null)); // Should throw if target subkey is system subkey and name is empty - Assert.Throws(() => Registry.CurrentUser.DeleteSubKeyTree(string.Empty)); + AssertExtensions.Throws(null, () => Registry.CurrentUser.DeleteSubKeyTree(string.Empty)); // Should throw because subkey doesn't exists - Assert.Throws(() => TestRegistryKey.DeleteSubKeyTree(name)); + AssertExtensions.Throws(null, () => TestRegistryKey.DeleteSubKeyTree(name)); // Should throw because RegistryKey is readonly using (var rk = TestRegistryKey.OpenSubKey(string.Empty, false)) diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKey_Str_Bln.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKey_Str_Bln.cs index ddf9a94650c..8d4523624d2 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKey_Str_Bln.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKey_Str_Bln.cs @@ -20,7 +20,7 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.DeleteSubKey(null, false)); // Should throw because subkey doesn't exists - Assert.Throws(() => TestRegistryKey.DeleteSubKey(name, throwOnMissingSubKey: true)); + AssertExtensions.Throws(null, () => TestRegistryKey.DeleteSubKey(name, throwOnMissingSubKey: true)); // Should throw if subkey has child subkeys using (var rk = TestRegistryKey.CreateSubKey(name)) diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKey_str.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKey_str.cs index 635b8aa59f0..9a0fc44b084 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKey_str.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteSubKey_str.cs @@ -18,7 +18,7 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.DeleteSubKey(null)); // Should throw because subkey doesn't exists - Assert.Throws(() => TestRegistryKey.DeleteSubKey(name)); + AssertExtensions.Throws(null, () => TestRegistryKey.DeleteSubKey(name)); // Should throw if subkey has child subkeys using (var rk = TestRegistryKey.CreateSubKey(name)) diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteValue_Str_Bln.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteValue_Str_Bln.cs index 94faa1cc1dc..a1f1c1264c3 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteValue_Str_Bln.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteValue_Str_Bln.cs @@ -15,13 +15,13 @@ namespace Microsoft.Win32.RegistryTests { const string valueName = "TestValue"; - Assert.Throws(() => TestRegistryKey.DeleteValue(null, true)); + AssertExtensions.Throws(null, () => TestRegistryKey.DeleteValue(null, true)); // Should NOT throw because value doesn't exists TestRegistryKey.DeleteValue(valueName, throwOnMissingValue: false); // Should throw because value doesn't exists - Assert.Throws(() => TestRegistryKey.DeleteValue(valueName, throwOnMissingValue: true)); + AssertExtensions.Throws(null, () => TestRegistryKey.DeleteValue(valueName, throwOnMissingValue: true)); TestRegistryKey.SetValue(valueName, 42); diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteValue_str.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteValue_str.cs index ab69546ca11..9a3e6067f28 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteValue_str.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_DeleteValue_str.cs @@ -16,10 +16,10 @@ namespace Microsoft.Win32.RegistryTests const string valueName = "TestValue"; // Should throw if passed subkey name is null - Assert.Throws(() => TestRegistryKey.DeleteValue(null)); + AssertExtensions.Throws(null, () => TestRegistryKey.DeleteValue(null)); // Should throw because value doesn't exists - Assert.Throws(() => TestRegistryKey.DeleteValue(valueName)); + AssertExtensions.Throws(null, () => TestRegistryKey.DeleteValue(valueName)); TestRegistryKey.SetValue(valueName, 42); diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_GetValue_str_obj_b.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_GetValue_str_obj_b.cs index 571e11243d9..7c32b0baa1d 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_GetValue_str_obj_b.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_GetValue_str_obj_b.cs @@ -13,8 +13,8 @@ namespace Microsoft.Win32.RegistryTests [Fact] public void NegativeTests() { - Assert.Throws(() => TestRegistryKey.GetValue(null, null, (RegistryValueOptions)(-1))); - Assert.Throws(() => TestRegistryKey.GetValue(null, null, (RegistryValueOptions)2)); + AssertExtensions.Throws("options", () => TestRegistryKey.GetValue(null, null, (RegistryValueOptions)(-1))); + AssertExtensions.Throws("options", () => TestRegistryKey.GetValue(null, null, (RegistryValueOptions)2)); Assert.Throws(() => { diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str.cs index 93393b68845..110abe3b8a9 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str.cs @@ -17,7 +17,7 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.OpenSubKey(name: null)); // Should throw if subkey name greater than 255 chars - Assert.Throws(() => TestRegistryKey.OpenSubKey(new string('a', 256))); + AssertExtensions.Throws("name", null, () => TestRegistryKey.OpenSubKey(new string('a', 256))); // OpenSubKey should be read only by default const string name = "FooBar"; diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_b.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_b.cs index 103f1373a0f..5b40bf5e636 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_b.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_b.cs @@ -16,7 +16,7 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.OpenSubKey(name: null, writable: false)); // Should throw if subkey name greater than 255 chars - Assert.Throws(() => TestRegistryKey.OpenSubKey(new string('a', 256), true)); + AssertExtensions.Throws("name", null, () => TestRegistryKey.OpenSubKey(new string('a', 256), true)); // OpenSubKey should be read only const string name = "FooBar"; diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rkpc.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rkpc.cs index 5f3423aae9f..7583cc0c963 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rkpc.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rkpc.cs @@ -16,7 +16,7 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.OpenSubKey(name: null, permissionCheck: RegistryKeyPermissionCheck.ReadSubTree)); // Should throw if subkey name greater than 255 chars - Assert.Throws(() => TestRegistryKey.OpenSubKey(new string('a', 256), RegistryKeyPermissionCheck.Default)); + AssertExtensions.Throws("name", null, () => TestRegistryKey.OpenSubKey(new string('a', 256), RegistryKeyPermissionCheck.Default)); // Should throw when opened with default permission check const string name = "FooBar"; diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rkpc_rr.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rkpc_rr.cs index cc5ab92448b..1d624f8a43a 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rkpc_rr.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rkpc_rr.cs @@ -17,7 +17,7 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.OpenSubKey(name: null, permissionCheck: RegistryKeyPermissionCheck.ReadSubTree, rights: RegistryRights.ReadKey)); // Should throw if subkey name greater than 255 chars - Assert.Throws(() => TestRegistryKey.OpenSubKey(new string('a', 256), RegistryKeyPermissionCheck.Default, rights: RegistryRights.FullControl)); + AssertExtensions.Throws("name", null, () => TestRegistryKey.OpenSubKey(new string('a', 256), RegistryKeyPermissionCheck.Default, rights: RegistryRights.FullControl)); // Should throw when opened with default permission check and write rights const string name = "FooBar"; diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rr.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rr.cs index 334373d08dc..1003c3ff157 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rr.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_OpenSubKey_str_rr.cs @@ -17,7 +17,7 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => TestRegistryKey.OpenSubKey(name: null, rights: RegistryRights.ReadKey)); // Should throw if subkey name greater than 255 chars - Assert.Throws(() => TestRegistryKey.OpenSubKey(new string('a', 256), RegistryRights.FullControl)); + AssertExtensions.Throws("name", null, () => TestRegistryKey.OpenSubKey(new string('a', 256), RegistryRights.FullControl)); // OpenSubKey should be read only const string name = "FooBar"; diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_SetValueKind_str_obj_valueKind.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_SetValueKind_str_obj_valueKind.cs index 2a86386e80b..1e29e4d31a7 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_SetValueKind_str_obj_valueKind.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_SetValueKind_str_obj_valueKind.cs @@ -172,25 +172,25 @@ namespace Microsoft.Win32.RegistryTests // Should throw if key length above 255 characters but prior to V4 the limit is 16383 const int maxValueNameLength = 16383; string tooLongValueName = new string('a', maxValueNameLength + 1); - Assert.Throws(() => TestRegistryKey.SetValue(tooLongValueName, ulong.MaxValue, RegistryValueKind.String)); + AssertExtensions.Throws("name", null, () => TestRegistryKey.SetValue(tooLongValueName, ulong.MaxValue, RegistryValueKind.String)); const string valueName = "FooBar"; // Should throw if passed value is null Assert.Throws(() => TestRegistryKey.SetValue(valueName, null, RegistryValueKind.QWord)); // Should throw because valueKind is equal to -2 which is not an acceptable value - Assert.Throws(() => TestRegistryKey.SetValue(valueName, int.MinValue, (RegistryValueKind)(-2))); + AssertExtensions.Throws("valueKind", () => TestRegistryKey.SetValue(valueName, int.MinValue, (RegistryValueKind)(-2))); // Should throw because passed array contains null string[] strArr = { "one", "two", null, "three" }; - Assert.Throws(() => TestRegistryKey.SetValue(valueName, strArr, RegistryValueKind.MultiString)); + AssertExtensions.Throws(null, () => TestRegistryKey.SetValue(valueName, strArr, RegistryValueKind.MultiString)); // Should throw because passed array has wrong type - Assert.Throws(() => TestRegistryKey.SetValue(valueName, new[] { new object() }, RegistryValueKind.MultiString)); + AssertExtensions.Throws(null, () => TestRegistryKey.SetValue(valueName, new[] { new object() }, RegistryValueKind.MultiString)); // Should throw because passed array has wrong type object[] objTemp = { "my string", "your string", "Any once string" }; - Assert.Throws(() => TestRegistryKey.SetValue(valueName, objTemp, RegistryValueKind.Unknown)); + AssertExtensions.Throws(null, () => TestRegistryKey.SetValue(valueName, objTemp, RegistryValueKind.Unknown)); // Should throw because RegistryKey is readonly using (var rk = Registry.CurrentUser.OpenSubKey(TestRegistryKeyName, false)) diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_SetValue_str_obj.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_SetValue_str_obj.cs index 158cafb43fb..5b7c5e237a1 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_SetValue_str_obj.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/RegistryKey_SetValue_str_obj.cs @@ -28,14 +28,14 @@ namespace Microsoft.Win32.RegistryTests // Should throw if key length above 255 characters but prior to V4, the limit is 16383 const int maxValueNameLength = 16383; - Assert.Throws(() => TestRegistryKey.SetValue(new string('a', maxValueNameLength + 1), 5)); + AssertExtensions.Throws("name", null, () => TestRegistryKey.SetValue(new string('a', maxValueNameLength + 1), 5)); // Should throw if passed value is array with uninitialized elements - Assert.Throws(() => TestRegistryKey.SetValue("StringArr", value: new string[1])); + AssertExtensions.Throws(null, () => TestRegistryKey.SetValue("StringArr", value: new string[1])); // Should throw because only String[] (REG_MULTI_SZ) and byte[] (REG_BINARY) are supported. // RegistryKey.SetValue does not support arrays of type UInt32[]. - Assert.Throws(() => TestRegistryKey.SetValue("IntArray", value: new[] { 1, 2, 3 })); + AssertExtensions.Throws(null, () => TestRegistryKey.SetValue("IntArray", value: new[] { 1, 2, 3 })); // Should throw if RegistryKey closed Assert.Throws(() => diff --git a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/SafeRegistryHandle.cs b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/SafeRegistryHandle.cs index c5bad45c64a..7b7c8d19f92 100644 --- a/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/SafeRegistryHandle.cs +++ b/src/libraries/Microsoft.Win32.Registry/tests/RegistryKey/SafeRegistryHandle.cs @@ -18,8 +18,8 @@ namespace Microsoft.Win32.RegistryTests Assert.Throws(() => RegistryKey.FromHandle(handle: null, view: RegistryView.Default)); // invalid view - Assert.Throws(() => RegistryKey.FromHandle(TestRegistryKey.Handle, (RegistryView)(-1))); - Assert.Throws(() => RegistryKey.FromHandle(TestRegistryKey.Handle, (RegistryView)3)); + AssertExtensions.Throws("view", () => RegistryKey.FromHandle(TestRegistryKey.Handle, (RegistryView)(-1))); + AssertExtensions.Throws("view", () => RegistryKey.FromHandle(TestRegistryKey.Handle, (RegistryView)3)); // get handle of disposed RegistryKey Assert.Throws(() => diff --git a/src/libraries/System.CodeDom/tests/Compiler/CodeDomProviderTests.cs b/src/libraries/System.CodeDom/tests/Compiler/CodeDomProviderTests.cs index 9d66ecd654c..a8643d0c1ed 100644 --- a/src/libraries/System.CodeDom/tests/Compiler/CodeDomProviderTests.cs +++ b/src/libraries/System.CodeDom/tests/Compiler/CodeDomProviderTests.cs @@ -247,7 +247,7 @@ namespace System.CodeDom.Compiler.Tests [Fact] public void CompileAssemblyFromDom_CallsCompilerMethod() { - Assert.Throws(() => new CustomProvider().CompileAssemblyFromDom(new CompilerParameters())); + AssertExtensions.Throws(null, () => new CustomProvider().CompileAssemblyFromDom(new CompilerParameters())); } [Fact] diff --git a/src/libraries/System.Collections.Concurrent/tests/BlockingCollectionTests.cs b/src/libraries/System.Collections.Concurrent/tests/BlockingCollectionTests.cs index b6764fea64d..3501a7b2473 100644 --- a/src/libraries/System.Collections.Concurrent/tests/BlockingCollectionTests.cs +++ b/src/libraries/System.Collections.Concurrent/tests/BlockingCollectionTests.cs @@ -819,7 +819,7 @@ namespace System.Collections.Concurrent.Tests Assert.Throws(() => { blockingCollection = new BlockingCollection(new ConcurrentStackCollection(), 0); }); Assert.Throws(() => { blockingCollection = new BlockingCollection(new ConcurrentStackCollection(), -1); }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { ConcurrentStackCollection concurrentStack = new ConcurrentStackCollection(); concurrentStack.TryAdd(1); @@ -882,10 +882,10 @@ namespace System.Collections.Concurrent.Tests Assert.Throws(() => BlockingCollection.TryAddToAny(blockingCollections, 0, new TimeSpan(0, 0, 0, 1, 2147483647)) ); Assert.Throws(() => BlockingCollection.TryAddToAny(blockingCollections, 0, -2) ); - Assert.Throws(() => BlockingCollection.TryAddToAny(new BlockingCollection[NUM_OF_COLLECTIONS], 0)); - Assert.Throws(() => BlockingCollection.TryAddToAny(new BlockingCollection[0], 0)); + AssertExtensions.Throws("collections", () => BlockingCollection.TryAddToAny(new BlockingCollection[NUM_OF_COLLECTIONS], 0)); + AssertExtensions.Throws("collections", () => BlockingCollection.TryAddToAny(new BlockingCollection[0], 0)); - Assert.Throws(() => + AssertExtensions.Throws("collections", () => { blockingCollections[NUM_OF_COLLECTIONS - 1].CompleteAdding(); BlockingCollection.TryAddToAny(blockingCollections, 0); @@ -914,8 +914,8 @@ namespace System.Collections.Concurrent.Tests Assert.Throws(() => BlockingCollection.TryTakeFromAny(blockingCollections, out item, new TimeSpan(0, 0, 0, 1, 2147483647)) ); Assert.Throws(() => BlockingCollection.TryTakeFromAny(blockingCollections, out item, -2) ); - Assert.Throws(() => BlockingCollection.TryTakeFromAny(new BlockingCollection[NUM_OF_COLLECTIONS], out item) ); - Assert.Throws(() => BlockingCollection.TryTakeFromAny(new BlockingCollection[0], out item) ); + AssertExtensions.Throws("collections", () => BlockingCollection.TryTakeFromAny(new BlockingCollection[NUM_OF_COLLECTIONS], out item) ); + AssertExtensions.Throws("collections", () => BlockingCollection.TryTakeFromAny(new BlockingCollection[0], out item) ); Assert.Throws(() => BlockingCollection.TryTakeFromAny(null, out item) ); // new behavior for TakeFromAny after Dev10, to throw ArgumentException if all the collections are completed, @@ -924,7 +924,7 @@ namespace System.Collections.Concurrent.Tests { blockingCollections[i].CompleteAdding(); } - Assert.Throws(() => BlockingCollection.TakeFromAny(blockingCollections, out item) ); + AssertExtensions.Throws("collections", () => BlockingCollection.TakeFromAny(blockingCollections, out item) ); } /// Verifies that the correct exceptions are thrown for invalid inputs. @@ -939,14 +939,14 @@ namespace System.Collections.Concurrent.Tests Assert.Throws(() => blockingCollection.CopyTo(null, 0)); Assert.Throws(() => blockingCollection.CopyTo(arr, -1)); - Assert.Throws(() => blockingCollection.CopyTo(arr, 2)); - Assert.Throws(() => + AssertExtensions.Throws("index", () => blockingCollection.CopyTo(arr, 2)); + AssertExtensions.Throws("array", () => { int[,] twoDArray = new int[2, 2]; ((ICollection)blockingCollection).CopyTo(twoDArray, 0); }); - Assert.Throws(() => + AssertExtensions.Throws("array", () => { float[,] twoDArray = new float[2, 2]; ((ICollection)blockingCollection).CopyTo(twoDArray, 0); diff --git a/src/libraries/System.Collections.Concurrent/tests/ConcurrentDictionary/ConcurrentDictionaryTests.cs b/src/libraries/System.Collections.Concurrent/tests/ConcurrentDictionary/ConcurrentDictionaryTests.cs index 68d1d0150b8..bf21767cc97 100644 --- a/src/libraries/System.Collections.Concurrent/tests/ConcurrentDictionary/ConcurrentDictionaryTests.cs +++ b/src/libraries/System.Collections.Concurrent/tests/ConcurrentDictionary/ConcurrentDictionaryTests.cs @@ -859,7 +859,7 @@ namespace System.Collections.Concurrent.Tests //add one item to the dictionary ((ConcurrentDictionary)dictionary).TryAdd(1, 1); - Assert.Throws(() => dictionary.CopyTo(new object[] { }, 0)); + AssertExtensions.Throws(null, () => dictionary.CopyTo(new object[] { }, 0)); // "TestICollection: FAILED. CopyTo didn't throw AE when the Array size is smaller than the dictionary count"); } diff --git a/src/libraries/System.Collections.Concurrent/tests/ConcurrentStackTests.cs b/src/libraries/System.Collections.Concurrent/tests/ConcurrentStackTests.cs index 83dbd34e966..a5501673df5 100644 --- a/src/libraries/System.Collections.Concurrent/tests/ConcurrentStackTests.cs +++ b/src/libraries/System.Collections.Concurrent/tests/ConcurrentStackTests.cs @@ -135,7 +135,7 @@ namespace System.Collections.Concurrent.Tests Assert.Throws(() => stack.PushRange(new int[1], 0, -1)); Assert.Throws(() => stack.PushRange(new int[1], -1, 1)); Assert.Throws(() => stack.PushRange(new int[1], 2, 1)); - Assert.Throws(() => stack.PushRange(new int[1], 0, 10)); + AssertExtensions.Throws(null, () => stack.PushRange(new int[1], 0, 10)); } [Fact] @@ -147,7 +147,7 @@ namespace System.Collections.Concurrent.Tests Assert.Throws(() => stack.TryPopRange(new int[1], 0, -1)); Assert.Throws(() => stack.TryPopRange(new int[1], -1, 1)); Assert.Throws(() => stack.TryPopRange(new int[1], 2, 1)); - Assert.Throws(() => stack.TryPopRange(new int[1], 0, 10)); + AssertExtensions.Throws(null, () => stack.TryPopRange(new int[1], 0, 10)); } protected sealed class StackOracle : IProducerConsumerCollection diff --git a/src/libraries/System.Collections.NonGeneric/tests/ArrayListTests.cs b/src/libraries/System.Collections.NonGeneric/tests/ArrayListTests.cs index e24b4c9def3..85e9f667f42 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/ArrayListTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/ArrayListTests.cs @@ -814,7 +814,7 @@ namespace System.Collections.Tests var arrCopy = new int[arrList2.Count]; Assert.Throws(() => arrList2.CopyTo(null)); // Array is null - Assert.Throws(() => arrList2.CopyTo(new object[10, 10])); // Array is multidimensional + AssertExtensions.Throws("array", null, () => arrList2.CopyTo(new object[10, 10])); // Array is multidimensional Assert.Throws(() => arrList2.CopyTo(arrCopy, -1)); // Index < 0 Assert.Throws(() => arrList2.CopyTo(new object[11], 2)); // Invalid index and length @@ -871,17 +871,17 @@ namespace System.Collections.Tests Assert.Throws(() => arrList2.CopyTo(-1, arrCopy, 0, 1)); // Index < 0 Assert.Throws(() => arrList2.CopyTo(0, arrCopy, 0, -1)); // Count < 0 - Assert.Throws(() => + AssertExtensions.Throws(null, () => { arrCopy = new string[100]; arrList2.CopyTo(arrList2.Count - 1, arrCopy, 0, 24); }); Assert.Throws(() => arrList2.CopyTo(0, null, 3, 3)); // Array is null - Assert.Throws(() => arrList2.CopyTo(0, new object[arrList2.Count, arrList2.Count], 0, arrList2.Count)); // Array is multidimensional + AssertExtensions.Throws("array", null, () => arrList2.CopyTo(0, new object[arrList2.Count, arrList2.Count], 0, arrList2.Count)); // Array is multidimensional // Array index and count is out of bounds - Assert.Throws(() => + AssertExtensions.Throws(null, () => { arrCopy = new string[1]; arrList2.CopyTo(0, arrCopy, 3, 15); diff --git a/src/libraries/System.Collections.NonGeneric/tests/DictionaryBaseTests.cs b/src/libraries/System.Collections.NonGeneric/tests/DictionaryBaseTests.cs index 480f9a31502..f815ada8ada 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/DictionaryBaseTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/DictionaryBaseTests.cs @@ -184,7 +184,7 @@ namespace System.Collections.Tests MyDictionary dictBase = CreateDictionary(100); AssertExtensions.Throws("array", () => dictBase.CopyTo(null, 0)); // Array is null - Assert.Throws(() => dictBase.CopyTo(new object[100, 100], 0)); // Array is multidimensional + AssertExtensions.Throws("array", null, () => dictBase.CopyTo(new object[100, 100], 0)); // Array is multidimensional AssertExtensions.Throws("arrayIndex", () => dictBase.CopyTo(new DictionaryEntry[100], -1)); // Index < 0 diff --git a/src/libraries/System.Collections.NonGeneric/tests/HashtableTests.cs b/src/libraries/System.Collections.NonGeneric/tests/HashtableTests.cs index 27e52bb1b5d..ce17cd0ecff 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/HashtableTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/HashtableTests.cs @@ -127,7 +127,7 @@ namespace System.Collections.Tests public static void Ctor_Int_Invalid() { AssertExtensions.Throws("capacity", () => new Hashtable(-1)); // Capacity < 0 - Assert.Throws(() => new Hashtable(int.MaxValue)); // Capacity / load factor > int.MaxValue + AssertExtensions.Throws("capacity", null, () => new Hashtable(int.MaxValue)); // Capacity / load factor > int.MaxValue } [Fact] @@ -253,7 +253,7 @@ namespace System.Collections.Tests public static void Ctor_Int_Int_Invalid() { AssertExtensions.Throws("capacity", () => new Hashtable(-1, 1f)); // Capacity < 0 - Assert.Throws(() => new Hashtable(int.MaxValue, 0.1f)); // Capacity / load factor > int.MaxValue + AssertExtensions.Throws("capacity", null, () => new Hashtable(int.MaxValue, 0.1f)); // Capacity / load factor > int.MaxValue AssertExtensions.Throws("loadFactor", () => new Hashtable(100, 0.09f)); // Load factor < 0.1f AssertExtensions.Throws("loadFactor", () => new Hashtable(100, 1.01f)); // Load factor > 1f @@ -287,7 +287,7 @@ namespace System.Collections.Tests public static void Ctor_Int_IEqualityComparer_Invalid() { AssertExtensions.Throws("capacity", () => new Hashtable(-1, null)); // Capacity < 0 - Assert.Throws(() => new Hashtable(int.MaxValue, null)); // Capacity / load factor > int.MaxValue + AssertExtensions.Throws("capacity", null, () => new Hashtable(int.MaxValue, null)); // Capacity / load factor > int.MaxValue } [Fact] @@ -354,7 +354,7 @@ namespace System.Collections.Tests public static void Ctor_Capacity_LoadFactor_IEqualityComparer_Invalid() { AssertExtensions.Throws("capacity", () => new Hashtable(-1, 1f, null)); // Capacity < 0 - Assert.Throws(() => new Hashtable(int.MaxValue, 0.1f, null)); // Capacity / load factor > int.MaxValue + AssertExtensions.Throws("capacity", null, () => new Hashtable(int.MaxValue, 0.1f, null)); // Capacity / load factor > int.MaxValue AssertExtensions.Throws("loadFactor", () => new Hashtable(100, 0.09f, null)); // Load factor < 0.1f AssertExtensions.Throws("loadFactor", () => new Hashtable(100, 1.01f, null)); // Load factor > 1f @@ -843,11 +843,11 @@ namespace System.Collections.Tests { var hash = new ComparableHashtable(StringComparer.CurrentCulture); - Assert.Throws(() => hash.HashCodeProvider); - Assert.Throws(() => hash.Comparer); + AssertExtensions.Throws(null, () => hash.HashCodeProvider); + AssertExtensions.Throws(null, () => hash.Comparer); - Assert.Throws(() => hash.HashCodeProvider = CaseInsensitiveHashCodeProvider.DefaultInvariant); - Assert.Throws(() => hash.Comparer = StringComparer.OrdinalIgnoreCase); + AssertExtensions.Throws(null, () => hash.HashCodeProvider = CaseInsensitiveHashCodeProvider.DefaultInvariant); + AssertExtensions.Throws(null, () => hash.Comparer = StringComparer.OrdinalIgnoreCase); } [Fact] diff --git a/src/libraries/System.Collections.NonGeneric/tests/QueueTests.cs b/src/libraries/System.Collections.NonGeneric/tests/QueueTests.cs index 47ddf5ae969..39dacdf336d 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/QueueTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/QueueTests.cs @@ -379,7 +379,7 @@ namespace System.Collections.Tests Helpers.PerformActionOnAllQueueWrappers(queue1, queue2 => { AssertExtensions.Throws("array", () => queue2.CopyTo(null, 0)); // Array is null - Assert.Throws(() => queue2.CopyTo(new object[150, 150], 0)); // Array is multidimensional + AssertExtensions.Throws("array", null, () => queue2.CopyTo(new object[150, 150], 0)); // Array is multidimensional AssertExtensions.Throws("index", () => queue2.CopyTo(new object[150], -1)); // Index < 0 diff --git a/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs b/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs index 36d02163bca..94f1d78c0ec 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/SortedListTests.cs @@ -483,7 +483,7 @@ namespace System.Collections.Tests Helpers.PerformActionOnAllSortedListWrappers(sortList1, sortList2 => { AssertExtensions.Throws("array", () => sortList2.CopyTo(null, 0)); // Array is null - Assert.Throws(() => sortList2.CopyTo(new object[10, 10], 0)); // Array is multidimensional + AssertExtensions.Throws("array", null, () => sortList2.CopyTo(new object[10, 10], 0)); // Array is multidimensional AssertExtensions.Throws("arrayIndex", () => sortList2.CopyTo(new object[100], -1)); // Index < 0 Assert.Throws(null, () => sortList2.CopyTo(new object[150], 51)); // Index + list.Count > array.Count diff --git a/src/libraries/System.Collections.NonGeneric/tests/StackTests.cs b/src/libraries/System.Collections.NonGeneric/tests/StackTests.cs index 66ff15be25d..df77df6f2be 100644 --- a/src/libraries/System.Collections.NonGeneric/tests/StackTests.cs +++ b/src/libraries/System.Collections.NonGeneric/tests/StackTests.cs @@ -237,7 +237,7 @@ namespace System.Collections.Tests Helpers.PerformActionOnAllStackWrappers(stack1, stack2 => { AssertExtensions.Throws("array", () => stack2.CopyTo(null, 0)); // Array is null - Assert.Throws(() => stack2.CopyTo(new object[10, 10], 0)); // Array is multidimensional + AssertExtensions.Throws("array", null, () => stack2.CopyTo(new object[10, 10], 0)); // Array is multidimensional AssertExtensions.Throws("index", () => stack2.CopyTo(new object[100], -1)); // Index < 0 Assert.Throws(null, () => stack2.CopyTo(new object[0], 0)); // Index >= array.Count diff --git a/src/libraries/System.Collections.Specialized/tests/ListDictionaryTests.cs b/src/libraries/System.Collections.Specialized/tests/ListDictionaryTests.cs index c5139d956fa..70b4cd2a9ce 100644 --- a/src/libraries/System.Collections.Specialized/tests/ListDictionaryTests.cs +++ b/src/libraries/System.Collections.Specialized/tests/ListDictionaryTests.cs @@ -69,7 +69,7 @@ namespace System.Collections.Specialized.Tests Assert.Equal(i + 1, added.Count); CollectionAsserts.Equal(keys, added.Keys); CollectionAsserts.Equal(values, added.Values); - Assert.Throws(() => added.Add(key, value)); + AssertExtensions.Throws(null, () => added.Add(key, value)); added[key] = value; } } @@ -96,7 +96,7 @@ namespace System.Collections.Specialized.Tests comparer.AssertCompared(i + 1, () => Assert.Equal(value, added[key])); comparer.AssertCompared(i + 1, () => Assert.True(added.Contains(key))); Assert.Equal(i + 1, added.Count); - comparer.AssertCompared(i + 1, () => Assert.Throws(() => added.Add(key, "duplicate"))); + comparer.AssertCompared(i + 1, () => AssertExtensions.Throws(null, () => added.Add(key, "duplicate"))); } Assert.Equal(s_dictionaryData.Length, added.Count); @@ -110,7 +110,7 @@ namespace System.Collections.Specialized.Tests Assert.True(added.Contains(middleKey)); // Index is 0-based, count is 1-based // ... Add throws exception - comparer.AssertCompared(middleIndex + 1, () => Assert.Throws(() => added.Add(middleKey, "middleValue"))); + comparer.AssertCompared(middleIndex + 1, () => AssertExtensions.Throws(null, () => added.Add(middleKey, "middleValue"))); Assert.Equal(middleValue, added[middleKey]); Assert.True(added.Contains(middleKey)); } diff --git a/src/libraries/System.Collections.Specialized/tests/NameObjectCollectionBase/NameObjectCollectionBase.CopyToTests.cs b/src/libraries/System.Collections.Specialized/tests/NameObjectCollectionBase/NameObjectCollectionBase.CopyToTests.cs index 69c357bf1c9..744c62e259f 100644 --- a/src/libraries/System.Collections.Specialized/tests/NameObjectCollectionBase/NameObjectCollectionBase.CopyToTests.cs +++ b/src/libraries/System.Collections.Specialized/tests/NameObjectCollectionBase/NameObjectCollectionBase.CopyToTests.cs @@ -49,7 +49,7 @@ namespace System.Collections.Specialized.Tests ICollection collection = nameObjectCollection; AssertExtensions.Throws("array", () => collection.CopyTo(null, 0)); - Assert.Throws(() => collection.CopyTo(new string[count, count], 0)); + AssertExtensions.Throws("array", null, () => collection.CopyTo(new string[count, count], 0)); if (count > 0) { diff --git a/src/libraries/System.Collections.Specialized/tests/NameObjectCollectionBase/NameObjectCollectionBase.KeysTests.cs b/src/libraries/System.Collections.Specialized/tests/NameObjectCollectionBase/NameObjectCollectionBase.KeysTests.cs index 58a97c8fcd8..d4efd42c5e2 100644 --- a/src/libraries/System.Collections.Specialized/tests/NameObjectCollectionBase/NameObjectCollectionBase.KeysTests.cs +++ b/src/libraries/System.Collections.Specialized/tests/NameObjectCollectionBase/NameObjectCollectionBase.KeysTests.cs @@ -156,7 +156,7 @@ namespace System.Collections.Specialized.Tests ICollection keysCollection = keys; AssertExtensions.Throws("array", () => keysCollection.CopyTo(null, 0)); - Assert.Throws(() => keysCollection.CopyTo(new string[count, count], 0)); + AssertExtensions.Throws("array", null, () => keysCollection.CopyTo(new string[count, count], 0)); if (count > 0) { diff --git a/src/libraries/System.Collections.Specialized/tests/OrderedDictionary/OrderedDictionaryTests.cs b/src/libraries/System.Collections.Specialized/tests/OrderedDictionary/OrderedDictionaryTests.cs index 402bb913bb2..df7ab194c68 100644 --- a/src/libraries/System.Collections.Specialized/tests/OrderedDictionary/OrderedDictionaryTests.cs +++ b/src/libraries/System.Collections.Specialized/tests/OrderedDictionary/OrderedDictionaryTests.cs @@ -42,7 +42,7 @@ namespace System.Collections.Specialized.Tests var eqComp = new CaseInsensitiveEqualityComparer(); var d1 = new OrderedDictionary(eqComp); d1.Add("foo", "bar"); - Assert.Throws(() => d1.Add("FOO", "bar")); + AssertExtensions.Throws(null, () => d1.Add("FOO", "bar")); // The equality comparer should also test for a non-existent key d1.Remove("foofoo"); @@ -322,12 +322,12 @@ namespace System.Collections.Specialized.Tests d.Add("5", "foo6"); Assert.Equal("foo6", d["5"]); - Assert.Throws(() => d.Add((int)5, "foo")); - Assert.Throws(() => d.Add((double)5, "foo")); - Assert.Throws(() => d.Add((long)5, "foo")); - Assert.Throws(() => d.Add((short)5, "foo")); - Assert.Throws(() => d.Add((uint)5, "foo")); - Assert.Throws(() => d.Add("5", "foo")); + AssertExtensions.Throws(null, () => d.Add((int)5, "foo")); + AssertExtensions.Throws(null, () => d.Add((double)5, "foo")); + AssertExtensions.Throws(null, () => d.Add((long)5, "foo")); + AssertExtensions.Throws(null, () => d.Add((short)5, "foo")); + AssertExtensions.Throws(null, () => d.Add((uint)5, "foo")); + AssertExtensions.Throws(null, () => d.Add("5", "foo")); Assert.Throws(() => d.Add(null, "foobar")); } @@ -403,7 +403,7 @@ namespace System.Collections.Specialized.Tests Assert.Throws(() => d.CopyTo(null, 0)); Assert.Throws(() => d.CopyTo(arr, -1)); - Assert.Throws(() => d.CopyTo(arr, 3)); + AssertExtensions.Throws(null, () => d.CopyTo(arr, 3)); d.CopyTo(arr, 0); for (int i = 0; i < 2; i++) @@ -497,7 +497,7 @@ namespace System.Collections.Specialized.Tests d.Insert(0, "foo", "bar"); Assert.Equal("bar", d["foo"]); Assert.Equal("bar", d[0]); - Assert.Throws(() => d.Insert(0, "foo", "bar")); + AssertExtensions.Throws(null, () => d.Insert(0, "foo", "bar")); d.Insert(0, "aaa", "bbb"); Assert.Equal("bbb", d["aaa"]); diff --git a/src/libraries/System.Collections.Specialized/tests/StringCollectionTests.cs b/src/libraries/System.Collections.Specialized/tests/StringCollectionTests.cs index cbddc7e0682..6404773d539 100644 --- a/src/libraries/System.Collections.Specialized/tests/StringCollectionTests.cs +++ b/src/libraries/System.Collections.Specialized/tests/StringCollectionTests.cs @@ -234,8 +234,8 @@ namespace System.Collections.Specialized.Tests Assert.Throws(() => collection.CopyTo(data, -1)); if (data.Length > 0) { - Assert.Throws(() => collection.CopyTo(new string[0], data.Length - 1)); - Assert.Throws(() => collection.CopyTo(new string[data.Length - 1], 0)); + AssertExtensions.Throws("destinationArray", "", () => collection.CopyTo(new string[0], data.Length - 1)); + AssertExtensions.Throws("destinationArray", "", () => collection.CopyTo(new string[data.Length - 1], 0)); } // As explicit interface implementation @@ -243,8 +243,8 @@ namespace System.Collections.Specialized.Tests Assert.Throws(() => ((ICollection)collection).CopyTo(data, -1)); if (data.Length > 0) { - Assert.Throws(() => ((ICollection)collection).CopyTo(new string[0], data.Length - 1)); - Assert.Throws(() => ((ICollection)collection).CopyTo(new string[data.Length - 1], 0)); + AssertExtensions.Throws("destinationArray", "", () => ((ICollection)collection).CopyTo(new string[0], data.Length - 1)); + AssertExtensions.Throws("destinationArray", "", () => ((ICollection)collection).CopyTo(new string[data.Length - 1], 0)); } } diff --git a/src/libraries/System.Collections.Specialized/tests/StringDictionary/StringDictionary.CopyToTests.cs b/src/libraries/System.Collections.Specialized/tests/StringDictionary/StringDictionary.CopyToTests.cs index 80004cb3018..b8bff01c6a9 100644 --- a/src/libraries/System.Collections.Specialized/tests/StringDictionary/StringDictionary.CopyToTests.cs +++ b/src/libraries/System.Collections.Specialized/tests/StringDictionary/StringDictionary.CopyToTests.cs @@ -48,10 +48,10 @@ namespace System.Collections.Specialized.Tests Assert.Throws(() => stringDictionary.CopyTo(null, 0)); Assert.Throws(() => stringDictionary.CopyTo(new string[count], -1)); - Assert.Throws(() => stringDictionary.CopyTo(new string[count], count / 2 + 1)); - Assert.Throws(() => stringDictionary.CopyTo(new string[count], count)); - Assert.Throws(() => stringDictionary.CopyTo(new string[count], count + 1)); - Assert.Throws(() => stringDictionary.CopyTo(new string[count, count], 0)); + AssertExtensions.Throws(null, () => stringDictionary.CopyTo(new string[count], count / 2 + 1)); + AssertExtensions.Throws(null, () => stringDictionary.CopyTo(new string[count], count)); + AssertExtensions.Throws(null, () => stringDictionary.CopyTo(new string[count], count + 1)); + AssertExtensions.Throws("array", null, () => stringDictionary.CopyTo(new string[count, count], 0)); } } } diff --git a/src/libraries/System.Collections/tests/BitArray/BitArray_GetSetTests.cs b/src/libraries/System.Collections/tests/BitArray/BitArray_GetSetTests.cs index 4f9b3b84209..989e8c2c435 100644 --- a/src/libraries/System.Collections/tests/BitArray/BitArray_GetSetTests.cs +++ b/src/libraries/System.Collections/tests/BitArray/BitArray_GetSetTests.cs @@ -314,8 +314,8 @@ namespace System.Collections.Tests { ICollection bitArray = new BitArray(10); AssertExtensions.Throws("array", () => bitArray.CopyTo(null, 0)); - Assert.Throws(() => bitArray.CopyTo(new long[10], 0)); - Assert.Throws(() => bitArray.CopyTo(new int[10, 10], 0)); + AssertExtensions.Throws("array", null, () => bitArray.CopyTo(new long[10], 0)); + AssertExtensions.Throws("array", null, () => bitArray.CopyTo(new int[10, 10], 0)); } [Theory] diff --git a/src/libraries/System.Collections/tests/Generic/Comparers/Comparer.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/Comparers/Comparer.Generic.Tests.cs index bf19430b2cd..4e944df54e5 100644 --- a/src/libraries/System.Collections/tests/Generic/Comparers/Comparer.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Comparers/Comparer.Generic.Tests.cs @@ -83,13 +83,13 @@ namespace System.Collections.Generic.Tests Task notOfTypeT = Task.FromResult(default(T)); if (default(T) != null) // if default(T) is null these asserts will fail as IComparer.Compare returns early if either side is null { - Assert.Throws(() => comparer.Compare(notOfTypeT, default(T))); // lhs is the problem - Assert.Throws(() => comparer.Compare(default(T), notOfTypeT)); // rhs is the problem + AssertExtensions.Throws(null, () => comparer.Compare(notOfTypeT, default(T))); // lhs is the problem + AssertExtensions.Throws(null, () => comparer.Compare(default(T), notOfTypeT)); // rhs is the problem } if (!(notOfTypeT is T)) // catch cases where Task actually is a T, like object or non-generic Task { - Assert.Throws(() => comparer.Compare(notOfTypeT, notOfTypeT)); // The implementation should not attempt to short-circuit if both sides have reference equality - Assert.Throws(() => comparer.Compare(notOfTypeT, Task.FromResult(default(T)))); // And it should also work when they don't + AssertExtensions.Throws(null, () => comparer.Compare(notOfTypeT, notOfTypeT)); // The implementation should not attempt to short-circuit if both sides have reference equality + AssertExtensions.Throws(null, () => comparer.Compare(notOfTypeT, Task.FromResult(default(T)))); // And it should also work when they don't } } diff --git a/src/libraries/System.Collections/tests/Generic/Comparers/Comparer.Tests.cs b/src/libraries/System.Collections/tests/Generic/Comparers/Comparer.Tests.cs index b39818c3098..3a581d892f0 100644 --- a/src/libraries/System.Collections/tests/Generic/Comparers/Comparer.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Comparers/Comparer.Tests.cs @@ -210,7 +210,7 @@ namespace System.Collections.Generic.Tests var right = new object(); var comparer = Comparer.Default; - Assert.Throws(() => comparer.Compare(left, right)); + AssertExtensions.Throws(null, () => comparer.Compare(left, right)); } [Fact] diff --git a/src/libraries/System.Collections/tests/Generic/Comparers/EqualityComparer.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/Comparers/EqualityComparer.Generic.Tests.cs index 7dd42eccd9a..1264f442798 100644 --- a/src/libraries/System.Collections/tests/Generic/Comparers/EqualityComparer.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Comparers/EqualityComparer.Generic.Tests.cs @@ -89,13 +89,13 @@ namespace System.Collections.Generic.Tests if (default(T) != null) // if default(T) is null this assert will fail as IEqualityComparer.Equals returns early if either input is null { - Assert.Throws(() => comparer.Equals(notOfTypeT, default(T))); // lhs is the problem - Assert.Throws(() => comparer.Equals(default(T), notOfTypeT)); // rhs is the problem + AssertExtensions.Throws(null, () => comparer.Equals(notOfTypeT, default(T))); // lhs is the problem + AssertExtensions.Throws(null, () => comparer.Equals(default(T), notOfTypeT)); // rhs is the problem } if (!(notOfTypeT is T)) // catch cases where Task actually is a T, like object or non-generic Task { - Assert.Throws(() => comparer.Equals(notOfTypeT, Task.FromResult(default(T)))); + AssertExtensions.Throws(null, () => comparer.Equals(notOfTypeT, Task.FromResult(default(T)))); } } @@ -113,7 +113,7 @@ namespace System.Collections.Generic.Tests if (!(notOfTypeT is T)) { - Assert.Throws(() => comparer.GetHashCode(notOfTypeT)); + AssertExtensions.Throws(null, () => comparer.GetHashCode(notOfTypeT)); } } } diff --git a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs index 327052c1585..8198aa02d35 100644 --- a/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/Dictionary/Dictionary.Tests.cs @@ -54,7 +54,7 @@ namespace System.Collections.Tests if (!IsReadOnly) { IDictionary dictionary = new Dictionary(); - Assert.Throws(() => dictionary[23] = CreateTValue(12345)); + AssertExtensions.Throws("key", () => dictionary[23] = CreateTValue(12345)); Assert.Empty(dictionary); } } @@ -67,7 +67,7 @@ namespace System.Collections.Tests { IDictionary dictionary = new Dictionary(); object missingKey = GetNewKey(dictionary); - Assert.Throws(() => dictionary[missingKey] = 324); + AssertExtensions.Throws("value", () => dictionary[missingKey] = 324); Assert.Empty(dictionary); } } @@ -80,7 +80,7 @@ namespace System.Collections.Tests { IDictionary dictionary = new Dictionary(); object missingKey = 23; - Assert.Throws(() => dictionary.Add(missingKey, CreateTValue(12345))); + AssertExtensions.Throws("key", () => dictionary.Add(missingKey, CreateTValue(12345))); Assert.Empty(dictionary); } } @@ -93,7 +93,7 @@ namespace System.Collections.Tests { IDictionary dictionary = new Dictionary(); object missingKey = GetNewKey(dictionary); - Assert.Throws(() => dictionary.Add(missingKey, 324)); + AssertExtensions.Throws("value", () => dictionary.Add(missingKey, 324)); Assert.Empty(dictionary); } } @@ -132,7 +132,7 @@ namespace System.Collections.Tests { ICollection collection = NonGenericICollectionFactory(count); KeyValuePair[] array = new KeyValuePair[count * 3 / 2]; - Assert.Throws(() => collection.CopyTo(array, 0)); + AssertExtensions.Throws(null, () => collection.CopyTo(array, 0)); } [Theory] diff --git a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.BinarySearch.cs b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.BinarySearch.cs index 132d235e7db..bc3545faa76 100644 --- a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.BinarySearch.cs +++ b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.BinarySearch.cs @@ -59,10 +59,10 @@ namespace System.Collections.Tests List list = GenericListFactory(count); list.Sort(); T element = CreateT(3215); - Assert.Throws(() => list.BinarySearch(0, count + 1, element, GetIComparer())); //"Finding items longer than array should throw ArgumentException" + AssertExtensions.Throws(null, () => list.BinarySearch(0, count + 1, element, GetIComparer())); //"Finding items longer than array should throw ArgumentException" Assert.Throws(() => list.BinarySearch(-1, count, element, GetIComparer())); //"ArgumentOutOfRangeException should be thrown on negative index." Assert.Throws(() => list.BinarySearch(0, -1, element, GetIComparer())); //"ArgumentOutOfRangeException should be thrown on negative count." - Assert.Throws(() => list.BinarySearch(count + 1, count, element, GetIComparer())); //"ArgumentException should be thrown on index greater than length of array." + AssertExtensions.Throws(null, () => list.BinarySearch(count + 1, count, element, GetIComparer())); //"ArgumentException should be thrown on index greater than length of array." } } } diff --git a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Misc.cs b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Misc.cs index 1f6505f95df..1b183d05831 100644 --- a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Misc.cs +++ b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Misc.cs @@ -96,7 +96,7 @@ namespace System.Collections.Tests Assert.Throws(() => _ilist.Insert(bad[i], items[0])); //"ArgumentOutOfRangeException expected." } - Assert.Throws(() => _ilist.Insert(0, new LinkedListNode("blargh"))); //"ArgumentException expected." + AssertExtensions.Throws("value", () => _ilist.Insert(0, new LinkedListNode("blargh"))); //"ArgumentException expected." } #endregion @@ -285,7 +285,7 @@ namespace System.Collections.Tests for (int i = 0; i < bad.Length; i++) { - Assert.Throws(() => list.GetRange(bad[i], bad[++i])); //"ArgumentException expected." + AssertExtensions.Throws(null, () => list.GetRange(bad[i], bad[++i])); //"ArgumentException expected." } bad = new int[] { diff --git a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Remove.cs b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Remove.cs index 88774209b77..d15601c3f8a 100644 --- a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Remove.cs +++ b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Remove.cs @@ -116,7 +116,7 @@ namespace System.Collections.Tests Assert.All(InvalidParameters, invalidSet => { if (invalidSet.Item1 >= 0 && invalidSet.Item2 >= 0) - Assert.Throws(() => list.RemoveRange(invalidSet.Item1, invalidSet.Item2)); + AssertExtensions.Throws(null, () => list.RemoveRange(invalidSet.Item1, invalidSet.Item2)); }); } diff --git a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Reverse.cs b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Reverse.cs index 5037a28841b..947bb1902f0 100644 --- a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Reverse.cs +++ b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Reverse.cs @@ -129,7 +129,7 @@ namespace System.Collections.Tests Assert.All(InvalidParameters, invalidSet => { if (invalidSet.Item1 >= 0 && invalidSet.Item2 >= 0) - Assert.Throws(() => list.Reverse(invalidSet.Item1, invalidSet.Item2)); + AssertExtensions.Throws(null, () => list.Reverse(invalidSet.Item1, invalidSet.Item2)); }); } diff --git a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Sort.cs b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Sort.cs index 4f2dba9e016..8d4136dcc0d 100644 --- a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Sort.cs +++ b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.Sort.cs @@ -189,7 +189,7 @@ namespace System.Collections.Tests Assert.All(InvalidParameters, invalidSet => { - Assert.Throws(() => list.Sort(invalidSet.Item1, invalidSet.Item2, GetIComparer())); + AssertExtensions.Throws(null, () => list.Sort(invalidSet.Item1, invalidSet.Item2, GetIComparer())); }); } diff --git a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.cs index c07d93e5ca4..e867c2b411d 100644 --- a/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/List/List.Generic.Tests.cs @@ -58,8 +58,8 @@ namespace System.Collections.Tests public void CopyTo_ArgumentValidity(int count) { List list = GenericListFactory(count); - Assert.Throws(() => list.CopyTo(0, new T[0], 0, count + 1)); - Assert.Throws(() => list.CopyTo(count, new T[0], 0, 1)); + AssertExtensions.Throws(null, () => list.CopyTo(0, new T[0], 0, count + 1)); + AssertExtensions.Throws(null, () => list.CopyTo(count, new T[0], 0, 1)); } } } diff --git a/src/libraries/System.Collections/tests/Generic/SortedDictionary/SortedDictionary.Tests.cs b/src/libraries/System.Collections/tests/Generic/SortedDictionary/SortedDictionary.Tests.cs index a81d36e1d16..63e2754a422 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedDictionary/SortedDictionary.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedDictionary/SortedDictionary.Tests.cs @@ -57,7 +57,7 @@ namespace System.Collections.Tests if (!IsReadOnly) { IDictionary dictionary = new SortedDictionary(); - Assert.Throws(() => dictionary[23] = CreateTValue(12345)); + AssertExtensions.Throws("key", () => dictionary[23] = CreateTValue(12345)); Assert.Empty(dictionary); } } @@ -70,7 +70,7 @@ namespace System.Collections.Tests { IDictionary dictionary = new SortedDictionary(); object missingKey = GetNewKey(dictionary); - Assert.Throws(() => dictionary[missingKey] = 324); + AssertExtensions.Throws("value", () => dictionary[missingKey] = 324); Assert.Empty(dictionary); } } @@ -83,7 +83,7 @@ namespace System.Collections.Tests { IDictionary dictionary = new SortedDictionary(); object missingKey = 23; - Assert.Throws(() => dictionary.Add(missingKey, CreateTValue(12345))); + AssertExtensions.Throws("key", () => dictionary.Add(missingKey, CreateTValue(12345))); Assert.Empty(dictionary); } } @@ -96,7 +96,7 @@ namespace System.Collections.Tests { IDictionary dictionary = new SortedDictionary(); object missingKey = GetNewKey(dictionary); - Assert.Throws(() => dictionary.Add(missingKey, 324)); + AssertExtensions.Throws("value", () => dictionary.Add(missingKey, 324)); Assert.Empty(dictionary); } } @@ -142,7 +142,7 @@ namespace System.Collections.Tests { ICollection collection = NonGenericICollectionFactory(count); KeyValuePair[] array = new KeyValuePair[count * 3 / 2]; - Assert.Throws(() => collection.CopyTo(array, 0)); + AssertExtensions.Throws("array", null, () => collection.CopyTo(array, 0)); } [Theory] diff --git a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Tests.cs b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Tests.cs index 09b6e0c68db..c2856ca07ed 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedList/SortedList.Tests.cs @@ -61,7 +61,7 @@ namespace System.Collections.Tests { IDictionary dictionary = new SortedList(); object missingKey = GetNewKey(dictionary); - Assert.Throws(() => dictionary[missingKey] = 324); + AssertExtensions.Throws("value", () => dictionary[missingKey] = 324); Assert.Empty(dictionary); } } @@ -74,7 +74,7 @@ namespace System.Collections.Tests { IDictionary dictionary = new SortedList(); object missingKey = 23; - Assert.Throws(() => dictionary.Add(missingKey, CreateTValue(12345))); + AssertExtensions.Throws("key", () => dictionary.Add(missingKey, CreateTValue(12345))); Assert.Empty(dictionary); } } @@ -87,7 +87,7 @@ namespace System.Collections.Tests { IDictionary dictionary = new SortedList(); object missingKey = GetNewKey(dictionary); - Assert.Throws(() => dictionary.Add(missingKey, 324)); + AssertExtensions.Throws("value", () => dictionary.Add(missingKey, 324)); Assert.Empty(dictionary); } } @@ -135,7 +135,7 @@ namespace System.Collections.Tests { ICollection collection = NonGenericICollectionFactory(count); KeyValuePair[] array = new KeyValuePair[count * 3 / 2]; - Assert.Throws(() => collection.CopyTo(array, 0)); + AssertExtensions.Throws("array", null, () => collection.CopyTo(array, 0)); } [Theory] diff --git a/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.Tests.cs b/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.Tests.cs index 71398062762..a2ea7ab92e9 100644 --- a/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.Tests.cs +++ b/src/libraries/System.Collections/tests/Generic/SortedSet/SortedSet.Generic.Tests.cs @@ -160,7 +160,7 @@ namespace System.Collections.Tests T firstElement = set.ElementAt(0); T lastElement = set.ElementAt(setLength - 1); if (comparer.Compare(firstElement, lastElement) < 0) - Assert.Throws(() => set.GetViewBetween(lastElement, firstElement)); + AssertExtensions.Throws("lowerValue", null, () => set.GetViewBetween(lastElement, firstElement)); } } diff --git a/src/libraries/System.ComponentModel.Annotations/tests/CustomValidationAttributeTests.cs b/src/libraries/System.ComponentModel.Annotations/tests/CustomValidationAttributeTests.cs index 53dcb49abd1..351703b35c0 100644 --- a/src/libraries/System.ComponentModel.Annotations/tests/CustomValidationAttributeTests.cs +++ b/src/libraries/System.ComponentModel.Annotations/tests/CustomValidationAttributeTests.cs @@ -150,7 +150,7 @@ namespace System.ComponentModel.DataAnnotations.Tests public static void Validate_MethodThrowsCustomException_IsNotCaught() { CustomValidationAttribute attribute = GetAttribute(nameof(CustomValidator.ValidationMethodThrowsException)); - Assert.Throws(() => attribute.Validate(new IConvertibleImplementor(), s_testValidationContext)); + AssertExtensions.Throws(null, () => attribute.Validate(new IConvertibleImplementor(), s_testValidationContext)); } internal class NonPublicCustomValidator diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/ContainerTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/ContainerTests.cs index 3dd4f3ad21e..f154d8f132e 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/ContainerTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/ContainerTests.cs @@ -304,7 +304,7 @@ namespace System.ComponentModel.Tests TestComponent c2 = new TestComponent(); ArgumentException ex; - ex = Assert.Throws(() => container.Add(c2, "dup")); + ex = AssertExtensions.Throws(null, () => container.Add(c2, "dup")); Assert.Equal(typeof(ArgumentException), ex.GetType()); Assert.Null(ex.InnerException); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away exception messages and paramnames. @@ -317,7 +317,7 @@ namespace System.ComponentModel.Tests // new component, different case TestComponent c3 = new TestComponent(); - ex = Assert.Throws(() => container.Add(c3, "duP")); + ex = AssertExtensions.Throws(null, () => container.Add(c3, "duP")); // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.Equal(typeof(ArgumentException), ex.GetType()); @@ -342,7 +342,7 @@ namespace System.ComponentModel.Tests TestContainer container2 = new TestContainer(); TestComponent c5 = new TestComponent(); container2.Add(c5, "C5"); - ex = Assert.Throws(() => container.Add(c5, "dup")); + ex = AssertExtensions.Throws(null, () => container.Add(c5, "dup")); // Duplicate component name 'dup'. Component names must be // unique and case-insensitive Assert.Equal(typeof(ArgumentException), ex.GetType()); @@ -652,7 +652,7 @@ namespace System.ComponentModel.Tests _container.Add(compB, "B"); ArgumentException ex; - ex = Assert.Throws(() => _container.InvokeValidateName(compB, "dup")); + ex = AssertExtensions.Throws(null, () => _container.InvokeValidateName(compB, "dup")); // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.Equal(typeof(ArgumentException), ex.GetType()); @@ -668,7 +668,7 @@ namespace System.ComponentModel.Tests // new component, different case TestComponent compC = new TestComponent(); - ex = Assert.Throws(() => _container.InvokeValidateName(compC, "dup")); + ex = AssertExtensions.Throws(null, () => _container.InvokeValidateName(compC, "dup")); // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.Equal(typeof(ArgumentException), ex.GetType()); @@ -686,7 +686,7 @@ namespace System.ComponentModel.Tests TestContainer container2 = new TestContainer(); TestComponent compD = new TestComponent(); container2.Add(compD, "B"); - ex = Assert.Throws(() => _container.InvokeValidateName(compD, "dup")); + ex = AssertExtensions.Throws(null, () => _container.InvokeValidateName(compD, "dup")); // Duplicate component name 'duP'. Component names must be // unique and case-insensitive Assert.Equal(typeof(ArgumentException), ex.GetType()); @@ -760,4 +760,4 @@ namespace System.ComponentModel.Tests } } } -} \ No newline at end of file +} diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs index 7543564ce90..d4426cc59c3 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/CultureInfoConverterTests.cs @@ -65,8 +65,8 @@ namespace System.ComponentModel.Tests catch (CultureNotFoundException) { // if we cannot create the cultures we should get exception from the Converter too - Assert.Throws(() => c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "Dutch (Bel")); - Assert.Throws(() => c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "duTcH (Bel")); + AssertExtensions.Throws(null, () => c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "Dutch (Bel")); + AssertExtensions.Throws(null, () => c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "duTcH (Bel")); } c = (CultureInfo)converter.ConvertFrom(null, CultureInfo.InvariantCulture, "(Default)"); @@ -93,7 +93,7 @@ namespace System.ComponentModel.Tests catch (CultureNotFoundException) { // if we cannot create the cultures we should get exception from the Converter too - ex = Assert.Throws(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, "(default)")); + ex = AssertExtensions.Throws(null, () => converter.ConvertFrom(null, CultureInfo.InvariantCulture, "(default)")); // The (default) culture cannot be converted to // a CultureInfo object on this computer Assert.Equal(typeof(ArgumentException), ex.GetType()); @@ -114,7 +114,7 @@ namespace System.ComponentModel.Tests } catch (CultureNotFoundException) { - ex = Assert.Throws(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, " ")); + ex = AssertExtensions.Throws(null, () => converter.ConvertFrom(null, CultureInfo.InvariantCulture, " ")); // The culture cannot be converted to // a CultureInfo object on this computer Assert.Equal(typeof(ArgumentException), ex.GetType()); @@ -135,7 +135,7 @@ namespace System.ComponentModel.Tests } catch (CultureNotFoundException) { - ex = Assert.Throws(() => converter.ConvertFrom(null, CultureInfo.InvariantCulture, "\r\n")); + ex = AssertExtensions.Throws(null, () => converter.ConvertFrom(null, CultureInfo.InvariantCulture, "\r\n")); // The \r\n culture cannot be converted to // a CultureInfo object on this computer Assert.Equal(typeof(ArgumentException), ex.GetType()); @@ -209,4 +209,4 @@ namespace System.ComponentModel.Tests } } } -} \ No newline at end of file +} diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/ColorConverterTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/ColorConverterTests.cs index 2b86d4edab1..fef8e7bddce 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/ColorConverterTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/ColorConverterTests.cs @@ -166,7 +166,7 @@ namespace System.ComponentModel.TypeConverterTests public void ConvertFrom_ArgumentException(string value) { var conv = new ColorConverter(); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { conv.ConvertFrom(null, CultureInfo.InvariantCulture, value); }); @@ -326,7 +326,7 @@ namespace System.ComponentModel.TypeConverterTests public void ConvertFromInvariantString_Invalid() { var conv = new ColorConverter(); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { conv.ConvertFromInvariantString("1, 2, 3, 4, 5"); }); @@ -372,7 +372,7 @@ namespace System.ComponentModel.TypeConverterTests public void ConvertFromString_Invalid() { var conv = new ColorConverter(); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { conv.ConvertFromString(string.Format("1{0} 2{0} 3{0} 4{0} 5", CultureInfo.CurrentCulture.TextInfo.ListSeparator)); }); diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/PointConverterTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/PointConverterTests.cs index cd231d89dc1..c51d9a11ab7 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/PointConverterTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/PointConverterTests.cs @@ -160,7 +160,7 @@ namespace System.ComponentModel.TypeConverterTests [Fact] public void CreateInstance_CaseSensitive() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Converter.CreateInstance(null, new Dictionary { diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/RectangleConverterTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/RectangleConverterTests.cs index 065d442afad..3093765f381 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/RectangleConverterTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/RectangleConverterTests.cs @@ -158,7 +158,7 @@ namespace System.ComponentModel.TypeConverterTests [Fact] public void CreateInstance_CaseSensitive() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Converter.CreateInstance(null, new Dictionary { @@ -278,4 +278,4 @@ namespace System.ComponentModel.TypeConverterTests CultureInfo.CurrentCulture.TextInfo.ListSeparator), str); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/SizeConverterTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/SizeConverterTests.cs index 794ba38ad1c..ea0680a07f1 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/SizeConverterTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/SizeConverterTests.cs @@ -160,7 +160,7 @@ namespace System.ComponentModel.TypeConverterTests [Fact] public void CreateInstance_CaseSensitive() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Converter.CreateInstance(null, new Dictionary { diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/StringTypeConverterTestBase.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/StringTypeConverterTestBase.cs index 6895a2e4e37..5bb03f7bb6e 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/StringTypeConverterTestBase.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/Drawing/StringTypeConverterTestBase.cs @@ -80,7 +80,7 @@ namespace System.ComponentModel.TypeConverterTests protected void ConvertFromThrowsArgumentExceptionForString(string value) { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Converter.ConvertFrom(null, CultureInfo.InvariantCulture, value); }); @@ -137,7 +137,7 @@ namespace System.ComponentModel.TypeConverterTests protected void ConvertFromInvariantStringThrowsArgumentException(string str) { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Converter.ConvertFromInvariantString(str); }); @@ -155,7 +155,7 @@ namespace System.ComponentModel.TypeConverterTests protected void ConvertFromStringThrowsArgumentException(string str) { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Converter.ConvertFromString(str); }); @@ -171,4 +171,4 @@ namespace System.ComponentModel.TypeConverterTests Assert.IsType(ex.InnerException); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/InstanceDescriptorTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/InstanceDescriptorTests.cs index 4aa9903cf7b..e1ed3d6f6e1 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/InstanceDescriptorTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/InstanceDescriptorTests.cs @@ -50,7 +50,7 @@ namespace System.ComponentModel.Tests [Fact] public void Constructor0_Arguments_Mismatch() { - ArgumentException ex = Assert.Throws(() => new InstanceDescriptor(ci, null)); + ArgumentException ex = AssertExtensions.Throws(null, () => new InstanceDescriptor(ci, null)); // Length mismatch Assert.Equal(typeof(ArgumentException), ex.GetType()); Assert.Null(ex.InnerException); @@ -75,7 +75,7 @@ namespace System.ComponentModel.Tests [Fact] public void Constructor_MemberInfo_Null_Boolean() { - Assert.Throws(() => new InstanceDescriptor(ci, null, false)); + AssertExtensions.Throws(null, () => new InstanceDescriptor(ci, null, false)); // mismatch for required parameters } @@ -107,7 +107,7 @@ namespace System.ComponentModel.Tests { FieldInfo fi = typeof(StaticField).GetField(nameof(StaticField.Field)); - ArgumentException ex = Assert.Throws(() => new InstanceDescriptor(fi, new object[] { url })); + ArgumentException ex = AssertExtensions.Throws(null, () => new InstanceDescriptor(fi, new object[] { url })); // Parameter must be static Assert.Equal(typeof(ArgumentException), ex.GetType()); Assert.Null(ex.InnerException); @@ -135,7 +135,7 @@ namespace System.ComponentModel.Tests { FieldInfo fi = typeof(InstanceField).GetField(nameof(InstanceField.Name)); - ArgumentException ex = Assert.Throws(() => new InstanceDescriptor(fi, null)); + ArgumentException ex = AssertExtensions.Throws(null, () => new InstanceDescriptor(fi, null)); // Parameter must be static Assert.Equal(typeof(ArgumentException), ex.GetType()); Assert.Null(ex.InnerException); @@ -181,7 +181,7 @@ namespace System.ComponentModel.Tests ArgumentException ex; - ex = Assert.Throws(() => new InstanceDescriptor(pi, null)); + ex = AssertExtensions.Throws(null, () => new InstanceDescriptor(pi, null)); // Parameter must be static Assert.Equal(typeof(ArgumentException), ex.GetType()); Assert.Null(ex.InnerException); @@ -191,7 +191,7 @@ namespace System.ComponentModel.Tests Assert.Null(ex.ParamName); } - ex = Assert.Throws(() => new InstanceDescriptor(pi, null, false)); + ex = AssertExtensions.Throws(null, () => new InstanceDescriptor(pi, null, false)); // Parameter must be static Assert.Equal(typeof(ArgumentException), ex.GetType()); Assert.Null(ex.InnerException); @@ -207,7 +207,7 @@ namespace System.ComponentModel.Tests { PropertyInfo pi = typeof(WriteOnlyProperty).GetProperty(nameof(WriteOnlyProperty.Name)); - ArgumentException ex = Assert.Throws(() => new InstanceDescriptor(pi, null)); + ArgumentException ex = AssertExtensions.Throws(null, () => new InstanceDescriptor(pi, null)); // Parameter must be readable Assert.Equal(typeof(ArgumentException), ex.GetType()); Assert.Null(ex.InnerException); @@ -248,4 +248,4 @@ namespace System.ComponentModel.Tests public static string Property => "PropertyValue"; } } -} \ No newline at end of file +} diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/MemberDescriptorTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/MemberDescriptorTests.cs index 8e8e7f47aea..42c93264951 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/MemberDescriptorTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/MemberDescriptorTests.cs @@ -36,15 +36,15 @@ namespace System.ComponentModel.Tests [Fact] public void MemberDescriptorFromName() { - Assert.Throws(() => new MockMemberDescriptor((string)null)); - Assert.Throws(() => new MockMemberDescriptor("")); + AssertExtensions.Throws(null, () => new MockMemberDescriptor((string)null)); + AssertExtensions.Throws(null, () => new MockMemberDescriptor("")); } [Fact] public void MemberDescriptorFromNameAndAttributes() { - Assert.Throws(() => new MockMemberDescriptor((string)null, new Attribute[0])); - Assert.Throws(() => new MockMemberDescriptor("", new Attribute[0])); + AssertExtensions.Throws(null, () => new MockMemberDescriptor((string)null, new Attribute[0])); + AssertExtensions.Throws(null, () => new MockMemberDescriptor("", new Attribute[0])); var name = nameof(MemberDescriptorFromNameAndAttributes); var attributes = new Attribute[] { new MockAttribute1(), new MockAttribute2() }; diff --git a/src/libraries/System.ComponentModel.TypeConverter/tests/NullableConverterTests.cs b/src/libraries/System.ComponentModel.TypeConverter/tests/NullableConverterTests.cs index 9035ca227a5..1fa2989be88 100644 --- a/src/libraries/System.ComponentModel.TypeConverter/tests/NullableConverterTests.cs +++ b/src/libraries/System.ComponentModel.TypeConverter/tests/NullableConverterTests.cs @@ -17,7 +17,7 @@ namespace System.ComponentModel.Tests [Fact] public static void Constructor_Negative() { - Assert.Throws(() => new NullableConverter(typeof(string))); + AssertExtensions.Throws("type", () => new NullableConverter(typeof(string))); } [Fact] diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/CommaDelimitedStringCollectionConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/CommaDelimitedStringCollectionConverterTest.cs index 9b56c5f6c47..e5921a2645f 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/CommaDelimitedStringCollectionConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/CommaDelimitedStringCollectionConverterTest.cs @@ -113,7 +113,7 @@ namespace MonoTests.System.Configuration { CommaDelimitedStringCollectionConverter cv = new CommaDelimitedStringCollectionConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, 59, typeof(string))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, 59, typeof(string))); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/ConfigurationManagerTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/ConfigurationManagerTest.cs index f5184dc2e4a..f8cf76e191f 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/ConfigurationManagerTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/ConfigurationManagerTest.cs @@ -200,7 +200,7 @@ namespace MonoTests.System.Configuration ExeConfigurationFileMap map = new ExeConfigurationFileMap(); map.RoamingUserConfigFilename = "roaminguser"; - Assert.Throws(() => ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoaming)); + AssertExtensions.Throws("fileMap.ExeConfigFilename", () => ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoaming)); } [Fact] @@ -225,7 +225,7 @@ namespace MonoTests.System.Configuration map.RoamingUserConfigFilename = "roaminguser"; map.LocalUserConfigFilename = "localuser"; - Assert.Throws(() => ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoamingAndLocal)); + AssertExtensions.Throws("fileMap.ExeConfigFilename", () => ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoamingAndLocal)); } [Fact] @@ -237,7 +237,7 @@ namespace MonoTests.System.Configuration map.ExeConfigFilename = "execonfig"; map.LocalUserConfigFilename = "localuser"; - Assert.Throws(() => ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoamingAndLocal)); + AssertExtensions.Throws("fileMap.RoamingUserConfigFilename", () => ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.PerUserRoamingAndLocal)); } [Fact] diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/ExeConfigurationFileMapTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/ExeConfigurationFileMapTest.cs index 3c23839f25f..81c98a72a51 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/ExeConfigurationFileMapTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/ExeConfigurationFileMapTest.cs @@ -73,7 +73,7 @@ namespace MonoTests.System.Configuration var map = new ExeConfigurationFileMap(); map.ExeConfigFilename = filename; - Assert.Throws(() => + AssertExtensions.Throws("fileMap.RoamingUserConfigFilename", () => ConfigurationManager.OpenMappedExeConfiguration( map, ConfigurationUserLevel.PerUserRoaming)); }); @@ -87,7 +87,7 @@ namespace MonoTests.System.Configuration var map = new ExeConfigurationFileMap(); map.LocalUserConfigFilename = filename; - Assert.Throws(() => + AssertExtensions.Throws("fileMap.RoamingUserConfigFilename", () => ConfigurationManager.OpenMappedExeConfiguration( map, ConfigurationUserLevel.PerUserRoamingAndLocal)); }); @@ -102,7 +102,7 @@ namespace MonoTests.System.Configuration map.ExeConfigFilename = filename; map.RoamingUserConfigFilename = filename; - Assert.Throws(() => + AssertExtensions.Throws("fileMap.LocalUserConfigFilename", () => ConfigurationManager.OpenMappedExeConfiguration( map, ConfigurationUserLevel.PerUserRoamingAndLocal)); }); @@ -117,7 +117,7 @@ namespace MonoTests.System.Configuration map.RoamingUserConfigFilename = roaming; map.LocalUserConfigFilename = local; - Assert.Throws(() => + AssertExtensions.Throws("fileMap.ExeConfigFilename", () => ConfigurationManager.OpenMappedExeConfiguration( map, ConfigurationUserLevel.PerUserRoamingAndLocal)); }); @@ -131,7 +131,7 @@ namespace MonoTests.System.Configuration var map = new ExeConfigurationFileMap(); map.MachineConfigFilename = machine; - Assert.Throws(() => + AssertExtensions.Throws("fileMap.ExeConfigFilename", () => ConfigurationManager.OpenMappedExeConfiguration( map, ConfigurationUserLevel.None)); }); diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/GenericEnumConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/GenericEnumConverterTest.cs index 72c459bccfd..0f7648d81ff 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/GenericEnumConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/GenericEnumConverterTest.cs @@ -88,7 +88,7 @@ namespace MonoTests.System.Configuration public void ConvertFrom_Case() { GenericEnumConverter cv = new GenericEnumConverter(typeof(FooEnum)); - Assert.Throws(() => cv.ConvertFrom(null, null, "foo")); + AssertExtensions.Throws(null, () => cv.ConvertFrom(null, null, "foo")); } [Fact] @@ -97,7 +97,7 @@ namespace MonoTests.System.Configuration GenericEnumConverter cv = new GenericEnumConverter(typeof(FooEnum)); object o = null; - Assert.Throws(() => o = cv.ConvertFrom(null, null, "baz")); + AssertExtensions.Throws(null, () => o = cv.ConvertFrom(null, null, "baz")); Assert.Null(o); } @@ -107,7 +107,7 @@ namespace MonoTests.System.Configuration GenericEnumConverter cv = new GenericEnumConverter(typeof(FooEnum)); object o = null; - Assert.Throws(() => o = cv.ConvertFrom(null, null, null)); + AssertExtensions.Throws(null, () => o = cv.ConvertFrom(null, null, null)); Assert.Null(o); } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/InfiniteIntConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/InfiniteIntConverterTest.cs index c3522281a13..b307625c3a8 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/InfiniteIntConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/InfiniteIntConverterTest.cs @@ -120,7 +120,7 @@ namespace MonoTests.System.Configuration { InfiniteIntConverter cv = new InfiniteIntConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, "hi", typeof(string))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, "hi", typeof(string))); } [Fact] diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/InfiniteTimeSpanConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/InfiniteTimeSpanConverterTest.cs index b7ae4101f9b..46c9ccee291 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/InfiniteTimeSpanConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/InfiniteTimeSpanConverterTest.cs @@ -110,7 +110,7 @@ namespace MonoTests.System.Configuration { InfiniteTimeSpanConverter cv = new InfiniteTimeSpanConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, "hi", typeof(string))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, "hi", typeof(string))); } [Fact] @@ -118,7 +118,7 @@ namespace MonoTests.System.Configuration { InfiniteTimeSpanConverter cv = new InfiniteTimeSpanConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, 59, typeof(int))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, 59, typeof(int))); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/IntegerValidatorTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/IntegerValidatorTest.cs index 9d62d6af700..268fc33b310 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/IntegerValidatorTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/IntegerValidatorTest.cs @@ -77,21 +77,21 @@ namespace MonoTests.System.Configuration public void Validate_Exclusive_fail1() { IntegerValidator v = new IntegerValidator(5000, 10000, true); - Assert.Throws(() => v.Validate(5000)); + AssertExtensions.Throws(null, () => v.Validate(5000)); } [Fact] public void Validate_Exclusive_fail2() { IntegerValidator v = new IntegerValidator(5000, 10000, true); - Assert.Throws(() => v.Validate(10000)); + AssertExtensions.Throws(null, () => v.Validate(10000)); } [Fact] public void Validate_Exclusive_fail3() { IntegerValidator v = new IntegerValidator(5000, 10000, true); - Assert.Throws(() => v.Validate(7000)); + AssertExtensions.Throws(null, () => v.Validate(7000)); } [Fact] @@ -102,7 +102,7 @@ namespace MonoTests.System.Configuration false, 3000); - Assert.Throws(() => v.Validate(40000)); + AssertExtensions.Throws(null, () => v.Validate(40000)); } #region BNC654721 https://bugzilla.novell.com/show_bug.cgi?id=654721 diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/LongValidatorTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/LongValidatorTest.cs index 9427480483a..903381fbe90 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/LongValidatorTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/LongValidatorTest.cs @@ -72,21 +72,21 @@ namespace MonoTests.System.Configuration public void Validate_Exclusive_fail1() { LongValidator v = new LongValidator(5000L, 10000L, true); - Assert.Throws(() => v.Validate(5000L)); + AssertExtensions.Throws(null, () => v.Validate(5000L)); } [Fact] public void Validate_Exclusive_fail2() { LongValidator v = new LongValidator(5000L, 10000L, true); - Assert.Throws(() => v.Validate(10000L)); + AssertExtensions.Throws(null, () => v.Validate(10000L)); } [Fact] public void Validate_Exclusive_fail3() { LongValidator v = new LongValidator(5000L, 10000L, true); - Assert.Throws(() => v.Validate(7000L)); + AssertExtensions.Throws(null, () => v.Validate(7000L)); } [Fact] @@ -97,7 +97,7 @@ namespace MonoTests.System.Configuration false, 3000L); - Assert.Throws(() => v.Validate(40000L)); + AssertExtensions.Throws(null, () => v.Validate(40000L)); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/PositiveTimeSpanValidatorTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/PositiveTimeSpanValidatorTest.cs index c00bee222da..719bf6cb34a 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/PositiveTimeSpanValidatorTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/PositiveTimeSpanValidatorTest.cs @@ -57,14 +57,14 @@ namespace MonoTests.System.Configuration public void Validate_fail1() { PositiveTimeSpanValidator v = new PositiveTimeSpanValidator(); - Assert.Throws(() => v.Validate(new TimeSpan(0))); + AssertExtensions.Throws(null, () => v.Validate(new TimeSpan(0))); } [Fact] public void Validate_fail2() { PositiveTimeSpanValidator v = new PositiveTimeSpanValidator(); - Assert.Throws(() => v.Validate(new TimeSpan(-10000))); + AssertExtensions.Throws(null, () => v.Validate(new TimeSpan(-10000))); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/RegexStringValidatorTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/RegexStringValidatorTest.cs index 005a55ba2f6..0a0168b014c 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/RegexStringValidatorTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/RegexStringValidatorTest.cs @@ -61,13 +61,13 @@ namespace MonoTests.System.Configuration { RegexStringValidator v = new RegexStringValidator("[a-z]+"); - Assert.Throws(() => v.Validate("1234")); + AssertExtensions.Throws(null, () => v.Validate("1234")); } [Fact] public void IllegalRegex() { - Assert.Throws(() => new RegexStringValidator("[0-9+")); + AssertExtensions.Throws(null, () => new RegexStringValidator("[0-9+")); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/StringValidatorTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/StringValidatorTest.cs index 45789a93026..82d10520f78 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/StringValidatorTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/StringValidatorTest.cs @@ -59,7 +59,7 @@ namespace MonoTests.System.Configuration { StringValidator v = new StringValidator(1); - Assert.Throws(() => v.Validate(null)); + AssertExtensions.Throws(null, () => v.Validate(null)); } [Fact] @@ -77,7 +77,7 @@ namespace MonoTests.System.Configuration { StringValidator v = new StringValidator(5); - Assert.Throws(() => v.Validate("1234")); + AssertExtensions.Throws(null, () => v.Validate("1234")); } [Fact] @@ -95,7 +95,7 @@ namespace MonoTests.System.Configuration { StringValidator v = new StringValidator(5, 7); - Assert.Throws(() => v.Validate("1234")); + AssertExtensions.Throws(null, () => v.Validate("1234")); } [Fact] @@ -103,7 +103,7 @@ namespace MonoTests.System.Configuration { StringValidator v = new StringValidator(5, 7); - Assert.Throws(() => v.Validate("12345678")); + AssertExtensions.Throws(null, () => v.Validate("12345678")); } [Fact] @@ -119,7 +119,7 @@ namespace MonoTests.System.Configuration { StringValidator v = new StringValidator(5, 7, "345"); - Assert.Throws(() => v.Validate("123456")); + AssertExtensions.Throws(null, () => v.Validate("123456")); } [Fact] @@ -127,7 +127,7 @@ namespace MonoTests.System.Configuration { StringValidator v = new StringValidator(5, 7, "890"); - Assert.Throws(() => v.Validate("12345678")); + AssertExtensions.Throws(null, () => v.Validate("12345678")); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/SubclassTypeValidatorTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/SubclassTypeValidatorTest.cs index fc78b3e35d7..b0ae448eaa2 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/SubclassTypeValidatorTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/SubclassTypeValidatorTest.cs @@ -64,7 +64,7 @@ namespace MonoTests.System.Configuration { SubclassTypeValidator v = new SubclassTypeValidator(typeof(B)); - Assert.Throws(() => v.Validate(typeof(A))); + AssertExtensions.Throws(null, () => v.Validate(typeof(A))); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanMinutesConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanMinutesConverterTest.cs index 91d46bb3be4..2ef6ca2710e 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanMinutesConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanMinutesConverterTest.cs @@ -120,7 +120,7 @@ namespace MonoTests.System.Configuration { TimeSpanMinutesConverter cv = new TimeSpanMinutesConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, 59, typeof(string))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, 59, typeof(string))); } [Fact] diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanMinutesOrInfiniteConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanMinutesOrInfiniteConverterTest.cs index 565c5550884..5d9b33524cf 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanMinutesOrInfiniteConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanMinutesOrInfiniteConverterTest.cs @@ -130,7 +130,7 @@ namespace MonoTests.System.Configuration { TimeSpanMinutesOrInfiniteConverter cv = new TimeSpanMinutesOrInfiniteConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, 59, typeof(string))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, 59, typeof(string))); } [Fact] diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanSecondsConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanSecondsConverterTest.cs index ba4fed0c722..f83984a9b7f 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanSecondsConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanSecondsConverterTest.cs @@ -77,7 +77,7 @@ namespace MonoTests.System.Configuration TimeSpanSecondsConverter cv = new TimeSpanSecondsConverter(); object o = null; - Assert.Throws(() => o = cv.ConvertFrom(null, null, "100.5")); + AssertExtensions.Throws(null, () => o = cv.ConvertFrom(null, null, "100.5")); Assert.Null(o); } @@ -87,7 +87,7 @@ namespace MonoTests.System.Configuration TimeSpanSecondsConverter cv = new TimeSpanSecondsConverter(); object o = null; - Assert.Throws(() => o = cv.ConvertFrom(null, null, 59)); + AssertExtensions.Throws(null, () => o = cv.ConvertFrom(null, null, 59)); Assert.Null(o); } @@ -120,7 +120,7 @@ namespace MonoTests.System.Configuration { TimeSpanSecondsConverter cv = new TimeSpanSecondsConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, 59, typeof(string))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, 59, typeof(string))); } [Fact] diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanSecondsOrInfiniteConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanSecondsOrInfiniteConverterTest.cs index 200b6945bba..958d06eb093 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanSecondsOrInfiniteConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanSecondsOrInfiniteConverterTest.cs @@ -82,7 +82,7 @@ namespace MonoTests.System.Configuration TimeSpanSecondsOrInfiniteConverter cv = new TimeSpanSecondsOrInfiniteConverter(); object o = null; - Assert.Throws(() => o = cv.ConvertFrom(null, null, "100.5")); + AssertExtensions.Throws(null, () => o = cv.ConvertFrom(null, null, "100.5")); Assert.Null(o); } @@ -127,7 +127,7 @@ namespace MonoTests.System.Configuration { TimeSpanSecondsOrInfiniteConverter cv = new TimeSpanSecondsOrInfiniteConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, 59, typeof(string))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, 59, typeof(string))); } [Fact] diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanValidatorTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanValidatorTest.cs index e0363b428f1..f01e5468f7f 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanValidatorTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TimeSpanValidatorTest.cs @@ -74,21 +74,21 @@ namespace MonoTests.System.Configuration public void Validate_Exclusive_fail1() { TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(5000), new TimeSpan(10000), true); - Assert.Throws(() => v.Validate(new TimeSpan(5000))); + AssertExtensions.Throws(null, () => v.Validate(new TimeSpan(5000))); } [Fact] public void Validate_Exclusive_fail2() { TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(5000), new TimeSpan(10000), true); - Assert.Throws(() => v.Validate(new TimeSpan(10000))); + AssertExtensions.Throws(null, () => v.Validate(new TimeSpan(10000))); } [Fact] public void Validate_Exclusive_fail3() { TimeSpanValidator v = new TimeSpanValidator(new TimeSpan(5000), new TimeSpan(10000), true); - Assert.Throws(() => v.Validate(new TimeSpan(7000))); + AssertExtensions.Throws(null, () => v.Validate(new TimeSpan(7000))); } [Fact] @@ -99,7 +99,7 @@ namespace MonoTests.System.Configuration false, 2); - Assert.Throws(() => v.Validate(TimeSpan.FromTicks(40000))); + AssertExtensions.Throws(null, () => v.Validate(TimeSpan.FromTicks(40000))); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TypeNameConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TypeNameConverterTest.cs index 848d42dc8fc..b31b9ce2ac3 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TypeNameConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/TypeNameConverterTest.cs @@ -101,7 +101,7 @@ namespace MonoTests.System.Configuration { TypeNameConverter cv = new TypeNameConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, 59, typeof(string))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, 59, typeof(string))); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/WhiteSpaceTrimStringConverterTest.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/WhiteSpaceTrimStringConverterTest.cs index 09ad4e26e64..8517b4da182 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/WhiteSpaceTrimStringConverterTest.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/Mono/WhiteSpaceTrimStringConverterTest.cs @@ -105,7 +105,7 @@ namespace MonoTests.System.Configuration { WhiteSpaceTrimStringConverter cv = new WhiteSpaceTrimStringConverter(); - Assert.Throws(() => cv.ConvertTo(null, null, 59, typeof(string))); + AssertExtensions.Throws(null, () => cv.ConvertTo(null, null, 59, typeof(string))); } } } diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj b/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj index 0d65b286ee4..18fa12319be 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/System.Configuration.ConfigurationManager.Tests.csproj @@ -105,6 +105,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ConfigurationPropertyTests.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ConfigurationPropertyTests.cs index 1f3fbe34f8f..52a88f2ce30 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ConfigurationPropertyTests.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ConfigurationPropertyTests.cs @@ -25,13 +25,13 @@ namespace System.ConfigurationTests [Fact] public void NullNameThrows() { - Assert.Throws(() => new ConfigurationProperty(null, typeof(string))); + AssertExtensions.Throws("name", () => new ConfigurationProperty(null, typeof(string))); } [Fact] public void EmptyNameThrows() { - Assert.Throws(() => new ConfigurationProperty("", typeof(string))); + AssertExtensions.Throws("name", () => new ConfigurationProperty("", typeof(string))); } [Theory @@ -42,7 +42,7 @@ namespace System.ConfigurationTests ] public void ReservedNameThrows(string name) { - Assert.Throws(() => new ConfigurationProperty(name, typeof(string))); + AssertExtensions.Throws(null, () => new ConfigurationProperty(name, typeof(string))); } [Theory diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ImplicitMachineConfigTests.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ImplicitMachineConfigTests.cs index 6671d8a0fc3..96da21403b2 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ImplicitMachineConfigTests.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/ImplicitMachineConfigTests.cs @@ -33,7 +33,7 @@ namespace System.ConfigurationTests { // ConfigurationFileMap checks for existence in the constructor string missingFile = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".config"); - Assert.Throws(() => new ConfigurationFileMap(missingFile)); + AssertExtensions.Throws("machineConfigFilename", () => new ConfigurationFileMap(missingFile)); } [Fact] diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/StringValidatorTests.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/StringValidatorTests.cs index 0d64f9ed10c..77a9134cac0 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/StringValidatorTests.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/StringValidatorTests.cs @@ -29,21 +29,21 @@ namespace System.ConfigurationTests public void Validate_PassInNonString() { StringValidator validator = new StringValidator(5); - ArgumentException thrownException = Assert.Throws(() => validator.Validate(5)); + AssertExtensions.Throws("", () => validator.Validate(5)); } [Fact] public void Validate_StringTooSmall() { StringValidator validator = new StringValidator(5); - ArgumentException thrownException = Assert.Throws(() => validator.Validate("Hi")); + AssertExtensions.Throws(null, () => validator.Validate("Hi")); } [Fact] public void Validate_StringTooBig() { StringValidator validator = new StringValidator(5, 10); - ArgumentException thrownException = Assert.Throws(() => validator.Validate("This is more than ten")); + ArgumentException thrownException = AssertExtensions.Throws(null, () => validator.Validate("This is more than ten")); } [Fact] @@ -59,7 +59,7 @@ namespace System.ConfigurationTests public void Validate_UsinginvalidCharacters(string stringToValidate) { StringValidator validator = new StringValidator(1, 20, "_-"); - ArgumentException result = Assert.Throws(() => validator.Validate(stringToValidate)); + ArgumentException result = AssertExtensions.Throws(null, () => validator.Validate(stringToValidate)); } [Fact] @@ -88,4 +88,4 @@ namespace System.ConfigurationTests yield return new object[] { "-" }; } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/TypeUtilTests.cs b/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/TypeUtilTests.cs index 6a4c4bc9299..86e9d98b104 100644 --- a/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/TypeUtilTests.cs +++ b/src/libraries/System.Configuration.ConfigurationManager/tests/System/Configuration/TypeUtilTests.cs @@ -66,7 +66,7 @@ namespace System.ConfigurationTests public void GetTypeConfigHost_ThrowOnError() { TestHost host = new TestHost((s, b) => { if (b) throw new ArgumentException(); return null; }); - Assert.Throws(() => TypeUtil.GetType(host, "Mxyzptlk", throwOnError: true)); + AssertExtensions.Throws(null, () => TypeUtil.GetType(host, "Mxyzptlk", throwOnError: true)); } [Fact] diff --git a/src/libraries/System.Console/tests/Color.cs b/src/libraries/System.Console/tests/Color.cs index 7c30f0c23df..1445441af12 100644 --- a/src/libraries/System.Console/tests/Color.cs +++ b/src/libraries/System.Console/tests/Color.cs @@ -14,8 +14,8 @@ public class Color [Fact] public static void InvalidColors() { - Assert.Throws(() => Console.BackgroundColor = (ConsoleColor)42); - Assert.Throws(() => Console.ForegroundColor = (ConsoleColor)42); + AssertExtensions.Throws(null, () => Console.BackgroundColor = (ConsoleColor)42); + AssertExtensions.Throws(null, () => Console.ForegroundColor = (ConsoleColor)42); } [Fact] diff --git a/src/libraries/System.Console/tests/NegativeTesting.cs b/src/libraries/System.Console/tests/NegativeTesting.cs index 3c39fd9581d..dd5ef5cc511 100644 --- a/src/libraries/System.Console/tests/NegativeTesting.cs +++ b/src/libraries/System.Console/tests/NegativeTesting.cs @@ -49,7 +49,7 @@ public class NegativeTesting Assert.Throws(() => stream.Read(new byte[] { 0, 1 }, 0, -1)); //ConsoleStream.Read() should throw ArgumentException - Assert.Throws(() => stream.Read(new byte[] { 0, 1 }, 0, 50)); + AssertExtensions.Throws(null, () => stream.Read(new byte[] { 0, 1 }, 0, 50)); //ConsoleStream.Read() should throw NotSupportedException Assert.Throws(() => stream.Read(new byte[] { 0, 1 }, 0, 2)); @@ -64,7 +64,7 @@ public class NegativeTesting Assert.Throws(() => stream.Write(new byte[] { 0, 1 }, 0, -1)); //ConsoleStream.Write() should throw ArgumentException - Assert.Throws(() => stream.Write(new byte[] { 0, 1 }, 0, 50)); + AssertExtensions.Throws(null, () => stream.Write(new byte[] { 0, 1 }, 0, 50)); //ConsoleStream.Write() should throw NotSupportedException Assert.Throws(() => stream.Seek(0L, SeekOrigin.Begin)); diff --git a/src/libraries/System.Console/tests/SyncTextReader.cs b/src/libraries/System.Console/tests/SyncTextReader.cs index 2334ef36b7d..7e90aa11e06 100644 --- a/src/libraries/System.Console/tests/SyncTextReader.cs +++ b/src/libraries/System.Console/tests/SyncTextReader.cs @@ -176,7 +176,7 @@ public class SyncTextReader Assert.Throws(() => { Console.In.ReadBlockAsync(null, 0, 0); }); Assert.Throws(() => { Console.In.ReadBlockAsync(new char[1], -1, 0); }); Assert.Throws(() => { Console.In.ReadBlockAsync(new char[1], 0, -1); }); - Assert.Throws(() => { Console.In.ReadBlockAsync(new char[1], 1, 1); }); + AssertExtensions.Throws(null, () => { Console.In.ReadBlockAsync(new char[1], 1, 1); }); }); } @@ -200,7 +200,7 @@ public class SyncTextReader Assert.Throws(() => { Console.In.ReadAsync(null, 0, 0); }); Assert.Throws(() => { Console.In.ReadAsync(new char[1], -1, 0); }); Assert.Throws(() => { Console.In.ReadAsync(new char[1], 0, -1); }); - Assert.Throws(() => { Console.In.ReadAsync(new char[1], 1, 1); }); + AssertExtensions.Throws(null, () => { Console.In.ReadAsync(new char[1], 1, 1); }); }); } diff --git a/src/libraries/System.Data.Common/tests/System/Data/Common/DataColumnMappingCollectionTest.cs b/src/libraries/System.Data.Common/tests/System/Data/Common/DataColumnMappingCollectionTest.cs index 227455d522e..3e5e4c6df44 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/Common/DataColumnMappingCollectionTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/Common/DataColumnMappingCollectionTest.cs @@ -372,7 +372,7 @@ namespace System.Data.Tests.Common [Fact] public void RemoveException2() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { _columnMapCollection.AddRange(_cols); DataColumnMapping mymap = new DataColumnMapping("sourceAge", "dataSetAge"); @@ -486,4 +486,4 @@ namespace System.Data.Tests.Common Assert.Equal("dataSetPINSet", dataColumnMapping.DataSetColumn); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Data.Common/tests/System/Data/Common/DataTableMappingCollectionTest.cs b/src/libraries/System.Data.Common/tests/System/Data/Common/DataTableMappingCollectionTest.cs index d02e290fb38..3c5f2044dd8 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/Common/DataTableMappingCollectionTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/Common/DataTableMappingCollectionTest.cs @@ -306,7 +306,7 @@ namespace System.Data.Tests.Common [Fact] public void RemoveException2() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { _tableMapCollection.AddRange(_tabs); DataTableMapping mymap = new DataTableMapping("sourceAge", "dataSetAge"); diff --git a/src/libraries/System.Data.Common/tests/System/Data/Common/DbConnectionStringBuilderTest.cs b/src/libraries/System.Data.Common/tests/System/Data/Common/DbConnectionStringBuilderTest.cs index 688971873e6..e4339d3019d 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/Common/DbConnectionStringBuilderTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/Common/DbConnectionStringBuilderTest.cs @@ -1740,7 +1740,7 @@ namespace System.Data.Tests.Common [Fact] public void NegICollectionCopyToTest() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { KeyValuePair[] dict = new KeyValuePair[1]; _builder.Add(SERVER, SERVER_VALUE); diff --git a/src/libraries/System.Data.Common/tests/System/Data/ConstraintCollectionTest.cs b/src/libraries/System.Data.Common/tests/System/Data/ConstraintCollectionTest.cs index f98e1882d78..9aa29a9036a 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/ConstraintCollectionTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/ConstraintCollectionTest.cs @@ -146,7 +146,7 @@ namespace System.Data.Tests _table.Rows.Add(new object[] { 1 }); //FKC: can't create unique constraint because duplicate values already exist - Assert.Throws(() => + AssertExtensions.Throws(null, () => { var fkc = new ForeignKeyConstraint(_table.Columns[0], _table2.Columns[0]); _table2.Constraints.Add(fkc); @@ -167,7 +167,7 @@ namespace System.Data.Tests _table2.Rows.Add(new object[] { 3 }); var fkc = new ForeignKeyConstraint(_table.Columns[0], _table2.Columns[0]); - Assert.Throws(() => _table2.Constraints.Add(fkc)); + AssertExtensions.Throws(null, () => _table2.Constraints.Add(fkc)); } [Fact] @@ -177,7 +177,7 @@ namespace System.Data.Tests _table.Rows.Add(new object[] { 1 }); _table.Rows.Add(new object[] { 1 }); var uc = new UniqueConstraint(_table.Columns[0]); - Assert.Throws(() => _table.Constraints.Add(uc)); + AssertExtensions.Throws(null, () => _table.Constraints.Add(uc)); } [Fact] diff --git a/src/libraries/System.Data.Common/tests/System/Data/ConstraintCollectionTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/ConstraintCollectionTest2.cs index 8dedd9af54d..006b0652a56 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/ConstraintCollectionTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/ConstraintCollectionTest2.cs @@ -276,7 +276,7 @@ namespace System.Data.Tests Assert.False(col1.Unique); table.PrimaryKey = new DataColumn[] { col2 }; - Assert.Throws(() => table.Constraints.Remove(table.Constraints[0])); + AssertExtensions.Throws(null, () => table.Constraints.Remove(table.Constraints[0])); } [Fact] @@ -362,7 +362,7 @@ namespace System.Data.Tests c2 = table1.Constraints.Add("unique2", col2, false); c3 = table2.Constraints.Add("fk", col1, col3); - Assert.Throws(() => table1.Constraints.Remove(c1)); + AssertExtensions.Throws(null, () => table1.Constraints.Remove(c1)); Assert.Equal(2, table1.Constraints.Count); @@ -497,7 +497,7 @@ namespace System.Data.Tests [Fact] public void AddRange_C3() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { var ds = new DataSet(); ds.Tables.Add(DataProvider.CreateParentDataTable()); @@ -586,7 +586,7 @@ namespace System.Data.Tests DataTable table = new DataTable(); table.Columns.Add("col1"); Constraint c = table.Constraints.Add("c", table.Columns[0], false); - Assert.Throws(() => table.Constraints.Remove("sdfs")); + AssertExtensions.Throws(null, () => table.Constraints.Remove("sdfs")); table.Constraints.Remove(c); Assert.Equal(0, table.Constraints.Count); diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataColumnCollectionTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataColumnCollectionTest.cs index 168525e3098..0f8e6c5804f 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataColumnCollectionTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataColumnCollectionTest.cs @@ -612,7 +612,7 @@ namespace System.Data.Tests ds.Tables[1].Columns.Add("col2", typeof(int)); ds.Relations.Add("rel1", ds.Tables[0].Columns[0], ds.Tables[1].Columns[0]); - Assert.Throws(() => ds.Tables[0].Columns.RemoveAt(0)); + AssertExtensions.Throws(null, () => ds.Tables[0].Columns.RemoveAt(0)); } [Fact] diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataColumnCollectionTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataColumnCollectionTest2.cs index ee0025e9c7d..bd4bba64305 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataColumnCollectionTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataColumnCollectionTest2.cs @@ -450,7 +450,7 @@ namespace System.Data.Tests //------Check Remove column exception--------- dt = dtSource.Clone(); dt.ImportRow(dtSource.Rows[0]); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataColumn dc = new DataColumn(); dt.Columns.Remove(dc); @@ -474,7 +474,7 @@ namespace System.Data.Tests DataTable dt = new DataTable(); DataColumn col = new DataColumn("col1", Type.GetType("System.String")); dt.Columns.Add(col); - Assert.Throws(() => dt.Columns.Add(col)); + AssertExtensions.Throws(null, () => dt.Columns.Add(col)); } [Fact] @@ -571,7 +571,7 @@ namespace System.Data.Tests public void Clear2() { DataSet ds = DataProvider.CreateForigenConstraint(); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { ds.Tables[0].Columns.Clear(); }); @@ -767,14 +767,14 @@ namespace System.Data.Tests dt = dtSource.Clone(); dt.ImportRow(dtSource.Rows[0]); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { dt.Columns.Remove("NotExist"); }); dt.Columns.Clear(); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { dt.Columns.Remove("Col_0"); }); diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataColumnTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataColumnTest2.cs index 93a97c727dc..73a8820ee9a 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataColumnTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataColumnTest2.cs @@ -289,7 +289,7 @@ namespace System.Data.Tests dt.Rows.Add(new object[] { "a" }); //MaxLength = 5 - Assert.Throws(() => dt.Rows[0][0] = "123456"); + AssertExtensions.Throws(null, () => dt.Rows[0][0] = "123456"); } [Fact] @@ -550,20 +550,20 @@ namespace System.Data.Tests public void Expression_Exceptions() { DataTable dt = DataProvider.CreateParentDataTable(); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { dt.Columns[0].Unique = true; dt.Columns[0].Expression = "sum(" + dt.Columns[0].ColumnName + ")"; }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt1 = DataProvider.CreateParentDataTable(); dt1.Columns[0].AutoIncrement = true; dt1.Columns[0].Expression = "sum(" + dt1.Columns[0].ColumnName + ")"; }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt1 = DataProvider.CreateParentDataTable(); dt1.Constraints.Add(new UniqueConstraint(dt1.Columns[0], false)); @@ -576,7 +576,7 @@ namespace System.Data.Tests dt1.Columns[0].Expression = "CONVERT(" + dt1.Columns[1].ColumnName + ",'System.Int32')"; }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt1 = DataProvider.CreateParentDataTable(); dt1.Columns[0].Expression = "CONVERT(" + dt1.Columns[0].ColumnName + ",'System.DateTime')"; diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataRelationCollectionTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataRelationCollectionTest.cs index b99bf206bcb..22083e223e0 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataRelationCollectionTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataRelationCollectionTest.cs @@ -91,7 +91,7 @@ namespace System.Data.Tests [Fact] public void AddException2() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataRelationCollection drcol = _dataset.Relations; DataRelation dr1 = new DataRelation("CustOrder" @@ -288,7 +288,7 @@ namespace System.Data.Tests DataRelation newdr = new DataRelation("newdr" , _dataset.Tables["Customer"].Columns["custid"] , _dataset.Tables["Order"].Columns["custid"]); - Assert.Throws(() => drcol.Remove(newdr)); + AssertExtensions.Throws(null, () => drcol.Remove(newdr)); } [Fact] diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataRelationCollectionTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataRelationCollectionTest2.cs index 6c17ffe91ec..883acd70b86 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataRelationCollectionTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataRelationCollectionTest2.cs @@ -333,7 +333,7 @@ namespace System.Data.Tests Assert.Equal(typeof(UniqueConstraint), ds.Tables[0].Constraints[0].GetType()); Assert.Equal(typeof(ForeignKeyConstraint), ds.Tables[1].Constraints[0].GetType()); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { ds.Relations.Add(rel); }); @@ -420,7 +420,7 @@ namespace System.Data.Tests Assert.Equal(2, _changesCounter); ds.Relations.Remove((DataRelation)null); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataRelation rel3 = new DataRelation("rel3", ds1.Tables[0].Columns["ParentId"], ds1.Tables[1].Columns["ParentId"]); ds.Relations.Remove(rel3); @@ -450,12 +450,12 @@ namespace System.Data.Tests Assert.Equal(0, ds.Relations.Count); Assert.Equal(2, _changesCounter); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { ds.Relations.Remove((string)null); }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { ds.Relations.Remove("rel3"); }); diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataRelationTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataRelationTest2.cs index 25a69672b4f..90bf2d29c47 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataRelationTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataRelationTest2.cs @@ -240,7 +240,7 @@ namespace System.Data.Tests dRel = new DataRelation("MyRelation", dtParent.Columns[0], dtChild.Columns[0]); // Add relation which will create invalid constraint - Assert.Throws(() => + AssertExtensions.Throws(null, () => { ds.Relations.Add(dRel); }); @@ -277,7 +277,7 @@ namespace System.Data.Tests // Add relation which will create invalid constraint if (createConstraints == true) { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { ds.Relations.Add(dRel); }); @@ -325,14 +325,14 @@ namespace System.Data.Tests //check some exception // DataRelation - CTor ArgumentException, two columns child - Assert.Throws(() => + AssertExtensions.Throws(null, () => { dRel = new DataRelation("MyRelation", new DataColumn[] { dtParent.Columns[0] }, new DataColumn[] { dtChild.Columns[0], dtChild.Columns[2] }); }); dRel = new DataRelation("MyRelation", new DataColumn[] { dtParent.Columns[0], dtParent.Columns[1] }, new DataColumn[] { dtChild.Columns[0], dtChild.Columns[2] }); // DataRelation - Add Relation ArgumentException, fail on creating child Constraints - Assert.Throws(() => + AssertExtensions.Throws(null, () => { ds.Relations.Add(dRel); }); @@ -406,7 +406,7 @@ namespace System.Data.Tests // Add relation which will create invalid constraint if (createConstraints == true) { - Assert.Throws(() => ds.Relations.Add(dRel)); + AssertExtensions.Throws(null, () => ds.Relations.Add(dRel)); } else ds.Relations.Add(dRel); diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataRowCollectionTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataRowCollectionTest2.cs index 821e099bb6f..273455ce454 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataRowCollectionTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataRowCollectionTest2.cs @@ -117,7 +117,7 @@ namespace System.Data.Tests [Fact] public void DataRowCollection_Add_D2() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt = DataProvider.CreateParentDataTable(); dt.Rows.Add(dt.Rows[0]); @@ -137,7 +137,7 @@ namespace System.Data.Tests [Fact] public void DataRowCollection_Add_D4() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt = DataProvider.CreateParentDataTable(); DataTable dt1 = DataProvider.CreateParentDataTable(); @@ -302,7 +302,7 @@ namespace System.Data.Tests [Fact] public void DataRowCollection_Contains_O4() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt = DataProvider.CreateParentDataTable(); dt.PrimaryKey = new DataColumn[] { dt.Columns[0], dt.Columns[1] }; @@ -357,7 +357,7 @@ namespace System.Data.Tests [Fact] public void DataRowCollection_Find_O4() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt = DataProvider.CreateParentDataTable(); dt.PrimaryKey = new DataColumn[] { dt.Columns[0], dt.Columns[1] }; diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataRowTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataRowTest2.cs index 8ca72709040..01aebc8d5d2 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataRowTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataRowTest2.cs @@ -2665,7 +2665,7 @@ namespace System.Data.Tests Assert.Equal(2, (int)dr.ItemArray[0]); Assert.Equal("Oren", (string)dr.ItemArray[1]); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { dt.Rows[0].ItemArray = new object[] { 2, "Oren", "some1else" }; }); diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataRowViewTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataRowViewTest.cs index d7b80a57571..fa3ca7bb710 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataRowViewTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataRowViewTest.cs @@ -43,7 +43,7 @@ namespace System.Data.Tests [Fact] public void CreateChildViewNullStringArg() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataView dv = CreateTestView(); DataRowView dvr = dv[0]; @@ -54,7 +54,7 @@ namespace System.Data.Tests [Fact] public void CreateChildViewNullDataRelationArg() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataView dv = CreateTestView(); DataRowView dvr = dv[0]; @@ -65,7 +65,7 @@ namespace System.Data.Tests [Fact] public void CreateChildViewNonExistentName() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataView dv = CreateTestView(); DataRowView dvr = dv[0]; diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataRowViewTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataRowViewTest2.cs index c0003ac1c83..669dfbac9e7 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataRowViewTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataRowViewTest2.cs @@ -313,7 +313,7 @@ namespace System.Data.Tests Assert.Equal(dt.Rows[0]["ParentDateTime"], drv["ParentDateTime"]); // Item invalid - excpetion - Assert.Throws(() => drv["something"]); + AssertExtensions.Throws(null, () => drv["something"]); } [Fact] diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataSetReadXmlSchemaTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataSetReadXmlSchemaTest.cs index e04f9bcc376..d2e5cdf7acf 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataSetReadXmlSchemaTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataSetReadXmlSchemaTest.cs @@ -277,7 +277,7 @@ namespace System.Data.Tests // DataSet element cannot be converted into a DataTable. // (i.e. cannot be referenced in any other elements) var ds = new DataSet(); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { ds.ReadXmlSchema(new StringReader(xs)); }); diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataSetTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataSetTest.cs index 280f557b1b4..32275d849eb 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataSetTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataSetTest.cs @@ -1945,7 +1945,7 @@ namespace System.Data.Tests public void CreateDataReaderNoTable() { DataSet dsr = new DataSet(); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTableReader dtr = dsr.CreateDataReader(); }); @@ -1992,7 +1992,7 @@ namespace System.Data.Tests [Fact] public void Load_TableUnknown() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { localSetup(); DataSet dsLoad = new DataSet("LoadTableUnknown"); @@ -2029,7 +2029,7 @@ namespace System.Data.Tests [Fact] public void Load_TableConflictF() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { _fillErrCounter = 0; _fillErr[0].init("Table1", 1, false, diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataSetTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataSetTest2.cs index a39ad855c8b..10a6914d654 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataSetTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataSetTest2.cs @@ -2858,7 +2858,7 @@ namespace System.Data.Tests Assert.Equal(2, ds.Relations.Count); // Checking Relations - get by name case sensetive,ArgumentException - Assert.Throws(() => ds.Relations["PARENT-CHILD"]); + AssertExtensions.Throws(null, () => ds.Relations["PARENT-CHILD"]); } [Fact] @@ -2962,7 +2962,7 @@ namespace System.Data.Tests Assert.Equal(dt4, ds.Tables[dt4.TableName]); // Checking get table by name with diferent case, ArgumentException - Assert.Throws(() => ds.Tables[dt4.TableName.ToLower()]); + AssertExtensions.Throws(null, () => ds.Tables[dt4.TableName.ToLower()]); } [Fact] diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataTableCollectionTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataTableCollectionTest.cs index 4dd4417cb4e..0f76f6d84a8 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataTableCollectionTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataTableCollectionTest.cs @@ -108,7 +108,7 @@ namespace System.Data.Tests [Fact] public void AddException2() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { /* table already exist in the collection */ DataTableCollection tbcol = _dataset[0].Tables; diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataTableCollectionTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataTableCollectionTest2.cs index a52f3e040ed..6d29ba51751 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataTableCollectionTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataTableCollectionTest2.cs @@ -312,7 +312,7 @@ namespace System.Data.Tests DataSet ds1 = new DataSet(); ds1.Tables.Add(); - Assert.Throws(() => ds.Tables.Add(ds1.Tables[0])); + AssertExtensions.Throws(null, () => ds.Tables.Add(ds1.Tables[0])); } [Fact] @@ -386,7 +386,7 @@ namespace System.Data.Tests var ds = new DataSet(); DataTable dt = new DataTable("NewTable1"); - Assert.Throws(() => ds.Tables.Remove(dt)); + AssertExtensions.Throws(null, () => ds.Tables.Remove(dt)); } [Fact] @@ -417,7 +417,7 @@ namespace System.Data.Tests { var ds = new DataSet(); - Assert.Throws(() => ds.Tables.Remove("NewTable2")); + AssertExtensions.Throws(null, () => ds.Tables.Remove("NewTable2")); } [Fact] @@ -425,7 +425,7 @@ namespace System.Data.Tests { var ds = new DataSet(); - Assert.Throws(() => ds.Tables.Remove((string)null)); + AssertExtensions.Throws(null, () => ds.Tables.Remove((string)null)); } [Fact] @@ -455,7 +455,7 @@ namespace System.Data.Tests { DataSet ds = DataProvider.CreateForigenConstraint(); - Assert.Throws(() => ds.Tables.RemoveAt(0)); //Parent table + AssertExtensions.Throws(null, () => ds.Tables.RemoveAt(0)); //Parent table } [Fact] diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataTableReadXmlSchemaTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataTableReadXmlSchemaTest.cs index a579ff7254d..607efdb2e50 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataTableReadXmlSchemaTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataTableReadXmlSchemaTest.cs @@ -104,7 +104,7 @@ namespace System.Data.Tests "; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { var ds = new DataSet(); ds.Tables.Add(new DataTable("Root")); @@ -129,7 +129,7 @@ namespace System.Data.Tests "; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { // When explicit msdata:IsDataSet value is "false", then // treat as usual. @@ -168,7 +168,7 @@ namespace System.Data.Tests "; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { // DataSet element cannot be converted into a DataTable. // (i.e. cannot be referenced in any other elements) diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataTableReaderTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataTableReaderTest.cs index 7aa0a3d8b4f..81ea3fc59b7 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataTableReaderTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataTableReaderTest.cs @@ -275,7 +275,7 @@ namespace System.Data.Tests [Fact] public void NoTablesTest() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTableReader reader = new DataTableReader(new DataTable[] { }); try diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataTableTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataTableTest.cs index 4072f3e58cc..abb35ca2ab2 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataTableTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataTableTest.cs @@ -2058,7 +2058,7 @@ Assert.False(true); [Fact] public void ColumnObjectTypeTest() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt = new DataTable(); dt.Columns.Add("Series Label", typeof(SqlInt32)); @@ -4012,7 +4012,7 @@ Assert.False(true); "; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { using (var s = new StringReader(xml)) { diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataViewTest.cs b/src/libraries/System.Data.Common/tests/System/Data/DataViewTest.cs index 98a729fa35b..cca40166e9d 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataViewTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataViewTest.cs @@ -477,7 +477,7 @@ namespace System.Data.Tests [Fact] public void Find_1() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { /* since the sort key is not specified. Must raise a ArgumentException */ int sIndex = _dataView.Find("abc"); @@ -512,7 +512,7 @@ namespace System.Data.Tests [Fact] public void Find_3() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { _dataView.Sort = "itemID, itemName"; /* expecting order key count mismatch */ @@ -586,7 +586,7 @@ namespace System.Data.Tests [Fact] public void FindRowsWithoutSort() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt = new DataTable("table"); dt.Columns.Add("col1"); @@ -605,7 +605,7 @@ namespace System.Data.Tests [Fact] public void FindRowsInconsistentKeyLength() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable dt = new DataTable("table"); dt.Columns.Add("col1"); diff --git a/src/libraries/System.Data.Common/tests/System/Data/DataViewTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/DataViewTest2.cs index 8b383092560..7cab28a5881 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/DataViewTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/DataViewTest2.cs @@ -280,7 +280,7 @@ namespace System.Data.Tests DataView dv = new DataView(dt); // FindRows ,no sort - exception - Assert.Throws(() => + AssertExtensions.Throws(null, () => { dvArr = dv.FindRows(3); }); @@ -323,7 +323,7 @@ namespace System.Data.Tests DataView dv = new DataView(dt); // FindRows ,no sort - exception - Assert.Throws(() => + AssertExtensions.Throws(null, () => { dvArr = dv.FindRows(new object[] { "3", "3-String1" }); }); @@ -388,7 +388,7 @@ namespace System.Data.Tests } // Find ,no sort - exception - Assert.Throws(() => + AssertExtensions.Throws(null, () => { FindResult = dv.Find("3"); }); @@ -425,7 +425,7 @@ namespace System.Data.Tests } // Find ,no sort - exception - Assert.Throws(() => + AssertExtensions.Throws(null, () => { FindResult = dv.Find(new object[] { "3", "3-String1" }); }); diff --git a/src/libraries/System.Data.Common/tests/System/Data/ForeignKeyConstraintTest.cs b/src/libraries/System.Data.Common/tests/System/Data/ForeignKeyConstraintTest.cs index 0a59b1329f9..e00599cc359 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/ForeignKeyConstraintTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/ForeignKeyConstraintTest.cs @@ -300,7 +300,7 @@ namespace System.Data.Tests }); //zero length collection - Assert.Throws(() => + AssertExtensions.Throws(null, () => { fkc = new ForeignKeyConstraint(new DataColumn[] { }, new DataColumn[] { }); }); @@ -332,7 +332,7 @@ namespace System.Data.Tests ForeignKeyConstraint fkc; //Columns must belong to a Table - Assert.Throws(() => + AssertExtensions.Throws(null, () => { fkc = new ForeignKeyConstraint(col, _ds.Tables[0].Columns[0]); }); @@ -355,7 +355,7 @@ namespace System.Data.Tests new DataColumn[] { _ds.Tables[0].Columns[0], _ds.Tables[0].Columns[1] }; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { fkc = new ForeignKeyConstraint(twoCol, new DataColumn[] { _ds.Tables[0].Columns[0] }); @@ -399,7 +399,7 @@ namespace System.Data.Tests [Fact] public void ViolationTest() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { DataTable parent = _ds.Tables[0]; DataTable child = _ds.Tables[1]; diff --git a/src/libraries/System.Data.Common/tests/System/Data/ForeignKeyConstraintTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/ForeignKeyConstraintTest2.cs index 9e1b95ea47c..6cd1544a7fb 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/ForeignKeyConstraintTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/ForeignKeyConstraintTest2.cs @@ -196,7 +196,7 @@ namespace System.Data.Tests ForeignKeyConstraint fc = null; // Ctor ArgumentException - Assert.Throws(() => + AssertExtensions.Throws(null, () => { fc = new ForeignKeyConstraint(new DataColumn[] { dtParent.Columns[0] }, new DataColumn[] { dtChild.Columns[0], dtChild.Columns[1] }); }); @@ -204,7 +204,7 @@ namespace System.Data.Tests fc = new ForeignKeyConstraint(new DataColumn[] { dtParent.Columns[0], dtParent.Columns[1] }, new DataColumn[] { dtChild.Columns[0], dtChild.Columns[2] }); // Add constraint to table - ArgumentException - Assert.Throws(() => + AssertExtensions.Throws(null, () => { dtChild.Constraints.Add(fc); }); @@ -482,7 +482,7 @@ namespace System.Data.Tests [Fact] public void ctor_DclmDclm2() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { var ds = new DataSet(); ds.Tables.Add(DataProvider.CreateParentDataTable()); @@ -496,7 +496,7 @@ namespace System.Data.Tests [Fact] public void ctor_DclmDclm3() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { var ds = new DataSet(); ds.Tables.Add(DataProvider.CreateParentDataTable()); diff --git a/src/libraries/System.Data.Common/tests/System/Data/SqlTypes/SqlStringTest.cs b/src/libraries/System.Data.Common/tests/System/Data/SqlTypes/SqlStringTest.cs index 2b572479ec9..2ffbaa9815f 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/SqlTypes/SqlStringTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/SqlTypes/SqlStringTest.cs @@ -206,7 +206,7 @@ namespace System.Data.Tests.SqlTypes public void CompareToArgumentException() { SqlByte Test = new SqlByte(1); - Assert.Throws(() => _test1.CompareTo(Test)); + AssertExtensions.Throws(null, () => _test1.CompareTo(Test)); } [Fact] diff --git a/src/libraries/System.Data.Common/tests/System/Data/UniqueConstraintTest.cs b/src/libraries/System.Data.Common/tests/System/Data/UniqueConstraintTest.cs index b828ff7ed83..2d000eb82c0 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/UniqueConstraintTest.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/UniqueConstraintTest.cs @@ -50,7 +50,7 @@ namespace System.Data.Tests UniqueConstraint cst; //must have DataTable exception - Assert.Throws(() => new UniqueConstraint(new DataColumn(""))); + AssertExtensions.Throws(null, () => new UniqueConstraint(new DataColumn(""))); //Null exception Assert.Throws(() => new UniqueConstraint((DataColumn)null)); diff --git a/src/libraries/System.Data.Common/tests/System/Data/UniqueConstraintTest2.cs b/src/libraries/System.Data.Common/tests/System/Data/UniqueConstraintTest2.cs index 5cf1c1983f8..978d525390b 100644 --- a/src/libraries/System.Data.Common/tests/System/Data/UniqueConstraintTest2.cs +++ b/src/libraries/System.Data.Common/tests/System/Data/UniqueConstraintTest2.cs @@ -164,7 +164,7 @@ namespace System.Data.Tests //Column[1] is not unique, will throw exception // ArgumentException - Assert.Throws(() => dtChild.Constraints.Add(uc)); + AssertExtensions.Throws(null, () => dtChild.Constraints.Add(uc)); //reset the table dtParent = DataProvider.CreateParentDataTable(); @@ -178,7 +178,7 @@ namespace System.Data.Tests Assert.Equal(typeof(UniqueConstraint).FullName, dtParent.Constraints[0].GetType().FullName); // add UniqueConstarint that don't belong to the table - Assert.Throws(() => + AssertExtensions.Throws(null, () => { dtParent.Constraints.Add(uc); }); @@ -236,7 +236,7 @@ namespace System.Data.Tests //target columnn are not unnique, will throw an exception // ArgumentException - child - Assert.Throws(() => dtChild.Constraints.Add(uc)); + AssertExtensions.Throws(null, () => dtChild.Constraints.Add(uc)); } [Fact] diff --git a/src/libraries/System.Data.SqlClient/tests/FunctionalTests/SqlBulkCopyColumnMappingCollectionTest.cs b/src/libraries/System.Data.SqlClient/tests/FunctionalTests/SqlBulkCopyColumnMappingCollectionTest.cs index e9e1afa53b6..93231398559 100644 --- a/src/libraries/System.Data.SqlClient/tests/FunctionalTests/SqlBulkCopyColumnMappingCollectionTest.cs +++ b/src/libraries/System.Data.SqlClient/tests/FunctionalTests/SqlBulkCopyColumnMappingCollectionTest.cs @@ -468,9 +468,9 @@ namespace System.Data.SqlClient.Tests list.Remove(item2); Assert.Equal(0, list.Count); - Assert.Throws(() => list.Remove(item2)); - Assert.Throws(() => list.Remove(new SqlBulkCopyColumnMapping(2, 2))); - Assert.Throws(() => list.Remove("bogus")); + AssertExtensions.Throws(null, () => list.Remove(item2)); + AssertExtensions.Throws(null, () => list.Remove(new SqlBulkCopyColumnMapping(2, 2))); + AssertExtensions.Throws(null, () => list.Remove("bogus")); } [Fact] diff --git a/src/libraries/System.Data.SqlClient/tests/FunctionalTests/SqlErrorCollectionTest.cs b/src/libraries/System.Data.SqlClient/tests/FunctionalTests/SqlErrorCollectionTest.cs index 0cfc2ed0ec1..01ca0bc8c0e 100644 --- a/src/libraries/System.Data.SqlClient/tests/FunctionalTests/SqlErrorCollectionTest.cs +++ b/src/libraries/System.Data.SqlClient/tests/FunctionalTests/SqlErrorCollectionTest.cs @@ -95,7 +95,7 @@ namespace System.Data.SqlClient.Tests Assert.Throws(() => copyTo(c, null, 0)); Assert.Throws(() => copyTo(c, null, -1)); Assert.Throws(() => copyTo(c, new SqlError[10], -1)); - Assert.Throws(() => copyTo(c, new SqlError[10], 1000)); + AssertExtensions.Throws("destinationArray", "", () => copyTo(c, new SqlError[10], 1000)); additionalValidation?.Invoke(c); } diff --git a/src/libraries/System.Diagnostics.Contracts/tests/ExistsTests.cs b/src/libraries/System.Diagnostics.Contracts/tests/ExistsTests.cs index e54ddc1ec94..366c2e650db 100644 --- a/src/libraries/System.Diagnostics.Contracts/tests/ExistsTests.cs +++ b/src/libraries/System.Diagnostics.Contracts/tests/ExistsTests.cs @@ -15,7 +15,7 @@ namespace System.Diagnostics.Contracts.Tests Assert.Throws(() => Contract.Exists(0, 1, null)); Assert.Throws(() => Contract.Exists(null, i => true)); Assert.Throws(() => Contract.Exists(Enumerable.Empty(), null)); - Assert.Throws(() => Contract.Exists(1, 0, i => true)); // fromInclusive > toExclusive + AssertExtensions.Throws(null, () => Contract.Exists(1, 0, i => true)); // fromInclusive > toExclusive } [Fact] diff --git a/src/libraries/System.Diagnostics.Contracts/tests/ForAllTests.cs b/src/libraries/System.Diagnostics.Contracts/tests/ForAllTests.cs index 87e7867e902..be0198cf25b 100644 --- a/src/libraries/System.Diagnostics.Contracts/tests/ForAllTests.cs +++ b/src/libraries/System.Diagnostics.Contracts/tests/ForAllTests.cs @@ -15,7 +15,7 @@ namespace System.Diagnostics.Contracts.Tests Assert.Throws(() => Contract.ForAll(0, 1, null)); Assert.Throws(() => Contract.ForAll(null, i => true)); Assert.Throws(() => Contract.ForAll(Enumerable.Empty(), null)); - Assert.Throws(() => Contract.ForAll(1, 0, i => true)); // fromInclusive > toExclusive + AssertExtensions.Throws(null, () => Contract.ForAll(1, 0, i => true)); // fromInclusive > toExclusive } [Fact] diff --git a/src/libraries/System.Diagnostics.Contracts/tests/System.Diagnostics.Contracts.Tests.csproj b/src/libraries/System.Diagnostics.Contracts/tests/System.Diagnostics.Contracts.Tests.csproj index e456d1d099e..47324290ee0 100644 --- a/src/libraries/System.Diagnostics.Contracts/tests/System.Diagnostics.Contracts.Tests.csproj +++ b/src/libraries/System.Diagnostics.Contracts/tests/System.Diagnostics.Contracts.Tests.csproj @@ -14,6 +14,9 @@ + + Common\System\AssertExtensions.cs + Common\System\PlatformDetection.cs diff --git a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs index 128778f72b2..ab93ca8b11b 100644 --- a/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs +++ b/src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs @@ -185,7 +185,7 @@ namespace System.Diagnostics.Tests Assert.Throws(() => { environment.CopyTo(kvpa, -1); }); //Exception not thrown with null key - Assert.Throws(() => { environment.CopyTo(kvpa, 9); }); + AssertExtensions.Throws(null, () => { environment.CopyTo(kvpa, 9); }); //Exception not thrown with null key Assert.Throws(() => @@ -692,7 +692,7 @@ namespace System.Diagnostics.Tests Assert.Equal(CountItems + 1, environmentVariables.Count); //Exception not thrown with invalid key - Assert.Throws(() => { environmentVariables.Add("NewKey2", "NewValue2"); }); + AssertExtensions.Throws(null, () => { environmentVariables.Add("NewKey2", "NewValue2"); }); Assert.False(environmentVariables.ContainsKey("NewKey")); environmentVariables.Add("newkey2", "newvalue2"); @@ -754,7 +754,7 @@ namespace System.Diagnostics.Tests //Exception not thrown with invalid key Assert.Throws(() => environmentVariables.Add(null, "NewValue2")); - Assert.Throws(() => environmentVariables.Add("newkey2", "NewValue2")); + AssertExtensions.Throws(null, () => environmentVariables.Add("newkey2", "NewValue2")); //Use DictionaryEntry Enumerator var x = environmentVariables.GetEnumerator() as IEnumerator; @@ -774,14 +774,14 @@ namespace System.Diagnostics.Tests Assert.Equal("newvalue3", kvpa[2].Value); string[] kvp = new string[10]; - Assert.Throws(() => { environmentVariables.CopyTo(kvp, 6); }); + AssertExtensions.Throws(null, () => { environmentVariables.CopyTo(kvp, 6); }); environmentVariables.CopyTo(kvpa, 6); Assert.Equal("NewKey", kvpa[6].Key); Assert.Equal("newvalue", kvpa[6].Value); Assert.Throws(() => { environmentVariables.CopyTo(kvpa, -1); }); - Assert.Throws(() => { environmentVariables.CopyTo(kvpa, 9); }); + AssertExtensions.Throws(null, () => { environmentVariables.CopyTo(kvpa, 9); }); Assert.Throws(() => { diff --git a/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsDelimiterTests.cs b/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsDelimiterTests.cs index 3a7e72f4908..724c2796a96 100644 --- a/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsDelimiterTests.cs +++ b/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsDelimiterTests.cs @@ -92,7 +92,7 @@ namespace System.Diagnostics.TextWriterTraceListenerTests var target = new DelimitedListTraceListener(FileStream.Null); Assert.Equal(DefaultDelimiter, target.Delimiter); Assert.Throws(() => target.Delimiter = null); - Assert.Throws(() => target.Delimiter = string.Empty); + AssertExtensions.Throws(null, () => target.Delimiter = string.Empty); } } } diff --git a/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsStreamTests.cs b/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsStreamTests.cs index 8821e66539a..09a8dc3581e 100644 --- a/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsStreamTests.cs +++ b/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/CtorsStreamTests.cs @@ -20,10 +20,10 @@ namespace System.Diagnostics.TextWriterTraceListenerTests // error CS1061: 'System.IO.MemoryStream' does not contain a definition for 'Close'. // Calling Dispose should have same effect as calling Close. closedStream.Dispose(); - Assert.Throws(() => new TextWriterTraceListener(closedStream)); + AssertExtensions.Throws(null, () => new TextWriterTraceListener(closedStream)); var readOnlyStream = new MemoryStream(new byte[256], writable: false); - Assert.Throws(() => new TextWriterTraceListener(readOnlyStream)); + AssertExtensions.Throws(null, () => new TextWriterTraceListener(readOnlyStream)); } [Fact] diff --git a/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/System.Diagnostics.TextWriterTraceListener.Tests.csproj b/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/System.Diagnostics.TextWriterTraceListener.Tests.csproj index bceee637e12..163556b0ce8 100644 --- a/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/System.Diagnostics.TextWriterTraceListener.Tests.csproj +++ b/src/libraries/System.Diagnostics.TextWriterTraceListener/tests/System.Diagnostics.TextWriterTraceListener.Tests.csproj @@ -14,6 +14,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Diagnostics.TraceSource/tests/TraceListenerCollectionClassTests.cs b/src/libraries/System.Diagnostics.TraceSource/tests/TraceListenerCollectionClassTests.cs index 2a2c83ac20b..14f5a20685a 100644 --- a/src/libraries/System.Diagnostics.TraceSource/tests/TraceListenerCollectionClassTests.cs +++ b/src/libraries/System.Diagnostics.TraceSource/tests/TraceListenerCollectionClassTests.cs @@ -243,7 +243,7 @@ namespace System.Diagnostics.TraceSourceTests } else { - Assert.Throws(() => list.Add(item)); + AssertExtensions.Throws("value", () => list.Add(item)); } } @@ -275,7 +275,7 @@ namespace System.Diagnostics.TraceSourceTests Assert.Equal(item, list[1]); var nonItem = CreateNonItem(); - Assert.Throws(() => list[1] = nonItem); + AssertExtensions.Throws("value", () => list[1] = nonItem); } } @@ -307,7 +307,7 @@ namespace System.Diagnostics.TraceSourceTests public virtual void InsertExceptionTest() { var list = Create(2); - Assert.Throws(() => list.Insert(1, null)); + AssertExtensions.Throws("value", () => list.Insert(1, null)); } [Fact] @@ -401,7 +401,7 @@ namespace System.Diagnostics.TraceSourceTests { var list = Create(4); var arr = new Object[2]; - Assert.Throws(() => list.CopyTo(arr, 0)); + AssertExtensions.Throws("destinationArray", "", () => list.CopyTo(arr, 0)); } } diff --git a/src/libraries/System.Diagnostics.TraceSource/tests/TraceSourceClassTests.cs b/src/libraries/System.Diagnostics.TraceSource/tests/TraceSourceClassTests.cs index 20737dd6f4d..3a50d51d3b5 100644 --- a/src/libraries/System.Diagnostics.TraceSource/tests/TraceSourceClassTests.cs +++ b/src/libraries/System.Diagnostics.TraceSource/tests/TraceSourceClassTests.cs @@ -15,7 +15,7 @@ namespace System.Diagnostics.TraceSourceTests public void ConstrutorExceptionTest() { Assert.Throws(() => new TraceSource(null)); - Assert.Throws(() => new TraceSource("")); + AssertExtensions.Throws("name", null, () => new TraceSource("")); } [Fact] @@ -132,20 +132,8 @@ namespace System.Diagnostics.TraceSourceTests [Fact] public void EmptySourceName() { - ArgumentException exception1 = Assert.Throws(() => new TraceSource(string.Empty)); - ArgumentException exception2 = Assert.Throws(() => new TraceSource(string.Empty, SourceLevels.All)); - - // In Desktop in TraceSource.ctor we create the ArgumentException without param name, just with Message = "name", so ParamName is null - if (PlatformDetection.IsFullFramework) - { - Assert.Null(exception1.ParamName); - Assert.Null(exception2.ParamName); - } - else - { - Assert.Equal("name", exception1.ParamName); - Assert.Equal("name", exception2.ParamName); - } + AssertExtensions.Throws("name", null, () => new TraceSource(string.Empty)); + AssertExtensions.Throws("name", null, () => new TraceSource(string.Empty, SourceLevels.All)); } } diff --git a/src/libraries/System.Diagnostics.TraceSource/tests/TraceSwitchClassTests.cs b/src/libraries/System.Diagnostics.TraceSource/tests/TraceSwitchClassTests.cs index 3b7cf805486..0b42a3a5775 100644 --- a/src/libraries/System.Diagnostics.TraceSource/tests/TraceSwitchClassTests.cs +++ b/src/libraries/System.Diagnostics.TraceSource/tests/TraceSwitchClassTests.cs @@ -26,7 +26,7 @@ namespace System.Diagnostics.TraceSourceTests item = new TraceSwitch("SwitchName", null, "warning"); Assert.Equal(TraceLevel.Warning, item.Level); item = new TraceSwitch("Name", null, "NO_EXIST"); - Assert.Throws(() => item.Level); + AssertExtensions.Throws(null, () => item.Level); item = new TraceSwitch("Name", null, null); Assert.Throws(() => item.Level); @@ -40,8 +40,8 @@ namespace System.Diagnostics.TraceSourceTests Assert.Equal(TraceLevel.Error, item.Level); item.Level = TraceLevel.Info; Assert.Equal(TraceLevel.Info, item.Level); - Assert.Throws(() => item.Level = (TraceLevel)(TraceLevel.Off - 1)); - Assert.Throws(() => item.Level = (TraceLevel)(TraceLevel.Verbose + 1)); + AssertExtensions.Throws(null, () => item.Level = (TraceLevel)(TraceLevel.Off - 1)); + AssertExtensions.Throws(null, () => item.Level = (TraceLevel)(TraceLevel.Verbose + 1)); } [Theory] diff --git a/src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsManifestNegative.cs b/src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsManifestNegative.cs index 8122203f29a..8d63c13404e 100644 --- a/src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsManifestNegative.cs +++ b/src/libraries/System.Diagnostics.Tracing/tests/BasicEventSourceTest/TestsManifestNegative.cs @@ -58,10 +58,10 @@ namespace BasicEventSourceTests Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty)); - Exception e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions)); + Exception e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_TypeMustBeSealedOrAbstract"), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.UnsealedEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_TypeMustBeSealedOrAbstract"), e.Message); // starting with NuGet we allow non-void returning methods as long as they have the [Event] attribute @@ -71,16 +71,16 @@ namespace BasicEventSourceTests Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithReturnEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride)); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty)); Assert.Equal(GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.NegativeEventIdEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride)); Assert.Equal(GetResourceString("EventSource_NeedPositiveId", "WriteInteger"), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.OutOfRangeKwdEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.OutOfRangeKwdEventSource), string.Empty, strictOptions)); Assert.Equal(String.Join(Environment.NewLine, GetResourceString("EventSource_IllegalKeywordsValue", "Kwd1", "0x100000000000"), GetResourceString("EventSource_KeywordCollision", "Session3", "Kwd1", "0x100000000000")), @@ -96,103 +96,103 @@ namespace BasicEventSourceTests () => EventSource.GenerateManifest(typeof(Sdt.EventWithAdminChannelNoMessageEventSource), string.Empty, strictOptions)); #endif // USE_ETW - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions)); Assert.Equal(String.Join(Environment.NewLine, GetResourceString("EventSource_IllegalOpcodeValue", "Op1", 3), GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1)), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.ReservedOpcodeEventSource), string.Empty, strictOptions)); Assert.Equal(String.Join(Environment.NewLine, GetResourceString("EventSource_IllegalOpcodeValue", "Op1", 3), GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1)), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty)); Assert.Equal(GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger"), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, strictOptions)); Assert.Equal(String.Join(Environment.NewLine, GetResourceString("EventSource_EnumKindMismatch", "Op1", "EventKeywords", "Opcodes"), GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger")), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EnumKindMismatchEventSource), string.Empty, EventManifestOptions.AllowEventSourceOverride)); Assert.Equal(GetResourceString("EventSource_UndefinedKeyword", "0x1", "WriteInteger"), e.Message); Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty)); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_MismatchIdToWriteEvent", "WriteInteger", 10, 1), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.MismatchIdEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_MismatchIdToWriteEvent", "WriteInteger", 10, 1), e.Message); Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty)); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions)); Assert.Equal(String.Join(Environment.NewLine, GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"), GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EventIdReusedEventSource), string.Empty, strictOptions)); Assert.Equal(String.Join(Environment.NewLine, GetResourceString("EventSource_EventIdReused", "WriteInteger2", 1, "WriteInteger1"), GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 1, "WriteInteger1", 1)), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_EventNameReused", "WriteInteger"), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EventNameReusedEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_EventNameReused", "WriteInteger"), e.Message); Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty)); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 2, "WriteInteger1", 1), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.TaskOpcodePairReusedEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_TaskOpcodePairReused", "WriteInteger2", 2, "WriteInteger1", 1), e.Message); Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty)); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithOpcodeNoTaskEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_EventMustHaveTaskIfNonDefaultOpcode", "WriteInteger", 1), e.Message); Assert.NotNull(EventSource.GenerateManifest(typeof(Sdt.EventWithInvalidMessageEventSource), string.Empty)); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.EventWithInvalidMessageEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.EventWithInvalidMessageEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_UnsupportedMessageProperty", "WriteString", "Message = {0,12:G}"), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions)); Assert.Equal(String.Join(Environment.NewLine, GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Keywords"), GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Tasks"), GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Opcodes")), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithKwdTaskOpcodeEventSource), string.Empty, strictOptions)); Assert.Equal(String.Join(Environment.NewLine, GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Keywords"), GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Tasks"), GetResourceString("EventSource_AbstractMustNotDeclareKTOC", "Opcodes")), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_AbstractMustNotDeclareEventMethods", "WriteInteger", 1), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.AbstractWithEventsEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_AbstractMustNotDeclareEventMethods", "WriteInteger", 1), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_EventMustNotBeExplicitImplementation", "SdtEventSources.ILogging.Error", 1), e.Message); - e = Assert.Throws(() => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions)); + e = AssertExtensions.Throws(null, () => EventSource.GenerateManifest(typeof(Sdt.ImplementsInterfaceEventSource), string.Empty, strictOptions)); Assert.Equal(GetResourceString("EventSource_EventMustNotBeExplicitImplementation", "SdtEventSources.ILogging.Error", 1), e.Message); TestUtilities.CheckNoEventSourcesRunning("Stop"); diff --git a/src/libraries/System.Diagnostics.Tracing/tests/System.Diagnostics.Tracing.Tests.csproj b/src/libraries/System.Diagnostics.Tracing/tests/System.Diagnostics.Tracing.Tests.csproj index a03fafbe87a..eaac0b4029b 100644 --- a/src/libraries/System.Diagnostics.Tracing/tests/System.Diagnostics.Tracing.Tests.csproj +++ b/src/libraries/System.Diagnostics.Tracing/tests/System.Diagnostics.Tracing.Tests.csproj @@ -36,6 +36,9 @@ + + CommonTest\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.Drawing.Common/tests/BitmapTests.cs b/src/libraries/System.Drawing.Common/tests/BitmapTests.cs index b10c5f76586..765cfb82319 100644 --- a/src/libraries/System.Drawing.Common/tests/BitmapTests.cs +++ b/src/libraries/System.Drawing.Common/tests/BitmapTests.cs @@ -78,14 +78,14 @@ namespace System.Drawing.Tests } [ConditionalTheory(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsNanoServer))] - [InlineData("")] - [InlineData("\0")] - [InlineData("NoSuchPath")] - public void Ctor_InvalidFilePath_ThrowsArgumentException(string filename) + [InlineData("", "path")] + [InlineData("\0", "path")] + [InlineData("NoSuchPath", null)] + public void Ctor_InvalidFilePath_ThrowsArgumentException(string filename, string paramName) { - Assert.Throws(() => new Bitmap(filename)); - Assert.Throws(() => new Bitmap(filename, false)); - Assert.Throws(() => new Bitmap(filename, true)); + AssertExtensions.Throws(paramName, null, () => new Bitmap(filename)); + AssertExtensions.Throws(paramName, null, () => new Bitmap(filename, false)); + AssertExtensions.Throws(paramName, null, () => new Bitmap(filename, true)); } [ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsNanoServer))] diff --git a/src/libraries/System.Drawing.Common/tests/IconTests.cs b/src/libraries/System.Drawing.Common/tests/IconTests.cs index 265fe043b70..c4e212d0ea2 100644 --- a/src/libraries/System.Drawing.Common/tests/IconTests.cs +++ b/src/libraries/System.Drawing.Common/tests/IconTests.cs @@ -374,12 +374,12 @@ namespace System.Drawing.Tests } [ConditionalTheory(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsNanoServer))] - [InlineData(null)] - [InlineData("")] - [InlineData("\\\\uncpath")] - public void ExtractAssociatedIcon_InvalidFilePath_ThrowsArgumentException(string filePath) + [InlineData(null, null)] + [InlineData("", "path")] + [InlineData("\\\\uncpath", null)] + public void ExtractAssociatedIcon_InvalidFilePath_ThrowsArgumentException(string filePath, string paramName) { - Assert.Throws(() => Icon.ExtractAssociatedIcon(filePath)); + AssertExtensions.Throws(paramName, null, () => Icon.ExtractAssociatedIcon(filePath)); } [ConditionalFact(nameof(PlatformDetection) + "." + nameof(PlatformDetection.IsNotWindowsNanoServer))] diff --git a/src/libraries/System.Drawing.Common/tests/Printing/MarginsTests.cs b/src/libraries/System.Drawing.Common/tests/Printing/MarginsTests.cs index cc9df4236af..4f735b52b2f 100644 --- a/src/libraries/System.Drawing.Common/tests/Printing/MarginsTests.cs +++ b/src/libraries/System.Drawing.Common/tests/Printing/MarginsTests.cs @@ -61,7 +61,7 @@ namespace System.Drawing.Printing.Tests [InlineData(0, 0, 0, -1)] public void Ctor_BoundsBadValues_ThrowsArgumentException(int left, int right, int top, int bottom) { - Assert.Throws(() => new Margins(left, right, top, bottom)); + AssertExtensions.Throws(null, () => new Margins(left, right, top, bottom)); } private static IEnumerable Equals_TestData() @@ -120,10 +120,10 @@ namespace System.Drawing.Printing.Tests public void Bounds_BadValues_ThrowsArgumentException() { Margins m = new Margins(); - Assert.Throws(() => m.Bottom = -1); - Assert.Throws(() => m.Left = -1); - Assert.Throws(() => m.Right = -1); - Assert.Throws(() => m.Top = -1); + AssertExtensions.Throws(null, () => m.Bottom = -1); + AssertExtensions.Throws(null, () => m.Left = -1); + AssertExtensions.Throws(null, () => m.Right = -1); + AssertExtensions.Throws(null, () => m.Top = -1); } } } diff --git a/src/libraries/System.Drawing.Common/tests/Printing/PaperSizeTests.cs b/src/libraries/System.Drawing.Common/tests/Printing/PaperSizeTests.cs index 720521b1540..9413e9ea7e7 100644 --- a/src/libraries/System.Drawing.Common/tests/Printing/PaperSizeTests.cs +++ b/src/libraries/System.Drawing.Common/tests/Printing/PaperSizeTests.cs @@ -62,9 +62,9 @@ namespace System.Drawing.Printing.Tests { PaperSize ps = new PaperSize("foo", 100, 100); ps.RawKind = rawKind; - Assert.Throws(() => ps.Width = 1); - Assert.Throws(() => ps.Height = 1); - Assert.Throws(() => ps.PaperName = "NewName"); + AssertExtensions.Throws(null, () => ps.Width = 1); + AssertExtensions.Throws(null, () => ps.Height = 1); + AssertExtensions.Throws(null, () => ps.PaperName = "NewName"); } [Theory] diff --git a/src/libraries/System.Drawing.Primitives/tests/ColorTests.cs b/src/libraries/System.Drawing.Primitives/tests/ColorTests.cs index cb80989bdd7..2212342a728 100644 --- a/src/libraries/System.Drawing.Primitives/tests/ColorTests.cs +++ b/src/libraries/System.Drawing.Primitives/tests/ColorTests.cs @@ -299,11 +299,11 @@ namespace System.Drawing.Primitives.Tests [MemberData(nameof(InvalidValues))] public void FromArgb_InvalidAlpha(int alpha) { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Color.FromArgb(alpha, Color.Red); }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Color.FromArgb(alpha, 0, 0, 0); }); @@ -313,11 +313,11 @@ namespace System.Drawing.Primitives.Tests [MemberData(nameof(InvalidValues))] public void FromArgb_InvalidRed(int red) { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Color.FromArgb(red, 0, 0); }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Color.FromArgb(0, red, 0, 0); }); @@ -327,11 +327,11 @@ namespace System.Drawing.Primitives.Tests [MemberData(nameof(InvalidValues))] public void FromArgb_InvalidGreen(int green) { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Color.FromArgb(0, green, 0); }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Color.FromArgb(0, 0, green, 0); }); @@ -341,11 +341,11 @@ namespace System.Drawing.Primitives.Tests [MemberData(nameof(InvalidValues))] public void FromArgb_InvalidBlue(int blue) { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Color.FromArgb(0, 0, blue); }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Color.FromArgb(0, 0, 0, blue); }); diff --git a/src/libraries/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj b/src/libraries/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj index 6201723711e..fa5c15ceac8 100644 --- a/src/libraries/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj +++ b/src/libraries/System.Drawing.Primitives/tests/System.Drawing.Primitives.Tests.csproj @@ -20,11 +20,14 @@ - - Common\System\Diagnostics\DebuggerAttributes.cs + + Common\System\AssertExtensions.cs - CommonTest\System\PlatformDetection.cs + Common\System\PlatformDetection.cs + + + Common\System\Diagnostics\DebuggerAttributes.cs Common\System\Runtime\Serialization\Formatters\BinaryFormatterHelpers.cs diff --git a/src/libraries/System.Globalization.Calendars/tests/CalendarHelpers.cs b/src/libraries/System.Globalization.Calendars/tests/CalendarHelpers.cs index f99549039f6..3551a4ad03b 100644 --- a/src/libraries/System.Globalization.Calendars/tests/CalendarHelpers.cs +++ b/src/libraries/System.Globalization.Calendars/tests/CalendarHelpers.cs @@ -262,46 +262,46 @@ namespace System.Globalization.Tests [MemberData(nameof(Calendars_TestData))] public static void AddDays_Invalid(Calendar calendar) { - Assert.Throws(() => calendar.AddDays(calendar.MaxSupportedDateTime, 1)); - Assert.Throws(() => calendar.AddDays(calendar.MinSupportedDateTime, -1)); + AssertExtensions.Throws(null, () => calendar.AddDays(calendar.MaxSupportedDateTime, 1)); + AssertExtensions.Throws(null, () => calendar.AddDays(calendar.MinSupportedDateTime, -1)); - Assert.Throws(() => calendar.AddDays(DateTime.Now, -120001 * 30)); - Assert.Throws(() => calendar.AddDays(DateTime.Now, 120001 * 30)); + AssertExtensions.Throws(null, () => calendar.AddDays(DateTime.Now, -120001 * 30)); + AssertExtensions.Throws(null, () => calendar.AddDays(DateTime.Now, 120001 * 30)); } [Theory] [MemberData(nameof(Calendars_TestData))] public static void AddHours_Invalid(Calendar calendar) { - Assert.Throws(() => calendar.AddHours(calendar.MaxSupportedDateTime, 1)); - Assert.Throws(() => calendar.AddHours(calendar.MinSupportedDateTime, -1)); + AssertExtensions.Throws(null, () => calendar.AddHours(calendar.MaxSupportedDateTime, 1)); + AssertExtensions.Throws(null, () => calendar.AddHours(calendar.MinSupportedDateTime, -1)); - Assert.Throws(() => calendar.AddHours(DateTime.Now, -120001 * 30 * 24)); - Assert.Throws(() => calendar.AddHours(DateTime.Now, 120001 * 30 * 24)); + AssertExtensions.Throws(null, () => calendar.AddHours(DateTime.Now, -120001 * 30 * 24)); + AssertExtensions.Throws(null, () => calendar.AddHours(DateTime.Now, 120001 * 30 * 24)); } [Theory] [MemberData(nameof(Calendars_TestData))] public static void AddMinutes_Invalid(Calendar calendar) { - Assert.Throws(() => calendar.AddMinutes(calendar.MaxSupportedDateTime, 1)); - Assert.Throws(() => calendar.AddMinutes(calendar.MinSupportedDateTime, -1)); + AssertExtensions.Throws(null, () => calendar.AddMinutes(calendar.MaxSupportedDateTime, 1)); + AssertExtensions.Throws(null, () => calendar.AddMinutes(calendar.MinSupportedDateTime, -1)); } [Theory] [MemberData(nameof(Calendars_TestData))] public static void AddSeconds_Invalid(Calendar calendar) { - Assert.Throws(() => calendar.AddSeconds(calendar.MaxSupportedDateTime, 1)); - Assert.Throws(() => calendar.AddSeconds(calendar.MinSupportedDateTime, -1)); + AssertExtensions.Throws(null, () => calendar.AddSeconds(calendar.MaxSupportedDateTime, 1)); + AssertExtensions.Throws(null, () => calendar.AddSeconds(calendar.MinSupportedDateTime, -1)); } [Theory] [MemberData(nameof(Calendars_TestData))] public static void AddMilliseconds_Invalid(Calendar calendar) { - Assert.Throws(() => calendar.AddMilliseconds(calendar.MaxSupportedDateTime, 1)); - Assert.Throws(() => calendar.AddMilliseconds(calendar.MinSupportedDateTime, -1)); + AssertExtensions.Throws(null, () => calendar.AddMilliseconds(calendar.MaxSupportedDateTime, 1)); + AssertExtensions.Throws(null, () => calendar.AddMilliseconds(calendar.MinSupportedDateTime, -1)); } [Theory] diff --git a/src/libraries/System.Globalization.Extensions/tests/IdnMapping/IdnMappingUseStd3AsciiRulesTests.cs b/src/libraries/System.Globalization.Extensions/tests/IdnMapping/IdnMappingUseStd3AsciiRulesTests.cs index 77969279574..ce2ab70f582 100644 --- a/src/libraries/System.Globalization.Extensions/tests/IdnMapping/IdnMappingUseStd3AsciiRulesTests.cs +++ b/src/libraries/System.Globalization.Extensions/tests/IdnMapping/IdnMappingUseStd3AsciiRulesTests.cs @@ -62,12 +62,7 @@ namespace System.Globalization.Tests Assert.Equal(unicode, idnStd3False.GetAscii(unicode)); } - ArgumentException ae = Assert.Throws(() => idnStd3True.GetAscii(unicode)); - if (!PlatformDetection.IsNetNative) - { - // sometimes the desktop returns "Unicode" instead of "unicode" for the parameter name. - Assert.Equal("unicode", ae.ParamName, ignoreCase: true); - } + AssertExtensions.Throws("unicode", () => idnStd3True.GetAscii(unicode)); } [Fact] diff --git a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyDecimalSeparator.cs b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyDecimalSeparator.cs index c1e54170c5f..1d820675adc 100644 --- a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyDecimalSeparator.cs +++ b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyDecimalSeparator.cs @@ -28,7 +28,7 @@ namespace System.Globalization.Tests public void CurrencyDecimalSeparator_Set_Invalid() { AssertExtensions.Throws("CurrencyDecimalSeparator", () => new NumberFormatInfo().CurrencyDecimalSeparator = null); - Assert.Throws(() => new NumberFormatInfo().CurrencyDecimalSeparator = ""); + AssertExtensions.Throws(null, () => new NumberFormatInfo().CurrencyDecimalSeparator = ""); Assert.Throws(() => NumberFormatInfo.InvariantInfo.CurrencyDecimalSeparator = "string"); } } diff --git a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoNumberDecimalSeparator.cs b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoNumberDecimalSeparator.cs index 3121139b501..23c4535d2da 100644 --- a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoNumberDecimalSeparator.cs +++ b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoNumberDecimalSeparator.cs @@ -28,7 +28,7 @@ namespace System.Globalization.Tests public void NumberDecimalSeparator_Set_Invalid() { AssertExtensions.Throws("NumberDecimalSeparator", () => new NumberFormatInfo().NumberDecimalSeparator = null); - Assert.Throws(() => new NumberFormatInfo().NumberDecimalSeparator = ""); + AssertExtensions.Throws(null, () => new NumberFormatInfo().NumberDecimalSeparator = ""); Assert.Throws(() => NumberFormatInfo.InvariantInfo.NumberDecimalSeparator = "string"); } } diff --git a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoPercentDecimalSeparator.cs b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoPercentDecimalSeparator.cs index f50d260ded7..8df5d29efac 100644 --- a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoPercentDecimalSeparator.cs +++ b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoPercentDecimalSeparator.cs @@ -28,7 +28,7 @@ namespace System.Globalization.Tests public void PercentDecimalSeparator_Set_Invalid() { AssertExtensions.Throws("PercentDecimalSeparator", () => new NumberFormatInfo().PercentDecimalSeparator = null); - Assert.Throws(() => new NumberFormatInfo().PercentDecimalSeparator = ""); + AssertExtensions.Throws(null, () => new NumberFormatInfo().PercentDecimalSeparator = ""); Assert.Throws(() => NumberFormatInfo.InvariantInfo.PercentDecimalSeparator = "string"); } } diff --git a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoValidateParseStyle.cs b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoValidateParseStyle.cs index f62f156f099..ba9a1b29b57 100644 --- a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoValidateParseStyle.cs +++ b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoValidateParseStyle.cs @@ -2,7 +2,6 @@ // 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.Globalization.Tests @@ -10,15 +9,15 @@ namespace System.Globalization.Tests public class NumberFormatInfoValidateParseStyle { [Theory] - [InlineData(unchecked((NumberStyles)0xFFFFFC00), false)] - [InlineData(NumberStyles.HexNumber | NumberStyles.Integer, false)] - [InlineData(NumberStyles.AllowHexSpecifier, true)] - [InlineData(NumberStyles.None, true)] - public void ValidateParseStyle_Integer(NumberStyles style, bool valid) + [InlineData(unchecked((NumberStyles)0xFFFFFC00), false, "style")] + [InlineData(NumberStyles.HexNumber | NumberStyles.Integer, false, null)] + [InlineData(NumberStyles.AllowHexSpecifier, true, null)] + [InlineData(NumberStyles.None, true, null)] + public void ValidateParseStyle_Integer(NumberStyles style, bool valid, string paramName) { if (!valid) { - Assert.Throws(() => byte.Parse("0", style)); + AssertExtensions.Throws(paramName, () => byte.Parse("0", style)); } else { @@ -27,15 +26,15 @@ namespace System.Globalization.Tests } [Theory] - [InlineData(unchecked((NumberStyles)0xFFFFFC00), false)] - [InlineData(NumberStyles.HexNumber | NumberStyles.Integer, false)] - [InlineData(NumberStyles.AllowHexSpecifier, false)] - [InlineData(NumberStyles.None, true)] - public void ValidateParseStyle_Float(NumberStyles style, bool valid) + [InlineData(unchecked((NumberStyles)0xFFFFFC00), false, "style")] + [InlineData(NumberStyles.HexNumber | NumberStyles.Integer, false, null)] + [InlineData(NumberStyles.AllowHexSpecifier, false, null)] + [InlineData(NumberStyles.None, true, null)] + public void ValidateParseStyle_Float(NumberStyles style, bool valid, string paramName) { if (!valid) { - Assert.Throws(() => float.Parse("0", style)); + AssertExtensions.Throws(paramName, () => float.Parse("0", style)); } else { diff --git a/src/libraries/System.IO.Compression.ZipFile/tests/ZipFileInvalidFileTests.cs b/src/libraries/System.IO.Compression.ZipFile/tests/ZipFileInvalidFileTests.cs index 575d8b20cdb..427428b4558 100644 --- a/src/libraries/System.IO.Compression.ZipFile/tests/ZipFileInvalidFileTests.cs +++ b/src/libraries/System.IO.Compression.ZipFile/tests/ZipFileInvalidFileTests.cs @@ -22,7 +22,7 @@ namespace System.IO.Compression.Tests ZipArchiveEntry entry = archive.GetEntry("first.txt"); //null/empty string - Assert.Throws(() => archive.CreateEntry("")); + AssertExtensions.Throws("entryName", () => archive.CreateEntry("")); Assert.Throws(() => archive.CreateEntry(null)); } } @@ -219,7 +219,7 @@ namespace System.IO.Compression.Tests [PlatformSpecific(TestPlatforms.AnyUnix)] // Checks Unix-specific invalid file path public void Unix_ZipWithInvalidFileNames_ThrowsArgumentException(string zipName) { - Assert.Throws(() => ZipFile.ExtractToDirectory(compat(zipName) + ".zip", GetTestFilePath())); + AssertExtensions.Throws("path", () => ZipFile.ExtractToDirectory(compat(zipName) + ".zip", GetTestFilePath())); } [Theory] @@ -242,14 +242,14 @@ namespace System.IO.Compression.Tests /// when an attempt is made to extract them. /// [Theory] - [InlineData("WindowsInvalid_FromUnix")] - [InlineData("WindowsInvalid_FromWindows")] - [InlineData("NullCharFileName_FromWindows")] - [InlineData("NullCharFileName_FromUnix")] + [InlineData("WindowsInvalid_FromUnix", null)] + [InlineData("WindowsInvalid_FromWindows", null)] + [InlineData("NullCharFileName_FromWindows", "path")] + [InlineData("NullCharFileName_FromUnix", "path")] [PlatformSpecific(TestPlatforms.Windows)] // Checks Windows-specific invalid file path - public void Windows_ZipWithInvalidFileNames_ThrowsArgumentException(string zipName) + public void Windows_ZipWithInvalidFileNames_ThrowsArgumentException(string zipName, string paramName) { - Assert.Throws(() => ZipFile.ExtractToDirectory(compat(zipName) + ".zip", GetTestFilePath())); + AssertExtensions.Throws(paramName, null, () => ZipFile.ExtractToDirectory(compat(zipName) + ".zip", GetTestFilePath())); } [Theory] diff --git a/src/libraries/System.IO.Compression/tests/DeflateStreamTests.cs b/src/libraries/System.IO.Compression/tests/DeflateStreamTests.cs index 40478d6ff1a..837f35ecf61 100644 --- a/src/libraries/System.IO.Compression/tests/DeflateStreamTests.cs +++ b/src/libraries/System.IO.Compression/tests/DeflateStreamTests.cs @@ -131,12 +131,12 @@ namespace System.IO.Compression.Tests { var ms = new MemoryStream(); ms.Dispose(); - Assert.Throws(() => + AssertExtensions.Throws("stream", () => { var deflate = new DeflateStream(ms, CompressionMode.Decompress); }); - Assert.Throws(() => + AssertExtensions.Throws("stream", () => { var deflate = new DeflateStream(ms, CompressionMode.Compress); }); @@ -148,7 +148,7 @@ namespace System.IO.Compression.Tests var ms = new LocalMemoryStream(); ms.SetCanWrite(false); - Assert.Throws(() => + AssertExtensions.Throws("stream", () => { var gzip = new DeflateStream(ms, CompressionMode.Compress); }); @@ -160,7 +160,7 @@ namespace System.IO.Compression.Tests var ms = new LocalMemoryStream(); ms.SetCanRead(false); - Assert.Throws(() => + AssertExtensions.Throws("stream", () => { var gzip = new DeflateStream(ms, CompressionMode.Decompress); }); @@ -262,10 +262,10 @@ namespace System.IO.Compression.Tests Assert.Throws(() => new DeflateStream(null, CompressionMode.Decompress, false)); Assert.Throws(() => new DeflateStream(null, CompressionMode.Compress, true)); - Assert.Throws(() => new DeflateStream(new MemoryStream(), (CompressionMode)42)); - Assert.Throws(() => new DeflateStream(new MemoryStream(), (CompressionMode)43, true)); + AssertExtensions.Throws("mode", () => new DeflateStream(new MemoryStream(), (CompressionMode)42)); + AssertExtensions.Throws("mode", () => new DeflateStream(new MemoryStream(), (CompressionMode)43, true)); - Assert.Throws(() => new DeflateStream(new MemoryStream(new byte[1], writable: false), CompressionLevel.Optimal)); + AssertExtensions.Throws("stream", () => new DeflateStream(new MemoryStream(new byte[1], writable: false), CompressionLevel.Optimal)); } [Fact] @@ -364,8 +364,8 @@ namespace System.IO.Compression.Tests Assert.Throws(() => ds.Write(null, 0, 0)); Assert.Throws(() => ds.Write(new byte[1], -1, 0)); Assert.Throws(() => ds.Write(new byte[1], 0, -1)); - Assert.Throws(() => ds.Write(new byte[1], 0, 2)); - Assert.Throws(() => ds.Write(new byte[1], 1, 1)); + AssertExtensions.Throws(null, () => ds.Write(new byte[1], 0, 2)); + AssertExtensions.Throws(null, () => ds.Write(new byte[1], 1, 1)); Assert.Throws(() => ds.Read(new byte[1], 0, 1)); ds.Write(new byte[1], 0, 0); } @@ -374,8 +374,8 @@ namespace System.IO.Compression.Tests Assert.Throws(() => { ds.WriteAsync(null, 0, 0); }); Assert.Throws(() => { ds.WriteAsync(new byte[1], -1, 0); }); Assert.Throws(() => { ds.WriteAsync(new byte[1], 0, -1); }); - Assert.Throws(() => { ds.WriteAsync(new byte[1], 0, 2); }); - Assert.Throws(() => { ds.WriteAsync(new byte[1], 1, 1); }); + AssertExtensions.Throws(null, () => { ds.WriteAsync(new byte[1], 0, 2); }); + AssertExtensions.Throws(null, () => { ds.WriteAsync(new byte[1], 1, 1); }); Assert.Throws(() => { ds.Read(new byte[1], 0, 1); }); } @@ -384,8 +384,8 @@ namespace System.IO.Compression.Tests Assert.Throws(() => ds.Read(null, 0, 0)); Assert.Throws(() => ds.Read(new byte[1], -1, 0)); Assert.Throws(() => ds.Read(new byte[1], 0, -1)); - Assert.Throws(() => ds.Read(new byte[1], 0, 2)); - Assert.Throws(() => ds.Read(new byte[1], 1, 1)); + AssertExtensions.Throws(null, () => ds.Read(new byte[1], 0, 2)); + AssertExtensions.Throws(null, () => ds.Read(new byte[1], 1, 1)); Assert.Throws(() => ds.Write(new byte[1], 0, 1)); var data = new byte[1] { 42 }; @@ -397,8 +397,8 @@ namespace System.IO.Compression.Tests Assert.Throws(() => { ds.ReadAsync(null, 0, 0); }); Assert.Throws(() => { ds.ReadAsync(new byte[1], -1, 0); }); Assert.Throws(() => { ds.ReadAsync(new byte[1], 0, -1); }); - Assert.Throws(() => { ds.ReadAsync(new byte[1], 0, 2); }); - Assert.Throws(() => { ds.ReadAsync(new byte[1], 1, 1); }); + AssertExtensions.Throws(null, () => { ds.ReadAsync(new byte[1], 0, 2); }); + AssertExtensions.Throws(null, () => { ds.ReadAsync(new byte[1], 1, 1); }); Assert.Throws(() => { ds.Write(new byte[1], 0, 1); }); } } diff --git a/src/libraries/System.IO.Compression/tests/GZipStreamTests.cs b/src/libraries/System.IO.Compression/tests/GZipStreamTests.cs index 990d36aabca..ca4bb655aa8 100644 --- a/src/libraries/System.IO.Compression/tests/GZipStreamTests.cs +++ b/src/libraries/System.IO.Compression/tests/GZipStreamTests.cs @@ -177,12 +177,12 @@ namespace System.IO.Compression.Tests { var ms = new MemoryStream(); ms.Dispose(); - Assert.Throws(() => + AssertExtensions.Throws("stream", () => { var deflate = new GZipStream(ms, CompressionMode.Decompress); }); - Assert.Throws(() => + AssertExtensions.Throws("stream", () => { var deflate = new GZipStream(ms, CompressionMode.Compress); }); @@ -194,7 +194,7 @@ namespace System.IO.Compression.Tests var ms = new LocalMemoryStream(); ms.SetCanWrite(false); - Assert.Throws(() => + AssertExtensions.Throws("stream", () => { var gzip = new GZipStream(ms, CompressionMode.Compress); }); @@ -206,7 +206,7 @@ namespace System.IO.Compression.Tests var ms = new LocalMemoryStream(); ms.SetCanRead(false); - Assert.Throws(() => + AssertExtensions.Throws("stream", () => { var gzip = new GZipStream(ms, CompressionMode.Decompress); }); diff --git a/src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs b/src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs index 8522f5d9b41..223963dff59 100644 --- a/src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs +++ b/src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs @@ -40,7 +40,7 @@ namespace System.IO.Compression.Tests ZipArchiveEntry entry = archive.GetEntry("first.txt"); //null/empty string - Assert.Throws(() => archive.CreateEntry("")); //"Should throw on empty entry name" + AssertExtensions.Throws("entryName", () => archive.CreateEntry("")); //"Should throw on empty entry name" Assert.Throws(() => archive.CreateEntry(null)); //"should throw on null entry name" } } diff --git a/src/libraries/System.IO.FileSystem.AccessControl/tests/DirectoryObjectSecurityTests.cs b/src/libraries/System.IO.FileSystem.AccessControl/tests/DirectoryObjectSecurityTests.cs index a995a8e7456..d013a00370a 100644 --- a/src/libraries/System.IO.FileSystem.AccessControl/tests/DirectoryObjectSecurityTests.cs +++ b/src/libraries/System.IO.FileSystem.AccessControl/tests/DirectoryObjectSecurityTests.cs @@ -36,7 +36,7 @@ namespace System.Security.AccessControl public void GetAccessRules_InvalidTargetType() { var activeDirectorySecurity = new ActiveDirectorySecurity(); - Assert.Throws(() => + AssertExtensions.Throws("targetType", () => activeDirectorySecurity .GetAccessRules(false, false, typeof(System.Security.Principal.GenericPrincipal))); } diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/tests/DriveInfo.Windows.Tests.cs b/src/libraries/System.IO.FileSystem.DriveInfo/tests/DriveInfo.Windows.Tests.cs index 7a871bc92ed..ec4cbdb4f4e 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/tests/DriveInfo.Windows.Tests.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/tests/DriveInfo.Windows.Tests.cs @@ -16,19 +16,32 @@ namespace System.IO.FileSystem.DriveInfoTests { public class DriveInfoWindowsTests { + [Theory] + [InlineData(":\0", "driveName")] + [InlineData(":", null)] + [InlineData("://", null)] + [InlineData(@":\", null)] + [InlineData(":/", null)] + [InlineData(@":\\", null)] + [InlineData("Az", null)] + [InlineData("1", null)] + [InlineData("a1", null)] + [InlineData(@"\\share", null)] + [InlineData(@"\\", null)] + [InlineData("c ", null)] + [InlineData("", "path")] + [InlineData(" c", null)] + public void Ctor_InvalidPath_ThrowsArgumentException(string driveName, string paramName) + { + AssertExtensions.Throws(paramName, null, () => new DriveInfo(driveName)); + } + [Fact] [PlatformSpecific(TestPlatforms.Windows)] public void TestConstructor() { - string[] invalidInput = { ":\0", ":", "://", @":\", ":/", @":\\", "Az", "1", "a1", @"\\share", @"\\", "c ", string.Empty, " c" }; string[] variableInput = { "{0}", "{0}", "{0}:", "{0}:", @"{0}:\", @"{0}:\\", "{0}://" }; - // Test Invalid input - foreach (var input in invalidInput) - { - Assert.Throws(() => { new DriveInfo(input); }); - } - // Test Null Assert.Throws(() => { new DriveInfo(null); }); diff --git a/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs b/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs index 637ee15fd74..1bf1a12a619 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/tests/FileSystemWatcher.unit.cs @@ -528,13 +528,13 @@ namespace System.IO.Tests // FSW starts with String.Empty and will ignore setting this if it is already set, // but if you set it after some other valid string has been set it will throw. - Assert.Throws(() => watcher.Path = String.Empty); + AssertExtensions.Throws(null, () => watcher.Path = String.Empty); // Non-existent path - Assert.Throws(() => watcher.Path = GetTestFilePath()); + AssertExtensions.Throws(null, () => watcher.Path = GetTestFilePath()); // Web path - Assert.Throws(() => watcher.Path = "http://localhost"); + AssertExtensions.Throws(null, () => watcher.Path = "http://localhost"); // File protocol - Assert.Throws(() => watcher.Path = "file:///" + currentDir.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); + AssertExtensions.Throws(null, () => watcher.Path = "file:///" + currentDir.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); } [Fact] diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CopyFileTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CopyFileTests.cs index 921070b8a73..c3a9770de68 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CopyFileTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CopyFileTests.cs @@ -69,8 +69,8 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.CopyFile("\0bad", "bar")); - Assert.Throws(() => isf.CopyFile("foo", "\0bad")); + AssertExtensions.Throws("path", null, () => isf.CopyFile("\0bad", "bar")); + AssertExtensions.Throws("path", null, () => isf.CopyFile("foo", "\0bad")); } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CreateDirectoryTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CreateDirectoryTests.cs index fb652691487..e391e0c2285 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CreateDirectoryTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CreateDirectoryTests.cs @@ -54,7 +54,7 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.CreateDirectory("\0bad")); + AssertExtensions.Throws("path", null, () => isf.CreateDirectory("\0bad")); } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CreateFileTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CreateFileTests.cs index f1c45768e1f..09268409a81 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CreateFileTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/CreateFileTests.cs @@ -54,7 +54,7 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.CreateFile("\0bad")); + AssertExtensions.Throws("path", null, () => isf.CreateFile("\0bad")); } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/DirectoryExistsTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/DirectoryExistsTests.cs index c6c7e8486f6..2658a09e2e0 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/DirectoryExistsTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/DirectoryExistsTests.cs @@ -54,7 +54,7 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.DirectoryExists("\0bad")); + AssertExtensions.Throws("path", null, () => isf.DirectoryExists("\0bad")); } } @@ -71,7 +71,8 @@ namespace System.IO.IsolatedStorage } } - [Theory MemberData(nameof(ValidStores))] + [Theory] + [MemberData(nameof(ValidStores))] [ActiveIssue("dotnet/corefx #18268", TargetFrameworkMonikers.NetFramework)] public void DirectoryExists_Existance(PresetScopes scope) { diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/FileExistsTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/FileExistsTests.cs index cef377ddbbb..208e83c079b 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/FileExistsTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/FileExistsTests.cs @@ -54,11 +54,12 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.FileExists("\0bad")); + AssertExtensions.Throws("path", null, () => isf.FileExists("\0bad")); } } - [Theory MemberData(nameof(ValidStores))] + [Theory] + [MemberData(nameof(ValidStores))] [ActiveIssue("dotnet/corefx #18268", TargetFrameworkMonikers.NetFramework)] public void FileExists_Existance(PresetScopes scope) { diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetCreationTimeTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetCreationTimeTests.cs index f2c4d7bff2e..9e463854fd3 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetCreationTimeTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetCreationTimeTests.cs @@ -54,7 +54,7 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.GetCreationTime("\0bad")); + AssertExtensions.Throws("path", null, () => isf.GetCreationTime("\0bad")); } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetFileNamesTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetFileNamesTests.cs index 241cd42916e..78fb2f2c83c 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetFileNamesTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetFileNamesTests.cs @@ -57,7 +57,7 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.GetFileNames("\0bad")); + AssertExtensions.Throws("path", null, () => isf.GetFileNames("\0bad")); } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetLastAccessTimeTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetLastAccessTimeTests.cs index 311ab25b8c0..11adaef2bab 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetLastAccessTimeTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetLastAccessTimeTests.cs @@ -54,7 +54,7 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.GetLastAccessTime("\0bad")); + AssertExtensions.Throws("path", null, () => isf.GetLastAccessTime("\0bad")); } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetLastWriteTimeTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetLastWriteTimeTests.cs index 93badae6371..1e355d30c4a 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetLastWriteTimeTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/GetLastWriteTimeTests.cs @@ -54,7 +54,7 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.GetLastWriteTime("\0bad")); + AssertExtensions.Throws("path", null, () => isf.GetLastWriteTime("\0bad")); } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/MoveDirectoryTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/MoveDirectoryTests.cs index 02df0d44764..6bbf9c6ac92 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/MoveDirectoryTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/MoveDirectoryTests.cs @@ -65,8 +65,8 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.MoveDirectory("\0bad", "bar")); - Assert.Throws(() => isf.MoveDirectory("foo", "\0bad")); + AssertExtensions.Throws("path", null, () => isf.MoveDirectory("\0bad", "bar")); + AssertExtensions.Throws("path", null, () => isf.MoveDirectory("foo", "\0bad")); } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/MoveFileTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/MoveFileTests.cs index 06ce6a0d53e..818aeecff22 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/MoveFileTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/MoveFileTests.cs @@ -66,8 +66,8 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.MoveFile("\0bad", "bar")); - Assert.Throws(() => isf.MoveFile("foo", "\0bad")); + AssertExtensions.Throws("path", null, () => isf.MoveFile("\0bad", "bar")); + AssertExtensions.Throws("path", null, () => isf.MoveFile("foo", "\0bad")); } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/OpenFileTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/OpenFileTests.cs index ac37729a29e..84fab2e0353 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/OpenFileTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/OpenFileTests.cs @@ -62,9 +62,9 @@ namespace System.IO.IsolatedStorage { using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly()) { - Assert.Throws(() => isf.OpenFile("\0bad", FileMode.Create)); - Assert.Throws(() => isf.OpenFile("\0bad", FileMode.Create, FileAccess.ReadWrite)); - Assert.Throws(() => isf.OpenFile("\0bad", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)); + AssertExtensions.Throws("path", null, () => isf.OpenFile("\0bad", FileMode.Create)); + AssertExtensions.Throws("path", null, () => isf.OpenFile("\0bad", FileMode.Create, FileAccess.ReadWrite)); + AssertExtensions.Throws("path", null, () => isf.OpenFile("\0bad", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)); } } diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs index d9f3a0c000e..c14ce8750bc 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs @@ -57,14 +57,14 @@ namespace System.IO.MemoryMappedFiles.Tests AssertExtensions.Throws("mode", () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Append, null, 4096, MemoryMappedFileAccess.ReadWrite)); // FileMode.CreateNew/Create/OpenOrCreate can't be used with default capacity, as the file will be empty - Assert.Throws(() => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.CreateNew)); - Assert.Throws(() => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Create)); - Assert.Throws(() => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.OpenOrCreate)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.CreateNew)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.Create)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(GetTestFilePath(), FileMode.OpenOrCreate)); // FileMode.Truncate can't be used with default capacity, as resulting file will be empty using (TempFile file = new TempFile(GetTestFilePath())) { - Assert.Throws(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Truncate)); + AssertExtensions.Throws("mode", null, () => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Truncate)); } } @@ -188,13 +188,13 @@ namespace System.IO.MemoryMappedFiles.Tests using (TempFile file = new TempFile(GetTestFilePath())) { // Empty string is an invalid map name - Assert.Throws(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, string.Empty)); - Assert.Throws(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, string.Empty, 4096)); - Assert.Throws(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, string.Empty, 4096, MemoryMappedFileAccess.Read)); - Assert.Throws(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, string.Empty, 4096, MemoryMappedFileAccess.Read)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, string.Empty)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, string.Empty, 4096)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, string.Empty, 4096, MemoryMappedFileAccess.Read)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, string.Empty, 4096, MemoryMappedFileAccess.Read)); using (FileStream fs = File.Open(file.Path, FileMode.Open)) { - Assert.Throws(() => MemoryMappedFile.CreateFromFile(fs, string.Empty, 4096, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, true)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(fs, string.Empty, 4096, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, true)); } } } @@ -234,11 +234,11 @@ namespace System.IO.MemoryMappedFiles.Tests Assert.Throws(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, CreateUniqueMapName(), -1, MemoryMappedFileAccess.Read)); // Positive capacity required when creating a map from an empty file - Assert.Throws(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, null, 0, MemoryMappedFileAccess.Read)); - Assert.Throws(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, CreateUniqueMapName(), 0, MemoryMappedFileAccess.Read)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, null, 0, MemoryMappedFileAccess.Read)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, CreateUniqueMapName(), 0, MemoryMappedFileAccess.Read)); // With Read, the capacity can't be larger than the backing file's size. - Assert.Throws(() => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, CreateUniqueMapName(), 1, MemoryMappedFileAccess.Read)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(file.Path, FileMode.Open, CreateUniqueMapName(), 1, MemoryMappedFileAccess.Read)); // Now with a FileStream... using (FileStream fs = File.Open(file.Path, FileMode.Open)) @@ -251,13 +251,13 @@ namespace System.IO.MemoryMappedFiles.Tests Assert.Throws(() => MemoryMappedFile.CreateFromFile(fs, null, -1, MemoryMappedFileAccess.Read, HandleInheritability.None, true)); // Default (0) capacity with an empty file - Assert.Throws(() => MemoryMappedFile.CreateFromFile(fs, null, 0, MemoryMappedFileAccess.Read, HandleInheritability.None, true)); - Assert.Throws(() => MemoryMappedFile.CreateFromFile(fs, CreateUniqueMapName(), 0, MemoryMappedFileAccess.Read, HandleInheritability.None, true)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(fs, null, 0, MemoryMappedFileAccess.Read, HandleInheritability.None, true)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(fs, CreateUniqueMapName(), 0, MemoryMappedFileAccess.Read, HandleInheritability.None, true)); // Larger capacity than the underlying file, but read-only such that we can't expand the file fs.SetLength(4096); - Assert.Throws(() => MemoryMappedFile.CreateFromFile(fs, null, 8192, MemoryMappedFileAccess.Read, HandleInheritability.None, true)); - Assert.Throws(() => MemoryMappedFile.CreateFromFile(fs, CreateUniqueMapName(), 8192, MemoryMappedFileAccess.Read, HandleInheritability.None, true)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(fs, null, 8192, MemoryMappedFileAccess.Read, HandleInheritability.None, true)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateFromFile(fs, CreateUniqueMapName(), 8192, MemoryMappedFileAccess.Read, HandleInheritability.None, true)); // Capacity can't be less than the file size (for such cases a view can be created with the smaller size) AssertExtensions.Throws("capacity", () => MemoryMappedFile.CreateFromFile(fs, null, 1, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, true)); diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateNew.Tests.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateNew.Tests.cs index fec94bfac30..bf8d78cd1d2 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateNew.Tests.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateNew.Tests.cs @@ -21,9 +21,9 @@ namespace System.IO.MemoryMappedFiles.Tests public void InvalidArguments_MapName() { // Empty string is an invalid map name - Assert.Throws(() => MemoryMappedFile.CreateNew(string.Empty, 4096)); - Assert.Throws(() => MemoryMappedFile.CreateNew(string.Empty, 4096, MemoryMappedFileAccess.ReadWrite)); - Assert.Throws(() => MemoryMappedFile.CreateNew(string.Empty, 4096, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.None)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateNew(string.Empty, 4096)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateNew(string.Empty, 4096, MemoryMappedFileAccess.ReadWrite)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateNew(string.Empty, 4096, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.None)); } /// diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateOrOpen.Tests.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateOrOpen.Tests.cs index 812d8256169..d96ba3c80d4 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateOrOpen.Tests.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateOrOpen.Tests.cs @@ -21,9 +21,9 @@ namespace System.IO.MemoryMappedFiles.Tests AssertExtensions.Throws("mapName", () => MemoryMappedFile.CreateOrOpen(null, 4096, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.None)); // Empty string is always an invalid map name - Assert.Throws(() => MemoryMappedFile.CreateOrOpen(string.Empty, 4096)); - Assert.Throws(() => MemoryMappedFile.CreateOrOpen(string.Empty, 4096, MemoryMappedFileAccess.ReadWrite)); - Assert.Throws(() => MemoryMappedFile.CreateOrOpen(string.Empty, 4096, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.None)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateOrOpen(string.Empty, 4096)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateOrOpen(string.Empty, 4096, MemoryMappedFileAccess.ReadWrite)); + AssertExtensions.Throws(null, () => MemoryMappedFile.CreateOrOpen(string.Empty, 4096, MemoryMappedFileAccess.ReadWrite, MemoryMappedFileOptions.None, HandleInheritability.None)); } /// diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.OpenExisting.Tests.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.OpenExisting.Tests.cs index ccbd84d3526..0b75be093f9 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.OpenExisting.Tests.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.OpenExisting.Tests.cs @@ -19,7 +19,7 @@ namespace System.IO.MemoryMappedFiles.Tests AssertExtensions.Throws("mapName", () => MemoryMappedFile.OpenExisting(null)); // Empty is never a valid map name - Assert.Throws(() => MemoryMappedFile.OpenExisting(string.Empty)); + AssertExtensions.Throws(null, () => MemoryMappedFile.OpenExisting(string.Empty)); } /// diff --git a/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj b/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj index e2a2ecbbe05..84ffe560086 100644 --- a/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj +++ b/src/libraries/System.IO.Packaging/tests/System.IO.Packaging.Tests.csproj @@ -8,6 +8,9 @@ + + Common\System\AssertExtensions.cs + diff --git a/src/libraries/System.IO.Packaging/tests/Tests.cs b/src/libraries/System.IO.Packaging/tests/Tests.cs index 8b0928ba248..e4d619fa97d 100644 --- a/src/libraries/System.IO.Packaging/tests/Tests.cs +++ b/src/libraries/System.IO.Packaging/tests/Tests.cs @@ -127,7 +127,7 @@ namespace System.IO.Packaging.Tests Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); Assert.Equal(0, ms.Length); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop= ;"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop= ;"); }); } } @@ -261,7 +261,7 @@ namespace System.IO.Packaging.Tests { sw.Write(s_DocumentXml); } - Assert.Throws(() => + AssertExtensions.Throws(null, () => { package.CreateRelationship(packagePartDocument.Uri, TargetMode.Internal, ""); }); @@ -411,7 +411,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop=\"\u0022\""); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop=\"\u0022\""); }); } } @@ -428,7 +428,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop=\"\u0001value2\""); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop=\"\u0001value2\""); }); } } @@ -445,7 +445,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, "/"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "/"); }); } } @@ -462,7 +462,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop=;"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop=;"); }); } } @@ -479,7 +479,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop=\" value \" ; prop2=\"\u0001value2"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "image/jpeg; prop=\" value \" ; prop2=\"\u0001value2"); }); } } @@ -513,7 +513,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, "image\r\njpeg"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "image\r\njpeg"); }); } } @@ -629,7 +629,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "text/text;foo=\"value\";"); }); @@ -649,7 +649,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, Mime_MediaTypeNames_Text_Xml + ";\"value\""); }); @@ -703,7 +703,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, "image\rjpeg"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "image\rjpeg"); }); } } @@ -720,7 +720,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, "imagejpeg;property"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, "imagejpeg;property"); }); } } @@ -737,7 +737,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, Mime_MediaTypeNames_Text_Xml + ";property"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, Mime_MediaTypeNames_Text_Xml + ";property"); }); } } @@ -754,7 +754,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, Mime_MediaTypeNames_Text_Xml + ";"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, Mime_MediaTypeNames_Text_Xml + ";"); }); } } @@ -771,7 +771,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => { packagePartDocument = package.CreatePart(partUriDocument, Mime_MediaTypeNames_Text_Xml + ";; param1=value1"); }); + AssertExtensions.Throws(null, () => { packagePartDocument = package.CreatePart(partUriDocument, Mime_MediaTypeNames_Text_Xml + ";; param1=value1"); }); } } @@ -807,7 +807,7 @@ namespace System.IO.Packaging.Tests ms.Write(ba, 0, ba.Length); Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); PackagePart packagePartDocument = null; - Assert.Throws(() => packagePartDocument = package.CreatePart(partUriDocument, " " + Mime_MediaTypeNames_Text_Xml)); + AssertExtensions.Throws(null, () => packagePartDocument = package.CreatePart(partUriDocument, " " + Mime_MediaTypeNames_Text_Xml)); } } @@ -2110,7 +2110,7 @@ namespace System.IO.Packaging.Tests Uri uri = new Uri(@"c:/resources/image1.jpg", UriKind.Absolute); // Internal relationships cannot use absolute Uris - Assert.Throws(() => packagePartDocument.CreateRelationship(uri, + AssertExtensions.Throws("targetUri", () => packagePartDocument.CreateRelationship(uri, TargetMode.Internal, ResourceRelationshipType)); } @@ -2407,7 +2407,7 @@ namespace System.IO.Packaging.Tests File.WriteAllBytes(tempGuidName.FullName, ba); // Truncate is invalid - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Package package = Package.Open(tempGuidName.FullName, FileMode.Truncate, FileAccess.Read); }); @@ -2632,7 +2632,7 @@ namespace System.IO.Packaging.Tests var tempGuidName = GetTempFileInfoWithExtension(".docx"); File.WriteAllBytes(tempGuidName.FullName, ba); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Package package = Package.Open(tempGuidName.FullName, FileMode.OpenOrCreate, FileAccess.Write); }); @@ -2646,7 +2646,7 @@ namespace System.IO.Packaging.Tests var tempGuidName = GetTempFileInfoWithExtension(".docx"); File.WriteAllBytes(tempGuidName.FullName, ba); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Package package = Package.Open(tempGuidName.FullName, FileMode.OpenOrCreate, FileAccess.Read); }); @@ -2753,7 +2753,7 @@ namespace System.IO.Packaging.Tests var tempGuidName = GetTempFileInfoWithExtension(".docx"); File.WriteAllBytes(tempGuidName.FullName, ba); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Package package = Package.Open(tempGuidName.FullName, FileMode.Open, FileAccess.Write); }); @@ -3039,7 +3039,7 @@ namespace System.IO.Packaging.Tests CompressionOption.Normal); // Truncate is not a supported value - Assert.Throws(() => + AssertExtensions.Throws(null, () => { using (Stream partStream = packagePartDocument.GetStream(FileMode.Truncate, FileAccess.ReadWrite)) using (StreamWriter sw = new StreamWriter(partStream)) @@ -3065,7 +3065,7 @@ namespace System.IO.Packaging.Tests Mime_MediaTypeNames_Text_Xml, CompressionOption.Normal); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { using (Stream partStream = packagePartDocument.GetStream(FileMode.CreateNew, FileAccess.ReadWrite)) using (StreamWriter sw = new StreamWriter(partStream)) @@ -3171,7 +3171,7 @@ namespace System.IO.Packaging.Tests public void T113_String_CreateNew_Write_Open_Read() { var tempGuidName = GetTempFileInfoWithExtension(".docx"); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Package package = Package.Open(tempGuidName.FullName, FileMode.CreateNew, FileAccess.Write); }); @@ -3182,7 +3182,7 @@ namespace System.IO.Packaging.Tests public void T112_String_CreateNew_Read_Create_Read() { var tempGuidName = GetTempFileInfoWithExtension(".docx"); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Package package = Package.Open(tempGuidName.FullName, FileMode.CreateNew, FileAccess.Read); }); @@ -3194,7 +3194,7 @@ namespace System.IO.Packaging.Tests { var tempGuidName = GetTempFileInfoWithExtension(".docx"); // opening the package attempts to read the package, and no permissions. - Assert.Throws(() => Package.Open(tempGuidName.FullName, FileMode.Create, FileAccess.Write)); + AssertExtensions.Throws(null, () => Package.Open(tempGuidName.FullName, FileMode.Create, FileAccess.Write)); tempGuidName.Delete(); } @@ -3359,7 +3359,7 @@ namespace System.IO.Packaging.Tests using (Stream partStream = packagePartDocument.GetStream(FileMode.Open, FileAccess.Write)) { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { using (StreamReader sr = new StreamReader(partStream)) { @@ -3432,7 +3432,7 @@ namespace System.IO.Packaging.Tests Mime_MediaTypeNames_Text_Xml, CompressionOption.Normal); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { using (Stream partStream = packagePartDocument.GetStream(FileMode.Open, FileAccess.Read)) using (StreamWriter sw = new StreamWriter(partStream)) @@ -3482,7 +3482,7 @@ namespace System.IO.Packaging.Tests public void T100_String_Create_Read_Star() { var tempGuidName = GetTempFileInfoWithExtension(".docx"); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { Package package = Package.Open(tempGuidName.FullName, FileMode.Create, FileAccess.Read); }); diff --git a/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CreateClient.cs b/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CreateClient.cs index 59cd725b995..98293f9c65b 100644 --- a/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CreateClient.cs +++ b/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CreateClient.cs @@ -23,8 +23,8 @@ namespace System.IO.Pipes.Tests [Fact] public static void EmptyStringPipeName_Throws_ArgumentException() { - Assert.Throws(() => new NamedPipeClientStream("")); - Assert.Throws(() => new NamedPipeClientStream(".", "")); + AssertExtensions.Throws(null, () => new NamedPipeClientStream("")); + AssertExtensions.Throws(null, () => new NamedPipeClientStream(".", "")); } [Theory] @@ -45,10 +45,10 @@ namespace System.IO.Pipes.Tests [InlineData(PipeDirection.Out)] public static void EmptyStringServerName_Throws_ArgumentException(PipeDirection direction) { - Assert.Throws(() => new NamedPipeClientStream("", "client1")); - Assert.Throws(() => new NamedPipeClientStream("", "client1", direction)); - Assert.Throws(() => new NamedPipeClientStream("", "client1", direction, PipeOptions.None)); - Assert.Throws(() => new NamedPipeClientStream("", "client1", direction, PipeOptions.None, TokenImpersonationLevel.None)); + AssertExtensions.Throws(null, () => new NamedPipeClientStream("", "client1")); + AssertExtensions.Throws(null, () => new NamedPipeClientStream("", "client1", direction)); + AssertExtensions.Throws(null, () => new NamedPipeClientStream("", "client1", direction, PipeOptions.None)); + AssertExtensions.Throws(null, () => new NamedPipeClientStream("", "client1", direction, PipeOptions.None, TokenImpersonationLevel.None)); } [Theory] diff --git a/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CreateServer.cs b/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CreateServer.cs index 15de1ef1fe7..a606029ccc7 100644 --- a/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CreateServer.cs +++ b/src/libraries/System.IO.Pipes/tests/NamedPipeTests/NamedPipeTest.CreateServer.cs @@ -32,12 +32,12 @@ namespace System.IO.Pipes.Tests [InlineData(PipeDirection.Out)] public static void ZeroLengthPipeName_Throws_ArgumentException(PipeDirection direction) { - Assert.Throws(() => new NamedPipeServerStream("")); - Assert.Throws(() => new NamedPipeServerStream("", direction)); - Assert.Throws(() => new NamedPipeServerStream("", direction, 2)); - Assert.Throws(() => new NamedPipeServerStream("", direction, 3, PipeTransmissionMode.Byte)); - Assert.Throws(() => new NamedPipeServerStream("", direction, 3, PipeTransmissionMode.Byte, PipeOptions.None)); - Assert.Throws(() => new NamedPipeServerStream("", direction, 3, PipeTransmissionMode.Byte, PipeOptions.None, 0, 0)); + AssertExtensions.Throws(null, () => new NamedPipeServerStream("")); + AssertExtensions.Throws(null, () => new NamedPipeServerStream("", direction)); + AssertExtensions.Throws(null, () => new NamedPipeServerStream("", direction, 2)); + AssertExtensions.Throws(null, () => new NamedPipeServerStream("", direction, 3, PipeTransmissionMode.Byte)); + AssertExtensions.Throws(null, () => new NamedPipeServerStream("", direction, 3, PipeTransmissionMode.Byte, PipeOptions.None)); + AssertExtensions.Throws(null, () => new NamedPipeServerStream("", direction, 3, PipeTransmissionMode.Byte, PipeOptions.None, 0, 0)); } [Theory] @@ -247,7 +247,7 @@ namespace System.IO.Pipes.Tests // The pipe is already bound using (var pipe = new NamedPipeServerStream(GetUniquePipeName(), direction, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) { - Assert.Throws(() => new NamedPipeServerStream(direction, true, true, pipe.SafePipeHandle)); + AssertExtensions.Throws("handle", () => new NamedPipeServerStream(direction, true, true, pipe.SafePipeHandle)); } } diff --git a/src/libraries/System.IO.Pipes/tests/PipeTest.Read.cs b/src/libraries/System.IO.Pipes/tests/PipeTest.Read.cs index 1e518d2fe69..48842e05e41 100644 --- a/src/libraries/System.IO.Pipes/tests/PipeTest.Read.cs +++ b/src/libraries/System.IO.Pipes/tests/PipeTest.Read.cs @@ -94,7 +94,7 @@ namespace System.IO.Pipes.Tests Assert.Throws(null, () => pipe.Read(new byte[0], int.MaxValue, 0)); Assert.Throws(null, () => pipe.Read(new byte[0], int.MaxValue, int.MaxValue)); - Assert.Throws(() => pipe.Read(new byte[5], 3, 4)); + AssertExtensions.Throws(null, () => pipe.Read(new byte[5], 3, 4)); // offset out of bounds Assert.Throws(null, () => { pipe.ReadAsync(new byte[1], 1, 1); }); @@ -112,7 +112,7 @@ namespace System.IO.Pipes.Tests Assert.Throws(null, () => { pipe.ReadAsync(new byte[0], int.MaxValue, 0); }); Assert.Throws(null, () => { pipe.ReadAsync(new byte[0], int.MaxValue, int.MaxValue); }); - Assert.Throws(() => { pipe.ReadAsync(new byte[5], 3, 4); }); + AssertExtensions.Throws(null, () => { pipe.ReadAsync(new byte[5], 3, 4); }); } } diff --git a/src/libraries/System.IO.Pipes/tests/PipeTest.Write.cs b/src/libraries/System.IO.Pipes/tests/PipeTest.Write.cs index 754e0cda844..0504c579ef7 100644 --- a/src/libraries/System.IO.Pipes/tests/PipeTest.Write.cs +++ b/src/libraries/System.IO.Pipes/tests/PipeTest.Write.cs @@ -94,7 +94,7 @@ namespace System.IO.Pipes.Tests Assert.Throws(null, () => pipe.Write(new byte[0], int.MaxValue, 0)); Assert.Throws(null, () => pipe.Write(new byte[0], int.MaxValue, int.MaxValue)); - Assert.Throws(() => pipe.Write(new byte[5], 3, 4)); + AssertExtensions.Throws(null, () => pipe.Write(new byte[5], 3, 4)); // offset out of bounds Assert.Throws(null, () => { pipe.WriteAsync(new byte[1], 1, 1); }); @@ -112,7 +112,7 @@ namespace System.IO.Pipes.Tests Assert.Throws(null, () => { pipe.WriteAsync(new byte[0], int.MaxValue, 0); }); Assert.Throws(null, () => { pipe.WriteAsync(new byte[0], int.MaxValue, int.MaxValue); }); - Assert.Throws(() => { pipe.WriteAsync(new byte[5], 3, 4); }); + AssertExtensions.Throws(null, () => { pipe.WriteAsync(new byte[5], 3, 4); }); } } diff --git a/src/libraries/System.IO.Ports/tests/System.IO.Ports.Tests.csproj b/src/libraries/System.IO.Ports/tests/System.IO.Ports.Tests.csproj index f0412cb9ab8..e10d9f2ac5e 100644 --- a/src/libraries/System.IO.Ports/tests/System.IO.Ports.Tests.csproj +++ b/src/libraries/System.IO.Ports/tests/System.IO.Ports.Tests.csproj @@ -118,6 +118,9 @@ + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.IO.UnmanagedMemoryStream/tests/Uma.ReadWriteStruct.cs b/src/libraries/System.IO.UnmanagedMemoryStream/tests/Uma.ReadWriteStruct.cs index aedb6544150..1148ad70cb7 100644 --- a/src/libraries/System.IO.UnmanagedMemoryStream/tests/Uma.ReadWriteStruct.cs +++ b/src/libraries/System.IO.UnmanagedMemoryStream/tests/Uma.ReadWriteStruct.cs @@ -81,10 +81,10 @@ namespace System.IO.Tests using (TestSafeBuffer buffer = new TestSafeBuffer(capacity)) using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite)) { - Assert.Throws(() => uma.Write(capacity - UmaTestStruct_UnalignedSize + 1, ref inStruct)); - Assert.Throws(() => uma.Write(capacity - UmaTestStruct_AlignedSize + 1, ref inStruct)); - Assert.Throws(() => uma.Read(capacity - UmaTestStruct_UnalignedSize + 1, out inStruct)); - Assert.Throws(() => uma.Read(capacity - UmaTestStruct_AlignedSize + 1, out inStruct)); + AssertExtensions.Throws("position", () => uma.Write(capacity - UmaTestStruct_UnalignedSize + 1, ref inStruct)); + AssertExtensions.Throws("position", () => uma.Write(capacity - UmaTestStruct_AlignedSize + 1, ref inStruct)); + AssertExtensions.Throws("position", () => uma.Read(capacity - UmaTestStruct_UnalignedSize + 1, out inStruct)); + AssertExtensions.Throws("position", () => uma.Read(capacity - UmaTestStruct_AlignedSize + 1, out inStruct)); } } diff --git a/src/libraries/System.IO.UnmanagedMemoryStream/tests/Uma.ReadWriteStructArray.cs b/src/libraries/System.IO.UnmanagedMemoryStream/tests/Uma.ReadWriteStructArray.cs index 944c702d0f0..09470cd4cec 100644 --- a/src/libraries/System.IO.UnmanagedMemoryStream/tests/Uma.ReadWriteStructArray.cs +++ b/src/libraries/System.IO.UnmanagedMemoryStream/tests/Uma.ReadWriteStructArray.cs @@ -24,10 +24,10 @@ namespace System.IO.Tests AssertExtensions.Throws("offset", () => uma.ReadArray(0, structArr, -1, 1)); AssertExtensions.Throws("count", () => uma.WriteArray(0, structArr, 0, -1)); AssertExtensions.Throws("count", () => uma.ReadArray(0, structArr, 0, -1)); - Assert.Throws(() => uma.WriteArray(0, structArr, 2, 0)); - Assert.Throws(() => uma.ReadArray(0, structArr, 2, 0)); - Assert.Throws(() => uma.WriteArray(0, structArr, 0, 2)); - Assert.Throws(() => uma.ReadArray(0, structArr, 0, 2)); + AssertExtensions.Throws(null, () => uma.WriteArray(0, structArr, 2, 0)); + AssertExtensions.Throws(null, () => uma.ReadArray(0, structArr, 2, 0)); + AssertExtensions.Throws(null, () => uma.WriteArray(0, structArr, 0, 2)); + AssertExtensions.Throws(null, () => uma.ReadArray(0, structArr, 0, 2)); AssertExtensions.Throws("position", () => uma.WriteArray(-1, structArr, 0, 1)); AssertExtensions.Throws("position", () => uma.ReadArray(-1, structArr, 0, 1)); AssertExtensions.Throws("position", () => uma.WriteArray(capacity, structArr, 0, 1)); @@ -81,8 +81,8 @@ namespace System.IO.Tests using (TestSafeBuffer buffer = new TestSafeBuffer(capacity)) using (UnmanagedMemoryAccessor uma = new UnmanagedMemoryAccessor(buffer, 0, capacity, FileAccess.ReadWrite)) { - Assert.Throws(() => uma.WriteArray(capacity - UmaTestStruct_UnalignedSize + 1, structArr, 0, 1)); - Assert.Throws(() => uma.WriteArray(capacity - UmaTestStruct_AlignedSize + 1, structArr, 0, 1)); + AssertExtensions.Throws(null, () => uma.WriteArray(capacity - UmaTestStruct_UnalignedSize + 1, structArr, 0, 1)); + AssertExtensions.Throws(null, () => uma.WriteArray(capacity - UmaTestStruct_AlignedSize + 1, structArr, 0, 1)); Assert.Equal(0, uma.ReadArray(capacity - UmaTestStruct_UnalignedSize + 1, structArr, 0, 1)); Assert.Equal(0, uma.ReadArray(capacity - UmaTestStruct_AlignedSize + 1, structArr, 0, 1)); } diff --git a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmaCtorTests.cs b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmaCtorTests.cs index a2cc6719371..9a7130f09a7 100644 --- a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmaCtorTests.cs +++ b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmaCtorTests.cs @@ -45,11 +45,11 @@ namespace System.IO.Tests Assert.Throws(() => new UnmanagedMemoryAccessor(fakeBuffer, 1, 2, (FileAccess)(-1))); Assert.Throws(() => new UnmanagedMemoryAccessor(fakeBuffer, 1, 2, (FileAccess)42)); - Assert.Throws(() => new UnmanagedMemoryAccessor(fakeBuffer, 2, 999)); - Assert.Throws(() => new UnmanagedMemoryAccessor(fakeBuffer, 999, 9)); - Assert.Throws(() => new UnmanagedMemoryAccessor(fakeBuffer, 1, 100)); + AssertExtensions.Throws(null, () => new UnmanagedMemoryAccessor(fakeBuffer, 2, 999)); + AssertExtensions.Throws(null, () => new UnmanagedMemoryAccessor(fakeBuffer, 999, 9)); + AssertExtensions.Throws(null, () => new UnmanagedMemoryAccessor(fakeBuffer, 1, 100)); - Assert.Throws(() => new UnmanagedMemoryAccessor(fakeBuffer, Int32.MaxValue, 1)); + AssertExtensions.Throws(null, () => new UnmanagedMemoryAccessor(fakeBuffer, Int32.MaxValue, 1)); } // Derived class used to exercise protected members and to test behaviors before and after initialization diff --git a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmaTests.cs b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmaTests.cs index 3acbe88055f..2e0c5b87f77 100644 --- a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmaTests.cs +++ b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmaTests.cs @@ -18,11 +18,11 @@ namespace System.IO.Tests { Assert.Throws(() => uma.ReadChar(-1)); Assert.Throws(() => uma.ReadDecimal(capacity)); - Assert.Throws(() => uma.ReadSingle(capacity - 1)); + AssertExtensions.Throws("position", () => uma.ReadSingle(capacity - 1)); Assert.Throws(() => uma.Write(-1, true)); Assert.Throws(() => uma.Write(capacity, 12345)); - Assert.Throws(() => uma.Write(capacity - 1, 0.123)); + AssertExtensions.Throws("position", () => uma.Write(capacity - 1, 0.123)); uma.Dispose(); Assert.Throws(() => uma.ReadByte(0)); @@ -53,7 +53,7 @@ namespace System.IO.Tests uma.Write(4, 0); // mid uma.Write(8, 0); // hi uma.Write(12, -1); // flags (all bits are set, so this should raise an exception) - Assert.Throws(() => uma.ReadDecimal(0)); // Should throw same exception as decimal(int[]) ctor for compat + AssertExtensions.Throws(null, () => uma.ReadDecimal(0)); // Should throw same exception as decimal(int[]) ctor for compat } } diff --git a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsCtorTests.cs b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsCtorTests.cs index 120cabec6ac..4e0cf1986bf 100644 --- a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsCtorTests.cs +++ b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsCtorTests.cs @@ -22,11 +22,11 @@ namespace System.IO.Tests Assert.Throws(() => new UnmanagedMemoryStream(fakeBuffer, 1, 2, (FileAccess)(-1))); Assert.Throws(() => new UnmanagedMemoryStream(fakeBuffer, 1, 2, (FileAccess)42)); - Assert.Throws(() => new UnmanagedMemoryStream(fakeBuffer, 2, 999)); - Assert.Throws(() => new UnmanagedMemoryStream(fakeBuffer, 999, 9)); - Assert.Throws(() => new UnmanagedMemoryStream(fakeBuffer, 1, 100)); + AssertExtensions.Throws(null, () => new UnmanagedMemoryStream(fakeBuffer, 2, 999)); + AssertExtensions.Throws(null, () => new UnmanagedMemoryStream(fakeBuffer, 999, 9)); + AssertExtensions.Throws(null, () => new UnmanagedMemoryStream(fakeBuffer, 1, 100)); - Assert.Throws(() => new UnmanagedMemoryStream(fakeBuffer, Int32.MaxValue, 1)); + AssertExtensions.Throws(null, () => new UnmanagedMemoryStream(fakeBuffer, Int32.MaxValue, 1)); } [Fact] diff --git a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsRead.cs b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsRead.cs index 0eefac156d5..8f7aa3a4c3e 100644 --- a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsRead.cs +++ b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsRead.cs @@ -122,14 +122,14 @@ namespace System.IO.Tests Assert.Throws(() => stream.WriteAsync(new byte[] { }, 1, -2).GetAwaiter().GetResult()); //case#6: call Read with count > ums.Length-startIndex, ArgumentOutOfRangeException should be thrown. - Assert.Throws(() => stream.Read(new byte[10], 0, 11)); // "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection." - Assert.Throws(() => stream.ReadAsync(new byte[10], 0, 11).GetAwaiter().GetResult()); - Assert.Throws(() => stream.Write(new byte[3], 0, 4)); - Assert.Throws(() => stream.WriteAsync(new byte[3], 0, 4).GetAwaiter().GetResult()); + AssertExtensions.Throws(null, () => stream.Read(new byte[10], 0, 11)); // "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection." + AssertExtensions.Throws(null, () => stream.ReadAsync(new byte[10], 0, 11).GetAwaiter().GetResult()); + AssertExtensions.Throws(null, () => stream.Write(new byte[3], 0, 4)); + AssertExtensions.Throws(null, () => stream.WriteAsync(new byte[3], 0, 4).GetAwaiter().GetResult()); //case#10: Call Read on a n length stream, (Capacity is implicitly n), position is set to end, call it, should throw ArgumentException. - Assert.Throws(() => stream.Read(new byte[] { }, 0, 1)); - Assert.Throws(() => stream.Write(new byte[] { }, 0, 1)); + AssertExtensions.Throws(null, () => stream.Read(new byte[] { }, 0, 1)); + AssertExtensions.Throws(null, () => stream.Write(new byte[] { }, 0, 1)); } } diff --git a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsTests.cs b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsTests.cs index a2e716b6825..cb99c5711b7 100644 --- a/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsTests.cs +++ b/src/libraries/System.IO.UnmanagedMemoryStream/tests/UmsTests.cs @@ -93,7 +93,7 @@ namespace System.IO.Tests Assert.Throws(() => stream.Seek(unchecked(Int32.MaxValue + 1), SeekOrigin.Begin)); Assert.Throws(() => stream.Seek(Int64.MinValue, SeekOrigin.End)); - Assert.Throws(() => stream.Seek(0, (SeekOrigin)7)); // Invalid seek origin + AssertExtensions.Throws(null, () => stream.Seek(0, (SeekOrigin)7)); // Invalid seek origin stream.Seek(10, SeekOrigin.Begin); Assert.Equal(10, stream.Position); diff --git a/src/libraries/System.IO/tests/BinaryWriter/BinaryWriter.WriteByteCharTests.cs b/src/libraries/System.IO/tests/BinaryWriter/BinaryWriter.WriteByteCharTests.cs index 0098634dab4..d1d70747bd5 100644 --- a/src/libraries/System.IO/tests/BinaryWriter/BinaryWriter.WriteByteCharTests.cs +++ b/src/libraries/System.IO/tests/BinaryWriter/BinaryWriter.WriteByteCharTests.cs @@ -86,14 +86,14 @@ namespace System.IO.Tests for (int i = 0; i < randomNumbers.Length; i++) { ch = (char)randomNumbers[i]; - Assert.Throws(() => writer.Write(ch)); + AssertExtensions.Throws(null, () => writer.Write(ch)); } // between 56320 <= x < 57343 randomNumbers = new int[] { 56320, 57342, 56431, 57001, 56453, 57245, 57111 }; for (int i = 0; i < randomNumbers.Length; i++) { ch = (char)randomNumbers[i]; - Assert.Throws(() => writer.Write(ch)); + AssertExtensions.Throws(null, () => writer.Write(ch)); } writer.Dispose(); @@ -305,9 +305,9 @@ namespace System.IO.Tests for (int iLoop = 0; iLoop < iArrLargeValues.Length; iLoop++) { // [] Offset out of range - Assert.Throws(() => dw2.Write(bArr, iArrLargeValues[iLoop], 0)); + AssertExtensions.Throws(null, () => dw2.Write(bArr, iArrLargeValues[iLoop], 0)); // [] Invalid count value - Assert.Throws(() => dw2.Write(bArr, 0, iArrLargeValues[iLoop])); + AssertExtensions.Throws(null, () => dw2.Write(bArr, 0, iArrLargeValues[iLoop])); } dw2.Dispose(); mstr.Dispose(); diff --git a/src/libraries/System.IO/tests/BinaryWriter/BinaryWriterTests.cs b/src/libraries/System.IO/tests/BinaryWriter/BinaryWriterTests.cs index 1371889b686..79d2d49e259 100644 --- a/src/libraries/System.IO/tests/BinaryWriter/BinaryWriterTests.cs +++ b/src/libraries/System.IO/tests/BinaryWriter/BinaryWriterTests.cs @@ -42,14 +42,14 @@ namespace System.IO.Tests // [] Can't construct a BinaryWriter on a readonly stream using (Stream memStream = new MemoryStream(new byte[10], false)) { - Assert.Throws(() => new BinaryWriter(memStream)); + AssertExtensions.Throws(null, () => new BinaryWriter(memStream)); } // [] Can't construct a BinaryWriter with a closed stream { Stream memStream = CreateStream(); memStream.Dispose(); - Assert.Throws(() => new BinaryWriter(memStream)); + AssertExtensions.Throws(null, () => new BinaryWriter(memStream)); } } @@ -261,7 +261,7 @@ namespace System.IO.Tests { writer.Write("012345789".ToCharArray()); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { writer.Seek(3, ~SeekOrigin.Begin); }); diff --git a/src/libraries/System.IO/tests/BufferedStream/BufferedStream.InvalidParameters.cs b/src/libraries/System.IO/tests/BufferedStream/BufferedStream.InvalidParameters.cs index 70e9b552079..f6ac420501b 100644 --- a/src/libraries/System.IO/tests/BufferedStream/BufferedStream.InvalidParameters.cs +++ b/src/libraries/System.IO/tests/BufferedStream/BufferedStream.InvalidParameters.cs @@ -53,7 +53,7 @@ namespace System.IO.Tests AssertExtensions.Throws("array", () => stream.Read(null, 1, 1)); Assert.Throws(() => stream.Read(array, -1, 1)); Assert.Throws(() => stream.Read(array, 1, -1)); - Assert.Throws(() => stream.Read(array, 9, 2)); + AssertExtensions.Throws(null, () => stream.Read(array, 9, 2)); } } @@ -66,7 +66,7 @@ namespace System.IO.Tests AssertExtensions.Throws("array", () => stream.Write(null, 1, 1)); Assert.Throws(() => stream.Write(array, -1, 1)); Assert.Throws(() => stream.Write(array, 1, -1)); - Assert.Throws(() => stream.Write(array, 9, 2)); + AssertExtensions.Throws(null, () => stream.Write(array, 9, 2)); } } diff --git a/src/libraries/System.IO/tests/MemoryStream/MemoryStream.ConstructorTests.cs b/src/libraries/System.IO/tests/MemoryStream/MemoryStream.ConstructorTests.cs index d07571c59a5..ed4ce70112d 100644 --- a/src/libraries/System.IO/tests/MemoryStream/MemoryStream.ConstructorTests.cs +++ b/src/libraries/System.IO/tests/MemoryStream/MemoryStream.ConstructorTests.cs @@ -21,7 +21,7 @@ namespace System.IO.Tests [InlineData(7, 8, 2)] public static void MemoryStream_Ctor_OutOfRangeIndeces(int arraySize, int index, int count) { - Assert.Throws(() => new MemoryStream(new byte[arraySize], index, count)); + AssertExtensions.Throws(null, () => new MemoryStream(new byte[arraySize], index, count)); } [Fact] diff --git a/src/libraries/System.IO/tests/MemoryStream/MemoryStreamTests.cs b/src/libraries/System.IO/tests/MemoryStream/MemoryStreamTests.cs index c9ae996eabb..f57ac616e7e 100644 --- a/src/libraries/System.IO/tests/MemoryStream/MemoryStreamTests.cs +++ b/src/libraries/System.IO/tests/MemoryStream/MemoryStreamTests.cs @@ -127,8 +127,8 @@ namespace System.IO.Tests Assert.Throws(() => ms2.Read(null, 0, 0)); Assert.Throws(() => ms2.Read(new byte[] { 1 }, -1, 0)); Assert.Throws(() => ms2.Read(new byte[] { 1 }, 0, -1)); - Assert.Throws(() => ms2.Read(new byte[] { 1 }, 2, 0)); - Assert.Throws(() => ms2.Read(new byte[] { 1 }, 0, 2)); + AssertExtensions.Throws(null, () => ms2.Read(new byte[] { 1 }, 2, 0)); + AssertExtensions.Throws(null, () => ms2.Read(new byte[] { 1 }, 0, 2)); ms2.Dispose(); diff --git a/src/libraries/System.IO/tests/Stream/Stream.Methods.cs b/src/libraries/System.IO/tests/Stream/Stream.Methods.cs index a2929fc4e58..10b5fe86e34 100644 --- a/src/libraries/System.IO/tests/Stream/Stream.Methods.cs +++ b/src/libraries/System.IO/tests/Stream/Stream.Methods.cs @@ -284,8 +284,8 @@ namespace System.IO.Tests AssertExtensions.Throws("count", () => { stream.ReadAsync(new byte[1], 0, -1); }); AssertExtensions.Throws("count", () => { stream.WriteAsync(new byte[1], 0, -1); }); - Assert.Throws(() => { stream.ReadAsync(new byte[1], 0, 2); }); - Assert.Throws(() => { stream.WriteAsync(new byte[1], 0, 2); }); + AssertExtensions.Throws(null, () => { stream.ReadAsync(new byte[1], 0, 2); }); + AssertExtensions.Throws(null, () => { stream.WriteAsync(new byte[1], 0, 2); }); } } } diff --git a/src/libraries/System.IO/tests/StreamReader/StreamReader.CtorTests.cs b/src/libraries/System.IO/tests/StreamReader/StreamReader.CtorTests.cs index 52ba53016e4..37d8afa4bea 100644 --- a/src/libraries/System.IO/tests/StreamReader/StreamReader.CtorTests.cs +++ b/src/libraries/System.IO/tests/StreamReader/StreamReader.CtorTests.cs @@ -21,7 +21,7 @@ namespace System.IO.Tests var ms2 = new MemoryStream(); ms2.Dispose(); - Assert.Throws(() => new StreamReader(ms2, false)); + AssertExtensions.Throws(null, () => new StreamReader(ms2, false)); } [Fact] diff --git a/src/libraries/System.IO/tests/StreamReader/StreamReader.StringCtorTests.cs b/src/libraries/System.IO/tests/StreamReader/StreamReader.StringCtorTests.cs index 18f0216f559..ea2237f46bf 100644 --- a/src/libraries/System.IO/tests/StreamReader/StreamReader.StringCtorTests.cs +++ b/src/libraries/System.IO/tests/StreamReader/StreamReader.StringCtorTests.cs @@ -27,10 +27,10 @@ namespace System.IO.Tests public static void EmptyPath_ThrowsArgumentException() { // No argument name for the empty path exception - Assert.Throws(() => new StreamReader("")); - Assert.Throws(() => new StreamReader("", Encoding.UTF8)); - Assert.Throws(() => new StreamReader("", Encoding.UTF8, true)); - Assert.Throws(() => new StreamReader("", Encoding.UTF8, true, -1)); + AssertExtensions.Throws(null, () => new StreamReader("")); + AssertExtensions.Throws(null, () => new StreamReader("", Encoding.UTF8)); + AssertExtensions.Throws(null, () => new StreamReader("", Encoding.UTF8, true)); + AssertExtensions.Throws(null, () => new StreamReader("", Encoding.UTF8, true, -1)); } [Fact] diff --git a/src/libraries/System.IO/tests/StreamReader/StreamReaderTests.cs b/src/libraries/System.IO/tests/StreamReader/StreamReaderTests.cs index 933e7fa5eb1..0a70a82028e 100644 --- a/src/libraries/System.IO/tests/StreamReader/StreamReaderTests.cs +++ b/src/libraries/System.IO/tests/StreamReader/StreamReaderTests.cs @@ -195,14 +195,14 @@ namespace System.IO.Tests public void ArgumentOutOfRangeOnNegativCount() { var sr = GetCharArrayStream().Item2; - Assert.Throws(() => sr.Read(new char[0], 0, 1)); + AssertExtensions.Throws(null, () => sr.Read(new char[0], 0, 1)); } [Fact] public void ArgumentExceptionOffsetAndCount() { var sr = GetCharArrayStream().Item2; - Assert.Throws(() => sr.Read(new char[0], 2, 0)); + AssertExtensions.Throws(null, () => sr.Read(new char[0], 2, 0)); } [Fact] diff --git a/src/libraries/System.IO/tests/StreamWriter/StreamWriter.StringCtorTests.cs b/src/libraries/System.IO/tests/StreamWriter/StreamWriter.StringCtorTests.cs index 06844e01a6a..ab2aea773e8 100644 --- a/src/libraries/System.IO/tests/StreamWriter/StreamWriter.StringCtorTests.cs +++ b/src/libraries/System.IO/tests/StreamWriter/StreamWriter.StringCtorTests.cs @@ -29,10 +29,10 @@ namespace System.IO.Tests public static void EmptyPath_ThrowsArgumentException() { // No argument name for the empty path exception - Assert.Throws(() => new StreamWriter("")); - Assert.Throws(() => new StreamWriter("", true)); - Assert.Throws(() => new StreamWriter("", true, Encoding.UTF8)); - Assert.Throws(() => new StreamWriter("", true, Encoding.UTF8, -1)); + AssertExtensions.Throws(null, () => new StreamWriter("")); + AssertExtensions.Throws(null, () => new StreamWriter("", true)); + AssertExtensions.Throws(null, () => new StreamWriter("", true, Encoding.UTF8)); + AssertExtensions.Throws(null, () => new StreamWriter("", true, Encoding.UTF8, -1)); } [Fact] diff --git a/src/libraries/System.IO/tests/StreamWriter/StreamWriter.WriteTests.cs b/src/libraries/System.IO/tests/StreamWriter/StreamWriter.WriteTests.cs index b4e822946a1..5c913da954f 100644 --- a/src/libraries/System.IO/tests/StreamWriter/StreamWriter.WriteTests.cs +++ b/src/libraries/System.IO/tests/StreamWriter/StreamWriter.WriteTests.cs @@ -153,7 +153,7 @@ namespace System.IO.Tests Stream ms = CreateStream(); StreamWriter sw = new StreamWriter(ms); - Assert.Throws(() => sw.Write(chArr, 1, chArr.Length)); + AssertExtensions.Throws(null, () => sw.Write(chArr, 1, chArr.Length)); sw.Dispose(); } diff --git a/src/libraries/System.IO/tests/StringWriter/StringWriterTests.cs b/src/libraries/System.IO/tests/StringWriter/StringWriterTests.cs index 29da2171096..6655a2d5486 100644 --- a/src/libraries/System.IO/tests/StringWriter/StringWriterTests.cs +++ b/src/libraries/System.IO/tests/StringWriter/StringWriterTests.cs @@ -129,7 +129,7 @@ namespace System.IO.Tests for (int i = 0; i < iArrLargeValues.Length; i++) { StringWriter sw = new StringWriter(); - Assert.Throws(() => sw.Write(chArr, iArrLargeValues[i], chArr.Length)); + AssertExtensions.Throws(null, () => sw.Write(chArr, iArrLargeValues[i], chArr.Length)); } } @@ -140,7 +140,7 @@ namespace System.IO.Tests for (int i = 0; i < iArrLargeValues.Length; i++) { StringWriter sw = new StringWriter(); - Assert.Throws(() => sw.Write(chArr, 0, iArrLargeValues[i])); + AssertExtensions.Throws(null, () => sw.Write(chArr, 0, iArrLargeValues[i])); } } diff --git a/src/libraries/System.Linq.Expressions/tests/Array/ArrayAccessTests.cs b/src/libraries/System.Linq.Expressions/tests/Array/ArrayAccessTests.cs index 68078188a58..8d94ec108d3 100644 --- a/src/libraries/System.Linq.Expressions/tests/Array/ArrayAccessTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Array/ArrayAccessTests.cs @@ -58,7 +58,7 @@ namespace System.Linq.Expressions.Tests { ConstantExpression instance = Expression.Constant(new int[2,3]); ConstantExpression index = Expression.Constant(2); - Assert.Throws(() => Expression.ArrayAccess(instance, index)); + AssertExtensions.Throws(null, () => Expression.ArrayAccess(instance, index)); } [Fact] diff --git a/src/libraries/System.Linq.Expressions/tests/Array/ArrayIndexTests.cs b/src/libraries/System.Linq.Expressions/tests/Array/ArrayIndexTests.cs index 484a44b822c..389b6d47b31 100644 --- a/src/libraries/System.Linq.Expressions/tests/Array/ArrayIndexTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Array/ArrayIndexTests.cs @@ -2759,7 +2759,7 @@ namespace System.Linq.Expressions.Tests public static void UnreadableArray() { Expression array = Expression.Property(null, typeof(Unreadable), nameof(Unreadable.WriteOnly)); - Assert.Throws(() => Expression.ArrayIndex(array, Expression.Constant(0))); + AssertExtensions.Throws("array", () => Expression.ArrayIndex(array, Expression.Constant(0))); } [Fact] diff --git a/src/libraries/System.Linq.Expressions/tests/Array/ArrayLengthTests.cs b/src/libraries/System.Linq.Expressions/tests/Array/ArrayLengthTests.cs index ef6e5cf63fb..836d74b1053 100644 --- a/src/libraries/System.Linq.Expressions/tests/Array/ArrayLengthTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Array/ArrayLengthTests.cs @@ -1616,7 +1616,7 @@ namespace System.Linq.Expressions.Tests public static void UnreadableArray() { Expression array = Expression.Property(null, typeof(Unreadable), nameof(Unreadable.WriteOnly)); - Assert.Throws(() => Expression.ArrayLength(array)); + AssertExtensions.Throws("array", () => Expression.ArrayLength(array)); } private static IEnumerable TestArrays() diff --git a/src/libraries/System.Linq.Expressions/tests/Array/NewArrayListTests.cs b/src/libraries/System.Linq.Expressions/tests/Array/NewArrayListTests.cs index 53caabeb222..9bb3247d9bb 100644 --- a/src/libraries/System.Linq.Expressions/tests/Array/NewArrayListTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Array/NewArrayListTests.cs @@ -1645,7 +1645,7 @@ namespace System.Linq.Expressions.Tests [Fact] public static void VoidType() { - Assert.Throws(() => Expression.NewArrayInit(typeof(void))); + AssertExtensions.Throws("type", () => Expression.NewArrayInit(typeof(void))); } [Fact] @@ -1665,7 +1665,7 @@ namespace System.Linq.Expressions.Tests [Fact] public static void ByRefType() { - Assert.Throws(() => Expression.NewArrayInit(typeof(int).MakeByRefType())); + AssertExtensions.Throws("type", () => Expression.NewArrayInit(typeof(int).MakeByRefType())); } [Fact] @@ -1677,14 +1677,14 @@ namespace System.Linq.Expressions.Tests [Fact] public static void GenericType() { - Assert.Throws(() => Expression.NewArrayInit(typeof(List<>))); + AssertExtensions.Throws("type", () => Expression.NewArrayInit(typeof(List<>))); } [Fact] public static void TypeContainsGenericParameters() { - Assert.Throws(() => Expression.NewArrayInit(typeof(List<>.Enumerator))); - Assert.Throws(() => Expression.NewArrayInit(typeof(List<>).MakeGenericType(typeof(List<>)))); + AssertExtensions.Throws("type", () => Expression.NewArrayInit(typeof(List<>.Enumerator))); + AssertExtensions.Throws("type", () => Expression.NewArrayInit(typeof(List<>).MakeGenericType(typeof(List<>)))); } [Fact] diff --git a/src/libraries/System.Linq.Expressions/tests/BinaryOperators/Logical/BinaryLogicalTests.cs b/src/libraries/System.Linq.Expressions/tests/BinaryOperators/Logical/BinaryLogicalTests.cs index 7b121963e75..e7c4a131ada 100644 --- a/src/libraries/System.Linq.Expressions/tests/BinaryOperators/Logical/BinaryLogicalTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/BinaryOperators/Logical/BinaryLogicalTests.cs @@ -785,14 +785,14 @@ namespace System.Linq.Expressions.Tests public static void AndAlsoGlobalMethod() { MethodInfo method = GlobalMethod(typeof(int), new[] { typeof(int), typeof(int) }); - Assert.Throws(() => Expression.AndAlso(Expression.Constant(1), Expression.Constant(2), method)); + AssertExtensions.Throws(null, () => Expression.AndAlso(Expression.Constant(1), Expression.Constant(2), method)); } [Fact] public static void OrElseGlobalMethod() { MethodInfo method = GlobalMethod(typeof(int), new [] { typeof(int), typeof(int) }); - Assert.Throws(() => Expression.OrElse(Expression.Constant(1), Expression.Constant(2), method)); + AssertExtensions.Throws(null, () => Expression.OrElse(Expression.Constant(1), Expression.Constant(2), method)); } private static TypeBuilder GetTypeBuilder() diff --git a/src/libraries/System.Linq.Expressions/tests/Block/NoParameterBlockTests.cs b/src/libraries/System.Linq.Expressions/tests/Block/NoParameterBlockTests.cs index 1153529eebe..6f59c3da21e 100644 --- a/src/libraries/System.Linq.Expressions/tests/Block/NoParameterBlockTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Block/NoParameterBlockTests.cs @@ -376,7 +376,7 @@ namespace System.Linq.Expressions.Tests Assert.Throws(() => children.CopyTo(null, 0)); Assert.Throws(() => children.CopyTo(copyToTest, -1)); Assert.All(copyToTest, Assert.Null); // assert partial copy didn't happen before exception - Assert.Throws(() => children.CopyTo(copyToTest, 2)); + AssertExtensions.Throws(parCount >= 2 && parCount <= 5 ? null : "destinationArray", () => children.CopyTo(copyToTest, 2)); Assert.All(copyToTest, Assert.Null); children.CopyTo(copyToTest, 1); Assert.Equal(copyToTest, exps.Prepend(null)); diff --git a/src/libraries/System.Linq.Expressions/tests/Conditional/ConditionalTests.cs b/src/libraries/System.Linq.Expressions/tests/Conditional/ConditionalTests.cs index 4a126ef4742..06f36e5d216 100644 --- a/src/libraries/System.Linq.Expressions/tests/Conditional/ConditionalTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Conditional/ConditionalTests.cs @@ -187,7 +187,7 @@ namespace System.Linq.Expressions.Tests [Fact] public void ByRefType() { - Assert.Throws(() => Expression.Condition( + AssertExtensions.Throws(null, () => Expression.Condition( Expression.Constant(true), Expression.Constant(null), Expression.Constant(null), @@ -197,7 +197,7 @@ namespace System.Linq.Expressions.Tests [Fact] public void PointerType() { - Assert.Throws(() => Expression.Condition( + AssertExtensions.Throws(null, () => Expression.Condition( Expression.Constant(true), Expression.Constant(null), Expression.Constant(null), @@ -207,7 +207,7 @@ namespace System.Linq.Expressions.Tests [Fact] public void GenericType() { - Assert.Throws(() => Expression.Condition( + AssertExtensions.Throws(null, () => Expression.Condition( Expression.Constant(true), Expression.Constant(null), Expression.Constant(null), @@ -217,12 +217,12 @@ namespace System.Linq.Expressions.Tests [Fact] public void TypeContainsGenericParameters() { - Assert.Throws(() => Expression.Condition( + AssertExtensions.Throws(null, () => Expression.Condition( Expression.Constant(true), Expression.Constant(null), Expression.Constant(null), typeof(List<>.Enumerator))); - Assert.Throws(() => Expression.Condition( + AssertExtensions.Throws(null, () => Expression.Condition( Expression.Constant(true), Expression.Constant(null), Expression.Constant(null), diff --git a/src/libraries/System.Linq.Expressions/tests/Constant/ConstantTests.cs b/src/libraries/System.Linq.Expressions/tests/Constant/ConstantTests.cs index 5c5e4a012a2..9cf5e85a33c 100644 --- a/src/libraries/System.Linq.Expressions/tests/Constant/ConstantTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Constant/ConstantTests.cs @@ -974,7 +974,7 @@ namespace System.Linq.Expressions.Tests [Fact] public static void ByRefType() { - Assert.Throws(() => Expression.Constant(null, typeof(string).MakeByRefType())); + AssertExtensions.Throws("type", () => Expression.Constant(null, typeof(string).MakeByRefType())); } [Fact] @@ -986,14 +986,14 @@ namespace System.Linq.Expressions.Tests [Fact] public static void GenericType() { - Assert.Throws(() => Expression.Constant(null, typeof(List<>))); + AssertExtensions.Throws("type", () => Expression.Constant(null, typeof(List<>))); } [Fact] public static void TypeContainsGenericParameters() { - Assert.Throws(() => Expression.Constant(null, typeof(List<>.Enumerator))); - Assert.Throws(() => Expression.Constant(null, typeof(List<>).MakeGenericType(typeof(List<>)))); + AssertExtensions.Throws("type", () => Expression.Constant(null, typeof(List<>.Enumerator))); + AssertExtensions.Throws("type", () => Expression.Constant(null, typeof(List<>).MakeGenericType(typeof(List<>)))); } [Fact] diff --git a/src/libraries/System.Linq.Expressions/tests/Convert/ConvertTests.cs b/src/libraries/System.Linq.Expressions/tests/Convert/ConvertTests.cs index 602228b0f2e..b8d2b8032b4 100644 --- a/src/libraries/System.Linq.Expressions/tests/Convert/ConvertTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Convert/ConvertTests.cs @@ -16643,9 +16643,9 @@ namespace System.Linq.Expressions.Tests [Theory, ClassData(typeof(CompilationTypes))] public static void ImplicitHalfLiftedReverseConversion(bool useInterpreter) { - // In the case where there is a conversion from? → to, then if - // we want to do from? → to? we should do two conversions; - // from? → to → to?, since converting any value to the nullable + // In the case where there is a conversion from? -> to, then if + // we want to do from? -> to? we should do two conversions; + // from? -> to -> to?, since converting any value to the nullable // form of its type is always possible and well-defined. // The compiler correctly does this double-conversion in such cases. // We should probably not allow it to be done as a single lifted operation. @@ -16871,7 +16871,7 @@ namespace System.Linq.Expressions.Tests { Expression operand = Expression.Constant(new CustomConversions { Value = 9 }); MethodInfo method = typeof(CustomConversions).GetMethod(nameof(CustomConversions.FromAddition)); - Assert.Throws(() => Expression.Convert(operand, typeof(int), method)); + AssertExtensions.Throws("method", () => Expression.Convert(operand, typeof(int), method)); } [Fact] diff --git a/src/libraries/System.Linq.Expressions/tests/DelegateType/GetDelegateTypeTests.cs b/src/libraries/System.Linq.Expressions/tests/DelegateType/GetDelegateTypeTests.cs index f3cb6a91ebc..11b4cb48dd5 100644 --- a/src/libraries/System.Linq.Expressions/tests/DelegateType/GetDelegateTypeTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/DelegateType/GetDelegateTypeTests.cs @@ -114,13 +114,13 @@ namespace System.Linq.Expressions.Tests [Theory, MemberData(nameof(VoidTypeArgs), false)] public void VoidArgToFuncTypeDelegate(Type[] typeArgs) { - Assert.Throws(() => Expression.GetDelegateType(typeArgs)); + AssertExtensions.Throws(null, () => Expression.GetDelegateType(typeArgs)); } [Theory, MemberData(nameof(VoidTypeArgs), false)] public void VoidArgToActionTypeDelegate(Type[] typeArgs) { - Assert.Throws(() => Expression.GetDelegateType(typeArgs.Append(typeof(void)).ToArray())); + AssertExtensions.Throws(null, () => Expression.GetDelegateType(typeArgs.Append(typeof(void)).ToArray())); } } } diff --git a/src/libraries/System.Linq.Expressions/tests/Dynamic/CallSiteTests.cs b/src/libraries/System.Linq.Expressions/tests/Dynamic/CallSiteTests.cs index 9a6bca4d13d..2c75b3a5eb3 100644 --- a/src/libraries/System.Linq.Expressions/tests/Dynamic/CallSiteTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Dynamic/CallSiteTests.cs @@ -12,10 +12,10 @@ namespace System.Runtime.CompilerServices.Tests [Fact] public void CannotCreateForNonDelegate() { - string msg = Assert.Throws(() => CallSite.Create(null)).Message; + string msg = AssertExtensions.Throws(null, () => CallSite.Create(null)).Message; CallSiteBinder binder = new CallSiteBinderDefaultBehaviourTests.NopCallSiteBinder(); - Assert.Equal(msg, Assert.Throws(() => CallSite.Create(binder)).Message); - Assert.Equal(msg, Assert.Throws(() => CallSite.Create(typeof(Expression), binder)).Message); + Assert.Equal(msg, AssertExtensions.Throws(null, () => CallSite.Create(binder)).Message); + Assert.Equal(msg, AssertExtensions.Throws(null, () => CallSite.Create(typeof(Expression), binder)).Message); } [Fact] diff --git a/src/libraries/System.Linq.Expressions/tests/IndexExpression/IndexExpressionTests.cs b/src/libraries/System.Linq.Expressions/tests/IndexExpression/IndexExpressionTests.cs index 37bfc0d09e6..fc3e506dea6 100644 --- a/src/libraries/System.Linq.Expressions/tests/IndexExpression/IndexExpressionTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/IndexExpression/IndexExpressionTests.cs @@ -496,7 +496,7 @@ namespace System.Linq.Expressions.Tests Type type = info; PropertyInfo prop = type.GetProperties()[0]; Expression instance = Expression.Default(type); - Assert.Throws(() => Expression.Property(instance, prop, Expression.Constant(0))); + AssertExtensions.Throws("instance", () => Expression.Property(instance, prop, Expression.Constant(0))); } [Fact] @@ -610,8 +610,8 @@ namespace System.Linq.Expressions.Tests public void NoSuchPropertyExplicitlyNoIndices() { ConstantExpression instance = Expression.Constant(""); - Assert.Throws(() => Expression.Property(instance, "ThisDoesNotExist", Array.Empty())); - Assert.Throws(() => Expression.Property(instance, "ThisDoesNotExist", null)); + AssertExtensions.Throws(null, () => Expression.Property(instance, "ThisDoesNotExist", Array.Empty())); + AssertExtensions.Throws(null, () => Expression.Property(instance, "ThisDoesNotExist", null)); } [Theory, ClassData(typeof(CompilationTypes))] @@ -628,7 +628,7 @@ namespace System.Linq.Expressions.Tests public void FindNothingForNullArgument() { ConstantExpression instance = Expression.Constant("123"); - Assert.Throws(() => Expression.Property(instance, "Length", new Expression[] {null})); + AssertExtensions.Throws("propertyName", () => Expression.Property(instance, "Length", new Expression[] {null})); } [Fact] @@ -636,7 +636,7 @@ namespace System.Linq.Expressions.Tests { ConstantExpression instance = Expression.Constant(new Dictionary()); PropertyInfo prop = typeof(Dictionary).GetProperty("Item"); - Assert.Throws(() => Expression.Property(instance, "Item", new Expression[] {null})); + AssertExtensions.Throws("propertyName", () => Expression.Property(instance, "Item", new Expression[] {null})); AssertExtensions.Throws("arguments[0]", () => Expression.Property(instance, prop, new Expression[] {null})); } diff --git a/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs b/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs index 8bef10e7f8a..31ed6251393 100644 --- a/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Lambda/LambdaTests.cs @@ -437,7 +437,7 @@ namespace System.Linq.Expressions.Tests [Theory, ClassData(typeof(CompilationTypes))] public void NameNeedNotBeValidCSharpLabel(bool useInterpreter) { - string name = "1, 2, 3, 4. This is not a valid C♯ label!\"'<>.\uffff"; + string name = "1, 2, 3, 4. This is not a valid C\u266F label!\"'<>.\uffff"; var exp = (Expression>)Expression.Lambda(Expression.Constant(21), name, Array.Empty()); Assert.Equal(name, exp.Name); Assert.Equal(21, exp.Compile(useInterpreter)()); @@ -540,11 +540,11 @@ namespace System.Linq.Expressions.Tests private static void VerifyUpdateDifferentParamsReturnsDifferent(Expression lamda, ParameterExpression[] pars) { // Should try to create new lambda, but should fail as should have wrong number of arguments. - Assert.Throws(() => lamda.Update(lamda.Body, pars.Append(Expression.Parameter(typeof(int))))); + AssertExtensions.Throws(null, () => lamda.Update(lamda.Body, pars.Append(Expression.Parameter(typeof(int))))); if (pars.Length != 0) { - Assert.Throws(() => lamda.Update(lamda.Body, null)); + AssertExtensions.Throws(null, () => lamda.Update(lamda.Body, null)); for (int i = 0; i != pars.Length; ++i) { ParameterExpression[] newPars = new ParameterExpression[pars.Length]; @@ -776,7 +776,7 @@ namespace System.Linq.Expressions.Tests Assert.Throws(() => parameters.CopyTo(null, 0)); Assert.Throws(() => parameters.CopyTo(copyToTest, -1)); Assert.All(copyToTest, Assert.Null); // assert partial copy didn't happen before exception - Assert.Throws(() => parameters.CopyTo(copyToTest, 2)); + AssertExtensions.Throws(parCount >= 1 && parCount <= 3 && name == null && !tailCall ? null : "destinationArray", () => parameters.CopyTo(copyToTest, 2)); Assert.All(copyToTest, Assert.Null); parameters.CopyTo(copyToTest, 1); Assert.Equal(copyToTest, pars.Prepend(null)); diff --git a/src/libraries/System.Linq.Expressions/tests/ListInit/ListInitExpressionTests.cs b/src/libraries/System.Linq.Expressions/tests/ListInit/ListInitExpressionTests.cs index 1a6bb793d16..e0697180612 100644 --- a/src/libraries/System.Linq.Expressions/tests/ListInit/ListInitExpressionTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/ListInit/ListInitExpressionTests.cs @@ -171,9 +171,9 @@ namespace System.Linq.Expressions.Tests { NewExpression newExp = Expression.New(typeof(AnyTypeList)); MethodInfo adder = typeof(AnyTypeList).GetMethod(nameof(AnyTypeList.Add)); - Assert.Throws(() => Expression.ListInit(newExp, adder, Expression.Constant(0))); + AssertExtensions.Throws("addMethod", () => Expression.ListInit(newExp, adder, Expression.Constant(0))); adder = typeof(AnyTypeList).GetMethod(nameof(AnyTypeList.Add)).MakeGenericMethod(typeof(List)); - Assert.Throws(() => Expression.ListInit(newExp, adder, Expression.Constant(0))); + AssertExtensions.Throws("arguments[0]", () => Expression.ListInit(newExp, adder, Expression.Constant(0))); adder = typeof(AnyTypeList).GetMethod(nameof(AnyTypeList.AddIntRegardless)); AssertExtensions.Throws("addMethod", () => Expression.ListInit(newExp, adder, Expression.Constant(0))); adder = typeof(AnyTypeList).GetMethod(nameof(AnyTypeList.AddIntRegardless)).MakeGenericMethod(typeof(List<>)); diff --git a/src/libraries/System.Linq.Expressions/tests/Member/MemberAccessTests.cs b/src/libraries/System.Linq.Expressions/tests/Member/MemberAccessTests.cs index 17ac12b5be0..50238cc03ab 100644 --- a/src/libraries/System.Linq.Expressions/tests/Member/MemberAccessTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Member/MemberAccessTests.cs @@ -245,13 +245,13 @@ namespace System.Linq.Expressions.Tests [Fact] public static void Field_ByrefTypeFieldAccessor_ThrowsArgumentException() { - Assert.Throws(() => Expression.Property(null, typeof(GenericClass).MakeByRefType(), nameof(GenericClass.Field))); + AssertExtensions.Throws("propertyName", () => Expression.Property(null, typeof(GenericClass).MakeByRefType(), nameof(GenericClass.Field))); } [Fact] public static void Field_GenericFieldAccessor_ThrowsArgumentException() { - Assert.Throws(() => Expression.Property(null, typeof(GenericClass<>), nameof(GenericClass.Field))); + AssertExtensions.Throws("propertyName", () => Expression.Property(null, typeof(GenericClass<>), nameof(GenericClass.Field))); } [Fact] @@ -514,7 +514,7 @@ namespace System.Linq.Expressions.Tests [Fact] public static void Property_ByRefStaticAccess_ThrowsArgumentException() { - Assert.Throws(() => Expression.Property(null, typeof(NonGenericClass).MakeByRefType(), nameof(NonGenericClass.NonGenericProperty))); + AssertExtensions.Throws("propertyName", () => Expression.Property(null, typeof(NonGenericClass).MakeByRefType(), nameof(NonGenericClass.NonGenericProperty))); } [Fact] diff --git a/src/libraries/System.Linq.Expressions/tests/MemberInit/MemberBindTests.cs b/src/libraries/System.Linq.Expressions/tests/MemberInit/MemberBindTests.cs index e2d2205c31b..ccc9b9ec5c6 100644 --- a/src/libraries/System.Linq.Expressions/tests/MemberInit/MemberBindTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/MemberInit/MemberBindTests.cs @@ -93,7 +93,7 @@ namespace System.Linq.Expressions.Tests Expression.Bind(typeof(Inner).GetProperty(nameof(Inner.Value)), Expression.Constant(3)) ); NewExpression newExp = Expression.New(typeof(PropertyAndFields)); - Assert.Throws(() => Expression.MemberInit(newExp, bind)); + AssertExtensions.Throws("bindings[0]", () => Expression.MemberInit(newExp, bind)); } [Fact] @@ -271,14 +271,14 @@ namespace System.Linq.Expressions.Tests { MemberAssignment bind = Expression.Bind(typeof(Inner).GetProperty(nameof(Inner.Value)), Expression.Constant(0)); PropertyInfo property = typeof(Outer).GetProperty(nameof(Outer.WriteonlyInnerProperty)); - Assert.Throws(() => Expression.MemberBind(property, bind)); + AssertExtensions.Throws(null, () => Expression.MemberBind(property, bind)); } public void StaticWriteOnlyInnerProperty() { MemberAssignment bind = Expression.Bind(typeof(Inner).GetProperty(nameof(Inner.Value)), Expression.Constant(0)); PropertyInfo property = typeof(Outer).GetProperty(nameof(Outer.StaticWriteonlyInnerProperty)); - Assert.Throws(() => Expression.MemberBind(property, bind)); + AssertExtensions.Throws(null, () => Expression.MemberBind(property, bind)); } } } diff --git a/src/libraries/System.Linq.Expressions/tests/New/NewTests.cs b/src/libraries/System.Linq.Expressions/tests/New/NewTests.cs index 180b8a6d9c2..8d4781c4528 100644 --- a/src/libraries/System.Linq.Expressions/tests/New/NewTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/New/NewTests.cs @@ -526,7 +526,7 @@ namespace System.Linq.Expressions.Tests ConstructorInfo constructor = typeof(ClassWithCtors).GetConstructor(new Type[] { typeof(string) }); Expression[] arguments = { Expression.Constant(5) }; MemberInfo[] members = { globalMethodInfo }; - Assert.Throws(() => Expression.New(constructor, arguments, members)); + AssertExtensions.Throws("members[0]", () => Expression.New(constructor, arguments, members)); } [Fact] @@ -539,7 +539,7 @@ namespace System.Linq.Expressions.Tests ConstructorInfo constructor = typeof(ClassWithCtors).GetConstructor(new Type[] { typeof(string) }); Expression[] arguments = { Expression.Constant(5) }; MemberInfo[] members = { globalField }; - Assert.Throws(() => Expression.New(constructor, arguments, members)); + AssertExtensions.Throws("members[0]", () => Expression.New(constructor, arguments, members)); } #endif diff --git a/src/libraries/System.Linq.Expressions/tests/ReadOnlyCollectionBuilderTests.cs b/src/libraries/System.Linq.Expressions/tests/ReadOnlyCollectionBuilderTests.cs index 2a34e366530..c82b7f12178 100644 --- a/src/libraries/System.Linq.Expressions/tests/ReadOnlyCollectionBuilderTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/ReadOnlyCollectionBuilderTests.cs @@ -495,8 +495,8 @@ namespace System.Linq.Expressions.Tests Assert.True(Enumerable.Range(1, i).SequenceEqual(rocb.Cast())); } - Assert.Throws(() => rocb.Add(null)); - Assert.Throws(() => rocb.Add("foo")); + AssertExtensions.Throws("value", () => rocb.Add(null)); + AssertExtensions.Throws("value", () => rocb.Add("foo")); } [Fact] @@ -604,10 +604,10 @@ namespace System.Linq.Expressions.Tests AssertExtensions.Throws("count", () => rocb.Reverse(1, -1)); // CONSIDER: Throw ArgumentException just like List does, see https://github.com/dotnet/corefx/issues/14059 - // Assert.Throws(() => rocb.Reverse(3, 1)); - // Assert.Throws(() => rocb.Reverse(1, 3)); - // Assert.Throws(() => rocb.Reverse(2, 2)); - // Assert.Throws(() => rocb.Reverse(3, 1)); + // AssertExtensions.Throws(null, () => rocb.Reverse(3, 1)); + // AssertExtensions.Throws(null, () => rocb.Reverse(1, 3)); + // AssertExtensions.Throws(null, () => rocb.Reverse(2, 2)); + // AssertExtensions.Throws(null, () => rocb.Reverse(3, 1)); } [Fact] @@ -793,7 +793,7 @@ namespace System.Linq.Expressions.Tests Assert.Throws(() => rocb.CopyTo(null, 0)); Assert.Throws(() => rocb.CopyTo(new int[3], -1)); - Assert.Throws(() => rocb.CopyTo(new int[3], 3)); // NB: Consistent with List behavior + AssertExtensions.Throws("destinationArray", () => rocb.CopyTo(new int[3], 3)); // NB: Consistent with List behavior } [Fact] @@ -827,8 +827,8 @@ namespace System.Linq.Expressions.Tests Assert.Throws(() => rocb.CopyTo(null, 0)); Assert.Throws(() => rocb.CopyTo(new int[3], -1)); - Assert.Throws(() => rocb.CopyTo(new int[3], 3)); // NB: Consistent with List behavior - Assert.Throws(() => rocb.CopyTo(new int[3, 3], 0)); + AssertExtensions.Throws("destinationArray", () => rocb.CopyTo(new int[3], 3)); // NB: Consistent with List behavior + AssertExtensions.Throws(null, () => rocb.CopyTo(new int[3, 3], 0)); // CONSIDER: Throw ArgumentException instead to be consistent with List, see https://github.com/dotnet/corefx/issues/14059 Assert.Throws(() => rocb.CopyTo(new string[3], 0)); diff --git a/src/libraries/System.Linq.Expressions/tests/Unary/UnaryQuoteTests.cs b/src/libraries/System.Linq.Expressions/tests/Unary/UnaryQuoteTests.cs index 1f4624a34e4..df4518b14b0 100644 --- a/src/libraries/System.Linq.Expressions/tests/Unary/UnaryQuoteTests.cs +++ b/src/libraries/System.Linq.Expressions/tests/Unary/UnaryQuoteTests.cs @@ -502,7 +502,7 @@ namespace System.Linq.Expressions.Tests Expression q = Expression.Quote(exp); Assert.False(q.CanReduce); Assert.Same(q, q.Reduce()); - Assert.Throws(() => q.ReduceAndCheck()); + AssertExtensions.Throws(null, () => q.ReduceAndCheck()); } [Fact] diff --git a/src/libraries/System.Linq.Queryable/tests/EnumerableQueryTests.cs b/src/libraries/System.Linq.Queryable/tests/EnumerableQueryTests.cs index 10646863a2a..d450acc6820 100644 --- a/src/libraries/System.Linq.Queryable/tests/EnumerableQueryTests.cs +++ b/src/libraries/System.Linq.Queryable/tests/EnumerableQueryTests.cs @@ -34,7 +34,7 @@ namespace System.Linq.Tests { IQueryable query = new EnumerableQuery(Expression.Constant(Math.PI)); Assert.NotNull(query.Expression); - Assert.Throws(() => query.GetEnumerator()); + AssertExtensions.Throws(null, () => query.GetEnumerator()); } [Fact] @@ -151,7 +151,7 @@ namespace System.Linq.Tests { var exp = Expression.Constant(Math.PI); IQueryProvider provider = Enumerable.Empty().AsQueryable().Provider; - Assert.Throws(() => provider.CreateQuery(exp)); + AssertExtensions.Throws(null, () => provider.CreateQuery(exp)); } [Fact] @@ -159,7 +159,7 @@ namespace System.Linq.Tests { var exp = Expression.Constant(Math.PI); IQueryProvider provider = Enumerable.Empty().AsQueryable().Provider; - Assert.Throws(() => provider.CreateQuery(exp)); + AssertExtensions.Throws(null, () => provider.CreateQuery(exp)); } [Fact] @@ -205,7 +205,7 @@ namespace System.Linq.Tests { var exp = Expression.Constant(Math.PI); IQueryProvider provider = Enumerable.Empty().AsQueryable().Provider; - Assert.Throws(() => provider.Execute>(exp)); + AssertExtensions.Throws(null, () => provider.Execute>(exp)); } [Fact] diff --git a/src/libraries/System.Linq.Queryable/tests/QueryFromExpressionTests.cs b/src/libraries/System.Linq.Queryable/tests/QueryFromExpressionTests.cs index e04f6266a84..c125de3fe15 100644 --- a/src/libraries/System.Linq.Queryable/tests/QueryFromExpressionTests.cs +++ b/src/libraries/System.Linq.Queryable/tests/QueryFromExpressionTests.cs @@ -362,7 +362,7 @@ namespace System.Linq.Tests public void UnknownExpressionType() { IQueryable q = _prov.CreateQuery(new BogusExpression()); - Assert.Throws(() => q.GetEnumerator()); + AssertExtensions.Throws(null, () => q.GetEnumerator()); } private IQueryable SimpleMethod() diff --git a/src/libraries/System.Linq.Queryable/tests/Queryable.cs b/src/libraries/System.Linq.Queryable/tests/Queryable.cs index 9bd79a534db..2e160b76432 100644 --- a/src/libraries/System.Linq.Queryable/tests/Queryable.cs +++ b/src/libraries/System.Linq.Queryable/tests/Queryable.cs @@ -48,7 +48,7 @@ namespace System.Linq.Tests [Fact] public void NonGenericToQueryable() { - Assert.Throws(() => new NonGenericEnumerableSoWeDontNeedADependencyOnTheAssemblyWithNonGeneric().AsQueryable()); + AssertExtensions.Throws(null, () => new NonGenericEnumerableSoWeDontNeedADependencyOnTheAssemblyWithNonGeneric().AsQueryable()); } [Fact] diff --git a/src/libraries/System.Linq/tests/ToDictionaryTests.cs b/src/libraries/System.Linq/tests/ToDictionaryTests.cs index 54dbb88eadf..ef4bb0de6cd 100644 --- a/src/libraries/System.Linq/tests/ToDictionaryTests.cs +++ b/src/libraries/System.Linq/tests/ToDictionaryTests.cs @@ -196,7 +196,7 @@ namespace System.Linq.Tests int[] source = new int[] { 1, 2, 3 }; Func keySelector = key => 1; - Assert.Throws(() => source.ToDictionary(keySelector)); + AssertExtensions.Throws(null, () => source.ToDictionary(keySelector)); } [Fact] @@ -312,7 +312,7 @@ namespace System.Linq.Tests new { Name = "Bob", Score = 55 } }; - Assert.Throws(() => source.ToDictionary(e => e.Name, e => e, new AnagramEqualityComparer())); + AssertExtensions.Throws(null, () => source.ToDictionary(e => e.Name, e => e, new AnagramEqualityComparer())); } private static void AssertMatches(IEnumerable keys, IEnumerable values, Dictionary dict) diff --git a/src/libraries/System.Memory/tests/ReadOnlySpan/CtorPointerInt.cs b/src/libraries/System.Memory/tests/ReadOnlySpan/CtorPointerInt.cs index f428cd4da5d..1851b6d7703 100644 --- a/src/libraries/System.Memory/tests/ReadOnlySpan/CtorPointerInt.cs +++ b/src/libraries/System.Memory/tests/ReadOnlySpan/CtorPointerInt.cs @@ -58,8 +58,8 @@ namespace System.SpanTests { new ReadOnlySpan((void*)null, 0); new ReadOnlySpan((void*)null, 0); - Assert.Throws(() => new ReadOnlySpan((void*)null, 0).DontBox()); - Assert.Throws(() => new ReadOnlySpan((void*)null, 0).DontBox()); + AssertExtensions.Throws(null, () => new ReadOnlySpan((void*)null, 0).DontBox()); + AssertExtensions.Throws(null, () => new ReadOnlySpan((void*)null, 0).DontBox()); } } diff --git a/src/libraries/System.Memory/tests/Span/CtorPointerInt.cs b/src/libraries/System.Memory/tests/Span/CtorPointerInt.cs index 6bb247600c9..600801b94e4 100644 --- a/src/libraries/System.Memory/tests/Span/CtorPointerInt.cs +++ b/src/libraries/System.Memory/tests/Span/CtorPointerInt.cs @@ -58,8 +58,8 @@ namespace System.SpanTests { new Span((void*)null, 0); new Span((void*)null, 0); - Assert.Throws(() => new Span((void*)null, 0).DontBox()); - Assert.Throws(() => new Span((void*)null, 0).DontBox()); + AssertExtensions.Throws(null, () => new Span((void*)null, 0).DontBox()); + AssertExtensions.Throws(null, () => new Span((void*)null, 0).DontBox()); } } diff --git a/src/libraries/System.Memory/tests/System.Memory.Tests.csproj b/src/libraries/System.Memory/tests/System.Memory.Tests.csproj index 156b5a9edbc..3c98e4f75b7 100644 --- a/src/libraries/System.Memory/tests/System.Memory.Tests.csproj +++ b/src/libraries/System.Memory/tests/System.Memory.Tests.csproj @@ -76,6 +76,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj index 0c85f4e06a0..73218e57379 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj +++ b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/System.Net.Http.WinHttpHandler.Unit.Tests.csproj @@ -134,6 +134,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/WinHttpRequestStreamTest.cs b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/WinHttpRequestStreamTest.cs index 875e6340510..9bd2022a93a 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/WinHttpRequestStreamTest.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/WinHttpRequestStreamTest.cs @@ -193,7 +193,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests { Stream stream = MakeRequestStream(); - Assert.Throws(() => stream.Write(new byte[1], 0, 3)); + AssertExtensions.Throws("buffer", () => stream.Write(new byte[1], 0, 3)); } [Fact] @@ -201,7 +201,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests { Stream stream = MakeRequestStream(); - Assert.Throws(() => stream.Write(new byte[1], int.MaxValue, int.MaxValue)); + AssertExtensions.Throws("buffer", () => stream.Write(new byte[1], int.MaxValue, int.MaxValue)); } [Fact] diff --git a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/WinHttpResponseStreamTest.cs b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/WinHttpResponseStreamTest.cs index 2347e580e82..fbf080b4e94 100644 --- a/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/WinHttpResponseStreamTest.cs +++ b/src/libraries/System.Net.Http.WinHttpHandler/tests/UnitTests/WinHttpResponseStreamTest.cs @@ -190,7 +190,7 @@ namespace System.Net.Http.WinHttpHandlerUnitTests { Stream stream = MakeResponseStream(); - Assert.Throws(() => stream.Read(new byte[1], int.MaxValue, int.MaxValue)); + AssertExtensions.Throws("buffer", () => stream.Read(new byte[1], int.MaxValue, int.MaxValue)); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpMethodTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpMethodTest.cs index 96f220b2917..a487a06db8c 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpMethodTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpMethodTest.cs @@ -51,7 +51,7 @@ namespace System.Net.Http.Functional.Tests [Fact] public void Ctor_NullMethod_Exception() { - Assert.Throws(() => { new HttpMethod(null); } ); + AssertExtensions.Throws("method", () => { new HttpMethod(null); } ); } [Theory] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs index 3640082001e..bfc4d5042ec 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs @@ -104,7 +104,7 @@ namespace System.Net.Http.Functional.Tests [Fact] public void Ctor_NonHttpUri_ThrowsArgumentException() { - Assert.Throws(() => new HttpRequestMessage(HttpMethod.Put, "ftp://example.com")); + AssertExtensions.Throws("requestUri", () => new HttpRequestMessage(HttpMethod.Put, "ftp://example.com")); } [Fact] @@ -159,7 +159,7 @@ namespace System.Net.Http.Functional.Tests public void RequestUri_SetNonHttpUri_ThrowsArgumentException() { var rm = new HttpRequestMessage(); - Assert.Throws(() => { rm.RequestUri = new Uri("ftp://example.com"); }); + AssertExtensions.Throws("value", () => { rm.RequestUri = new Uri("ftp://example.com"); }); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/MultipartContentTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/MultipartContentTest.cs index b8e4bfc466b..a8ada40504e 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MultipartContentTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MultipartContentTest.cs @@ -15,17 +15,17 @@ namespace System.Net.Http.Functional.Tests [Fact] public void Ctor_NullOrEmptySubType_ThrowsArgumentException() { - Assert.Throws(() => new MultipartContent(null)); - Assert.Throws(() => new MultipartContent("")); - Assert.Throws(() => new MultipartContent(" ")); + AssertExtensions.Throws("subtype", () => new MultipartContent(null)); + AssertExtensions.Throws("subtype", () => new MultipartContent("")); + AssertExtensions.Throws("subtype", () => new MultipartContent(" ")); } [Fact] public void Ctor_NullOrEmptyBoundary_ThrowsArgumentException() { - Assert.Throws(() => new MultipartContent("Some", null)); - Assert.Throws(() => new MultipartContent("Some", "")); - Assert.Throws(() => new MultipartContent("Some", " ")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", null)); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", " ")); } [Fact] @@ -38,23 +38,23 @@ namespace System.Net.Http.Functional.Tests [Fact] public void Ctor_BadBoundary_ThrowsArgumentException() { - Assert.Throws(() => new MultipartContent("Some", "EndsInSpace ")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "EndsInSpace ")); // Invalid chars CTLs HT < > @ ; \ " [ ] { } ! # $ % & ^ ~ ` - Assert.Throws(() => new MultipartContent("Some", "a\t")); - Assert.Throws(() => new MultipartContent("Some", "<")); - Assert.Throws(() => new MultipartContent("Some", "@")); - Assert.Throws(() => new MultipartContent("Some", "[")); - Assert.Throws(() => new MultipartContent("Some", "{")); - Assert.Throws(() => new MultipartContent("Some", "!")); - Assert.Throws(() => new MultipartContent("Some", "#")); - Assert.Throws(() => new MultipartContent("Some", "$")); - Assert.Throws(() => new MultipartContent("Some", "%")); - Assert.Throws(() => new MultipartContent("Some", "&")); - Assert.Throws(() => new MultipartContent("Some", "^")); - Assert.Throws(() => new MultipartContent("Some", "~")); - Assert.Throws(() => new MultipartContent("Some", "`")); - Assert.Throws(() => new MultipartContent("Some", "\"quoted\"")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "a\t")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "<")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "@")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "[")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "{")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "!")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "#")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "$")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "%")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "&")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "^")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "~")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "`")); + AssertExtensions.Throws("boundary", () => new MultipartContent("Some", "\"quoted\"")); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/MultipartFormDataContentTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/MultipartFormDataContentTest.cs index 0ee8f8f46c2..2fc1d883c76 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/MultipartFormDataContentTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/MultipartFormDataContentTest.cs @@ -23,13 +23,13 @@ namespace System.Net.Http.Functional.Tests [Fact] public void Ctor_NullBoundary_ThrowsArgumentException() { - Assert.Throws(() => new MultipartFormDataContent(null)); + AssertExtensions.Throws("boundary", () => new MultipartFormDataContent(null)); } [Fact] public void Ctor_EmptyBoundary_ThrowsArgumentException() { - Assert.Throws(() => new MultipartFormDataContent(String.Empty)); + AssertExtensions.Throws("boundary", () => new MultipartFormDataContent(String.Empty)); } [Fact] @@ -43,28 +43,28 @@ namespace System.Net.Http.Functional.Tests public void Add_NullName_ThrowsArgumentException() { var content = new MultipartFormDataContent(); - Assert.Throws(() => content.Add(new StringContent("Hello world"), null)); + AssertExtensions.Throws("name", () => content.Add(new StringContent("Hello world"), null)); } [Fact] public void Add_EmptyName_ThrowsArgumentException() { var content = new MultipartFormDataContent(); - Assert.Throws(() => content.Add(new StringContent("Hello world"), String.Empty)); + AssertExtensions.Throws("name", () => content.Add(new StringContent("Hello world"), String.Empty)); } [Fact] public void Add_NullFileName_ThrowsArgumentException() { var content = new MultipartFormDataContent(); - Assert.Throws(() => content.Add(new StringContent("Hello world"), "name", null)); + AssertExtensions.Throws("fileName", () => content.Add(new StringContent("Hello world"), "name", null)); } [Fact] public void Add_EmptyFileName_ThrowsArgumentException() { var content = new MultipartFormDataContent(); - Assert.Throws(() => content.Add(new StringContent("Hello world"), "name", String.Empty)); + AssertExtensions.Throws("fileName", () => content.Add(new StringContent("Hello world"), "name", String.Empty)); } [Fact] @@ -158,7 +158,7 @@ namespace System.Net.Http.Functional.Tests public async Task Serialize_InvalidName_Encoded() { var content = new MultipartFormDataContent("test_boundary"); - content.Add(new StringContent("Hello World"), "testク\r\n namé"); + content.Add(new StringContent("Hello World"), "test\u30AF\r\n nam\u00E9"); MemoryStream output = new MemoryStream(); await content.CopyToAsync(output); @@ -177,7 +177,7 @@ namespace System.Net.Http.Functional.Tests public async Task Serialize_InvalidQuotedName_Encoded() { var content = new MultipartFormDataContent("test_boundary"); - content.Add(new StringContent("Hello World"), "\"testク\r\n namé\""); + content.Add(new StringContent("Hello World"), "\"test\u30AF\r\n nam\u00E9\""); var output = new MemoryStream(); await content.CopyToAsync(output); @@ -196,7 +196,7 @@ namespace System.Net.Http.Functional.Tests public async Task Serialize_InvalidNamedFileName_Encoded() { var content = new MultipartFormDataContent("test_boundary"); - content.Add(new StringContent("Hello World"), "testク\r\n namé", "fileク\r\n namé"); + content.Add(new StringContent("Hello World"), "test\u30AF\r\n nam\u00E9", "file\u30AF\r\n nam\u00E9"); MemoryStream output = new MemoryStream(); await content.CopyToAsync(output); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/AuthenticationHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/AuthenticationHeaderValueTest.cs index d7622b721d0..7cf64f0c3c2 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/AuthenticationHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/AuthenticationHeaderValueTest.cs @@ -17,8 +17,8 @@ namespace System.Net.Http.Tests Assert.Equal("Basic", auth.Scheme); Assert.Equal("realm=\"contoso.com\"", auth.Parameter); - Assert.Throws(() => { new AuthenticationHeaderValue(null, "x"); }); - Assert.Throws(() => { new AuthenticationHeaderValue("", "x"); }); + AssertExtensions.Throws("scheme", () => { new AuthenticationHeaderValue(null, "x"); }); + AssertExtensions.Throws("scheme", () => { new AuthenticationHeaderValue("", "x"); }); Assert.Throws(() => { new AuthenticationHeaderValue(" x", "x"); }); Assert.Throws(() => { new AuthenticationHeaderValue("x ", "x"); }); Assert.Throws(() => { new AuthenticationHeaderValue("x y", "x"); }); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/CacheControlHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/CacheControlHeaderValueTest.cs index ae31a9686d9..8641ea023bd 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/CacheControlHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/CacheControlHeaderValueTest.cs @@ -52,14 +52,14 @@ namespace System.Net.Http.Tests // String collection properties Assert.NotNull(cacheControl.NoCacheHeaders); - Assert.Throws(() => { cacheControl.NoCacheHeaders.Add(null); }); + AssertExtensions.Throws("item", () => { cacheControl.NoCacheHeaders.Add(null); }); Assert.Throws(() => { cacheControl.NoCacheHeaders.Add("invalid token"); }); cacheControl.NoCacheHeaders.Add("token"); Assert.Equal(1, cacheControl.NoCacheHeaders.Count); Assert.Equal("token", cacheControl.NoCacheHeaders.First()); Assert.NotNull(cacheControl.PrivateHeaders); - Assert.Throws(() => { cacheControl.PrivateHeaders.Add(null); }); + AssertExtensions.Throws("item", () => { cacheControl.PrivateHeaders.Add(null); }); Assert.Throws(() => { cacheControl.PrivateHeaders.Add("invalid token"); }); cacheControl.PrivateHeaders.Add("token"); Assert.Equal(1, cacheControl.PrivateHeaders.Count); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ContentDispositionHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ContentDispositionHeaderValueTest.cs index 48e3a22242d..d1e65ec6a08 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ContentDispositionHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ContentDispositionHeaderValueTest.cs @@ -17,14 +17,14 @@ namespace System.Net.Http.Tests [Fact] public void Ctor_ContentDispositionNull_Throw() { - Assert.Throws(() => { new ContentDispositionHeaderValue(null); }); + AssertExtensions.Throws("dispositionType", () => { new ContentDispositionHeaderValue(null); }); } [Fact] public void Ctor_ContentDispositionEmpty_Throw() { // null and empty should be treated the same. So we also throw for empty strings. - Assert.Throws(() => { new ContentDispositionHeaderValue(string.Empty); }); + AssertExtensions.Throws("dispositionType", () => { new ContentDispositionHeaderValue(string.Empty); }); } [Fact] @@ -37,7 +37,7 @@ namespace System.Net.Http.Tests AssertFormatException("\"inline\""); AssertFormatException("te xt"); AssertFormatException("te=xt"); - AssertFormatException("teäxt"); + AssertFormatException("te\u00E4xt"); AssertFormatException("text;"); AssertFormatException("te/xt;"); AssertFormatException("inline; name=someName; "); @@ -618,14 +618,14 @@ namespace System.Net.Http.Tests { "valid13", new ContentDispositionValue(@"attachment; FILENAME=""foo.html""", @"'attachment', specifying a filename of foo.html", true) }, { "valid14", new ContentDispositionValue(@"attachment; filename=foo.html", @"'attachment', specifying a filename of foo.html using a token instead of a quoted-string.", true) }, { "valid15", new ContentDispositionValue(@"attachment; filename='foo.bar'", @"'attachment', specifying a filename of 'foo.bar' using single quotes. ", true) }, - { "valid16", new ContentDispositionValue(@"attachment; filename=""foo-ä.html""", @"'attachment', specifying a filename of foo-ä.html, using plain ISO-8859-1", true) }, - { "valid17", new ContentDispositionValue(@"attachment; filename=""foo-ä.html""", @"'attachment', specifying a filename of foo-ä.html, which happens to be foo-ä.html using UTF-8 encoding.", true) }, + { "valid16", new ContentDispositionValue(@"attachment; filename=""foo-\u00E4.html""", @"'attachment', specifying a filename of foo-\u00E4.html, using plain ISO-8859-1", true) }, + { "valid17", new ContentDispositionValue(@"attachment; filename=""foo-ä.html""", @"'attachment', specifying a filename of foo-ä.html, which happens to be foo-\u00E4.html using UTF-8 encoding.", true) }, { "valid18", new ContentDispositionValue(@"attachment; filename=""foo-%41.html""", @"'attachment', specifying a filename of foo-%41.html", true) }, { "valid19", new ContentDispositionValue(@"attachment; filename=""50%.html""", @"'attachment', specifying a filename of 50%.html", true) }, { "valid20", new ContentDispositionValue(@"attachment; filename=""foo-%\41.html""", @"'attachment', specifying a filename of foo-%41.html, using an escape character (this tests whether adding an escape character inside a %xx sequence can be used to disable the non-conformant %xx-unescaping).", true) }, { "valid21", new ContentDispositionValue(@"attachment; name=""foo-%41.html""", @"'attachment', specifying a name parameter of foo-%41.html. (this test was added to observe the behavior of the (unspecified) treatment of ""name"" as synonym for ""filename""; see Ned Freed's summary where this comes from in MIME messages)", true) }, - { "valid22", new ContentDispositionValue(@"attachment; filename=""ä-%41.html""", @"'attachment', specifying a filename parameter of ä-%41.html. (this test was added to observe the behavior when non-ASCII characters and percent-hexdig sequences are combined)", true) }, - { "valid23", new ContentDispositionValue(@"attachment; filename=""foo-%c3%a4-%e2%82%ac.html""", @"'attachment', specifying a filename of foo-%c3%a4-%e2%82%ac.html, using raw percent encoded UTF-8 to represent foo-ä-€.html", true) }, + { "valid22", new ContentDispositionValue(@"attachment; filename=""\u00E4-%41.html""", @"'attachment', specifying a filename parameter of \u00E4-%41.html. (this test was added to observe the behavior when non-ASCII characters and percent-hexdig sequences are combined)", true) }, + { "valid23", new ContentDispositionValue(@"attachment; filename=""foo-%c3%a4-%e2%82%ac.html""", @"'attachment', specifying a filename of foo-%c3%a4-%e2%82%ac.html, using raw percent encoded UTF-8 to represent foo-\u00E4-€.html", true) }, { "valid24", new ContentDispositionValue(@"attachment; filename =""foo.html""", @"'attachment', specifying a filename of foo.html, with one blank space before the equals character.", true) }, { "valid25", new ContentDispositionValue(@"attachment; xfilename=foo.html", @"'attachment', specifying an ""xfilename"" parameter.", true) }, { "valid26", new ContentDispositionValue(@"attachment; filename=""/foo.html""", @"'attachment', specifying an absolute filename in the filesystem root.", true) }, @@ -634,22 +634,22 @@ namespace System.Net.Http.Tests { "valid29", new ContentDispositionValue(@"attachment; modification-date=""Wed, 12 Feb 1997 16:29:51 -0500""", @"'attachment', plus modification-date (see Section 2.5 of RFC 2183)", true) }, { "valid30", new ContentDispositionValue(@"foobar", @"This should be equivalent to using ""attachment"".", true) }, { "valid31", new ContentDispositionValue(@"attachment; example=""filename=example.txt""", @"'attachment', with no filename parameter", true) }, - { "valid32", new ContentDispositionValue(@"attachment; filename*=iso-8859-1''foo-%E4.html", @"'attachment', specifying a filename of foo-ä.html, using RFC2231 encoded ISO-8859-1", true) }, - { "valid33", new ContentDispositionValue(@"attachment; filename*=UTF-8''foo-%c3%a4-%e2%82%ac.html", @"'attachment', specifying a filename of foo-ä-€.html, using RFC2231 encoded UTF-8", true) }, + { "valid32", new ContentDispositionValue(@"attachment; filename*=iso-8859-1''foo-%E4.html", @"'attachment', specifying a filename of foo-\u00E4.html, using RFC2231 encoded ISO-8859-1", true) }, + { "valid33", new ContentDispositionValue(@"attachment; filename*=UTF-8''foo-%c3%a4-%e2%82%ac.html", @"'attachment', specifying a filename of foo-\u00E4-€.html, using RFC2231 encoded UTF-8", true) }, { "valid34", new ContentDispositionValue(@"attachment; filename*=''foo-%c3%a4-%e2%82%ac.html", @"Behavior is undefined in RFC 2231, the charset part is missing, although UTF-8 was used.", true) }, - { "valid35", new ContentDispositionValue(@"attachment; filename*=UTF-8''foo-a%cc%88.html", @"'attachment', specifying a filename of foo-ä.html, using RFC2231 encoded UTF-8, but choosing the decomposed form (lowercase a plus COMBINING DIAERESIS) -- on a Windows target system, this should be translated to the preferred Unicode normal form (composed).", true) }, - { "valid36", new ContentDispositionValue(@"attachment; filename*= UTF-8''foo-%c3%a4.html", @"'attachment', specifying a filename of foo-ä.html, using RFC2231 encoded UTF-8, with whitespace after ""*=""", true) }, - { "valid37", new ContentDispositionValue(@"attachment; filename* =UTF-8''foo-%c3%a4.html", @"'attachment', specifying a filename of foo-ä.html, using RFC2231 encoded UTF-8, with whitespace inside ""* =""", true) }, + { "valid35", new ContentDispositionValue(@"attachment; filename*=UTF-8''foo-a%cc%88.html", @"'attachment', specifying a filename of foo-\u00E4.html, using RFC2231 encoded UTF-8, but choosing the decomposed form (lowercase a plus COMBINING DIAERESIS) -- on a Windows target system, this should be translated to the preferred Unicode normal form (composed).", true) }, + { "valid36", new ContentDispositionValue(@"attachment; filename*= UTF-8''foo-%c3%a4.html", @"'attachment', specifying a filename of foo-\u00E4.html, using RFC2231 encoded UTF-8, with whitespace after ""*=""", true) }, + { "valid37", new ContentDispositionValue(@"attachment; filename* =UTF-8''foo-%c3%a4.html", @"'attachment', specifying a filename of foo-\u00E4.html, using RFC2231 encoded UTF-8, with whitespace inside ""* =""", true) }, { "valid38", new ContentDispositionValue(@"attachment; filename*=UTF-8''A-%2541.html", @"'attachment', specifying a filename of A-%41.html, using RFC2231 encoded UTF-8.", true) }, { "valid39", new ContentDispositionValue(@"attachment; filename*=UTF-8''%5cfoo.html", @"'attachment', specifying a filename of /foo.html, using RFC2231 encoded UTF-8.", true) }, { "valid40", new ContentDispositionValue(@"attachment; filename*0=""foo.""; filename*1=""html""", @"'attachment', specifying a filename of foo.html, using RFC2231-style parameter continuations.", true) }, - { "valid41", new ContentDispositionValue(@"attachment; filename*0*=UTF-8''foo-%c3%a4; filename*1="".html""", @"'attachment', specifying a filename of foo-ä.html, using both RFC2231-style parameter continuations and UTF-8 encoding.", true) }, + { "valid41", new ContentDispositionValue(@"attachment; filename*0*=UTF-8''foo-%c3%a4; filename*1="".html""", @"'attachment', specifying a filename of foo-\u00E4.html, using both RFC2231-style parameter continuations and UTF-8 encoding.", true) }, { "valid42", new ContentDispositionValue(@"attachment; filename*0=""foo""; filename*01=""bar""", @"'attachment', specifying a filename of foo (the parameter filename*01 should be ignored because of the leading zero)", true) }, { "valid43", new ContentDispositionValue(@"attachment; filename*0=""foo""; filename*2=""bar""", @"'attachment', specifying a filename of foo (the parameter filename*2 should be ignored because there's no filename*1 parameter)", true) }, { "valid44", new ContentDispositionValue(@"attachment; filename*1=""foo.""; filename*2=""html""", @"'attachment' (the filename* parameters should be ignored because filename*0 is missing)", true) }, { "valid45", new ContentDispositionValue(@"attachment; filename*1=""bar""; filename*0=""foo""", "'attachment', specifying a filename of foobar", true) }, - { "valid46", new ContentDispositionValue(@"attachment; filename=""foo-ae.html""; filename*=UTF-8''foo-%c3%a4.html", @"'attachment', specifying a filename of foo-ae.html in the traditional format, and foo-ä.html in RFC2231 format.", true) }, - { "valid47", new ContentDispositionValue(@"attachment; filename*=UTF-8''foo-%c3%a4.html; filename=""foo-ae.html""", @"'attachment', specifying a filename of foo-ae.html in the traditional format, and foo-ä.html in RFC2231 format.", true) }, + { "valid46", new ContentDispositionValue(@"attachment; filename=""foo-ae.html""; filename*=UTF-8''foo-%c3%a4.html", @"'attachment', specifying a filename of foo-ae.html in the traditional format, and foo-\u00E4.html in RFC2231 format.", true) }, + { "valid47", new ContentDispositionValue(@"attachment; filename*=UTF-8''foo-%c3%a4.html; filename=""foo-ae.html""", @"'attachment', specifying a filename of foo-ae.html in the traditional format, and foo-\u00E4.html in RFC2231 format.", true) }, { "valid48", new ContentDispositionValue(@"attachment; foobar=x; filename=""foo.html""", @"'attachment', specifying a new parameter ""foobar"", plus a filename of foo.html in the traditional format.", true) }, { "valid49", new ContentDispositionValue(@"attachment; filename=""=?ISO-8859-1?Q?foo-=E4.html?=""", @"attachment; filename=""=?ISO-8859-1?Q?foo-=E4.html?=""", true) }, { "valid50", new ContentDispositionValue(@"attachment; filename=""=?utf-8?B?Zm9vLeQuaHRtbA==?=""", @"attachment; filename=""=?utf-8?B?Zm9vLeQuaHRtbA==?=""", true) }, @@ -660,7 +660,7 @@ namespace System.Net.Http.Tests { "invalid3", new ContentDispositionValue(@"attachment; filename=foo.html ;", @"'attachment', specifying a filename of foo.html using a token instead of a quoted-string, and adding a trailing semicolon.", false) }, { "invalid4", new ContentDispositionValue(@"attachment; filename=foo bar.html", @"'attachment', specifying a filename of foo bar.html without using quoting.", false) }, { "invalid6", new ContentDispositionValue(@"attachment; filename=foo[1](2).html", @"'attachment', specifying a filename of foo[1](2).html, but missing the quotes. Also, ""["", ""]"", ""("" and "")"" are not allowed in the HTTP token production.", false) }, - { "invalid7", new ContentDispositionValue(@"attachment; filename=foo-ä.html", @"'attachment', specifying a filename of foo-ä.html, but missing the quotes.", false) }, + { "invalid7", new ContentDispositionValue(@"attachment; filename=foo-\u00E4.html", @"'attachment', specifying a filename of foo-\u00E4.html, but missing the quotes.", false) }, { "invalid9", new ContentDispositionValue(@"filename=foo.html", @"Disposition type missing, filename specified.", false) }, { "invalid10", new ContentDispositionValue(@"x=y; filename=foo.html", @"Disposition type missing, filename specified after extension parameter.", false) }, { "invalid11", new ContentDispositionValue(@"""foo; filename=bar;baz""; filename=qux", @"Disposition type missing, filename ""qux"". Can it be more broken? (Probably)", false) }, @@ -822,7 +822,7 @@ namespace System.Net.Http.Tests { ContentDispositionValue cd = ContentDispositionTestCases["valid16"]; ContentDispositionHeaderValue header = TryParse(cd); - ValidateHeaderValues(header, "attachment", @"""foo-ä.html"""); + ValidateHeaderValues(header, "attachment", @"""foo-\u00E4.html"""); } [Fact] @@ -871,7 +871,7 @@ namespace System.Net.Http.Tests { ContentDispositionValue cd = ContentDispositionTestCases["valid22"]; ContentDispositionHeaderValue header = TryParse(cd); - ValidateHeaderValues(header, "attachment", @"""ä-%41.html"""); + ValidateHeaderValues(header, "attachment", @"""\u00E4-%41.html"""); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ContentRangeHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ContentRangeHeaderValueTest.cs index 3c4a2c845ce..57fe0d8edfd 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ContentRangeHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ContentRangeHeaderValueTest.cs @@ -80,8 +80,8 @@ namespace System.Net.Http.Tests range.Unit = "myunit"; Assert.Equal("myunit", range.Unit); // "Unit (custom value)" - Assert.Throws(() => { range.Unit = null; }); // "" - Assert.Throws(() => { range.Unit = ""; }); // "empty string" + AssertExtensions.Throws("value", () => { range.Unit = null; }); // "" + AssertExtensions.Throws("value", () => { range.Unit = ""; }); // "empty string" Assert.Throws(() => { range.Unit = " x"; }); // "leading space" Assert.Throws(() => { range.Unit = "x "; }); // "trailing space" Assert.Throws(() => { range.Unit = "x y"; }); // "invalid token" diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/EntityTagHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/EntityTagHeaderValueTest.cs index 6dc4023b205..5b6b5ba9ae8 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/EntityTagHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/EntityTagHeaderValueTest.cs @@ -17,14 +17,14 @@ namespace System.Net.Http.Tests [Fact] public void Ctor_ETagNull_Throw() { - Assert.Throws(() => { new EntityTagHeaderValue(null); }); + AssertExtensions.Throws("tag", () => { new EntityTagHeaderValue(null); }); } [Fact] public void Ctor_ETagEmpty_Throw() { // null and empty should be treated the same. So we also throw for empty strings. - Assert.Throws(() => { new EntityTagHeaderValue(string.Empty); }); + AssertExtensions.Throws("tag", () => { new EntityTagHeaderValue(string.Empty); }); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/HeaderUtilitiesTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/HeaderUtilitiesTest.cs index f1d4fe5a05a..db572884ef3 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/HeaderUtilitiesTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/HeaderUtilitiesTest.cs @@ -87,8 +87,8 @@ namespace System.Net.Http.Tests HeaderUtilities.CheckValidQuotedString("\"x\"", "param"); HeaderUtilities.CheckValidQuotedString("\"x y\"", "param"); - Assert.Throws(() => { HeaderUtilities.CheckValidQuotedString(null, "param"); }); - Assert.Throws(() => { HeaderUtilities.CheckValidQuotedString("", "param"); }); + AssertExtensions.Throws("param", () => { HeaderUtilities.CheckValidQuotedString(null, "param"); }); + AssertExtensions.Throws("param", () => { HeaderUtilities.CheckValidQuotedString("", "param"); }); Assert.Throws(() => { HeaderUtilities.CheckValidQuotedString("\"x", "param"); }); Assert.Throws(() => { HeaderUtilities.CheckValidQuotedString("\"x\"y", "param"); }); } diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeaderValueCollectionTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeaderValueCollectionTest.cs index d17196f1ec4..40b8a106359 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeaderValueCollectionTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeaderValueCollectionTest.cs @@ -355,7 +355,7 @@ namespace System.Net.Http.Tests Uri[] array = new Uri[2]; // startIndex + Count = 1 + 2 > array.Length - Assert.Throws(() => { collection.CopyTo(array, 1); }); + AssertExtensions.Throws("destinationArray", "", () => { collection.CopyTo(array, 1); }); } [Fact] @@ -510,23 +510,23 @@ namespace System.Net.Http.Tests headers.Add(knownHeader, "special"); array = new string[0]; - Assert.Throws(() => { collection.CopyTo(array, 0); }); + AssertExtensions.Throws(null, () => { collection.CopyTo(array, 0); }); headers.Add(knownHeader, "special"); headers.Add(knownHeader, "special"); array = new string[1]; - Assert.Throws(() => { collection.CopyTo(array, 0); }); + AssertExtensions.Throws("destinationArray", "", () => { collection.CopyTo(array, 0); }); headers.Add(knownHeader, "value1"); array = new string[0]; - Assert.Throws(() => { collection.CopyTo(array, 0); }); + AssertExtensions.Throws("destinationArray", "", () => { collection.CopyTo(array, 0); }); headers.Add(knownHeader, "value2"); array = new string[1]; - Assert.Throws(() => { collection.CopyTo(array, 0); }); + AssertExtensions.Throws("destinationArray", "", () => { collection.CopyTo(array, 0); }); array = new string[2]; - Assert.Throws(() => { collection.CopyTo(array, 1); }); + AssertExtensions.Throws("destinationArray", "", () => { collection.CopyTo(array, 1); }); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeadersTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeadersTest.cs index df916d82b8c..cb578e5ad7a 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeadersTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/HttpHeadersTest.cs @@ -423,7 +423,7 @@ namespace System.Net.Http.Tests { MockHeaders headers = new MockHeaders(); - Assert.Throws(() => { headers.Add(null, "value"); }); + AssertExtensions.Throws("name", () => { headers.Add(null, "value"); }); } [Fact] @@ -1031,7 +1031,7 @@ namespace System.Net.Http.Tests { MockHeaders headers = new MockHeaders(); - Assert.Throws(() => { headers.Remove(null); }); + AssertExtensions.Throws("name", () => { headers.Remove(null); }); } [Fact] @@ -1152,7 +1152,7 @@ namespace System.Net.Http.Tests { MockHeaders headers = new MockHeaders(); - Assert.Throws(() => { headers.GetValues(null); }); + AssertExtensions.Throws("name", () => { headers.GetValues(null); }); } [Fact] @@ -1427,7 +1427,7 @@ namespace System.Net.Http.Tests { MockHeaders headers = new MockHeaders(); - Assert.Throws(() => { headers.Contains(null); }); + AssertExtensions.Throws("name", () => { headers.Contains(null); }); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/MediaTypeHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/MediaTypeHeaderValueTest.cs index c3df4b35eb7..5c35c69ecf0 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/MediaTypeHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/MediaTypeHeaderValueTest.cs @@ -17,14 +17,14 @@ namespace System.Net.Http.Tests [Fact] public void Ctor_MediaTypeNull_Throw() { - Assert.Throws(() => { new MediaTypeHeaderValue(null); }); + AssertExtensions.Throws("mediaType", () => { new MediaTypeHeaderValue(null); }); } [Fact] public void Ctor_MediaTypeEmpty_Throw() { // null and empty should be treated the same. So we also throw for empty strings. - Assert.Throws(() => { new MediaTypeHeaderValue(string.Empty); }); + AssertExtensions.Throws("mediaType", () => { new MediaTypeHeaderValue(string.Empty); }); } [Fact] @@ -39,8 +39,8 @@ namespace System.Net.Http.Tests AssertFormatException(" text/plain"); AssertFormatException("te xt/plain"); AssertFormatException("te=xt/plain"); - AssertFormatException("teäxt/plain"); - AssertFormatException("text/pläin"); + AssertFormatException("te\u00E4xt/plain"); + AssertFormatException("text/pl\u00E4in"); AssertFormatException("text"); AssertFormatException("\"text/plain\""); AssertFormatException("text/plain; charset=utf-8; "); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/NameValueHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/NameValueHeaderValueTest.cs index 25a506d5a33..fefa383ce3a 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/NameValueHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/NameValueHeaderValueTest.cs @@ -17,14 +17,14 @@ namespace System.Net.Http.Tests [Fact] public void Ctor_NameNull_Throw() { - Assert.Throws(() => { NameValueHeaderValue nameValue = new NameValueHeaderValue(null); }); + AssertExtensions.Throws("name", () => { NameValueHeaderValue nameValue = new NameValueHeaderValue(null); }); } [Fact] public void Ctor_NameEmpty_Throw() { // null and empty should be treated the same. So we also throw for empty strings. - Assert.Throws(() => { NameValueHeaderValue nameValue = new NameValueHeaderValue(string.Empty); }); + AssertExtensions.Throws("name", () => { NameValueHeaderValue nameValue = new NameValueHeaderValue(string.Empty); }); } [Fact] @@ -36,7 +36,7 @@ namespace System.Net.Http.Tests AssertFormatException(" text", null); AssertFormatException("te xt", null); AssertFormatException("te=xt", null); // The ctor takes a name which must not contain '='. - AssertFormatException("teäxt", null); + AssertFormatException("te\u00E4xt", null); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/NameValueWithParametersHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/NameValueWithParametersHeaderValueTest.cs index cec8033c33f..a73fde48f25 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/NameValueWithParametersHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/NameValueWithParametersHeaderValueTest.cs @@ -15,14 +15,14 @@ namespace System.Net.Http.Tests [Fact] public void Ctor_NameNull_Throw() { - Assert.Throws(() => { NameValueWithParametersHeaderValue nameValue = new NameValueWithParametersHeaderValue(null); }); + AssertExtensions.Throws("name", () => { NameValueWithParametersHeaderValue nameValue = new NameValueWithParametersHeaderValue(null); }); } [Fact] public void Ctor_NameEmpty_Throw() { // null and empty should be treated the same. So we also throw for empty strings. - Assert.Throws(() => { NameValueWithParametersHeaderValue nameValue = new NameValueWithParametersHeaderValue(string.Empty); }); + AssertExtensions.Throws("name", () => { NameValueWithParametersHeaderValue nameValue = new NameValueWithParametersHeaderValue(string.Empty); }); } [Fact] @@ -208,7 +208,7 @@ namespace System.Net.Http.Tests [Fact] public void Parse_SetOfInvalidValueStrings_Throws() { - CheckInvalidParse("custom会"); + CheckInvalidParse("custom\u4F1A"); CheckInvalidParse("custom; name=value;"); CheckInvalidParse("custom; name1=value1; name2=value2;"); CheckInvalidParse(null); @@ -236,7 +236,7 @@ namespace System.Net.Http.Tests [Fact] public void TryParse_SetOfInvalidValueStrings_ReturnsFalse() { - CheckInvalidTryParse("custom会"); + CheckInvalidTryParse("custom\u4F1A"); CheckInvalidTryParse("custom; name=value;"); CheckInvalidTryParse("custom; name1=value1; name2=value2;"); CheckInvalidTryParse(null); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ProductHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ProductHeaderValueTest.cs index 011228631ee..766c345d24f 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ProductHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ProductHeaderValueTest.cs @@ -33,8 +33,8 @@ namespace System.Net.Http.Tests [Fact] public void Ctor_UseInvalidValues_Throw() { - Assert.Throws(() => { new ProductHeaderValue(null); }); - Assert.Throws(() => { new ProductHeaderValue(string.Empty); }); + AssertExtensions.Throws("name", () => { new ProductHeaderValue(null); }); + AssertExtensions.Throws("name", () => { new ProductHeaderValue(string.Empty); }); Assert.Throws(() => { new ProductHeaderValue(" x"); }); Assert.Throws(() => { new ProductHeaderValue("x "); }); Assert.Throws(() => { new ProductHeaderValue("x y"); }); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ProductInfoHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ProductInfoHeaderValueTest.cs index f8b083fe8b1..d99e9fc7103 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ProductInfoHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ProductInfoHeaderValueTest.cs @@ -40,7 +40,7 @@ namespace System.Net.Http.Tests Assert.Null(productInfo.Product); Assert.Equal("(this is a comment)", productInfo.Comment); - Assert.Throws(() => { new ProductInfoHeaderValue((string)null); }); + AssertExtensions.Throws("comment", () => { new ProductInfoHeaderValue((string)null); }); Assert.Throws(() => { new ProductInfoHeaderValue("invalid comment"); }); Assert.Throws(() => { new ProductInfoHeaderValue(" (leading space)"); }); Assert.Throws(() => { new ProductInfoHeaderValue("(trailing space) "); }); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeConditionHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeConditionHeaderValueTest.cs index d345fce0f86..a08b859ecd8 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeConditionHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeConditionHeaderValueTest.cs @@ -28,7 +28,7 @@ namespace System.Net.Http.Tests Assert.Equal(new EntityTagHeaderValue("\"y\""), rangeCondition.EntityTag); Assert.Null(rangeCondition.Date); - Assert.Throws(() => { new RangeConditionHeaderValue((string)null); }); + AssertExtensions.Throws("tag", () => { new RangeConditionHeaderValue((string)null); }); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeHeaderValueTest.cs index dde29fa2b6a..28c77a51277 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeHeaderValueTest.cs @@ -24,8 +24,8 @@ namespace System.Net.Http.Tests range.Unit = "myunit"; Assert.Equal("myunit", range.Unit); - Assert.Throws(() => { range.Unit = null; }); - Assert.Throws(() => { range.Unit = ""; }); + AssertExtensions.Throws("value", () => { range.Unit = null; }); + AssertExtensions.Throws("value", () => { range.Unit = ""; }); Assert.Throws(() => { range.Unit = " x"; }); Assert.Throws(() => { range.Unit = "x "; }); Assert.Throws(() => { range.Unit = "x y"; }); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeItemHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeItemHeaderValueTest.cs index 9255f03996c..dcda2f9adb7 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeItemHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/RangeItemHeaderValueTest.cs @@ -14,7 +14,7 @@ namespace System.Net.Http.Tests [Fact] public void Ctor_BothValuesNull_Throw() { - Assert.Throws(() => { new RangeItemHeaderValue(null, null); }); + AssertExtensions.Throws(null, () => { new RangeItemHeaderValue(null, null); }); } [Fact] diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/StringWithQualityHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/StringWithQualityHeaderValueTest.cs index c9b9a8be06b..b264f8e0dbc 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/StringWithQualityHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/StringWithQualityHeaderValueTest.cs @@ -17,8 +17,8 @@ namespace System.Net.Http.Tests Assert.Equal("token", value.Value); Assert.Null(value.Quality); - Assert.Throws(() => { new StringWithQualityHeaderValue(null); }); - Assert.Throws(() => { new StringWithQualityHeaderValue(""); }); + AssertExtensions.Throws("value", () => { new StringWithQualityHeaderValue(null); }); + AssertExtensions.Throws("value", () => { new StringWithQualityHeaderValue(""); }); Assert.Throws(() => { new StringWithQualityHeaderValue("in valid"); }); } @@ -29,8 +29,8 @@ namespace System.Net.Http.Tests Assert.Equal("token", value.Value); Assert.Equal(0.5, value.Quality); - Assert.Throws(() => { new StringWithQualityHeaderValue(null, 0.1); }); - Assert.Throws(() => { new StringWithQualityHeaderValue("", 0.1); }); + AssertExtensions.Throws("value", () => { new StringWithQualityHeaderValue(null, 0.1); }); + AssertExtensions.Throws("value", () => { new StringWithQualityHeaderValue("", 0.1); }); Assert.Throws(() => { new StringWithQualityHeaderValue("in valid", 0.1); }); Assert.Throws(() => { new StringWithQualityHeaderValue("t", 1.1); }); @@ -191,14 +191,14 @@ namespace System.Net.Http.Tests CheckInvalidParse(" ,, text, , ,next"); CheckInvalidParse(" ,, text, , ,"); CheckInvalidParse(", \r\n text \r\n ; \r\n q = 0.123"); - CheckInvalidParse("teäxt"); - CheckInvalidParse("text会"); - CheckInvalidParse("会"); - CheckInvalidParse("t;q=会"); + CheckInvalidParse("te\u00E4xt"); + CheckInvalidParse("text\u4F1A"); + CheckInvalidParse("\u4F1A"); + CheckInvalidParse("t;q=\u4F1A"); CheckInvalidParse("t;q="); CheckInvalidParse("t;q"); - CheckInvalidParse("t;会=1"); - CheckInvalidParse("t;q会=1"); + CheckInvalidParse("t;\u4F1A=1"); + CheckInvalidParse("t;q\u4F1A=1"); CheckInvalidParse("t y"); CheckInvalidParse("t;q=1 y"); @@ -228,14 +228,14 @@ namespace System.Net.Http.Tests CheckInvalidTryParse(" ,, text, , ,next"); CheckInvalidTryParse(" ,, text, , ,"); CheckInvalidTryParse(", \r\n text \r\n ; \r\n q = 0.123"); - CheckInvalidTryParse("teäxt"); - CheckInvalidTryParse("text会"); - CheckInvalidTryParse("会"); - CheckInvalidTryParse("t;q=会"); + CheckInvalidTryParse("te\u00E4xt"); + CheckInvalidTryParse("text\u4F1A"); + CheckInvalidTryParse("\u4F1A"); + CheckInvalidTryParse("t;q=\u4F1A"); CheckInvalidTryParse("t;q="); CheckInvalidTryParse("t;q"); - CheckInvalidTryParse("t;会=1"); - CheckInvalidTryParse("t;q会=1"); + CheckInvalidTryParse("t;\u4F1A=1"); + CheckInvalidTryParse("t;q\u4F1A=1"); CheckInvalidTryParse("t y"); CheckInvalidTryParse("t;q=1 y"); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/TransferCodingHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/TransferCodingHeaderValueTest.cs index 4df44cfdfa2..95fff1cdb42 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/TransferCodingHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/TransferCodingHeaderValueTest.cs @@ -17,14 +17,14 @@ namespace System.Net.Http.Tests [Fact] public void Ctor_ValueNull_Throw() { - Assert.Throws(() => { new TransferCodingHeaderValue(null); }); + AssertExtensions.Throws("value", () => { new TransferCodingHeaderValue(null); }); } [Fact] public void Ctor_ValueEmpty_Throw() { // null and empty should be treated the same. So we also throw for empty strings. - Assert.Throws(() => { new TransferCodingHeaderValue(string.Empty); }); + AssertExtensions.Throws("value", () => { new TransferCodingHeaderValue(string.Empty); }); } [Fact] @@ -33,7 +33,7 @@ namespace System.Net.Http.Tests // When adding values using strongly typed objects, no leading/trailing LWS (whitespace) are allowed. AssertFormatException(" custom "); AssertFormatException("custom;"); - AssertFormatException("chänked"); + AssertFormatException("ch??nked"); AssertFormatException("\"chunked\""); AssertFormatException("custom; name=value"); } diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ViaHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ViaHeaderValueTest.cs index ef716b7ffca..cda29769e7b 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/ViaHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/ViaHeaderValueTest.cs @@ -23,13 +23,13 @@ namespace System.Net.Http.Tests Assert.Equal("x11", via.ProtocolVersion); Assert.Equal("[::1]:1818", via.ReceivedBy); - Assert.Throws(() => { new ViaHeaderValue(null, "host"); }); - Assert.Throws(() => { new ViaHeaderValue("", "host"); }); + AssertExtensions.Throws("protocolVersion", () => { new ViaHeaderValue(null, "host"); }); + AssertExtensions.Throws("protocolVersion", () => { new ViaHeaderValue("", "host"); }); Assert.Throws(() => { new ViaHeaderValue("x y", "h"); }); Assert.Throws(() => { new ViaHeaderValue("x ", "h"); }); Assert.Throws(() => { new ViaHeaderValue(" x", "h"); }); - Assert.Throws(() => { new ViaHeaderValue("1.1", null); }); - Assert.Throws(() => { new ViaHeaderValue("1.1", ""); }); + AssertExtensions.Throws("receivedBy", () => { new ViaHeaderValue("1.1", null); }); + AssertExtensions.Throws("receivedBy", () => { new ViaHeaderValue("1.1", ""); }); Assert.Throws(() => { new ViaHeaderValue("v", "x y"); }); Assert.Throws(() => { new ViaHeaderValue("v", "x "); }); Assert.Throws(() => { new ViaHeaderValue("v", " x"); }); @@ -214,7 +214,7 @@ namespace System.Net.Http.Tests CheckInvalidGetViaLength("HTTP=/1.1 host", 0); CheckInvalidGetViaLength("HTTP/1.1[ host", 0); CheckInvalidGetViaLength("HTTP/ = host", 0); - CheckInvalidGetViaLength("HTTP/务 host", 0); + CheckInvalidGetViaLength("HTTP/\u52A1 host", 0); CheckInvalidGetViaLength("HTTP/ ", 0); CheckInvalidGetViaLength("HTTP ", 0); CheckInvalidGetViaLength("HTTP/1.1 / ", 0); @@ -247,7 +247,7 @@ namespace System.Net.Http.Tests CheckInvalidParse("HTTP/1.1 host ="); CheckInvalidParse("1.1 host invalid"); CheckInvalidParse("1.1 host ="); - CheckInvalidParse("会"); + CheckInvalidParse("\u4F1A"); CheckInvalidParse("HTTP/test [::1]:80\r(comment)"); CheckInvalidParse("HTTP/test [::1]:80\n(comment)"); @@ -282,7 +282,7 @@ namespace System.Net.Http.Tests CheckInvalidTryParse("HTTP/1.1 host ="); CheckInvalidTryParse("1.1 host invalid"); CheckInvalidTryParse("1.1 host ="); - CheckInvalidTryParse("会"); + CheckInvalidTryParse("\u4F1A"); CheckInvalidTryParse("HTTP/test [::1]:80\r(comment)"); CheckInvalidTryParse("HTTP/test [::1]:80\n(comment)"); diff --git a/src/libraries/System.Net.Http/tests/UnitTests/Headers/WarningHeaderValueTest.cs b/src/libraries/System.Net.Http/tests/UnitTests/Headers/WarningHeaderValueTest.cs index ac5b9bd1e17..806f8e54082 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/Headers/WarningHeaderValueTest.cs +++ b/src/libraries/System.Net.Http/tests/UnitTests/Headers/WarningHeaderValueTest.cs @@ -28,14 +28,14 @@ namespace System.Net.Http.Tests Assert.Throws(() => { new WarningHeaderValue(-1, "host", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(1000, "host", "\"\""); }); - Assert.Throws(() => { new WarningHeaderValue(100, null, "\"\""); }); - Assert.Throws(() => { new WarningHeaderValue(100, "", "\"\""); }); + AssertExtensions.Throws("agent", () => { new WarningHeaderValue(100, null, "\"\""); }); + AssertExtensions.Throws("agent", () => { new WarningHeaderValue(100, "", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(100, "x y", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(100, "x ", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(100, " x", "\"\""); }); - Assert.Throws(() => { new WarningHeaderValue(100, null, "\"\""); }); - Assert.Throws(() => { new WarningHeaderValue(100, "", "\"\""); }); + AssertExtensions.Throws("agent", () => { new WarningHeaderValue(100, null, "\"\""); }); + AssertExtensions.Throws("agent", () => { new WarningHeaderValue(100, "", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(100, "h", "x"); }); Assert.Throws(() => { new WarningHeaderValue(100, "h", "\"x"); }); } @@ -53,14 +53,14 @@ namespace System.Net.Http.Tests Assert.Throws(() => { new WarningHeaderValue(-1, "host", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(1000, "host", "\"\""); }); - Assert.Throws(() => { new WarningHeaderValue(100, null, "\"\""); }); - Assert.Throws(() => { new WarningHeaderValue(100, "", "\"\""); }); + AssertExtensions.Throws("agent", () => { new WarningHeaderValue(100, null, "\"\""); }); + AssertExtensions.Throws("agent", () => { new WarningHeaderValue(100, "", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(100, "[::1]:80(x)", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(100, "host::80", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(100, "192.168.0.1=", "\"\""); }); - Assert.Throws(() => { new WarningHeaderValue(100, null, "\"\""); }); - Assert.Throws(() => { new WarningHeaderValue(100, "", "\"\""); }); + AssertExtensions.Throws("agent", () => { new WarningHeaderValue(100, null, "\"\""); }); + AssertExtensions.Throws("agent", () => { new WarningHeaderValue(100, "", "\"\""); }); Assert.Throws(() => { new WarningHeaderValue(100, "h", "(x)"); }); Assert.Throws(() => { new WarningHeaderValue(100, "h", "\"x\"y"); }); } diff --git a/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj b/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj index b337debad79..29000a96bbc 100644 --- a/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj +++ b/src/libraries/System.Net.Http/tests/UnitTests/System.Net.Http.Unit.Tests.csproj @@ -388,6 +388,9 @@ + + Common\System\AssertExtensions.cs + diff --git a/src/libraries/System.Net.Mail/tests/Functional/MailAddressTest.cs b/src/libraries/System.Net.Mail/tests/Functional/MailAddressTest.cs index 5623c8461d6..6a7977af695 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/MailAddressTest.cs +++ b/src/libraries/System.Net.Mail/tests/Functional/MailAddressTest.cs @@ -84,7 +84,7 @@ namespace System.Net.Mail.Tests [Fact] public void TestConstructorWithEmptyString() { - Assert.Throws(() => new MailAddress("")); + AssertExtensions.Throws("address", () => new MailAddress("")); } [Fact] diff --git a/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs b/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs index aaf46c56b2a..cdc1bb68dc2 100644 --- a/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs +++ b/src/libraries/System.Net.Mail/tests/Functional/SmtpClientTest.cs @@ -89,7 +89,7 @@ namespace System.Net.Mail.Tests public void InvalidHostTest() { Assert.Throws(() => Smtp.Host = null); - Assert.Throws(() => Smtp.Host = ""); + AssertExtensions.Throws("value", () => Smtp.Host = ""); } [Fact] diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/CredentialCacheTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/CredentialCacheTest.cs index ea98681e58c..776d16e0f4d 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/CredentialCacheTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/CredentialCacheTest.cs @@ -171,7 +171,7 @@ namespace System.Net.Primitives.Functional.Tests CredentialCache cc = new CredentialCache(); cc.Add(uriPrefix1, authenticationType1, credential1); - Assert.Throws(() => cc.Add(uriPrefix1, authenticationType1, credential1)); + AssertExtensions.Throws(null, () => cc.Add(uriPrefix1, authenticationType1, credential1)); } [Fact] @@ -218,7 +218,7 @@ namespace System.Net.Primitives.Functional.Tests CredentialCache cc = new CredentialCache(); cc.Add(host1, port1, authenticationType1, credential1); - Assert.Throws(() => cc.Add(host1, port1, authenticationType1, credential1)); + AssertExtensions.Throws(null, () => cc.Add(host1, port1, authenticationType1, credential1)); } [Fact] diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/DnsEndPointTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/DnsEndPointTest.cs index 9a190adaba5..adbb3a33d5f 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/DnsEndPointTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/DnsEndPointTest.cs @@ -32,12 +32,12 @@ namespace System.Net.Primitives.Functional.Tests public static void Ctor_HostPortAddressFamily_Invalid() { Assert.Throws(() => new DnsEndPoint(null, 500, AddressFamily.InterNetwork)); //Null host - Assert.Throws(() => new DnsEndPoint("", 500, AddressFamily.InterNetwork)); //Empty host + AssertExtensions.Throws(null, () => new DnsEndPoint("", 500, AddressFamily.InterNetwork)); //Empty host Assert.Throws(() => new DnsEndPoint("host", IPEndPoint.MinPort - 1, AddressFamily.InterNetwork)); //Port < min port (0) Assert.Throws(() => new DnsEndPoint("host", IPEndPoint.MaxPort + 1, AddressFamily.InterNetwork)); //Port > max port (65535) - Assert.Throws(() => new DnsEndPoint("host", 500, AddressFamily.AppleTalk + AssertExtensions.Throws("addressFamily", () => new DnsEndPoint("host", 500, AddressFamily.AppleTalk )); //Invalid address family } diff --git a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPEndPointTest.cs b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPEndPointTest.cs index 4439f434626..5201e097b35 100644 --- a/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPEndPointTest.cs +++ b/src/libraries/System.Net.Primitives/tests/FunctionalTests/IPEndPointTest.cs @@ -98,8 +98,8 @@ namespace System.Net.Primitives.Functional.Tests public static void Create_Set_Invalid() { IPEndPoint ep = new IPEndPoint(testIpV41, 500); - Assert.Throws(() => ep.Create(new SocketAddress(Sockets.AddressFamily.InterNetworkV6))); //Different address families - Assert.Throws(() => ep.Create(new SocketAddress(Sockets.AddressFamily.InterNetwork, 7))); // + AssertExtensions.Throws("socketAddress", () => ep.Create(new SocketAddress(Sockets.AddressFamily.InterNetworkV6))); //Different address families + AssertExtensions.Throws("socketAddress", () => ep.Create(new SocketAddress(Sockets.AddressFamily.InterNetwork, 7))); // } [Fact] diff --git a/src/libraries/System.Net.Primitives/tests/UnitTests/CookieContainerTest.cs b/src/libraries/System.Net.Primitives/tests/UnitTests/CookieContainerTest.cs index 6bb4e0d17b4..3f44d625151 100644 --- a/src/libraries/System.Net.Primitives/tests/UnitTests/CookieContainerTest.cs +++ b/src/libraries/System.Net.Primitives/tests/UnitTests/CookieContainerTest.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -348,7 +348,7 @@ namespace System.Net.Primitives.Unit.Tests [Fact] public void Ctor_Capacity_Invalid() { - Assert.Throws(() => new CookieContainer(0)); // Capacity <= 0 + AssertExtensions.Throws("Capacity", () => new CookieContainer(0)); // Capacity <= 0 } [Fact] @@ -457,7 +457,7 @@ namespace System.Net.Primitives.Unit.Tests { CookieContainer cc = new CookieContainer(); Assert.Throws(() => cc.Add((Cookie)null)); // Null cookie - Assert.Throws(() => cc.Add(new Cookie("name", "value", "", ""))); // Empty domain + AssertExtensions.Throws("cookie.Domain", () => cc.Add(new Cookie("name", "value", "", ""))); // Empty domain cc.MaxCookieSize = 1; Assert.Throws(() => cc.Add(new Cookie("name", "long-text", "", "contoso.com"))); // Value.Length > MaxCookieSize @@ -487,11 +487,11 @@ namespace System.Net.Primitives.Unit.Tests [Fact] public void Ctor_CapacityPerDomainCapacityMaxCookieSize_Invalid() { - Assert.Throws(() => new CookieContainer(0, 10, 5)); // Capacity <= 0 + AssertExtensions.Throws("Capacity", () => new CookieContainer(0, 10, 5)); // Capacity <= 0 Assert.Throws(() => new CookieContainer(5, 0, 5)); // Per domain capacity <= 0 Assert.Throws(() => new CookieContainer(5, 10, 5)); // Per domain capacity > Capacity - Assert.Throws(() => new CookieContainer(15, 10, 0)); // Max cookie size <= 0 + AssertExtensions.Throws("MaxCookieSize", () => new CookieContainer(15, 10, 0)); // Max cookie size <= 0 } [Fact] diff --git a/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj b/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj index 775697471fd..1641d03c144 100644 --- a/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj +++ b/src/libraries/System.Net.Primitives/tests/UnitTests/System.Net.Primitives.UnitTests.Tests.csproj @@ -77,6 +77,9 @@ + + Common\System\AssertExtensions.cs + Common\System\StringExtensions.cs diff --git a/src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs b/src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs index 592fd560b9b..cc49907526e 100644 --- a/src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs +++ b/src/libraries/System.Net.Requests/tests/HttpWebRequestTest.cs @@ -915,7 +915,7 @@ namespace System.Net.Tests using (Stream requestStream = await request.GetRequestStreamAsync()) { requestStream.Write(_requestBodyBytes, 0, _requestBodyBytes.Length); - Assert.Throws(() => new StreamReader(requestStream)); + AssertExtensions.Throws(null, () => new StreamReader(requestStream)); } }); } diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/ParameterValidationTest.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/ParameterValidationTest.cs index 0bf97ee65db..1f06f0a954f 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/ParameterValidationTest.cs +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/ParameterValidationTest.cs @@ -31,7 +31,7 @@ namespace System.Net.Security.Tests { await client.ConnectAsync(_remoteServer.RemoteEndPoint.Address, _remoteServer.RemoteEndPoint.Port); - Assert.Throws(() => + AssertExtensions.Throws("encryptionPolicy", () => { SslStream sslStream = new SslStream(client.GetStream(), false, AllowAnyServerCertificate, null, (EncryptionPolicy)100); }); diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/ServiceNameCollectionTest.cs b/src/libraries/System.Net.Security/tests/FunctionalTests/ServiceNameCollectionTest.cs index da8643215bc..dbf37bb617f 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/ServiceNameCollectionTest.cs +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/ServiceNameCollectionTest.cs @@ -23,9 +23,9 @@ namespace System.Security.Authentication.ExtendedProtection.Tests [InlineData("")] public void Constructor_CollectionContainsNullOrEmpty_Throws(string item) { - Assert.Throws(() => new ServiceNameCollection(new[] { item })); - Assert.Throws(() => new ServiceNameCollection(new[] { "first", item })); - Assert.Throws(() => new ServiceNameCollection(new[] { item, "second" })); + AssertExtensions.Throws(null, () => new ServiceNameCollection(new[] { item })); + AssertExtensions.Throws(null, () => new ServiceNameCollection(new[] { "first", item })); + AssertExtensions.Throws(null, () => new ServiceNameCollection(new[] { item, "second" })); } [Fact] @@ -124,7 +124,7 @@ namespace System.Security.Authentication.ExtendedProtection.Tests { ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); int[] destination = new int[collection.Count - 1]; - Assert.Throws(() => collection.CopyTo(destination, 0)); + AssertExtensions.Throws("destinationArray", "", () => collection.CopyTo(destination, 0)); } [Fact] @@ -133,7 +133,7 @@ namespace System.Security.Authentication.ExtendedProtection.Tests ICollection collection = new ServiceNameCollection(new[] { "first", "second" }); int[] destination = new int[collection.Count]; Assert.Throws(() => collection.CopyTo(destination, -1)); - Assert.Throws(() => collection.CopyTo(destination, destination.Length)); + AssertExtensions.Throws("destinationArray", "", () => collection.CopyTo(destination, destination.Length)); } [Fact] @@ -185,8 +185,8 @@ namespace System.Security.Authentication.ExtendedProtection.Tests public void Merge_NullOrEmptyString_Throws() { var collection = new ServiceNameCollection(new[] { "first", "second" }); - Assert.Throws(() => collection.Merge((string)null)); - Assert.Throws(() => collection.Merge(string.Empty)); + AssertExtensions.Throws(null, () => collection.Merge((string)null)); + AssertExtensions.Throws(null, () => collection.Merge(string.Empty)); } [Fact] @@ -227,16 +227,16 @@ namespace System.Security.Authentication.ExtendedProtection.Tests public void Merge_EnumerableContainingNullOrEmpty_Throws(string item) { var collection = new ServiceNameCollection(new[] { "first", "second" }); - Assert.Throws(() => collection.Merge(new[] { item })); - Assert.Throws(() => collection.Merge(new[] { "third", item })); + AssertExtensions.Throws(null, () => collection.Merge(new[] { item })); + AssertExtensions.Throws(null, () => collection.Merge(new[] { "third", item })); } [Fact] public void Merge_NonStringEnumerable_Throws() { var collection = new ServiceNameCollection(new[] { "first", "second" }); - Assert.Throws(() => collection.Merge(new[] { 3 })); - Assert.Throws(() => collection.Merge(new[] { new object() })); + AssertExtensions.Throws(null, () => collection.Merge(new[] { 3 })); + AssertExtensions.Throws(null, () => collection.Merge(new[] { new object() })); } public static object[][] MergeCollectionsTestData = diff --git a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj index 42bfbd468be..70f26f4c9cb 100644 --- a/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj +++ b/src/libraries/System.Net.Security/tests/FunctionalTests/System.Net.Security.Tests.csproj @@ -47,6 +47,9 @@ + + Common\System\AssertExtensions.cs + Common\System\PlatformDetection.cs diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/AcceptAsync.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/AcceptAsync.cs index ce32b72cc4d..49047fa6f23 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/AcceptAsync.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/AcceptAsync.cs @@ -288,7 +288,7 @@ namespace System.Net.Sockets.Tests byte[] buffer = new byte[1]; acceptArgs.SetBuffer(buffer, 0, buffer.Length); - Assert.Throws(() => server.AcceptAsync(acceptArgs)); + AssertExtensions.Throws(null, () => server.AcceptAsync(acceptArgs)); } } diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/ArgumentValidationTests.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/ArgumentValidationTests.cs index 735cf91b2f8..9784c5d1b5e 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/ArgumentValidationTests.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/ArgumentValidationTests.cs @@ -200,7 +200,7 @@ namespace System.Net.Sockets.Tests [Fact] public void Connect_IPAddresses_EmptyArray_Throws_Argument() { - Assert.Throws(() => GetSocket().Connect(new IPAddress[0], 1)); + AssertExtensions.Throws("addresses", () => GetSocket().Connect(new IPAddress[0], 1)); } [Fact] @@ -261,7 +261,7 @@ namespace System.Net.Sockets.Tests public void Send_Buffers_EmptyBuffers_Throws_Argument() { SocketError errorCode; - Assert.Throws(() => GetSocket().Send(new List>(), SocketFlags.None, out errorCode)); + AssertExtensions.Throws("buffers", () => GetSocket().Send(new List>(), SocketFlags.None, out errorCode)); } [Fact] @@ -328,7 +328,7 @@ namespace System.Net.Sockets.Tests public void Receive_Buffers_EmptyBuffers_Throws_Argument() { SocketError errorCode; - Assert.Throws(() => GetSocket().Receive(new List>(), SocketFlags.None, out errorCode)); + AssertExtensions.Throws("buffers", () => GetSocket().Receive(new List>(), SocketFlags.None, out errorCode)); } [Fact] @@ -349,7 +349,7 @@ namespace System.Net.Sockets.Tests public void ReceiveFrom_AddressFamily_Throws_Argument() { EndPoint endpoint = new IPEndPoint(IPAddress.IPv6Loopback, 1); - Assert.Throws(() => GetSocket(AddressFamily.InterNetwork).ReceiveFrom(s_buffer, 0, 0, SocketFlags.None, ref endpoint)); + AssertExtensions.Throws("remoteEP", () => GetSocket(AddressFamily.InterNetwork).ReceiveFrom(s_buffer, 0, 0, SocketFlags.None, ref endpoint)); } [Fact] @@ -403,7 +403,7 @@ namespace System.Net.Sockets.Tests EndPoint remote = new IPEndPoint(IPAddress.IPv6Loopback, 1); IPPacketInformation packetInfo; - Assert.Throws(() => GetSocket(AddressFamily.InterNetwork).ReceiveMessageFrom(s_buffer, 0, 0, ref flags, ref remote, out packetInfo)); + AssertExtensions.Throws("remoteEP", () => GetSocket(AddressFamily.InterNetwork).ReceiveMessageFrom(s_buffer, 0, 0, ref flags, ref remote, out packetInfo)); } [Fact] @@ -448,34 +448,34 @@ namespace System.Net.Sockets.Tests [Fact] public void SetSocketOption_Linger_NotLingerOption_Throws_Argument() { - Assert.Throws(() => GetSocket().SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, new object())); + AssertExtensions.Throws("optionValue", () => GetSocket().SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, new object())); } [Fact] public void SetSocketOption_Linger_InvalidLingerTime_Throws_Argument() { - Assert.Throws(() => GetSocket().SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, new LingerOption(true, -1))); - Assert.Throws(() => GetSocket().SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, new LingerOption(true, (int)ushort.MaxValue + 1))); + AssertExtensions.Throws("optionValue.LingerTime", () => GetSocket().SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, new LingerOption(true, -1))); + AssertExtensions.Throws("optionValue.LingerTime", () => GetSocket().SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, new LingerOption(true, (int)ushort.MaxValue + 1))); } [Fact] public void SetSocketOption_IPMulticast_NotIPMulticastOption_Throws_Argument() { - Assert.Throws(() => GetSocket().SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new object())); - Assert.Throws(() => GetSocket().SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DropMembership, new object())); + AssertExtensions.Throws("optionValue", () => GetSocket().SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new object())); + AssertExtensions.Throws("optionValue", () => GetSocket().SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DropMembership, new object())); } [Fact] public void SetSocketOption_IPv6Multicast_NotIPMulticastOption_Throws_Argument() { - Assert.Throws(() => GetSocket().SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, new object())); - Assert.Throws(() => GetSocket().SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.DropMembership, new object())); + AssertExtensions.Throws("optionValue", () => GetSocket().SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, new object())); + AssertExtensions.Throws("optionValue", () => GetSocket().SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.DropMembership, new object())); } [Fact] public void SetSocketOption_Object_InvalidOptionName_Throws_Argument() { - Assert.Throws(() => GetSocket().SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, new object())); + AssertExtensions.Throws("optionValue", () => GetSocket().SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, new object())); } [Fact] @@ -517,7 +517,7 @@ namespace System.Net.Sockets.Tests BufferList = s_buffers }; - Assert.Throws(() => GetSocket().AcceptAsync(eventArgs)); + AssertExtensions.Throws("BufferList", () => GetSocket().AcceptAsync(eventArgs)); } [Fact] @@ -550,7 +550,7 @@ namespace System.Net.Sockets.Tests BufferList = s_buffers }; - Assert.Throws(() => GetSocket().ConnectAsync(eventArgs)); + AssertExtensions.Throws("BufferList", () => GetSocket().ConnectAsync(eventArgs)); } [Fact] @@ -601,7 +601,7 @@ namespace System.Net.Sockets.Tests BufferList = s_buffers }; - Assert.Throws(() => Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, eventArgs)); + AssertExtensions.Throws("BufferList", () => Socket.ConnectAsync(SocketType.Stream, ProtocolType.Tcp, eventArgs)); } [Fact] @@ -637,7 +637,7 @@ namespace System.Net.Sockets.Tests RemoteEndPoint = new IPEndPoint(IPAddress.IPv6Loopback, 1) }; - Assert.Throws(() => GetSocket(AddressFamily.InterNetwork).ReceiveFromAsync(eventArgs)); + AssertExtensions.Throws("RemoteEndPoint", () => GetSocket(AddressFamily.InterNetwork).ReceiveFromAsync(eventArgs)); } [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in ReceiveMessageFromAsync that dereferences null SAEA argument")] @@ -660,7 +660,7 @@ namespace System.Net.Sockets.Tests RemoteEndPoint = new IPEndPoint(IPAddress.IPv6Loopback, 1) }; - Assert.Throws(() => GetSocket(AddressFamily.InterNetwork).ReceiveMessageFromAsync(eventArgs)); + AssertExtensions.Throws("RemoteEndPoint", () => GetSocket(AddressFamily.InterNetwork).ReceiveMessageFromAsync(eventArgs)); } [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "Bug in SendAsync that dereferences null SAEA argument")] @@ -1056,8 +1056,8 @@ namespace System.Net.Sockets.Tests [Fact] public void BeginConnect_IPAddresses_EmptyIPAddresses_Throws_Argument() { - Assert.Throws(() => GetSocket().BeginConnect(new IPAddress[0], 1, TheAsyncCallback, null)); - Assert.Throws(() => { GetSocket().ConnectAsync(new IPAddress[0], 1); }); + AssertExtensions.Throws("addresses", () => GetSocket().BeginConnect(new IPAddress[0], 1, TheAsyncCallback, null)); + AssertExtensions.Throws("addresses", () => { GetSocket().ConnectAsync(new IPAddress[0], 1); }); } [Theory] @@ -1096,7 +1096,7 @@ namespace System.Net.Sockets.Tests [Fact] public void EndConnect_UnrelatedAsyncResult_Throws_Argument() { - Assert.Throws(() => GetSocket().EndConnect(Task.CompletedTask)); + AssertExtensions.Throws("asyncResult", () => GetSocket().EndConnect(Task.CompletedTask)); } [Fact] @@ -1138,8 +1138,8 @@ namespace System.Net.Sockets.Tests [Fact] public void BeginSend_Buffers_EmptyBuffers_Throws_Argument() { - Assert.Throws(() => GetSocket().BeginSend(new List>(), SocketFlags.None, TheAsyncCallback, null)); - Assert.Throws(() => { GetSocket().SendAsync(new List>(), SocketFlags.None); }); + AssertExtensions.Throws("buffers", () => GetSocket().BeginSend(new List>(), SocketFlags.None, TheAsyncCallback, null)); + AssertExtensions.Throws("buffers", () => { GetSocket().SendAsync(new List>(), SocketFlags.None); }); } [Fact] @@ -1151,7 +1151,7 @@ namespace System.Net.Sockets.Tests [Fact] public void EndSend_UnrelatedAsyncResult_Throws_Argument() { - Assert.Throws(() => GetSocket().EndSend(Task.CompletedTask)); + AssertExtensions.Throws("asyncResult", () => GetSocket().EndSend(Task.CompletedTask)); } [Fact] @@ -1203,7 +1203,7 @@ namespace System.Net.Sockets.Tests [Fact] public void EndSendto_UnrelatedAsyncResult_Throws_Argument() { - Assert.Throws(() => GetSocket().EndSendTo(Task.CompletedTask)); + AssertExtensions.Throws("asyncResult", () => GetSocket().EndSendTo(Task.CompletedTask)); } [Fact] @@ -1245,8 +1245,8 @@ namespace System.Net.Sockets.Tests [Fact] public void BeginReceive_Buffers_EmptyBuffers_Throws_Argument() { - Assert.Throws(() => GetSocket().BeginReceive(new List>(), SocketFlags.None, TheAsyncCallback, null)); - Assert.Throws(() => { GetSocket().ReceiveAsync(new List>(), SocketFlags.None); }); + AssertExtensions.Throws("buffers", () => GetSocket().BeginReceive(new List>(), SocketFlags.None, TheAsyncCallback, null)); + AssertExtensions.Throws("buffers", () => { GetSocket().ReceiveAsync(new List>(), SocketFlags.None); }); } [Fact] @@ -1275,8 +1275,8 @@ namespace System.Net.Sockets.Tests public void BeginReceiveFrom_AddressFamily_Throws_Argument() { EndPoint endpoint = new IPEndPoint(IPAddress.IPv6Loopback, 1); - Assert.Throws(() => GetSocket(AddressFamily.InterNetwork).BeginReceiveFrom(s_buffer, 0, 0, SocketFlags.None, ref endpoint, TheAsyncCallback, null)); - Assert.Throws(() => { GetSocket(AddressFamily.InterNetwork).ReceiveFromAsync(new ArraySegment(s_buffer, 0, 0), SocketFlags.None, endpoint); }); + AssertExtensions.Throws("remoteEP", () => GetSocket(AddressFamily.InterNetwork).BeginReceiveFrom(s_buffer, 0, 0, SocketFlags.None, ref endpoint, TheAsyncCallback, null)); + AssertExtensions.Throws("remoteEP", () => { GetSocket(AddressFamily.InterNetwork).ReceiveFromAsync(new ArraySegment(s_buffer, 0, 0), SocketFlags.None, endpoint); }); } [Fact] @@ -1343,8 +1343,8 @@ namespace System.Net.Sockets.Tests { EndPoint remote = new IPEndPoint(IPAddress.IPv6Loopback, 1); - Assert.Throws(() => GetSocket(AddressFamily.InterNetwork).BeginReceiveMessageFrom(s_buffer, 0, 0, SocketFlags.None, ref remote, TheAsyncCallback, null)); - Assert.Throws(() => { GetSocket(AddressFamily.InterNetwork).ReceiveMessageFromAsync(new ArraySegment(s_buffer, 0, 0), SocketFlags.None, remote); }); + AssertExtensions.Throws("remoteEP", () => GetSocket(AddressFamily.InterNetwork).BeginReceiveMessageFrom(s_buffer, 0, 0, SocketFlags.None, ref remote, TheAsyncCallback, null)); + AssertExtensions.Throws("remoteEP", () => { GetSocket(AddressFamily.InterNetwork).ReceiveMessageFromAsync(new ArraySegment(s_buffer, 0, 0), SocketFlags.None, remote); }); } [Fact] @@ -1399,7 +1399,7 @@ namespace System.Net.Sockets.Tests EndPoint remote = new IPEndPoint(IPAddress.IPv6Loopback, 1); IPPacketInformation packetInfo; - Assert.Throws(() => GetSocket(AddressFamily.InterNetwork).EndReceiveMessageFrom(null, ref flags, ref remote, out packetInfo)); + AssertExtensions.Throws("endPoint", () => GetSocket(AddressFamily.InterNetwork).EndReceiveMessageFrom(null, ref flags, ref remote, out packetInfo)); } [Fact] diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/DnsEndPointTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/DnsEndPointTest.cs index 93fb1a3a65d..b3476fbe6cd 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/DnsEndPointTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/DnsEndPointTest.cs @@ -82,7 +82,7 @@ namespace System.Net.Sockets.Tests { using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { sock.SendTo(new byte[10], new DnsEndPoint("localhost", UnusedPort)); }); @@ -98,7 +98,7 @@ namespace System.Net.Sockets.Tests int port = sock.BindToAnonymousPort(IPAddress.Loopback); EndPoint endpoint = new DnsEndPoint("localhost", port); - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { sock.ReceiveFrom(new byte[10], ref endpoint); }); @@ -174,7 +174,7 @@ namespace System.Net.Sockets.Tests { using (Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)) { - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { sock.BeginSendTo(new byte[10], 0, 0, SocketFlags.None, new DnsEndPoint("localhost", UnusedPort), null, null); }); diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs index a5661e52c3b..ef120ada456 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/DualModeSocketTest.cs @@ -269,7 +269,7 @@ namespace System.Net.Sockets.Tests int port; using (SocketServer server = new SocketServer(_log, IPAddress.Loopback, false, out port)) { - Assert.Throws(() => + AssertExtensions.Throws("addresses", () => { socket.Connect(new IPAddress[] { IPAddress.Loopback }, port); }); @@ -710,7 +710,7 @@ namespace System.Net.Sockets.Tests [Fact] public void Socket_BindDnsEndPoint_Throws() { - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { using (Socket socket = new Socket(SocketType.Stream, ProtocolType.Tcp)) { @@ -1081,7 +1081,7 @@ namespace System.Net.Sockets.Tests { using (Socket socket = new Socket(SocketType.Dgram, ProtocolType.Udp)) { - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { socket.SendTo(new byte[1], new DnsEndPoint("localhost", UnusedPort)); }); @@ -1182,7 +1182,7 @@ namespace System.Net.Sockets.Tests { using (Socket socket = new Socket(SocketType.Dgram, ProtocolType.Udp)) { - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { socket.BeginSendTo(new byte[1], 0, 1, SocketFlags.None, new DnsEndPoint("localhost", UnusedPort), null, null); }); @@ -1302,7 +1302,7 @@ namespace System.Net.Sockets.Tests SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.RemoteEndPoint = new DnsEndPoint("localhost", UnusedPort); args.SetBuffer(new byte[1], 0, 1); - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { socket.SendToAsync(args); }); @@ -1410,7 +1410,7 @@ namespace System.Net.Sockets.Tests socket.DualMode = false; EndPoint receivedFrom = new IPEndPoint(IPAddress.Loopback, UnusedPort); - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { int received = socket.ReceiveFrom(new byte[1], ref receivedFrom); }); @@ -1426,7 +1426,7 @@ namespace System.Net.Sockets.Tests { int port = socket.BindToAnonymousPort(IPAddress.IPv6Loopback); EndPoint receivedFrom = new DnsEndPoint("localhost", port, AddressFamily.InterNetworkV6); - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { int received = socket.ReceiveFrom(new byte[1], ref receivedFrom); }); @@ -1540,7 +1540,7 @@ namespace System.Net.Sockets.Tests socket.DualMode = false; EndPoint receivedFrom = new IPEndPoint(IPAddress.Loopback, UnusedPort); - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { socket.BeginReceiveFrom(new byte[1], 0, 1, SocketFlags.None, ref receivedFrom, null, null); }); @@ -1557,7 +1557,7 @@ namespace System.Net.Sockets.Tests int port = socket.BindToAnonymousPort(IPAddress.IPv6Loopback); EndPoint receivedFrom = new DnsEndPoint("localhost", port, AddressFamily.InterNetworkV6); - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { socket.BeginReceiveFrom(new byte[1], 0, 1, SocketFlags.None, ref receivedFrom, null, null); }); @@ -1689,7 +1689,7 @@ namespace System.Net.Sockets.Tests args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, UnusedPort); args.SetBuffer(new byte[1], 0, 1); - Assert.Throws(() => + AssertExtensions.Throws("RemoteEndPoint", () => { socket.ReceiveFromAsync(args); }); @@ -1708,7 +1708,7 @@ namespace System.Net.Sockets.Tests args.RemoteEndPoint = new DnsEndPoint("localhost", port, AddressFamily.InterNetworkV6); args.SetBuffer(new byte[1], 0, 1); - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { socket.ReceiveFromAsync(args); }); @@ -1885,7 +1885,7 @@ namespace System.Net.Sockets.Tests EndPoint receivedFrom = new IPEndPoint(IPAddress.Loopback, UnusedPort); SocketFlags socketFlags = SocketFlags.None; IPPacketInformation ipPacketInformation; - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { int received = socket.ReceiveMessageFrom(new byte[1], 0, 1, ref socketFlags, ref receivedFrom, out ipPacketInformation); }); @@ -1904,7 +1904,7 @@ namespace System.Net.Sockets.Tests SocketFlags socketFlags = SocketFlags.None; IPPacketInformation ipPacketInformation; - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { int received = socket.ReceiveMessageFrom(new byte[1], 0, 1, ref socketFlags, ref receivedFrom, out ipPacketInformation); }); @@ -2060,7 +2060,7 @@ namespace System.Net.Sockets.Tests EndPoint receivedFrom = new IPEndPoint(IPAddress.Loopback, UnusedPort); SocketFlags socketFlags = SocketFlags.None; - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { socket.BeginReceiveMessageFrom(new byte[1], 0, 1, socketFlags, ref receivedFrom, null, null); }); @@ -2078,7 +2078,7 @@ namespace System.Net.Sockets.Tests EndPoint receivedFrom = new DnsEndPoint("localhost", port, AddressFamily.InterNetworkV6); SocketFlags socketFlags = SocketFlags.None; - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { socket.BeginReceiveMessageFrom(new byte[1], 0, 1, socketFlags, ref receivedFrom, null, null); }); @@ -2158,7 +2158,7 @@ namespace System.Net.Sockets.Tests [PlatformSpecific(TestPlatforms.Linux)] // Read the comment above public void BeginReceiveMessageFromV4BoundToSpecificV6_NotReceived_Linux() { - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { BeginReceiveMessageFrom_Helper(IPAddress.IPv6Loopback, IPAddress.Loopback, expectedToTimeout: true); }); @@ -2233,7 +2233,7 @@ namespace System.Net.Sockets.Tests args.RemoteEndPoint = new IPEndPoint(IPAddress.Loopback, UnusedPort); args.SetBuffer(new byte[1], 0, 1); - Assert.Throws(() => + AssertExtensions.Throws("RemoteEndPoint", () => { socket.ReceiveMessageFromAsync(args); }); @@ -2253,7 +2253,7 @@ namespace System.Net.Sockets.Tests args.RemoteEndPoint = new DnsEndPoint("localhost", port, AddressFamily.InterNetworkV6); args.SetBuffer(new byte[1], 0, 1); - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { socket.ReceiveMessageFromAsync(args); }); @@ -2333,7 +2333,7 @@ namespace System.Net.Sockets.Tests [PlatformSpecific(TestPlatforms.Linux)] // Read the comment above public void ReceiveMessageFromAsyncV4BoundToSpecificV6_NotReceived_Linux() { - Assert.Throws(() => + AssertExtensions.Throws("remoteEP", () => { ReceiveFrom_Helper(IPAddress.IPv6Loopback, IPAddress.Loopback); }); diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/LingerStateTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/LingerStateTest.cs index 9440a6adc9d..c995b52e4a1 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/LingerStateTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/LingerStateTest.cs @@ -19,7 +19,7 @@ namespace System.Net.Sockets.Tests private void TestLingerState_ArgumentException(Socket sock, bool enabled, int lingerTime) { - Assert.Throws(() => + AssertExtensions.Throws("optionValue.LingerTime", () => { sock.LingerState = new LingerOption(enabled, lingerTime); }); diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SendPacketsAsync.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SendPacketsAsync.cs index 2258d8c6ddf..8426e3be153 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SendPacketsAsync.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SendPacketsAsync.cs @@ -276,7 +276,7 @@ namespace System.Net.Sockets.Tests [InlineData(SocketImplementationType.Async)] public void SendPacketsElement_EmptyFileName_Throws(SocketImplementationType type) { - Assert.Throws(() => + AssertExtensions.Throws("path", null, () => { SendPackets(type, new SendPacketsElement(String.Empty), 0); }); @@ -288,7 +288,7 @@ namespace System.Net.Sockets.Tests [PlatformSpecific(TestPlatforms.Windows)] // whitespace-only is a valid name on Unix public void SendPacketsElement_BlankFileName_Throws(SocketImplementationType type) { - Assert.Throws(() => + AssertExtensions.Throws("path", null, () => { // Existence is validated on send SendPackets(type, new SendPacketsElement(" \t "), 0); @@ -301,7 +301,7 @@ namespace System.Net.Sockets.Tests [PlatformSpecific(TestPlatforms.Windows)] // valid filename chars on Unix public void SendPacketsElement_BadCharactersFileName_Throws(SocketImplementationType type) { - Assert.Throws(() => + AssertExtensions.Throws("path", null, () => { // Existence is validated on send SendPackets(type, new SendPacketsElement("blarkd@dfa?/sqersf"), 0); diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs index 38b73fc6cb8..d6cf16679ba 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketAsyncEventArgsTest.cs @@ -184,7 +184,7 @@ namespace System.Net.Sockets.Tests byte[] buffer = new byte[1]; saea.SetBuffer(buffer, 0, 1); - Assert.Throws(() => saea.BufferList = bufferList); + AssertExtensions.Throws(null, () => saea.BufferList = bufferList); Assert.Same(buffer, saea.Buffer); Assert.Null(saea.BufferList); @@ -200,7 +200,7 @@ namespace System.Net.Sockets.Tests { var bufferList = new List> { new ArraySegment(new byte[1]) }; saea.BufferList = bufferList; - Assert.Throws(() => saea.SetBuffer(new byte[1], 0, 1)); + AssertExtensions.Throws(null, () => saea.SetBuffer(new byte[1], 0, 1)); Assert.Same(bufferList, saea.BufferList); Assert.Null(saea.Buffer); diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/TcpClientTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/TcpClientTest.cs index 22446782feb..7afdf02489c 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/TcpClientTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/TcpClientTest.cs @@ -28,7 +28,7 @@ namespace System.Net.Sockets.Tests [InlineData(AddressFamily.Unknown)] public void Ctor_InvalidFamily_Throws(AddressFamily family) { - Assert.Throws(() => new TcpClient(family)); + AssertExtensions.Throws("family", () => new TcpClient(family)); } [Fact] diff --git a/src/libraries/System.Net.Sockets/tests/FunctionalTests/TcpListenerTest.cs b/src/libraries/System.Net.Sockets/tests/FunctionalTests/TcpListenerTest.cs index 4adc1053d25..78ef0fe6b96 100644 --- a/src/libraries/System.Net.Sockets/tests/FunctionalTests/TcpListenerTest.cs +++ b/src/libraries/System.Net.Sockets/tests/FunctionalTests/TcpListenerTest.cs @@ -91,8 +91,8 @@ namespace System.Net.Sockets.Tests Assert.Throws(() => listener.EndAcceptSocket(null)); Assert.Throws(() => listener.EndAcceptTcpClient(null)); - Assert.Throws(() => listener.EndAcceptSocket(Task.CompletedTask)); - Assert.Throws(() => listener.EndAcceptTcpClient(Task.CompletedTask)); + AssertExtensions.Throws("asyncResult", () => listener.EndAcceptSocket(Task.CompletedTask)); + AssertExtensions.Throws("asyncResult", () => listener.EndAcceptTcpClient(Task.CompletedTask)); } [Fact] diff --git a/src/libraries/System.Net.WebHeaderCollection/tests/WebHeaderCollectionTest.cs b/src/libraries/System.Net.WebHeaderCollection/tests/WebHeaderCollectionTest.cs index f69dd7ddb45..3c7e40a7632 100644 --- a/src/libraries/System.Net.WebHeaderCollection/tests/WebHeaderCollectionTest.cs +++ b/src/libraries/System.Net.WebHeaderCollection/tests/WebHeaderCollectionTest.cs @@ -623,8 +623,8 @@ namespace System.Net.Tests WebHeaderCollection w = new WebHeaderCollection(); char[] arr = new char[ushort.MaxValue + 1]; string maxStr = new string(arr); - Assert.Throws(() => w.Add(HttpRequestHeader.ContentLength,maxStr)); - Assert.Throws(() => w.Add("ContentLength", maxStr)); + AssertExtensions.Throws("value", () => w.Add(HttpRequestHeader.ContentLength,maxStr)); + AssertExtensions.Throws("value", () => w.Add("ContentLength", maxStr)); } [Fact] diff --git a/src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs b/src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs index e589f6b0ae8..4da27c31b36 100644 --- a/src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs +++ b/src/libraries/System.Net.WebProxy/tests/WebProxyTest.cs @@ -113,7 +113,7 @@ namespace System.Net.Tests AssertExtensions.Throws("destination", () => p.GetProxy(null)); AssertExtensions.Throws("host", () => p.IsBypassed(null)); AssertExtensions.Throws("c", () => p.BypassList = null); - Assert.Throws(() => p.BypassList = new string[] { "*.com" }); + AssertExtensions.Throws(null, () => p.BypassList = new string[] { "*.com" }); } [Fact] diff --git a/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.cs b/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.cs index 9a92892bccb..b8168bb1ca2 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/CloseTest.cs @@ -115,7 +115,7 @@ namespace System.Net.WebSockets.Client.Tests var expectedException = new ArgumentException(expectedInnerMessage, "statusDescription"); string expectedMessage = expectedException.Message; - Assert.Throws(() => + AssertExtensions.Throws("statusDescription", () => { Task t = cws.CloseAsync(WebSocketCloseStatus.NormalClosure, closeDescription, cts.Token); }); Assert.Equal(WebSocketState.Open, cws.State); diff --git a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.cs b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.cs index f236f8cc3ce..29c0fc11621 100644 --- a/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.cs +++ b/src/libraries/System.Net.WebSockets.Client/tests/SendReceiveTest.cs @@ -113,7 +113,7 @@ namespace System.Net.WebSockets.Client.Tests var expectedException = new ArgumentException(expectedInnerMessage, "messageType"); string expectedMessage = expectedException.Message; - Assert.Throws(() => + AssertExtensions.Throws("messageType", () => { Task t = cws.SendAsync(new ArraySegment(), WebSocketMessageType.Close, true, cts.Token); }); diff --git a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs index 237b9637498..88e11b93e43 100644 --- a/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/GenericVectorTests.cs @@ -310,7 +310,7 @@ namespace System.Numerics.Tests Assert.Throws(() => vector.CopyTo(null, 0)); Assert.Throws(() => vector.CopyTo(array, -1)); Assert.Throws(() => vector.CopyTo(array, array.Length)); - Assert.Throws(() => vector.CopyTo(array, array.Length - 1)); + AssertExtensions.Throws(null, () => vector.CopyTo(array, array.Length - 1)); vector.CopyTo(array); for (int g = 0; g < array.Length; g++) @@ -2695,4 +2695,4 @@ namespace System.Numerics.Tests } #endregion } -} \ No newline at end of file +} diff --git a/src/libraries/System.Numerics.Vectors/tests/System.Numerics.Vectors.Tests.csproj b/src/libraries/System.Numerics.Vectors/tests/System.Numerics.Vectors.Tests.csproj index e623866e58f..6a6d6ac63a4 100644 --- a/src/libraries/System.Numerics.Vectors/tests/System.Numerics.Vectors.Tests.csproj +++ b/src/libraries/System.Numerics.Vectors/tests/System.Numerics.Vectors.Tests.csproj @@ -32,6 +32,9 @@ + + Common\System\AssertExtensions.cs + Common\System\PlatformDetection.cs diff --git a/src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs b/src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs index 9c1297bb1c8..982e20da6b0 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Vector2Tests.cs @@ -31,7 +31,7 @@ namespace System.Numerics.Tests if (!PlatformDetection.IsNetNative) { - Assert.Throws(() => v1.CopyTo(a, 2)); + AssertExtensions.Throws(null, () => v1.CopyTo(a, 2)); } else { diff --git a/src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs b/src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs index 3ad0e11a497..594495488c0 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Vector3Tests.cs @@ -28,7 +28,7 @@ namespace System.Numerics.Tests Assert.Throws(() => v1.CopyTo(null, 0)); Assert.Throws(() => v1.CopyTo(a, -1)); Assert.Throws(() => v1.CopyTo(a, a.Length)); - Assert.Throws(() => v1.CopyTo(a, a.Length - 2)); + AssertExtensions.Throws(null, () => v1.CopyTo(a, a.Length - 2)); v1.CopyTo(a, 1); v1.CopyTo(b); diff --git a/src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs b/src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs index 11f8b8313b2..7149a2fb483 100644 --- a/src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs +++ b/src/libraries/System.Numerics.Vectors/tests/Vector4Tests.cs @@ -28,7 +28,7 @@ namespace System.Numerics.Tests Assert.Throws(() => v1.CopyTo(null, 0)); Assert.Throws(() => v1.CopyTo(a, -1)); Assert.Throws(() => v1.CopyTo(a, a.Length)); - Assert.Throws(() => v1.CopyTo(a, a.Length - 2)); + AssertExtensions.Throws(null, () => v1.CopyTo(a, a.Length - 2)); v1.CopyTo(a, 1); v1.CopyTo(b); diff --git a/src/libraries/System.ObjectModel/tests/ObservableCollection/ObservableCollection_MethodsTest.cs b/src/libraries/System.ObjectModel/tests/ObservableCollection/ObservableCollection_MethodsTest.cs index 1ceddc58972..7f95a4b4c0d 100644 --- a/src/libraries/System.ObjectModel/tests/ObservableCollection/ObservableCollection_MethodsTest.cs +++ b/src/libraries/System.ObjectModel/tests/ObservableCollection/ObservableCollection_MethodsTest.cs @@ -423,16 +423,16 @@ namespace System.Collections.ObjectModel.Tests foreach (var index in iArrLargeValues) { string[] aCopy = new string[collection.Count]; - Assert.Throws(() => collection.CopyTo(aCopy, index)); + AssertExtensions.Throws("destinationArray", null, () => collection.CopyTo(aCopy, index)); } Assert.Throws(() => collection.CopyTo(null, 1)); string[] copy = new string[collection.Count - 1]; - Assert.Throws(() => collection.CopyTo(copy, 0)); + AssertExtensions.Throws("destinationArray", "", () => collection.CopyTo(copy, 0)); copy = new string[0]; - Assert.Throws(() => collection.CopyTo(copy, 0)); + AssertExtensions.Throws("destinationArray", "", () => collection.CopyTo(copy, 0)); } /// diff --git a/src/libraries/System.ObjectModel/tests/ReadOnlyObservableCollection/ReadOnlyObservableCollectionTests.cs b/src/libraries/System.ObjectModel/tests/ReadOnlyObservableCollection/ReadOnlyObservableCollectionTests.cs index 047b17c3e4f..116dda0479f 100644 --- a/src/libraries/System.ObjectModel/tests/ReadOnlyObservableCollection/ReadOnlyObservableCollectionTests.cs +++ b/src/libraries/System.ObjectModel/tests/ReadOnlyObservableCollection/ReadOnlyObservableCollectionTests.cs @@ -132,16 +132,16 @@ namespace System.Collections.ObjectModel.Tests foreach (var index in iArrLargeValues) { string[] aCopy = new string[anArray.Length]; - Assert.Throws(() => readOnlyCol.CopyTo(aCopy, index)); + AssertExtensions.Throws("destinationArray", null, () => readOnlyCol.CopyTo(aCopy, index)); } Assert.Throws(() => readOnlyCol.CopyTo(null, 1)); string[] copy = new string[anArray.Length - 1]; - Assert.Throws(() => readOnlyCol.CopyTo(copy, 0)); + AssertExtensions.Throws("destinationArray", "", () => readOnlyCol.CopyTo(copy, 0)); copy = new string[0]; - Assert.Throws(() => readOnlyCol.CopyTo(copy, 0)); + AssertExtensions.Throws("destinationArray", "", () => readOnlyCol.CopyTo(copy, 0)); } /// diff --git a/src/libraries/System.Private.Uri/tests/ExtendedFunctionalTests/UriTests.cs b/src/libraries/System.Private.Uri/tests/ExtendedFunctionalTests/UriTests.cs index 82580e86f47..8002da8c3b7 100644 --- a/src/libraries/System.Private.Uri/tests/ExtendedFunctionalTests/UriTests.cs +++ b/src/libraries/System.Private.Uri/tests/ExtendedFunctionalTests/UriTests.cs @@ -237,7 +237,7 @@ namespace System.PrivateUri.Tests [Fact] public static void TestHexMethods_Invalid() { - Assert.Throws(() => Uri.FromHex('?')); + AssertExtensions.Throws(null, () => Uri.FromHex('?')); Assert.Throws(() => Uri.HexEscape('\x100')); int index = -1; Assert.Throws(() => Uri.HexUnescape("%75", ref index)); diff --git a/src/libraries/System.Private.Uri/tests/FunctionalTests/UriBuilderTests.cs b/src/libraries/System.Private.Uri/tests/FunctionalTests/UriBuilderTests.cs index 931a6890a8c..31835a66023 100644 --- a/src/libraries/System.Private.Uri/tests/FunctionalTests/UriBuilderTests.cs +++ b/src/libraries/System.Private.Uri/tests/FunctionalTests/UriBuilderTests.cs @@ -167,7 +167,7 @@ namespace System.PrivateUri.Tests [InlineData("fragment?fragment")] public void Ctor_InvalidExtraValue_ThrowsArgumentException(string extraValue) { - Assert.Throws(() => new UriBuilder("scheme", "host", 80, "path", extraValue)); + AssertExtensions.Throws("extraValue", null, () => new UriBuilder("scheme", "host", 80, "path", extraValue)); } [Theory] @@ -187,12 +187,12 @@ namespace System.PrivateUri.Tests [InlineData("-")] public void InvalidScheme_ThrowsArgumentException(string schemeName) { - Assert.Throws(() => new UriBuilder(schemeName, "host")); - Assert.Throws(() => new UriBuilder(schemeName, "host", 80)); - Assert.Throws(() => new UriBuilder(schemeName, "host", 80, "path")); - Assert.Throws(() => new UriBuilder(schemeName, "host", 80, "?query#fragment")); + AssertExtensions.Throws("value", null, () => new UriBuilder(schemeName, "host")); + AssertExtensions.Throws("value", null, () => new UriBuilder(schemeName, "host", 80)); + AssertExtensions.Throws("value", null, () => new UriBuilder(schemeName, "host", 80, "path")); + AssertExtensions.Throws("value", null, () => new UriBuilder(schemeName, "host", 80, "?query#fragment")); - Assert.Throws(() => new UriBuilder().Scheme = schemeName); + AssertExtensions.Throws("value", null, () => new UriBuilder().Scheme = schemeName); } [Theory] diff --git a/src/libraries/System.Private.Xml.Linq/tests/Properties/DocOrderComparer.cs b/src/libraries/System.Private.Xml.Linq/tests/Properties/DocOrderComparer.cs index 3917b8b3a06..029de3b39cf 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/Properties/DocOrderComparer.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/Properties/DocOrderComparer.cs @@ -132,19 +132,19 @@ namespace System.Xml.Linq.Tests public static IEnumerable GetNotXNodes() { - yield return new object[] { new XAttribute("a", "A"), new XElement("E") }; - yield return new object[] { new XDeclaration("1.0", "UFT8", "false"), new XElement("E") }; - yield return new object[] { "", new XElement("E") }; - yield return new object[] { new XElement("E"), new XAttribute("a", "A") }; - yield return new object[] { new XElement("E"), new XDeclaration("1.0", "UFT8", "false") }; - yield return new object[] { new XElement("E"), "" }; + yield return new object[] { new XAttribute("a", "A"), new XElement("E"), "x" }; + yield return new object[] { new XDeclaration("1.0", "UFT8", "false"), new XElement("E"), "x" }; + yield return new object[] { "", new XElement("E"), "x" }; + yield return new object[] { new XElement("E"), new XAttribute("a", "A"), "y" }; + yield return new object[] { new XElement("E"), new XDeclaration("1.0", "UFT8", "false"), "y" }; + yield return new object[] { new XElement("E"), "", "y" }; } [Theory] [MemberData(nameof(GetNotXNodes))] - public void NotXNode(object x, object y) + public void NotXNode(object x, object y, string paramName) { - Assert.Throws(() => ((IComparer)XNode.DocumentOrderComparer).Compare(x, y)); + AssertExtensions.Throws(paramName, () => ((IComparer)XNode.DocumentOrderComparer).Compare(x, y)); } [Fact] diff --git a/src/libraries/System.Private.Xml.Linq/tests/Properties/System.Xml.Linq.Properties.Tests.csproj b/src/libraries/System.Private.Xml.Linq/tests/Properties/System.Xml.Linq.Properties.Tests.csproj index 772734494a2..578b5720fbd 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/Properties/System.Xml.Linq.Properties.Tests.csproj +++ b/src/libraries/System.Private.Xml.Linq/tests/Properties/System.Xml.Linq.Properties.Tests.csproj @@ -18,6 +18,9 @@ + + Common\System\AssertExtensions.cs + diff --git a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMContainer.cs b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMContainer.cs index ce0d6ade937..3dc1d58ea81 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMContainer.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMContainer.cs @@ -60,7 +60,7 @@ namespace XDocumentTests.SDMSample // Not allowed to add a document as a child. XDocument document = new XDocument(); - Assert.Throws(() => element.Add(document)); + AssertExtensions.Throws(null, () => element.Add(document)); } /// @@ -72,7 +72,7 @@ namespace XDocumentTests.SDMSample // Not allowed to add attributes in the general case. // The only general case of a container is a document. XDocument document = new XDocument(); - Assert.Throws(() => document.Add(new XAttribute("foo", "bar"))); + AssertExtensions.Throws(null, () => document.Add(new XAttribute("foo", "bar"))); // Can add to elements, but no duplicates allowed. XElement e = new XElement("element"); @@ -127,7 +127,7 @@ namespace XDocumentTests.SDMSample // Can't use to add attributes. XAttribute a = new XAttribute("foo", "bar"); - Assert.Throws(() => element.AddFirst(a)); + AssertExtensions.Throws(null, () => element.AddFirst(a)); } /// diff --git a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMDocument.cs b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMDocument.cs index 79f6db73958..1efa4b1edc6 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMDocument.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMDocument.cs @@ -141,8 +141,8 @@ namespace XDocumentTests.SDMSample doc.Add(" \t" + Environment.NewLine); Assert.Equal(" \t" + Environment.NewLine, doc.ToString(SaveOptions.DisableFormatting)); - Assert.Throws(() => doc.Add("a")); - Assert.Throws(() => doc.Add("\tab")); + AssertExtensions.Throws(null, () => doc.Add("a")); + AssertExtensions.Throws(null, () => doc.Add("\tab")); } } } diff --git a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMElement.cs b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMElement.cs index a5ac9fcc4cd..4bcefe1d3b4 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMElement.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMElement.cs @@ -769,7 +769,7 @@ namespace XDocumentTests.SDMSample XElement e = new XElement(ns + "foo"); Assert.Throws(() => e.GetNamespaceOfPrefix(null)); - Assert.Throws(() => e.GetNamespaceOfPrefix(string.Empty)); + AssertExtensions.Throws(null, () => e.GetNamespaceOfPrefix(string.Empty)); XNamespace n = e.GetNamespaceOfPrefix("xmlns"); Assert.Equal("http://www.w3.org/2000/xmlns/", n.NamespaceName); diff --git a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMXName.cs b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMXName.cs index 9fbf35195cd..fd5f1a8d0e6 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMXName.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/SDMXName.cs @@ -30,9 +30,9 @@ namespace XDocumentTests.SDMSample Assert.Throws(() => XName.Get(null)); Assert.Throws(() => XName.Get(null, "foo")); Assert.Throws(() => XName.Get(string.Empty, "foo")); - Assert.Throws(() => XName.Get(string.Empty)); - Assert.Throws(() => XName.Get("{}")); - Assert.Throws(() => XName.Get("{foo}")); + AssertExtensions.Throws(null, () => XName.Get(string.Empty)); + AssertExtensions.Throws(null, () => XName.Get("{}")); + AssertExtensions.Throws(null, () => XName.Get("{foo}")); } /// diff --git a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/System.Xml.Linq.SDMSample.Tests.csproj b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/System.Xml.Linq.SDMSample.Tests.csproj index efa7daccce8..a1346c0047d 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/SDMSample/System.Xml.Linq.SDMSample.Tests.csproj +++ b/src/libraries/System.Private.Xml.Linq/tests/SDMSample/System.Xml.Linq.SDMSample.Tests.csproj @@ -21,6 +21,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Private.Xml.Linq/tests/Streaming/StreamingOutput.cs b/src/libraries/System.Private.Xml.Linq/tests/Streaming/StreamingOutput.cs index 9a308a114f8..99fe0fa05da 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/Streaming/StreamingOutput.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/Streaming/StreamingOutput.cs @@ -61,7 +61,7 @@ namespace XDocumentTests.Streaming [Fact] public void XNameAsEmptyStringConstructor() { - Assert.Throws(() => new XStreamingElement(string.Empty)); + AssertExtensions.Throws(null, () => new XStreamingElement(string.Empty)); Assert.Throws(() => new XStreamingElement(" ")); } diff --git a/src/libraries/System.Private.Xml.Linq/tests/Streaming/System.Xml.Linq.Streaming.Tests.csproj b/src/libraries/System.Private.Xml.Linq/tests/Streaming/System.Xml.Linq.Streaming.Tests.csproj index 3e8d88ec487..e47da7e696f 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/Streaming/System.Xml.Linq.Streaming.Tests.csproj +++ b/src/libraries/System.Private.Xml.Linq/tests/Streaming/System.Xml.Linq.Streaming.Tests.csproj @@ -12,6 +12,9 @@ + + Common\System\AssertExtensions.cs + diff --git a/src/libraries/System.Private.Xml.Linq/tests/axes/InvalidParamValidation.cs b/src/libraries/System.Private.Xml.Linq/tests/axes/InvalidParamValidation.cs index b49a61f75fe..1781bde2c7c 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/axes/InvalidParamValidation.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/axes/InvalidParamValidation.cs @@ -51,9 +51,9 @@ namespace System.Xml.Linq.Tests public static void InvalidXNameTest() { Assert.Throws(() => { TestData.GetDocumentWithContacts().Root.Attribute("*&^%_#@!"); }); - Assert.Throws(() => { TestData.GetDocumentWithContacts().Root.Attribute(""); }); + AssertExtensions.Throws(null, () => { TestData.GetDocumentWithContacts().Root.Attribute(""); }); Assert.Throws(() => { TestData.GetDocumentWithContacts().Root.Attributes("*&^%_#@!"); }); - Assert.Throws(() => { TestData.GetDocumentWithContacts().Root.Attributes(""); }); + AssertExtensions.Throws(null, () => { TestData.GetDocumentWithContacts().Root.Attributes(""); }); } } diff --git a/src/libraries/System.Private.Xml.Linq/tests/axes/System.Xml.Linq.Axes.Tests.csproj b/src/libraries/System.Private.Xml.Linq/tests/axes/System.Xml.Linq.Axes.Tests.csproj index 574b48d62c7..47d22b02b8b 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/axes/System.Xml.Linq.Axes.Tests.csproj +++ b/src/libraries/System.Private.Xml.Linq/tests/axes/System.Xml.Linq.Axes.Tests.csproj @@ -14,6 +14,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Private.Xml.Linq/tests/misc/RegressionTests.cs b/src/libraries/System.Private.Xml.Linq/tests/misc/RegressionTests.cs index b3dabcff111..adf475fe365 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/misc/RegressionTests.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/misc/RegressionTests.cs @@ -217,8 +217,8 @@ namespace System.Xml.Linq.Tests XStreamingElement se = new XStreamingElement("se", t); se.Add(t); - Assert.Throws(() => new XDocument(t)); - Assert.Throws(() => new XDocument(t)); + AssertExtensions.Throws(null, () => new XDocument(t)); + AssertExtensions.Throws(null, () => new XDocument(t)); } public static IEnumerable GetObjects() diff --git a/src/libraries/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs b/src/libraries/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs index 3081221d4e6..bf5589d9cb0 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs +++ b/src/libraries/System.Private.Xml.Linq/tests/xNodeBuilder/CommonTests.cs @@ -3415,7 +3415,7 @@ namespace CoreXml.Test.XLinq using (XmlReader reader = doc.CreateReader()) { - Exception exception = Assert.Throws(() => MoveToFirstElement(reader).ReadOuterXml()); + Exception exception = AssertExtensions.Throws(null, () => MoveToFirstElement(reader).ReadOuterXml()); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages { string expectedMsg = "Cannot have ']]>' inside an XML CDATA block."; @@ -3609,7 +3609,7 @@ namespace CoreXml.Test.XLinq using (XmlReader reader = doc.CreateReader()) { - Exception exception = Assert.Throws(() => MoveToFirstElement(reader).ReadOuterXml()); + Exception exception = AssertExtensions.Throws(null, () => MoveToFirstElement(reader).ReadOuterXml()); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages { string expectedMsg = "An XML comment cannot contain '--', and '-' cannot be the last character."; @@ -4212,7 +4212,7 @@ namespace CoreXml.Test.XLinq using (XmlReader reader = doc.CreateReader()) { - Exception exception = Assert.Throws(() => MoveToFirstElement(reader).ReadOuterXml()); + Exception exception = AssertExtensions.Throws(null, () => MoveToFirstElement(reader).ReadOuterXml()); if (!PlatformDetection.IsNetNative) // .Net Native toolchain optimizes away Exception messages { string expectedMsg = "Cannot have '?>' inside an XML processing instruction."; diff --git a/src/libraries/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj b/src/libraries/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj index 993626a53f4..5d852f9271d 100644 --- a/src/libraries/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj +++ b/src/libraries/System.Private.Xml.Linq/tests/xNodeBuilder/System.Xml.Linq.xNodeBuilder.Tests.csproj @@ -13,6 +13,9 @@ Common\System\Collections\DictionaryExtensions.cs + + Common\System\AssertExtensions.cs + Common\System\PlatformDetection.cs diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/System.Xml.XmlDocument.Tests.csproj b/src/libraries/System.Private.Xml/tests/XmlDocument/System.Xml.XmlDocument.Tests.csproj index 4c9179e286a..a7db6c26423 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/System.Xml.XmlDocument.Tests.csproj +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/System.Xml.XmlDocument.Tests.csproj @@ -99,6 +99,9 @@ + + Common\System\AssertExtensions.cs + diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/AppendTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/AppendTests.cs index 130a132bf5a..16a28f63498 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/AppendTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/AppendTests.cs @@ -21,7 +21,7 @@ namespace System.Xml.Tests XmlDocument doc = CreateDocumentWithElement(); XmlAttribute anotherDocumentAttr = new XmlDocument().CreateAttribute("attr"); XmlAttributeCollection target = doc.DocumentElement.Attributes; - Assert.Throws(() => target.Append(anotherDocumentAttr)); + AssertExtensions.Throws(null, () => target.Append(anotherDocumentAttr)); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/InsertAfterTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/InsertAfterTests.cs index d093dfd428a..3ca84f6334e 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/InsertAfterTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/InsertAfterTests.cs @@ -64,7 +64,7 @@ namespace System.Xml.Tests XmlAttribute anotherOwnerElementAttr = anotherElement.SetAttributeNode("anotherOwnerElementAttr", string.Empty); XmlAttributeCollection target = element.Attributes; - Assert.Throws(() => target.InsertAfter(newAttr, anotherOwnerElementAttr)); + AssertExtensions.Throws(null, () => target.InsertAfter(newAttr, anotherOwnerElementAttr)); } [Fact] @@ -77,7 +77,7 @@ namespace System.Xml.Tests XmlAttribute anotherOwnerDocumentAttr = new XmlDocument().CreateAttribute("anotherOwnerDocumentAttr"); XmlAttributeCollection target = element.Attributes; - Assert.Throws(() => target.InsertAfter(anotherOwnerDocumentAttr, existingAttr)); + AssertExtensions.Throws(null, () => target.InsertAfter(anotherOwnerDocumentAttr, existingAttr)); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/InsertBeforeTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/InsertBeforeTests.cs index 93a200743b5..738d066c999 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/InsertBeforeTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/InsertBeforeTests.cs @@ -64,7 +64,7 @@ namespace System.Xml.Tests XmlAttribute anotherOwnerElementAttr = anotherElement.SetAttributeNode("anotherOwnerElementAttr", string.Empty); XmlAttributeCollection target = element.Attributes; - Assert.Throws(() => target.InsertBefore(newAttr, anotherOwnerElementAttr)); + AssertExtensions.Throws(null, () => target.InsertBefore(newAttr, anotherOwnerElementAttr)); } [Fact] @@ -77,7 +77,7 @@ namespace System.Xml.Tests XmlAttribute anotherOwnerDocumentAttr = new XmlDocument().CreateAttribute("anotherOwnerDocumentAttr"); XmlAttributeCollection target = element.Attributes; - Assert.Throws(() => target.InsertBefore(anotherOwnerDocumentAttr, existingAttr)); + AssertExtensions.Throws(null, () => target.InsertBefore(anotherOwnerDocumentAttr, existingAttr)); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/PrependTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/PrependTests.cs index 9583338a01d..b354d2bd111 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/PrependTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/PrependTests.cs @@ -21,7 +21,7 @@ namespace System.Xml.Tests XmlDocument doc = CreateDocumentWithElement(); XmlAttribute anotherDocumentAttr = new XmlDocument().CreateAttribute("attr"); XmlAttributeCollection target = doc.DocumentElement.Attributes; - Assert.Throws(() => target.Prepend(anotherDocumentAttr)); + AssertExtensions.Throws(null, () => target.Prepend(anotherDocumentAttr)); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/SetNamedItemTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/SetNamedItemTests.cs index e262a759405..d13775ff13e 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/SetNamedItemTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlAttributeCollectionTests/SetNamedItemTests.cs @@ -31,7 +31,7 @@ namespace System.Xml.Tests XmlDocument doc = CreateDocumentWithElement(); XmlElement element = doc.DocumentElement; XmlAttributeCollection target = element.Attributes; - Assert.Throws(() => target.SetNamedItem(element)); + AssertExtensions.Throws(null, () => target.SetNamedItem(element)); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateCDataSectionTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateCDataSectionTests.cs index d8926ea504b..1cfc659ff41 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateCDataSectionTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateCDataSectionTests.cs @@ -38,7 +38,7 @@ namespace System.Xml.Tests var xmlDocument = new XmlDocument(); var cdata = xmlDocument.CreateCDataSection("]]>"); - Assert.Throws(() => { var test = cdata.OuterXml; }); + AssertExtensions.Throws(null, () => { var test = cdata.OuterXml; }); Assert.Equal(String.Empty, cdata.InnerXml); Assert.Equal("]]>", cdata.InnerText); Assert.Equal(XmlNodeType.CDATA, cdata.NodeType); diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateElementTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateElementTests.cs index d3247f6b8b4..06a1fb83f40 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateElementTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateElementTests.cs @@ -48,7 +48,7 @@ namespace System.Xml.Tests { var xmlDocument = new XmlDocument(); - Assert.Throws(() => xmlDocument.CreateElement(String.Empty)); + AssertExtensions.Throws(null, () => xmlDocument.CreateElement(String.Empty)); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateXmlDeclarationTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateXmlDeclarationTests.cs index 49f76615881..ea66dec3a80 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateXmlDeclarationTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlDocumentTests/CreateXmlDeclarationTests.cs @@ -51,7 +51,7 @@ namespace System.Xml.Tests { var xmlDocument = new XmlDocument(); - Assert.Throws(() => xmlDocument.CreateXmlDeclaration("3.0", "UTF-8", "yes")); + AssertExtensions.Throws(null, () => xmlDocument.CreateXmlDeclaration("3.0", "UTF-8", "yes")); } [Fact] @@ -66,7 +66,7 @@ namespace System.Xml.Tests { var xmlDocument = new XmlDocument(); - Assert.Throws(() => xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", "Wrong")); + AssertExtensions.Throws(null, () => xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", "Wrong")); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/AppendChildTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/AppendChildTests.cs index 4449afecaa1..cafbdf831c7 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/AppendChildTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/AppendChildTests.cs @@ -45,7 +45,7 @@ namespace System.Xml.Tests var xmlDocument2 = new XmlDocument(); xmlDocument2.LoadXml(""); - Assert.Throws(() => xmlDocument2.DocumentElement.AppendChild(xmlDocument1.DocumentElement)); + AssertExtensions.Throws(null, () => xmlDocument2.DocumentElement.AppendChild(xmlDocument1.DocumentElement)); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/NamespaceURITests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/NamespaceURITests.cs index 65406f85e53..262b592fade 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/NamespaceURITests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/NamespaceURITests.cs @@ -120,7 +120,7 @@ namespace System.Xml.Tests { var xmlDocument = new XmlDocument(); - Assert.Throws(() => xmlDocument.CreateAttribute("xmlns", "aa")); + AssertExtensions.Throws(null, () => xmlDocument.CreateAttribute("xmlns", "aa")); } } } diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/RemoveChildTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/RemoveChildTests.cs index 10fb9e94642..162111d8b4f 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/RemoveChildTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/RemoveChildTests.cs @@ -101,7 +101,7 @@ namespace System.Xml.Tests var child1 = xmlDocument.DocumentElement.ChildNodes[0]; var child2 = xmlDocument.DocumentElement.ChildNodes[1]; - Assert.Throws(() => child1.RemoveChild(child2)); + AssertExtensions.Throws(null, () => child1.RemoveChild(child2)); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/ReplaceChildTests.cs b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/ReplaceChildTests.cs index f33f497bf2d..c0de9ad3e52 100644 --- a/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/ReplaceChildTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlDocument/XmlNodeTests/ReplaceChildTests.cs @@ -79,7 +79,7 @@ namespace System.Xml.Tests var child2 = xmlDocument.DocumentElement.ChildNodes[1]; var newChild = xmlDocument.CreateElement("newElem"); - Assert.Throws(() => child1.ReplaceChild(newChild, child2)); + AssertExtensions.Throws(null, () => child1.ReplaceChild(newChild, child2)); } [Fact] @@ -93,7 +93,7 @@ namespace System.Xml.Tests var child1 = xmlDocument1.DocumentElement.ChildNodes[0]; var newChild = xmlDocument2.CreateElement("newChild"); - Assert.Throws(() => xmlDocument1.DocumentElement.ReplaceChild(newChild, child1)); + AssertExtensions.Throws(null, () => xmlDocument1.DocumentElement.ReplaceChild(newChild, child1)); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlSerializer/ReflectionOnly/System.Xml.XmlSerializer.ReflectionOnly.Tests.csproj b/src/libraries/System.Private.Xml/tests/XmlSerializer/ReflectionOnly/System.Xml.XmlSerializer.ReflectionOnly.Tests.csproj index 64a6facf545..1545b3e32ca 100644 --- a/src/libraries/System.Private.Xml/tests/XmlSerializer/ReflectionOnly/System.Xml.XmlSerializer.ReflectionOnly.Tests.csproj +++ b/src/libraries/System.Private.Xml/tests/XmlSerializer/ReflectionOnly/System.Xml.XmlSerializer.ReflectionOnly.Tests.csproj @@ -16,6 +16,9 @@ + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.Private.Xml/tests/XmlSerializer/System.Xml.XmlSerializer.Tests.csproj b/src/libraries/System.Private.Xml/tests/XmlSerializer/System.Xml.XmlSerializer.Tests.csproj index b3bc738f4ec..2db3899b2dd 100644 --- a/src/libraries/System.Private.Xml/tests/XmlSerializer/System.Xml.XmlSerializer.Tests.csproj +++ b/src/libraries/System.Private.Xml/tests/XmlSerializer/System.Xml.XmlSerializer.Tests.csproj @@ -14,6 +14,9 @@ + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs b/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs index e248c9e595c..e65bf7607f8 100644 --- a/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs +++ b/src/libraries/System.Private.Xml/tests/XmlSerializer/XmlSerializerTests.cs @@ -1737,7 +1737,7 @@ string.Format(@" attrs.XmlElements.Remove(item2); Assert.False(attrs.XmlElements.Contains(item2)); - Assert.Throws(() => { attrs.XmlElements.Remove(item2); }); + AssertExtensions.Throws(null, () => { attrs.XmlElements.Remove(item2); }); } [Fact] @@ -1769,7 +1769,7 @@ string.Format(@" attrs.XmlArrayItems.Remove(item2); Assert.False(attrs.XmlArrayItems.Contains(item2)); - Assert.Throws(() => { attrs.XmlArrayItems.Remove(item2); }); + AssertExtensions.Throws(null, () => { attrs.XmlArrayItems.Remove(item2); }); } [Fact] @@ -1801,7 +1801,7 @@ string.Format(@" attrs.XmlAnyElements.Remove(item2); Assert.False(attrs.XmlAnyElements.Contains(item2)); - Assert.Throws(() => { attrs.XmlAnyElements.Remove(item2); }); + AssertExtensions.Throws(null, () => { attrs.XmlAnyElements.Remove(item2); }); } [Fact] diff --git a/src/libraries/System.Private.Xml/tests/XmlWriter/System.Xml.RW.XmlWriter.Tests.csproj b/src/libraries/System.Private.Xml/tests/XmlWriter/System.Xml.RW.XmlWriter.Tests.csproj index eeb5cac4bea..1abf82be511 100644 --- a/src/libraries/System.Private.Xml/tests/XmlWriter/System.Xml.RW.XmlWriter.Tests.csproj +++ b/src/libraries/System.Private.Xml/tests/XmlWriter/System.Xml.RW.XmlWriter.Tests.csproj @@ -14,6 +14,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Private.Xml/tests/XmlWriter/WriteWithInvalidSurrogate.cs b/src/libraries/System.Private.Xml/tests/XmlWriter/WriteWithInvalidSurrogate.cs index ab9f21a365d..97eb11ddd21 100644 --- a/src/libraries/System.Private.Xml/tests/XmlWriter/WriteWithInvalidSurrogate.cs +++ b/src/libraries/System.Private.Xml/tests/XmlWriter/WriteWithInvalidSurrogate.cs @@ -29,7 +29,7 @@ namespace System.Xml.Tests writer.WriteStartElement("test"); char[] invalidSurrogatePair = new char[] { (char)(SurHighStart + 5), (char)(SurLowStart - 1) }; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { writer.WriteRaw(invalidSurrogatePair, 0, invalidSurrogatePair.Length); }); @@ -49,7 +49,7 @@ namespace System.Xml.Tests writer.WriteStartElement("test"); char[] invalidSurrogatePair = new char[] { (char)(SurHighStart + 5), (char)(SurLowEnd + 1) }; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { writer.WriteRaw(invalidSurrogatePair, 0, invalidSurrogatePair.Length); }); diff --git a/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_Assembly.cs b/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_Assembly.cs index 612f67884a1..437ed258b97 100644 --- a/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_Assembly.cs +++ b/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_Assembly.cs @@ -75,7 +75,7 @@ namespace System.Reflection.Tests attribute = CustomAttributeExtensions.GetCustomAttribute(thisAsm); Assert.Null(attribute); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { CustomAttributeExtensions.GetCustomAttributes(thisAsm, typeof(String)); }); diff --git a/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_MemberInfo.cs b/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_MemberInfo.cs index 806f582e2a2..9a58a1df4d4 100644 --- a/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_MemberInfo.cs +++ b/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_MemberInfo.cs @@ -25,7 +25,7 @@ namespace System.Reflection.Tests { Assert.True(CustomAttributeExtensions.IsDefined(s_typeTestClass.GetTypeInfo(), typeof(MyAttribute_Single_M))); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { CustomAttributeExtensions.IsDefined(s_typeTestClass.GetTypeInfo(), typeof(String)); }); @@ -93,7 +93,7 @@ namespace System.Reflection.Tests attribute = CustomAttributeExtensions.GetCustomAttribute(s_typeTestClass.GetTypeInfo(), typeof(MyAttribute_AllowMultiple_Inherited)); }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { attribute = CustomAttributeExtensions.GetCustomAttribute(s_typeTestClass.GetTypeInfo(), typeof(String)); }); @@ -113,7 +113,7 @@ namespace System.Reflection.Tests attributes = CustomAttributeExtensions.GetCustomAttributes(s_typeTestClass.GetTypeInfo(), typeof(SecurityCriticalAttribute)); Assert.Equal(0, attributes.Count()); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { attributes = CustomAttributeExtensions.GetCustomAttributes(s_typeTestClass.GetTypeInfo(), typeof(String)); }); diff --git a/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_ParamterInfo.cs b/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_ParamterInfo.cs index f044e892b8b..929d38e95d7 100644 --- a/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_ParamterInfo.cs +++ b/src/libraries/System.Reflection.Extensions/tests/GetCustomAttributes_ParamterInfo.cs @@ -32,7 +32,7 @@ namespace System.Reflection.Tests Assert.True(CustomAttributeExtensions.IsDefined(piWithAttributes, typeof(MyAttribute_Single_P))); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { CustomAttributeExtensions.IsDefined(piWithAttributes, typeof(String)); }); @@ -127,7 +127,7 @@ namespace System.Reflection.Tests attribute = CustomAttributeExtensions.GetCustomAttribute(piWithAttributes, typeof(MyAttribute_AllowMultiple_P)); }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { attribute = CustomAttributeExtensions.GetCustomAttribute(piWithAttributes, typeof(String)); }); @@ -167,7 +167,7 @@ namespace System.Reflection.Tests attributes = CustomAttributeExtensions.GetCustomAttributes(piWithAttributes, typeof(CLSCompliantAttribute)); Assert.Equal(0, attributes.Count()); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { attributes = CustomAttributeExtensions.GetCustomAttributes(piWithAttributes, typeof(String)); }); diff --git a/src/libraries/System.Reflection.Extensions/tests/System.Reflection.Extensions.Tests.csproj b/src/libraries/System.Reflection.Extensions/tests/System.Reflection.Extensions.Tests.csproj index e0d45e8fa09..4c5d443cdcb 100644 --- a/src/libraries/System.Reflection.Extensions/tests/System.Reflection.Extensions.Tests.csproj +++ b/src/libraries/System.Reflection.Extensions/tests/System.Reflection.Extensions.Tests.csproj @@ -20,6 +20,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/BlobContentIdTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/BlobContentIdTests.cs index 3c430ec5a48..7bb8686a644 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/BlobContentIdTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/BlobContentIdTests.cs @@ -79,8 +79,8 @@ namespace System.Reflection.Metadata.Tests Assert.Throws(() => BlobContentId.FromHash(default(ImmutableArray))); Assert.Throws(() => BlobContentId.FromHash(null)); - Assert.Throws(() => BlobContentId.FromHash(new byte[0])); - Assert.Throws(() => BlobContentId.FromHash(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 })); + AssertExtensions.Throws("hashCode", () => BlobContentId.FromHash(new byte[0])); + AssertExtensions.Throws("hashCode", () => BlobContentId.FromHash(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 })); } } } diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/CodedIndexTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/CodedIndexTests.cs index e5d252bd2c8..626691a58a2 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/CodedIndexTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/CodedIndexTests.cs @@ -13,21 +13,21 @@ namespace System.Reflection.Metadata.Ecma335.Tests { var badHandleKind = CustomAttributeHandle.FromRowId(1); - Assert.Throws(() => CodedIndex.HasCustomAttribute(badHandleKind)); - Assert.Throws(() => CodedIndex.HasConstant(badHandleKind)); - Assert.Throws(() => CodedIndex.CustomAttributeType(badHandleKind)); - Assert.Throws(() => CodedIndex.HasDeclSecurity(badHandleKind)); - Assert.Throws(() => CodedIndex.HasFieldMarshal(badHandleKind)); - Assert.Throws(() => CodedIndex.HasSemantics(badHandleKind)); - Assert.Throws(() => CodedIndex.Implementation(badHandleKind)); - Assert.Throws(() => CodedIndex.MemberForwarded(badHandleKind)); - Assert.Throws(() => CodedIndex.MemberRefParent(badHandleKind)); - Assert.Throws(() => CodedIndex.MethodDefOrRef(badHandleKind)); - Assert.Throws(() => CodedIndex.ResolutionScope(badHandleKind)); - Assert.Throws(() => CodedIndex.TypeDefOrRef(badHandleKind)); - Assert.Throws(() => CodedIndex.TypeDefOrRefOrSpec(badHandleKind)); - Assert.Throws(() => CodedIndex.TypeOrMethodDef(badHandleKind)); - Assert.Throws(() => CodedIndex.HasCustomDebugInformation(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.HasCustomAttribute(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.HasConstant(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.CustomAttributeType(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.HasDeclSecurity(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.HasFieldMarshal(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.HasSemantics(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.Implementation(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.MemberForwarded(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.MemberRefParent(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.MethodDefOrRef(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.ResolutionScope(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.TypeDefOrRef(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.TypeDefOrRefOrSpec(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.TypeOrMethodDef(badHandleKind)); + AssertExtensions.Throws(null, () => CodedIndex.HasCustomDebugInformation(badHandleKind)); } [Fact] diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/BlobEncodersTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/BlobEncodersTests.cs index 299c7f52cba..240cba947ba 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/BlobEncodersTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/BlobEncodersTests.cs @@ -575,7 +575,7 @@ namespace System.Reflection.Metadata.Ecma335.Tests AssertEx.Equal(new byte[] { 0x03, 0xED, 0xA0, 0x80 }, b.ToArray()); b.Clear(); - Assert.Throws(() => e.SystemType("")); + AssertExtensions.Throws("serializedTypeName", () => e.SystemType("")); } [Fact] @@ -626,7 +626,7 @@ namespace System.Reflection.Metadata.Ecma335.Tests b.Clear(); Assert.Throws(() => e.Name(null)); - Assert.Throws(() => e.Name("")); + AssertExtensions.Throws("name", () => e.Name("")); } [Fact] @@ -888,7 +888,7 @@ namespace System.Reflection.Metadata.Ecma335.Tests b.Clear(); Assert.Throws(() => e.Enum(null)); - Assert.Throws(() => e.Enum("")); + AssertExtensions.Throws("enumTypeName", () => e.Enum("")); } [Fact] @@ -1083,8 +1083,8 @@ namespace System.Reflection.Metadata.Ecma335.Tests AssertEx.Equal(new byte[] { 0x12, 0x05 }, b.ToArray()); b.Clear(); - Assert.Throws(() => e.Type(MetadataTokens.TypeSpecificationHandle(1), isValueType: false)); - Assert.Throws(() => e.Type(default(EntityHandle), isValueType: false)); + AssertExtensions.Throws(null, () => e.Type(MetadataTokens.TypeSpecificationHandle(1), isValueType: false)); + AssertExtensions.Throws(null, () => e.Type(default(EntityHandle), isValueType: false)); Assert.Equal(0, b.Count); } @@ -1118,7 +1118,7 @@ namespace System.Reflection.Metadata.Ecma335.Tests AssertEx.Equal(new byte[] { 0x1B, 0x00 }, b.ToArray()); b.Clear(); - Assert.Throws(() => e.FunctionPointer(0, (FunctionPointerAttributes)1000, genericParameterCount: 0)); + AssertExtensions.Throws("attributes", () => e.FunctionPointer(0, (FunctionPointerAttributes)1000, genericParameterCount: 0)); Assert.Throws(() => e.FunctionPointer(0, 0, genericParameterCount: -1)); Assert.Throws(() => e.FunctionPointer(0, 0, genericParameterCount: ushort.MaxValue + 1)); Assert.Equal(0, b.Count); @@ -1148,8 +1148,8 @@ namespace System.Reflection.Metadata.Ecma335.Tests AssertEx.Equal(new byte[] { 0x15, 0x12, 0x04, 0xC0, 0x00, 0xFF, 0xFF }, b.ToArray()); b.Clear(); - Assert.Throws(() => e.GenericInstantiation(MetadataTokens.TypeSpecificationHandle(1), 1, isValueType: false)); - Assert.Throws(() => e.GenericInstantiation(default(EntityHandle), 1, isValueType: false)); + AssertExtensions.Throws(null, () => e.GenericInstantiation(MetadataTokens.TypeSpecificationHandle(1), 1, isValueType: false)); + AssertExtensions.Throws(null, () => e.GenericInstantiation(default(EntityHandle), 1, isValueType: false)); Assert.Throws(() => e.GenericInstantiation(default(TypeDefinitionHandle), 0, true)); Assert.Throws(() => e.GenericInstantiation(default(TypeDefinitionHandle), -1, true)); Assert.Throws(() => e.GenericInstantiation(default(TypeDefinitionHandle), ushort.MaxValue + 1, true)); @@ -1263,11 +1263,11 @@ namespace System.Reflection.Metadata.Ecma335.Tests AssertEx.Equal(new byte[] { 0x1f, 0x06 }, b.ToArray()); b.Clear(); - Assert.Throws(() => e.AddModifier(default(EntityHandle), true)); - Assert.Throws(() => e.AddModifier(default(TypeDefinitionHandle), true)); - Assert.Throws(() => e.AddModifier(default(TypeReferenceHandle), true)); - Assert.Throws(() => e.AddModifier(default(TypeSpecificationHandle), true)); - Assert.Throws(() => e.AddModifier(MetadataTokens.FieldDefinitionHandle(1), true)); + AssertExtensions.Throws("type", () => e.AddModifier(default(EntityHandle), true)); + AssertExtensions.Throws("type", () => e.AddModifier(default(TypeDefinitionHandle), true)); + AssertExtensions.Throws("type", () => e.AddModifier(default(TypeReferenceHandle), true)); + AssertExtensions.Throws("type", () => e.AddModifier(default(TypeSpecificationHandle), true)); + AssertExtensions.Throws(null, () => e.AddModifier(MetadataTokens.FieldDefinitionHandle(1), true)); } [Fact] diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/ControlFlowBuilderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/ControlFlowBuilderTests.cs index 4ca7924c15b..eb0debf6faa 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/ControlFlowBuilderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/ControlFlowBuilderTests.cs @@ -189,18 +189,18 @@ namespace System.Reflection.Metadata.Ecma335.Tests il.OpCode(ILOpCode.Nop); il.MarkLabel(l5); - Assert.Throws(() => flow.AddCatchRegion(l1, l2, l3, l4, default(TypeDefinitionHandle))); - Assert.Throws(() => flow.AddCatchRegion(l1, l2, l3, l4, MetadataTokens.MethodDefinitionHandle(1))); + AssertExtensions.Throws("catchType", () => flow.AddCatchRegion(l1, l2, l3, l4, default(TypeDefinitionHandle))); + AssertExtensions.Throws("catchType", () => flow.AddCatchRegion(l1, l2, l3, l4, MetadataTokens.MethodDefinitionHandle(1))); Assert.Throws(() => flow.AddCatchRegion(default(LabelHandle), l2, l3, l4, MetadataTokens.TypeReferenceHandle(1))); Assert.Throws(() => flow.AddCatchRegion(l1, default(LabelHandle), l3, l4, MetadataTokens.TypeReferenceHandle(1))); Assert.Throws(() => flow.AddCatchRegion(l1, l2, default(LabelHandle), l4, MetadataTokens.TypeReferenceHandle(1))); Assert.Throws(() => flow.AddCatchRegion(l1, l2, l3, default(LabelHandle), MetadataTokens.TypeReferenceHandle(1))); - Assert.Throws(() => flow.AddCatchRegion(lx, l2, l3, l4, MetadataTokens.TypeReferenceHandle(1))); - Assert.Throws(() => flow.AddCatchRegion(l1, lx, l3, l4, MetadataTokens.TypeReferenceHandle(1))); - Assert.Throws(() => flow.AddCatchRegion(l1, l2, lx, l4, MetadataTokens.TypeReferenceHandle(1))); - Assert.Throws(() => flow.AddCatchRegion(l1, l2, l3, lx, MetadataTokens.TypeReferenceHandle(1))); + AssertExtensions.Throws("tryStart", () => flow.AddCatchRegion(lx, l2, l3, l4, MetadataTokens.TypeReferenceHandle(1))); + AssertExtensions.Throws("tryEnd", () => flow.AddCatchRegion(l1, lx, l3, l4, MetadataTokens.TypeReferenceHandle(1))); + AssertExtensions.Throws("handlerStart", () => flow.AddCatchRegion(l1, l2, lx, l4, MetadataTokens.TypeReferenceHandle(1))); + AssertExtensions.Throws("handlerEnd", () => flow.AddCatchRegion(l1, l2, l3, lx, MetadataTokens.TypeReferenceHandle(1))); } [Fact] diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/ExceptionRegionEncoderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/ExceptionRegionEncoderTests.cs index 567b51c140d..b5f40578ce2 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/ExceptionRegionEncoderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/ExceptionRegionEncoderTests.cs @@ -207,8 +207,8 @@ namespace System.Reflection.Metadata.Ecma335.Tests Assert.Throws(() => fatEncoder.Add((ExceptionRegionKind)5, 1, 2, 4, 5)); Assert.Throws(() => fatEncoder.Add(ExceptionRegionKind.Filter, 1, 2, 4, 5, filterOffset: -1)); - Assert.Throws(() => fatEncoder.Add(ExceptionRegionKind.Catch, 1, 2, 4, 5, catchType: default(EntityHandle))); - Assert.Throws(() => fatEncoder.Add(ExceptionRegionKind.Catch, 1, 2, 4, 5, catchType: MetadataTokens.ImportScopeHandle(1))); + AssertExtensions.Throws("catchType", () => fatEncoder.Add(ExceptionRegionKind.Catch, 1, 2, 4, 5, catchType: default(EntityHandle))); + AssertExtensions.Throws("catchType", () => fatEncoder.Add(ExceptionRegionKind.Catch, 1, 2, 4, 5, catchType: MetadataTokens.ImportScopeHandle(1))); } } } diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/InstructionEncoderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/InstructionEncoderTests.cs index 8e5ac18a45e..76ae0a4f820 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/InstructionEncoderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/InstructionEncoderTests.cs @@ -494,10 +494,10 @@ namespace System.Reflection.Metadata.Ecma335.Tests Assert.Throws(() => ilcf1.Branch(ILOpCode.Br, default(LabelHandle))); Assert.Throws(() => ilcf1.MarkLabel(default(LabelHandle))); - Assert.Throws(() => ilcf1.Branch(ILOpCode.Br, l2)); - Assert.Throws(() => ilcf1.MarkLabel(l2)); + AssertExtensions.Throws("label", () => ilcf1.Branch(ILOpCode.Br, l2)); + AssertExtensions.Throws("label", () => ilcf1.MarkLabel(l2)); - Assert.Throws(() => ilcf1.Branch(ILOpCode.Box, l1)); + AssertExtensions.Throws("opCode", () => ilcf1.Branch(ILOpCode.Box, l1)); } [Fact] diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/MethodBodyStreamEncoderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/MethodBodyStreamEncoderTests.cs index 0de8f1137ea..36ecfade226 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/MethodBodyStreamEncoderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/Encoding/MethodBodyStreamEncoderTests.cs @@ -444,9 +444,9 @@ namespace System.Reflection.Metadata.Ecma335.Tests il = new InstructionEncoder(codeBuilder, flowBuilder); var l0 = il.DefineLabel(); - Assert.Throws(() => il.Branch(ILOpCode.Nop, l0)); + AssertExtensions.Throws("opCode", () => il.Branch(ILOpCode.Nop, l0)); Assert.Throws(() => il.Branch(ILOpCode.Br, default(LabelHandle))); - Assert.Throws(() => il.Branch(ILOpCode.Br, l2)); + AssertExtensions.Throws("label", () => il.Branch(ILOpCode.Br, l2)); } [Fact] diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataAggregatorTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataAggregatorTests.cs index b457efb6326..e6374934158 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataAggregatorTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataAggregatorTests.cs @@ -120,7 +120,7 @@ namespace System.Reflection.Metadata.Ecma335.Tests TestGenerationHandle(aggregator, MetadataTokens.Handle(0x1800003a), expectedHandle: MetadataTokens.Handle(0x18000002), expectedGeneration: 3); - Assert.Throws(() => TestGenerationHandle(aggregator, MetadataTokens.Handle(0x11000032), expectedHandle: MetadataTokens.Handle(0x00000000), expectedGeneration: 0)); + AssertExtensions.Throws("handle", () => TestGenerationHandle(aggregator, MetadataTokens.Handle(0x11000032), expectedHandle: MetadataTokens.Handle(0x00000000), expectedGeneration: 0)); } [Fact] @@ -170,7 +170,7 @@ namespace System.Reflection.Metadata.Ecma335.Tests TestGenerationHandle(aggregator, MetadataTokens.UserStringHandle(12), expectedHandle: MetadataTokens.UserStringHandle(2), expectedGeneration: 2); TestGenerationHandle(aggregator, MetadataTokens.StringHandle(0), expectedHandle: MetadataTokens.StringHandle(0), expectedGeneration: 2); - Assert.Throws(() => TestGenerationHandle(aggregator, MetadataTokens.StringHandle(22), expectedHandle: MetadataTokens.StringHandle(0), expectedGeneration: 0)); + AssertExtensions.Throws("handle", () => TestGenerationHandle(aggregator, MetadataTokens.StringHandle(22), expectedHandle: MetadataTokens.StringHandle(0), expectedGeneration: 0)); } } } diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataBuilderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataBuilderTests.cs index c50c61ea7c9..ea3eb43d0f6 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataBuilderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataBuilderTests.cs @@ -18,7 +18,7 @@ namespace System.Reflection.Metadata.Ecma335.Tests Assert.Throws(() => new MetadataBuilder(0, -1)); Assert.Throws(() => new MetadataBuilder(0, 0, -1)); Assert.Throws(() => new MetadataBuilder(0, 0, 0, -1)); - Assert.Throws(() => new MetadataBuilder(0, 0, 0, 1)); + AssertExtensions.Throws("guidHeapStartOffset", () => new MetadataBuilder(0, 0, 0, 1)); new MetadataBuilder(userStringHeapStartOffset: 0x00fffffe); Assert.Throws(() => new MetadataBuilder(userStringHeapStartOffset: 0x00ffffff)); @@ -214,25 +214,25 @@ namespace System.Reflection.Metadata.Ecma335.Tests Assert.Throws(() => builder.AddAssembly(default(StringHandle), null, default(StringHandle), default(BlobHandle), 0, 0)); Assert.Throws(() => builder.AddAssemblyReference(default(StringHandle), null, default(StringHandle), default(BlobHandle), 0, default(BlobHandle))); - Assert.Throws(() => builder.AddTypeDefinition(0, default(StringHandle), default(StringHandle), badHandleKind, default(FieldDefinitionHandle), default(MethodDefinitionHandle))); - Assert.Throws(() => builder.AddInterfaceImplementation(default(TypeDefinitionHandle), badHandleKind)); - Assert.Throws(() => builder.AddTypeReference(badHandleKind, default(StringHandle), default(StringHandle))); - Assert.Throws(() => builder.AddEvent(0, default(StringHandle), badHandleKind)); - Assert.Throws(() => builder.AddConstant(badHandleKind, 0)); - Assert.Throws(() => builder.AddMethodSemantics(badHandleKind, 0, default(MethodDefinitionHandle))); - Assert.Throws(() => builder.AddCustomAttribute(badHandleKind, default(MethodDefinitionHandle), default(BlobHandle))); - Assert.Throws(() => builder.AddCustomAttribute(default(TypeDefinitionHandle), badHandleKind, default(BlobHandle))); - Assert.Throws(() => builder.AddMethodSpecification(badHandleKind, default(BlobHandle))); - Assert.Throws(() => builder.AddGenericParameter(badHandleKind, 0, default(StringHandle), 0)); - Assert.Throws(() => builder.AddGenericParameterConstraint(default(GenericParameterHandle), badHandleKind)); - Assert.Throws(() => builder.AddMarshallingDescriptor(badHandleKind, default(BlobHandle))); - Assert.Throws(() => builder.AddMethodImplementation(default(TypeDefinitionHandle), badHandleKind, default(MethodDefinitionHandle))); - Assert.Throws(() => builder.AddMethodImplementation(default(TypeDefinitionHandle), default(MethodDefinitionHandle), badHandleKind)); - Assert.Throws(() => builder.AddMemberReference(badHandleKind, default(StringHandle), default(BlobHandle))); - Assert.Throws(() => builder.AddManifestResource(0, default(StringHandle), badHandleKind, 0)); - Assert.Throws(() => builder.AddExportedType(0, default(StringHandle), default(StringHandle), badHandleKind, 0)); - Assert.Throws(() => builder.AddDeclarativeSecurityAttribute(badHandleKind, 0, default(BlobHandle))); - Assert.Throws(() => builder.AddCustomDebugInformation(badHandleKind, default(GuidHandle), default(BlobHandle))); + AssertExtensions.Throws(null, () => builder.AddTypeDefinition(0, default(StringHandle), default(StringHandle), badHandleKind, default(FieldDefinitionHandle), default(MethodDefinitionHandle))); + AssertExtensions.Throws(null, () => builder.AddInterfaceImplementation(default(TypeDefinitionHandle), badHandleKind)); + AssertExtensions.Throws(null, () => builder.AddTypeReference(badHandleKind, default(StringHandle), default(StringHandle))); + AssertExtensions.Throws(null, () => builder.AddEvent(0, default(StringHandle), badHandleKind)); + AssertExtensions.Throws(null, () => builder.AddConstant(badHandleKind, 0)); + AssertExtensions.Throws(null, () => builder.AddMethodSemantics(badHandleKind, 0, default(MethodDefinitionHandle))); + AssertExtensions.Throws(null, () => builder.AddCustomAttribute(badHandleKind, default(MethodDefinitionHandle), default(BlobHandle))); + AssertExtensions.Throws(null, () => builder.AddCustomAttribute(default(TypeDefinitionHandle), badHandleKind, default(BlobHandle))); + AssertExtensions.Throws(null, () => builder.AddMethodSpecification(badHandleKind, default(BlobHandle))); + AssertExtensions.Throws(null, () => builder.AddGenericParameter(badHandleKind, 0, default(StringHandle), 0)); + AssertExtensions.Throws(null, () => builder.AddGenericParameterConstraint(default(GenericParameterHandle), badHandleKind)); + AssertExtensions.Throws(null, () => builder.AddMarshallingDescriptor(badHandleKind, default(BlobHandle))); + AssertExtensions.Throws(null, () => builder.AddMethodImplementation(default(TypeDefinitionHandle), badHandleKind, default(MethodDefinitionHandle))); + AssertExtensions.Throws(null, () => builder.AddMethodImplementation(default(TypeDefinitionHandle), default(MethodDefinitionHandle), badHandleKind)); + AssertExtensions.Throws(null, () => builder.AddMemberReference(badHandleKind, default(StringHandle), default(BlobHandle))); + AssertExtensions.Throws(null, () => builder.AddManifestResource(0, default(StringHandle), badHandleKind, 0)); + AssertExtensions.Throws(null, () => builder.AddExportedType(0, default(StringHandle), default(StringHandle), badHandleKind, 0)); + AssertExtensions.Throws(null, () => builder.AddDeclarativeSecurityAttribute(badHandleKind, 0, default(BlobHandle))); + AssertExtensions.Throws(null, () => builder.AddCustomDebugInformation(badHandleKind, default(GuidHandle), default(BlobHandle))); Assert.Throws(() => builder.AddModule(-1, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle))); Assert.Throws(() => builder.AddModule(ushort.MaxValue + 1, default(StringHandle), default(GuidHandle), default(GuidHandle), default(GuidHandle))); diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataRootBuilderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataRootBuilderTests.cs index b71aea027f0..b6c05bce30e 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataRootBuilderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataRootBuilderTests.cs @@ -24,7 +24,7 @@ namespace System.Reflection.Metadata.Ecma335.Tests var mdBuilder = new MetadataBuilder(); Assert.Throws(() => new MetadataRootBuilder(null)); - Assert.Throws(() => new MetadataRootBuilder(mdBuilder, new string('x', 255))); + AssertExtensions.Throws("metadataVersion", () => new MetadataRootBuilder(mdBuilder, new string('x', 255))); } [Fact] diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataTokensTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataTokensTests.cs index 6ed4966aaa0..0e2157cdb27 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataTokensTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/MetadataTokensTests.cs @@ -59,8 +59,8 @@ namespace System.Reflection.Metadata.Ecma335.Tests Assert.Equal(1, MetadataTokens.GetHeapOffset(s_writerGuidHandle)); Assert.Equal(1, MetadataTokens.GetHeapOffset((GuidHandle)s_writerGuidHandle)); - Assert.Throws(() => MetadataTokens.GetHeapOffset(s_assemblyRefHandle)); - Assert.Throws(() => MetadataTokens.GetHeapOffset(s_virtualAssemblyRefHandle)); + AssertExtensions.Throws("handle", () => MetadataTokens.GetHeapOffset(s_assemblyRefHandle)); + AssertExtensions.Throws("handle", () => MetadataTokens.GetHeapOffset(s_virtualAssemblyRefHandle)); } [Fact] @@ -73,11 +73,11 @@ namespace System.Reflection.Metadata.Ecma335.Tests Assert.Equal(0, MetadataTokens.GetToken(s_virtualAssemblyRefHandle)); Assert.Equal(0x70000001, MetadataTokens.GetToken(s_userStringHandle)); - Assert.Throws(() => MetadataTokens.GetToken(s_virtualBlobHandle)); - Assert.Throws(() => MetadataTokens.GetToken(s_stringHandle)); - Assert.Throws(() => MetadataTokens.GetToken(s_winrtPrefixedStringHandle)); - Assert.Throws(() => MetadataTokens.GetToken(s_blobHandle)); - Assert.Throws(() => MetadataTokens.GetToken(s_guidHandle)); + AssertExtensions.Throws("handle", () => MetadataTokens.GetToken(s_virtualBlobHandle)); + AssertExtensions.Throws("handle", () => MetadataTokens.GetToken(s_stringHandle)); + AssertExtensions.Throws("handle", () => MetadataTokens.GetToken(s_winrtPrefixedStringHandle)); + AssertExtensions.Throws("handle", () => MetadataTokens.GetToken(s_blobHandle)); + AssertExtensions.Throws("handle", () => MetadataTokens.GetToken(s_guidHandle)); } [Fact] @@ -183,14 +183,14 @@ namespace System.Reflection.Metadata.Ecma335.Tests Assert.Equal(s_userStringHandle, MetadataTokens.Handle(0x70000001)); Assert.Equal(s_exportedTypeHandle, MetadataTokens.ExportedTypeHandle((int)(TokenTypeIds.ExportedType | s_exportedTypeHandle.RowId))); - Assert.Throws(() => MetadataTokens.Handle(-1)); - Assert.Throws(() => MetadataTokens.Handle(0x71000001)); - Assert.Throws(() => MetadataTokens.Handle(0x72000001)); - Assert.Throws(() => MetadataTokens.Handle(0x73000001)); - Assert.Throws(() => MetadataTokens.Handle(0x74000001)); - Assert.Throws(() => MetadataTokens.Handle(0x7a000001)); - Assert.Throws(() => MetadataTokens.Handle(0x7e000001)); - Assert.Throws(() => MetadataTokens.Handle(0x7fffffff)); + AssertExtensions.Throws("token", () => MetadataTokens.Handle(-1)); + AssertExtensions.Throws("token", () => MetadataTokens.Handle(0x71000001)); + AssertExtensions.Throws("token", () => MetadataTokens.Handle(0x72000001)); + AssertExtensions.Throws("token", () => MetadataTokens.Handle(0x73000001)); + AssertExtensions.Throws("token", () => MetadataTokens.Handle(0x74000001)); + AssertExtensions.Throws("token", () => MetadataTokens.Handle(0x7a000001)); + AssertExtensions.Throws("token", () => MetadataTokens.Handle(0x7e000001)); + AssertExtensions.Throws("token", () => MetadataTokens.Handle(0x7fffffff)); } [Fact] diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/PortablePdbBuilderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/PortablePdbBuilderTests.cs index 34a7def57c6..fdfc9ece332 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/PortablePdbBuilderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/Ecma335/PortablePdbBuilderTests.cs @@ -20,19 +20,19 @@ namespace System.Reflection.Metadata.Ecma335.Tests var rowCounts = new int[128]; rowCounts[64] = 1; - Assert.Throws(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle))); + AssertExtensions.Throws("typeSystemRowCounts", () => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle))); rowCounts = new int[64]; rowCounts[63] = 1; - Assert.Throws(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle))); + AssertExtensions.Throws("typeSystemRowCounts", () => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle))); rowCounts = new int[64]; rowCounts[(int)TableIndex.EventPtr] = 1; - Assert.Throws(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle))); + AssertExtensions.Throws("typeSystemRowCounts", () => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle))); rowCounts = new int[64]; rowCounts[(int)TableIndex.CustomDebugInformation] = 1; - Assert.Throws(() => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle))); + AssertExtensions.Throws("typeSystemRowCounts", () => new PortablePdbBuilder(mdBuilder, ImmutableArray.Create(rowCounts), default(MethodDefinitionHandle))); rowCounts = new int[64]; rowCounts[(int)TableIndex.MethodDef] = -1; diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderProviderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderProviderTests.cs index 8bcb8208046..22c2df4092b 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderProviderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderProviderTests.cs @@ -66,8 +66,8 @@ namespace System.Reflection.Metadata.Tests [Fact] public void FromMetadataStream2() { - Assert.Throws(() => MetadataReaderProvider.FromMetadataStream(new CustomAccessMemoryStream(canRead: false, canSeek: false, canWrite: false))); - Assert.Throws(() => MetadataReaderProvider.FromMetadataStream(new CustomAccessMemoryStream(canRead: true, canSeek: false, canWrite: false))); + AssertExtensions.Throws("stream", () => MetadataReaderProvider.FromMetadataStream(new CustomAccessMemoryStream(canRead: false, canSeek: false, canWrite: false))); + AssertExtensions.Throws("stream", () => MetadataReaderProvider.FromMetadataStream(new CustomAccessMemoryStream(canRead: true, canSeek: false, canWrite: false))); MetadataReaderProvider.FromMetadataStream(new CustomAccessMemoryStream(canRead: true, canSeek: true, canWrite: false)); } diff --git a/src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderTests.cs b/src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderTests.cs index ee99dc845ec..16133431b86 100644 --- a/src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/Metadata/MetadataReaderTests.cs @@ -130,8 +130,7 @@ namespace System.Reflection.Metadata.Tests public void CannotInstantiateReaderWithNonUtf8Decoder() { var decoder = new MetadataStringDecoder(Encoding.ASCII); - var exception = Assert.Throws(() => GetMetadataReader(Misc.Members, decoder: decoder)); - Assert.Equal("utf8Decoder", exception.ParamName); + AssertExtensions.Throws("utf8Decoder", () => GetMetadataReader(Misc.Members, decoder: decoder)); } [Fact] diff --git a/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/DebugDirectoryBuilderTests.cs b/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/DebugDirectoryBuilderTests.cs index e50235da50d..62638b6cf3a 100644 --- a/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/DebugDirectoryBuilderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/DebugDirectoryBuilderTests.cs @@ -29,9 +29,9 @@ namespace System.Reflection.PortableExecutable.Tests public void AddCodeViewEntry_Args() { var builder = new DebugDirectoryBuilder(); - Assert.Throws(() => builder.AddCodeViewEntry("", default(BlobContentId), 0x0100)); - Assert.Throws(() => builder.AddCodeViewEntry("\0", default(BlobContentId), 0x0100)); - Assert.Throws(() => builder.AddCodeViewEntry("\0xx", default(BlobContentId), 0x0100)); + AssertExtensions.Throws("pdbPath", () => builder.AddCodeViewEntry("", default(BlobContentId), 0x0100)); + AssertExtensions.Throws("pdbPath", () => builder.AddCodeViewEntry("\0", default(BlobContentId), 0x0100)); + AssertExtensions.Throws("pdbPath", () => builder.AddCodeViewEntry("\0xx", default(BlobContentId), 0x0100)); Assert.Throws(() => builder.AddCodeViewEntry("xx", default(BlobContentId), 0x0100, int.MinValue)); Assert.Throws(() => builder.AddCodeViewEntry("xx", default(BlobContentId), 0x0100, -1)); Assert.Throws(() => builder.AddCodeViewEntry("xx", default(BlobContentId), 0x0100, 0)); diff --git a/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/PEHeadersTests.cs b/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/PEHeadersTests.cs index 0cbfdde042c..00813631abc 100644 --- a/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/PEHeadersTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/PEHeadersTests.cs @@ -29,8 +29,8 @@ namespace System.Reflection.PortableExecutable.Tests [Fact] public void Ctor_Streams() { - Assert.Throws(() => new PEHeaders(new CustomAccessMemoryStream(canRead: false, canSeek: false, canWrite: false))); - Assert.Throws(() => new PEHeaders(new CustomAccessMemoryStream(canRead: true, canSeek: false, canWrite: false))); + AssertExtensions.Throws("peStream", () => new PEHeaders(new CustomAccessMemoryStream(canRead: false, canSeek: false, canWrite: false))); + AssertExtensions.Throws("peStream", () => new PEHeaders(new CustomAccessMemoryStream(canRead: true, canSeek: false, canWrite: false))); var s = new CustomAccessMemoryStream(canRead: true, canSeek: true, canWrite: false, buffer: Misc.Members); diff --git a/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/PEReaderTests.cs b/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/PEReaderTests.cs index 2155c308bd9..d385aadcce6 100644 --- a/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/PEReaderTests.cs +++ b/src/libraries/System.Reflection.Metadata/tests/PortableExecutable/PEReaderTests.cs @@ -55,8 +55,8 @@ namespace System.Reflection.PortableExecutable.Tests [Fact] public void Ctor_Streams() { - Assert.Throws(() => new PEReader(new CustomAccessMemoryStream(canRead: false, canSeek: false, canWrite: false))); - Assert.Throws(() => new PEReader(new CustomAccessMemoryStream(canRead: true, canSeek: false, canWrite: false))); + AssertExtensions.Throws("peStream", () => new PEReader(new CustomAccessMemoryStream(canRead: false, canSeek: false, canWrite: false))); + AssertExtensions.Throws("peStream", () => new PEReader(new CustomAccessMemoryStream(canRead: true, canSeek: false, canWrite: false))); var s = new CustomAccessMemoryStream(canRead: true, canSeek: true, canWrite: false); @@ -756,7 +756,7 @@ namespace System.Reflection.PortableExecutable.Tests string pdbPath; // pass-thru: - Assert.Throws(() => + AssertExtensions.Throws(null, () => reader.TryOpenAssociatedPortablePdb(Path.Combine("pedir", "file.exe"), _ => { throw new ArgumentException(); }, out pdbProvider, out pdbPath)); Assert.Throws(() => diff --git a/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs b/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs index 57ca18c1e43..5bc838ff53e 100644 --- a/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs +++ b/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs @@ -140,7 +140,7 @@ namespace System.Reflection.Tests public void Invoke_ParameterWrongType_ThrowsArgumentException() { ConstructorInfo[] constructors = GetConstructors(typeof(ClassWith3Constructors)); - Assert.Throws(() => (ClassWith3Constructors)constructors[1].Invoke(new object[] { "hello" })); + AssertExtensions.Throws(null, () => (ClassWith3Constructors)constructors[1].Invoke(new object[] { "hello" })); } [Fact] diff --git a/src/libraries/System.Reflection/tests/FieldInfoTests.cs b/src/libraries/System.Reflection/tests/FieldInfoTests.cs index 8fa34f7ae88..2611c6362e5 100644 --- a/src/libraries/System.Reflection/tests/FieldInfoTests.cs +++ b/src/libraries/System.Reflection/tests/FieldInfoTests.cs @@ -314,9 +314,9 @@ namespace System.Reflection.Tests object obj = Activator.CreateInstance(type); FieldInfo fieldInfo = GetField(type, "bArray"); - Assert.Throws(() => fieldInfo.SetValue(obj, ATypeWithMixedAB)); - Assert.Throws(() => fieldInfo.SetValue(obj, ATypeWithAllA)); - Assert.Throws(() => fieldInfo.SetValue(obj, ATypeWithAllB)); + AssertExtensions.Throws(null, () => fieldInfo.SetValue(obj, ATypeWithMixedAB)); + AssertExtensions.Throws(null, () => fieldInfo.SetValue(obj, ATypeWithAllA)); + AssertExtensions.Throws(null, () => fieldInfo.SetValue(obj, ATypeWithAllB)); fieldInfo.SetValue(obj, BTypeWithAllB); Assert.Equal(BTypeWithAllB, fieldInfo.GetValue(obj)); @@ -348,7 +348,7 @@ namespace System.Reflection.Tests fieldInfo.SetValue(obj, intArray); Assert.Equal(intArray, fieldInfo.GetValue(obj)); - Assert.Throws(() => fieldInfo.SetValue(obj, new byte[] { 2, 3, 4 })); + AssertExtensions.Throws(null, () => fieldInfo.SetValue(obj, new byte[] { 2, 3, 4 })); } [Fact] @@ -366,8 +366,8 @@ namespace System.Reflection.Tests fieldInfo.SetValue(obj, BTypeWithAllB_Contra); Assert.Equal(BTypeWithAllB_Contra, fieldInfo.GetValue(obj)); - Assert.Throws(() => fieldInfo.SetValue(obj, new int[] { 1, -1, 2, -2 })); - Assert.Throws(() => fieldInfo.SetValue(obj, new byte[] { 2, 3, 4 })); + AssertExtensions.Throws(null, () => fieldInfo.SetValue(obj, new int[] { 1, -1, 2, -2 })); + AssertExtensions.Throws(null, () => fieldInfo.SetValue(obj, new byte[] { 2, 3, 4 })); } public static IEnumerable FieldInfoRTGenericTests_TestData() diff --git a/src/libraries/System.Reflection/tests/GetTypeTests.cs b/src/libraries/System.Reflection/tests/GetTypeTests.cs index 4468dba7282..3d87ff5318d 100644 --- a/src/libraries/System.Reflection/tests/GetTypeTests.cs +++ b/src/libraries/System.Reflection/tests/GetTypeTests.cs @@ -26,7 +26,7 @@ namespace System.Reflection.Tests Assert.Null(Type.GetType(aqn, throwOnError: false)); Assert.Throws(() => Type.GetType(typeName, throwOnError: true)); - Assert.Throws(() => Type.GetType(aqn, throwOnError: true)); + AssertExtensions.Throws("typeName@0", () => Type.GetType(aqn, throwOnError: true)); Assert.Null(Type.GetType(typeName, throwOnError: false, ignoreCase: false)); Assert.Null(Type.GetType(typeName, throwOnError: false, ignoreCase: true)); @@ -35,33 +35,33 @@ namespace System.Reflection.Tests Assert.Throws(() => Type.GetType(typeName, throwOnError: true, ignoreCase: false)); Assert.Throws(() => Type.GetType(typeName, throwOnError: true, ignoreCase: true)); - Assert.Throws(() => Type.GetType(aqn, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => Type.GetType(aqn, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws("typeName@0", () => Type.GetType(aqn, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws("typeName@0", () => Type.GetType(aqn, throwOnError: true, ignoreCase: true)); // Assembly.GetType - Assert.Throws(() => a.GetType(typeName)); + AssertExtensions.Throws(null, () => a.GetType(typeName)); Assert.Null(a.GetType(aqn)); - Assert.Throws(() => a.GetType(typeName, throwOnError: false, ignoreCase: false)); - Assert.Throws(() => a.GetType(typeName, throwOnError: false, ignoreCase: true)); + AssertExtensions.Throws(null, () => a.GetType(typeName, throwOnError: false, ignoreCase: false)); + AssertExtensions.Throws(null, () => a.GetType(typeName, throwOnError: false, ignoreCase: true)); Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: false)); Assert.Null(a.GetType(aqn, throwOnError: false, ignoreCase: true)); - Assert.Throws(() => a.GetType(typeName, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => a.GetType(typeName, throwOnError: true, ignoreCase: true)); - Assert.Throws(() => a.GetType(aqn, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => a.GetType(aqn, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws(null, () => a.GetType(typeName, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws(null, () => a.GetType(typeName, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws("typeName@0", () => a.GetType(aqn, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws("typeName@0", () => a.GetType(aqn, throwOnError: true, ignoreCase: true)); // Module.GetType - Assert.Throws(() => m.GetType(typeName, throwOnError: false, ignoreCase: false)); - Assert.Throws(() => m.GetType(typeName, throwOnError: false, ignoreCase: true)); + AssertExtensions.Throws(null, () => m.GetType(typeName, throwOnError: false, ignoreCase: false)); + AssertExtensions.Throws(null, () => m.GetType(typeName, throwOnError: false, ignoreCase: true)); Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: false)); Assert.Null(m.GetType(aqn, throwOnError: false, ignoreCase: true)); - Assert.Throws(() => m.GetType(typeName, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => m.GetType(typeName, throwOnError: true, ignoreCase: true)); - Assert.Throws(() => m.GetType(aqn, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => m.GetType(aqn, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws(null, () => m.GetType(typeName, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws(null, () => m.GetType(typeName, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws("typeName@0", () => m.GetType(aqn, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws("typeName@0", () => m.GetType(aqn, throwOnError: true, ignoreCase: true)); } public static IEnumerable GetType_TestData() @@ -126,8 +126,8 @@ namespace System.Reflection.Tests Assert.Throws(() => a.GetType(typeName, throwOnError: true, ignoreCase: false)); Assert.Throws(() => a.GetType(typeName, throwOnError: true, ignoreCase: true)); - Assert.Throws(() => a.GetType(aqn, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => a.GetType(aqn, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: true)); // Module.GetType Assert.Null(m.GetType(typeName, throwOnError: false, ignoreCase: false)); @@ -137,8 +137,8 @@ namespace System.Reflection.Tests Assert.Throws(() => m.GetType(typeName, throwOnError: true, ignoreCase: false)); Assert.Throws(() => m.GetType(typeName, throwOnError: true, ignoreCase: true)); - Assert.Throws(() => m.GetType(aqn, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => m.GetType(aqn, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: true)); } else if (expectedResult.FullName == typeName) { @@ -180,8 +180,8 @@ namespace System.Reflection.Tests Assert.Equal(expectedResult, a.GetType(typeName, throwOnError: true, ignoreCase: false)); Assert.Equal(expectedName, a.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase); - Assert.Throws(() => a.GetType(aqn, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => a.GetType(aqn, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: true)); // Module.GetType Assert.Equal(expectedResult, m.GetType(typeName, throwOnError: false, ignoreCase: false)); @@ -191,8 +191,8 @@ namespace System.Reflection.Tests Assert.Equal(expectedResult, m.GetType(typeName, throwOnError: true, ignoreCase: false)); Assert.Equal(expectedName, m.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase); - Assert.Throws(() => m.GetType(aqn, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => m.GetType(aqn, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: true)); } else if (expectedResult.FullName.Equals(typeName, StringComparison.OrdinalIgnoreCase)) { @@ -234,8 +234,8 @@ namespace System.Reflection.Tests Assert.Throws(() => a.GetType(typeName, throwOnError: true, ignoreCase: false)); Assert.Equal(expectedName, a.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase); - Assert.Throws(() => a.GetType(aqn, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => a.GetType(aqn, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws(null, () => a.GetType(aqn, throwOnError: true, ignoreCase: true)); // Module.GetType Assert.Null(m.GetType(typeName, throwOnError: false, ignoreCase: false)); @@ -245,8 +245,8 @@ namespace System.Reflection.Tests Assert.Throws(() => m.GetType(typeName, throwOnError: true, ignoreCase: false)); Assert.Equal(expectedName, m.GetType(typeName, throwOnError: true, ignoreCase: true).AssemblyQualifiedName, StringComparer.OrdinalIgnoreCase); - Assert.Throws(() => m.GetType(aqn, throwOnError: true, ignoreCase: false)); - Assert.Throws(() => m.GetType(aqn, throwOnError: true, ignoreCase: true)); + AssertExtensions.Throws(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws(null, () => m.GetType(aqn, throwOnError: true, ignoreCase: true)); } else { diff --git a/src/libraries/System.Reflection/tests/MethodInfoTests.cs b/src/libraries/System.Reflection/tests/MethodInfoTests.cs index 19b7867634a..705bc85bd90 100644 --- a/src/libraries/System.Reflection/tests/MethodInfoTests.cs +++ b/src/libraries/System.Reflection/tests/MethodInfoTests.cs @@ -296,7 +296,7 @@ namespace System.Reflection.Tests [Fact] public static void Invoke_OptionalParameterUnassingableFromMissing_WithMissingValue_ThrowsArgumentException() { - Assert.Throws(() => GetMethod(typeof(MethodInfoDefaultParameters), "OptionalStringParameter").Invoke(new MethodInfoDefaultParameters(), new object[] { Type.Missing })); + AssertExtensions.Throws(null, () => GetMethod(typeof(MethodInfoDefaultParameters), "OptionalStringParameter").Invoke(new MethodInfoDefaultParameters(), new object[] { Type.Missing })); } [Theory] @@ -323,9 +323,9 @@ namespace System.Reflection.Tests Assert.Throws(() => GetMethod(typeof(MI_SubClass), nameof(MI_SubClass.VoidMethodReturningInt)).MakeGenericMethod(typeof(int))); // Method is non generic // Number of typeArguments does not match - Assert.Throws(() => GetMethod(typeof(MI_SubClass), nameof(MI_SubClass.GenericMethod1)).MakeGenericMethod()); - Assert.Throws(() => GetMethod(typeof(MI_SubClass), nameof(MI_SubClass.GenericMethod1)).MakeGenericMethod(typeof(string), typeof(int))); - Assert.Throws(() => GetMethod(typeof(MI_SubClass), nameof(MI_SubClass.GenericMethod2)).MakeGenericMethod(typeof(int))); + AssertExtensions.Throws(null, () => GetMethod(typeof(MI_SubClass), nameof(MI_SubClass.GenericMethod1)).MakeGenericMethod()); + AssertExtensions.Throws(null, () => GetMethod(typeof(MI_SubClass), nameof(MI_SubClass.GenericMethod1)).MakeGenericMethod(typeof(string), typeof(int))); + AssertExtensions.Throws(null, () => GetMethod(typeof(MI_SubClass), nameof(MI_SubClass.GenericMethod2)).MakeGenericMethod(typeof(int))); } [Theory] diff --git a/src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj b/src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj index 6da89a1074a..68769fed632 100644 --- a/src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj +++ b/src/libraries/System.Reflection/tests/System.Reflection.Tests.csproj @@ -26,6 +26,9 @@ + + Common\System\AssertExtensions.cs + Common\System\PlatformDetection.cs diff --git a/src/libraries/System.Reflection/tests/TypeInfoTests.cs b/src/libraries/System.Reflection/tests/TypeInfoTests.cs index 20b227c4f76..ccc17587c84 100644 --- a/src/libraries/System.Reflection/tests/TypeInfoTests.cs +++ b/src/libraries/System.Reflection/tests/TypeInfoTests.cs @@ -388,7 +388,7 @@ namespace System.Reflection.Tests [Fact] public void GetEnumName_Invalid() { - Assert.Throws(() => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().GetEnumName("")); + AssertExtensions.Throws("value", () => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().GetEnumName("")); Assert.Throws(() => typeof(IntEnum).GetTypeInfo().GetEnumName(null)); } @@ -408,7 +408,7 @@ namespace System.Reflection.Tests [Fact] public void GetEnumNames_TypeNotEnum_ThrowsArgumentException() { - Assert.Throws(() => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().GetEnumNames()); + AssertExtensions.Throws("enumType", () => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().GetEnumNames()); } [Theory] @@ -422,7 +422,7 @@ namespace System.Reflection.Tests [Fact] public void GetEnumUnderlyingType_TypeNotEnum_ThrowsArgumentException() { - Assert.Throws(() => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().GetEnumUnderlyingType()); + AssertExtensions.Throws("enumType", () => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().GetEnumUnderlyingType()); } [Fact] @@ -445,7 +445,7 @@ namespace System.Reflection.Tests [Fact] public void GetEnumValues_TypeNotEnum_ThrowsArgumentException() { - Assert.Throws(() => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().GetEnumUnderlyingType()); + AssertExtensions.Throws("enumType", () => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().GetEnumUnderlyingType()); } [Theory] @@ -459,7 +459,7 @@ namespace System.Reflection.Tests [Fact] public void IsEnumDefined_Invalid() { - Assert.Throws(() => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().IsEnumDefined(10)); + AssertExtensions.Throws("", () => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().IsEnumDefined(10)); Assert.Throws(() => typeof(IntEnum).GetTypeInfo().IsEnumDefined(null)); Assert.Throws(() => typeof(IntEnum).GetTypeInfo().IsEnumDefined(new NonGenericClassWithNoInterfaces())); } diff --git a/src/libraries/System.Resources.Reader/tests/ResourceReaderUnitTest.cs b/src/libraries/System.Resources.Reader/tests/ResourceReaderUnitTest.cs index c38a27578f6..60e8fcdf282 100644 --- a/src/libraries/System.Resources.Reader/tests/ResourceReaderUnitTest.cs +++ b/src/libraries/System.Resources.Reader/tests/ResourceReaderUnitTest.cs @@ -325,7 +325,7 @@ namespace System.Resources.ResourceWriterTests bw.Write(2000);//Our resource reader expects the ResourceManager magic number here // ms2.Seek(0L, SeekOrigin.Begin); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { var resReader = new ResourceReader(ms2); }); @@ -444,7 +444,7 @@ namespace System.Resources.ResourceWriterTests { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { var rr = new ResourceReader(ms2); }); diff --git a/src/libraries/System.Resources.Reader/tests/System.Resources.Reader.Tests.csproj b/src/libraries/System.Resources.Reader/tests/System.Resources.Reader.Tests.csproj index 8711032818a..6ee67a8a18a 100644 --- a/src/libraries/System.Resources.Reader/tests/System.Resources.Reader.Tests.csproj +++ b/src/libraries/System.Resources.Reader/tests/System.Resources.Reader.Tests.csproj @@ -10,6 +10,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Resources.Writer/tests/ResourceWriterUnitTest.cs b/src/libraries/System.Resources.Writer/tests/ResourceWriterUnitTest.cs index c1e7071aab2..4d1cb6a1712 100644 --- a/src/libraries/System.Resources.Writer/tests/ResourceWriterUnitTest.cs +++ b/src/libraries/System.Resources.Writer/tests/ResourceWriterUnitTest.cs @@ -35,7 +35,7 @@ namespace System.Resources.ResourceWriterTests [Fact] public static void ExceptionforResWriter02() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { byte[] buffer = new byte[_RefBuffer.Length]; using (var ms2 = new MemoryStream(buffer, false)) @@ -59,7 +59,7 @@ namespace System.Resources.ResourceWriterTests [Fact] public static void ExceptionforResWriter04() { - Assert.Throws(() => + AssertExtensions.Throws(null, () => { byte[] buffer = new byte[_RefBuffer.Length]; using (var ms2 = new MemoryStream(buffer, true)) diff --git a/src/libraries/System.Resources.Writer/tests/System.Resources.Writer.Tests.csproj b/src/libraries/System.Resources.Writer/tests/System.Resources.Writer.Tests.csproj index 22dab774ab6..e21fc128cf6 100644 --- a/src/libraries/System.Resources.Writer/tests/System.Resources.Writer.Tests.csproj +++ b/src/libraries/System.Resources.Writer/tests/System.Resources.Writer.Tests.csproj @@ -10,6 +10,9 @@ + + Common\System\AssertExtensions.cs + \ No newline at end of file diff --git a/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs b/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs index 792cafce343..fa53ea565ff 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs @@ -197,7 +197,7 @@ namespace System.Tests public void ApplyPolicy() { AssertExtensions.Throws("assemblyName", () => { AppDomain.CurrentDomain.ApplyPolicy(null); }); - Assert.Throws(() => { AppDomain.CurrentDomain.ApplyPolicy(""); }); + AssertExtensions.Throws(null, () => { AppDomain.CurrentDomain.ApplyPolicy(""); }); Assert.Equal(AppDomain.CurrentDomain.ApplyPolicy(Assembly.GetEntryAssembly().FullName), Assembly.GetEntryAssembly().FullName); } @@ -261,7 +261,7 @@ namespace System.Tests public void IsCompatibilitySwitchSet() { Assert.Throws(() => { AppDomain.CurrentDomain.IsCompatibilitySwitchSet(null); }); - Assert.Throws(() => { AppDomain.CurrentDomain.IsCompatibilitySwitchSet("");}); + AssertExtensions.Throws("switchName", () => { AppDomain.CurrentDomain.IsCompatibilitySwitchSet("");}); Assert.Null(AppDomain.CurrentDomain.IsCompatibilitySwitchSet("randomSwitch")); } @@ -320,7 +320,7 @@ namespace System.Tests public void MonitoringIsEnabled() { Assert.False(AppDomain.MonitoringIsEnabled); - Assert.Throws(() => {AppDomain.MonitoringIsEnabled = false;}); + AssertExtensions.Throws(null, () => {AppDomain.MonitoringIsEnabled = false;}); Assert.Throws(() => {AppDomain.MonitoringIsEnabled = true;}); } diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Convert.ToString.cs b/src/libraries/System.Runtime.Extensions/tests/System/Convert.ToString.cs index 6ce783d0467..360519f373f 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/Convert.ToString.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/Convert.ToString.cs @@ -285,7 +285,7 @@ namespace System.Tests [Fact] public static void FromByteInvalidBase() { - Assert.Throws(() => Convert.ToString(Byte.MaxValue, 13)); + AssertExtensions.Throws(null, () => Convert.ToString(Byte.MaxValue, 13)); } [Fact] @@ -339,7 +339,7 @@ namespace System.Tests [Fact] public static void FromInt16InvalidBase() { - Assert.Throws(() => Convert.ToString(Int16.MaxValue, 0)); + AssertExtensions.Throws(null, () => Convert.ToString(Int16.MaxValue, 0)); } [Fact] @@ -393,7 +393,7 @@ namespace System.Tests [Fact] public static void FromInt32InvalidBase() { - Assert.Throws(() => Convert.ToString(Int32.MaxValue, 9)); + AssertExtensions.Throws(null, () => Convert.ToString(Int32.MaxValue, 9)); } [Fact] @@ -447,7 +447,7 @@ namespace System.Tests [Fact] public static void FromInt64InvalidBase() { - Assert.Throws(() => Convert.ToString(Int64.MaxValue, 1)); + AssertExtensions.Throws(null, () => Convert.ToString(Int64.MaxValue, 1)); } [Fact] diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Environment.SetEnvironmentVariable.cs b/src/libraries/System.Runtime.Extensions/tests/System/Environment.SetEnvironmentVariable.cs index df78b51f96f..c4a3f7f4194 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/Environment.SetEnvironmentVariable.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/Environment.SetEnvironmentVariable.cs @@ -28,12 +28,12 @@ namespace System.Tests [Fact] public void IncorrectVariableThrowsArgument() { - Assert.Throws(() => Environment.SetEnvironmentVariable(string.Empty, "test")); - Assert.Throws(() => Environment.SetEnvironmentVariable(NullString, "test")); - Assert.Throws(() => Environment.SetEnvironmentVariable("Variable=Something", "test")); + AssertExtensions.Throws("variable", () => Environment.SetEnvironmentVariable(string.Empty, "test")); + AssertExtensions.Throws("variable", () => Environment.SetEnvironmentVariable(NullString, "test")); + AssertExtensions.Throws("variable", null, () => Environment.SetEnvironmentVariable("Variable=Something", "test")); string varWithLenLongerThanAllowed = new string('c', MAX_VAR_LENGTH_ALLOWED + 1); - Assert.Throws(() => Environment.SetEnvironmentVariable(varWithLenLongerThanAllowed, "test")); + AssertExtensions.Throws("variable", null, () => Environment.SetEnvironmentVariable(varWithLenLongerThanAllowed, "test")); } private static void ExecuteAgainstTarget( diff --git a/src/libraries/System.Runtime.Extensions/tests/System/IO/PathTests.cs b/src/libraries/System.Runtime.Extensions/tests/System/IO/PathTests.cs index 88a36527122..c344c5ba186 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/IO/PathTests.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/IO/PathTests.cs @@ -41,7 +41,7 @@ namespace System.IO.Tests [InlineData("\r\n")] public static void GetDirectoryName_EmptyOrWhitespace_Throws(string path) { - Assert.Throws(() => Path.GetDirectoryName(path)); + AssertExtensions.Throws("path", null, () => Path.GetDirectoryName(path)); } [Theory] @@ -184,8 +184,8 @@ namespace System.IO.Tests public static void GetPathRoot() { Assert.Null(Path.GetPathRoot(null)); - Assert.Throws(() => Path.GetPathRoot(string.Empty)); - Assert.Throws(() => Path.GetPathRoot("\r\n")); + AssertExtensions.Throws("path", null, () => Path.GetPathRoot(string.Empty)); + AssertExtensions.Throws("path", null, () => Path.GetPathRoot("\r\n")); string cwd = Directory.GetCurrentDirectory(); Assert.Equal(cwd.Substring(0, cwd.IndexOf(Path.DirectorySeparatorChar) + 1), Path.GetPathRoot(cwd)); @@ -295,18 +295,18 @@ namespace System.IO.Tests Assert.All(Path.GetInvalidPathChars(), c => { string bad = c.ToString(); - Assert.Throws(() => Path.ChangeExtension(bad, "ok")); - Assert.Throws(() => Path.Combine(bad, "ok")); - Assert.Throws(() => Path.Combine("ok", "ok", bad)); - Assert.Throws(() => Path.Combine("ok", "ok", bad, "ok")); - Assert.Throws(() => Path.Combine(bad, bad, bad, bad, bad)); - Assert.Throws(() => Path.GetDirectoryName(bad)); - Assert.Throws(() => Path.GetExtension(bad)); - Assert.Throws(() => Path.GetFileName(bad)); - Assert.Throws(() => Path.GetFileNameWithoutExtension(bad)); - Assert.Throws(() => Path.GetFullPath(bad)); - Assert.Throws(() => Path.GetPathRoot(bad)); - Assert.Throws(() => Path.IsPathRooted(bad)); + AssertExtensions.Throws("path", null, () => Path.ChangeExtension(bad, "ok")); + AssertExtensions.Throws("path", null, () => Path.Combine(bad, "ok")); + AssertExtensions.Throws("path", null, () => Path.Combine("ok", "ok", bad)); + AssertExtensions.Throws("path", null, () => Path.Combine("ok", "ok", bad, "ok")); + AssertExtensions.Throws("path", null, () => Path.Combine(bad, bad, bad, bad, bad)); + AssertExtensions.Throws("path", null, () => Path.GetDirectoryName(bad)); + AssertExtensions.Throws("path", null, () => Path.GetExtension(bad)); + AssertExtensions.Throws("path", null, () => Path.GetFileName(bad)); + AssertExtensions.Throws("path", null, () => Path.GetFileNameWithoutExtension(bad)); + AssertExtensions.Throws(c == 124 ? null : "path", null, () => Path.GetFullPath(bad)); + AssertExtensions.Throws("path", null, () => Path.GetPathRoot(bad)); + AssertExtensions.Throws("path", null, () => Path.IsPathRooted(bad)); }); } @@ -421,7 +421,7 @@ namespace System.IO.Tests public static void GetFullPath_InvalidArgs() { Assert.Throws(() => Path.GetFullPath(null)); - Assert.Throws(() => Path.GetFullPath(string.Empty)); + AssertExtensions.Throws("path", null, () => Path.GetFullPath(string.Empty)); } public static IEnumerable GetFullPath_BasicExpansions_TestData() @@ -537,7 +537,7 @@ namespace System.IO.Tests } else { - Assert.Throws(() => Path.GetFullPath(path)); + AssertExtensions.Throws(null, () => Path.GetFullPath(path)); } } @@ -553,7 +553,7 @@ namespace System.IO.Tests if (PathFeatures.IsUsingLegacyPathNormalization()) { // We didn't allow these paths on < 4.6.2 - Assert.Throws(() => Path.GetFullPath(path)); + AssertExtensions.Throws(null, () => Path.GetFullPath(path)); } else { @@ -733,7 +733,7 @@ namespace System.IO.Tests { if (input.StartsWith(@"\\?\") && PathFeatures.IsUsingLegacyPathNormalization()) { - Assert.Throws(() => Path.GetFullPath(input)); + AssertExtensions.Throws(null, () => Path.GetFullPath(input)); } else { @@ -760,7 +760,7 @@ namespace System.IO.Tests [InlineData(@"\\LOCALHOST\..")] public static void GetFullPath_Windows_UNC_Invalid(string invalidPath) { - Assert.Throws(() => Path.GetFullPath(invalidPath)); + AssertExtensions.Throws(null, () => Path.GetFullPath(invalidPath)); } [Fact] diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Reflection/AssemblyNameProxyTests.cs b/src/libraries/System.Runtime.Extensions/tests/System/Reflection/AssemblyNameProxyTests.cs index 0a2c9e50a06..150fe30352a 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/Reflection/AssemblyNameProxyTests.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/Reflection/AssemblyNameProxyTests.cs @@ -19,7 +19,7 @@ namespace System.Reflection.Tests { AssemblyNameProxy anp = new AssemblyNameProxy(); AssertExtensions.Throws("assemblyFile", () => anp.GetAssemblyName(null)); - Assert.Throws(() => anp.GetAssemblyName(string.Empty)); + AssertExtensions.Throws("path", null, () => anp.GetAssemblyName(string.Empty)); Assert.Throws(() => anp.GetAssemblyName(Guid.NewGuid().ToString("N"))); Assembly a = typeof(AssemblyNameProxyTests).Assembly; diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Runtime/Versioning/FrameworkName.cs b/src/libraries/System.Runtime.Extensions/tests/System/Runtime/Versioning/FrameworkName.cs index ca5d52d0c2d..bf34541db6c 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/Runtime/Versioning/FrameworkName.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/Runtime/Versioning/FrameworkName.cs @@ -44,19 +44,19 @@ namespace System.Runtime.Versioning.Tests public static void ConstructFromInvalidString() { Assert.Throws(() => new FrameworkName(null)); - Assert.Throws(() => new FrameworkName(string.Empty)); - Assert.Throws(() => new FrameworkName(" ,A")); - Assert.Throws(() => new FrameworkName("A")); - Assert.Throws(() => new FrameworkName("A,B")); - Assert.Throws(() => new FrameworkName("A,B,C")); - Assert.Throws(() => new FrameworkName("A,Version=1.0.0.0,C")); - Assert.Throws(() => new FrameworkName("A,1.0.0.0,Profile=C")); - Assert.Throws(() => new FrameworkName("A,Version=1.z.0.0,Profile=C")); - Assert.Throws(() => new FrameworkName("A,Something=1.z.0.0,Profile=C")); - Assert.Throws(() => new FrameworkName("A,Profile=C")); - Assert.Throws(() => new FrameworkName("A,======")); - Assert.Throws(() => new FrameworkName("A, =B=")); - Assert.Throws(() => new FrameworkName("A,1 =2=3")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName(string.Empty)); + AssertExtensions.Throws("frameworkName", () => new FrameworkName(" ,A")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A,B")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A,B,C")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A,Version=1.0.0.0,C")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A,1.0.0.0,Profile=C")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A,Version=1.z.0.0,Profile=C")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A,Something=1.z.0.0,Profile=C")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A,Profile=C")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A,======")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A, =B=")); + AssertExtensions.Throws("frameworkName", () => new FrameworkName("A,1 =2=3")); } [Fact] @@ -70,8 +70,8 @@ namespace System.Runtime.Versioning.Tests public static void ConstructFromInvalidIdentifierVersion() { Assert.Throws(() => new FrameworkName(null, s_testVersion)); - Assert.Throws(() => new FrameworkName(string.Empty, s_testVersion)); - Assert.Throws(() => new FrameworkName(" \r\n\t", s_testVersion)); + AssertExtensions.Throws("identifier", () => new FrameworkName(string.Empty, s_testVersion)); + AssertExtensions.Throws("identifier", () => new FrameworkName(" \r\n\t", s_testVersion)); Assert.Throws(() => new FrameworkName(TestIdentifier, null)); } @@ -90,8 +90,8 @@ namespace System.Runtime.Versioning.Tests public static void ConstructFromInvalidIdentifierVersionProfile() { Assert.Throws(() => new FrameworkName(null, s_testVersion, TestProfile)); - Assert.Throws(() => new FrameworkName(string.Empty, s_testVersion, TestProfile)); - Assert.Throws(() => new FrameworkName(" \r\n\t", s_testVersion, TestProfile)); + AssertExtensions.Throws("identifier", () => new FrameworkName(string.Empty, s_testVersion, TestProfile)); + AssertExtensions.Throws("identifier", () => new FrameworkName(" \r\n\t", s_testVersion, TestProfile)); Assert.Throws(() => new FrameworkName(TestIdentifier, null, TestProfile)); } diff --git a/src/libraries/System.Runtime.Extensions/tests/System/StringComparer.netcoreapp.cs b/src/libraries/System.Runtime.Extensions/tests/System/StringComparer.netcoreapp.cs index b70996d9929..4b195dce9bc 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/StringComparer.netcoreapp.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/StringComparer.netcoreapp.cs @@ -36,8 +36,8 @@ namespace System.Tests StringComparison minInvalid = Enum.GetValues(typeof(StringComparison)).Cast().Min() - 1; StringComparison maxInvalid = Enum.GetValues(typeof(StringComparison)).Cast().Max() + 1; - Assert.Throws(() => StringComparer.FromComparison(minInvalid)); - Assert.Throws(() => StringComparer.FromComparison(maxInvalid)); + AssertExtensions.Throws("comparisonType", () => StringComparer.FromComparison(minInvalid)); + AssertExtensions.Throws("comparisonType", () => StringComparer.FromComparison(maxInvalid)); } } } diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs index 6c1019065dd..06736e00d5b 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/CheckPlatformTests.cs @@ -87,7 +87,7 @@ namespace System.Runtime.InteropServices.RuntimeInformationTests OSPlatform defaultObj = default(OSPlatform); OSPlatform conObj = new OSPlatform(); Assert.Throws(() => { OSPlatform nullObj = OSPlatform.Create(null); }); - Assert.Throws(() => { OSPlatform emptyObj = OSPlatform.Create(""); }); + AssertExtensions.Throws("osPlatform", () => { OSPlatform emptyObj = OSPlatform.Create(""); }); Assert.True(winObj == winProp); Assert.True(winObj != randomObj); diff --git a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj index 760bafe99d9..93c116a0ce9 100644 --- a/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj +++ b/src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/System.Runtime.InteropServices.RuntimeInformation.Tests.csproj @@ -14,6 +14,9 @@ + + Common\System\AssertExtensions.cs + Common\System\PlatformDetection.cs diff --git a/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs b/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs index d7c0183adbe..c3d2a1781d9 100644 --- a/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs +++ b/src/libraries/System.Runtime.Numerics/tests/BigInteger/parse.cs @@ -69,11 +69,11 @@ namespace System.Numerics.Tests //invalid number style // ******InvalidNumberStyles NumberStyles invalid = (NumberStyles)0x7c00; - Assert.Throws(() => + AssertExtensions.Throws(null, () => { BigInteger.Parse("1", invalid).ToString("d"); }); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { BigInteger junk; BigInteger.TryParse("1", invalid, null, out junk); diff --git a/src/libraries/System.Runtime.Serialization.Formatters/tests/FormatterServicesTests.cs b/src/libraries/System.Runtime.Serialization.Formatters/tests/FormatterServicesTests.cs index 1cf9a7b3866..e8d3ec4d8f9 100644 --- a/src/libraries/System.Runtime.Serialization.Formatters/tests/FormatterServicesTests.cs +++ b/src/libraries/System.Runtime.Serialization.Formatters/tests/FormatterServicesTests.cs @@ -284,7 +284,7 @@ namespace System.Runtime.Serialization.Formatters.Tests AssertExtensions.Throws("obj", () => FormatterServices.PopulateObjectMembers(null, new MemberInfo[0], new object[0])); AssertExtensions.Throws("members", () => FormatterServices.PopulateObjectMembers(new object(), null, new object[0])); AssertExtensions.Throws("data", () => FormatterServices.PopulateObjectMembers(new object(), new MemberInfo[0], null)); - Assert.Throws(() => FormatterServices.PopulateObjectMembers(new object(), new MemberInfo[1], new object[2])); + AssertExtensions.Throws(null, () => FormatterServices.PopulateObjectMembers(new object(), new MemberInfo[1], new object[2])); AssertExtensions.Throws("members", () => FormatterServices.PopulateObjectMembers(new object(), new MemberInfo[1], new object[1])); Assert.Throws(() => FormatterServices.PopulateObjectMembers(new object(), new MemberInfo[] { typeof(object).GetMethod("GetHashCode") }, new object[] { new object() })); } diff --git a/src/libraries/System.Runtime.Serialization.Json/tests/DataContractJsonSerializer.cs b/src/libraries/System.Runtime.Serialization.Json/tests/DataContractJsonSerializer.cs index 5b1f937cc85..243440c5c8d 100644 --- a/src/libraries/System.Runtime.Serialization.Json/tests/DataContractJsonSerializer.cs +++ b/src/libraries/System.Runtime.Serialization.Json/tests/DataContractJsonSerializer.cs @@ -2441,7 +2441,7 @@ public static partial class DataContractJsonSerializerTests }, }; var original = DateTime.Now; - Assert.Throws(() => SerializeAndDeserialize(original, null, dcjsSettings, null, true)); + AssertExtensions.Throws("style", () => SerializeAndDeserialize(original, null, dcjsSettings, null, true)); } } diff --git a/src/libraries/System.Runtime.Serialization.Json/tests/ReflectionOnly/System.Runtime.Serialization.Json.ReflectionOnly.Tests.csproj b/src/libraries/System.Runtime.Serialization.Json/tests/ReflectionOnly/System.Runtime.Serialization.Json.ReflectionOnly.Tests.csproj index b5b20ca4025..f0035b5149c 100644 --- a/src/libraries/System.Runtime.Serialization.Json/tests/ReflectionOnly/System.Runtime.Serialization.Json.ReflectionOnly.Tests.csproj +++ b/src/libraries/System.Runtime.Serialization.Json/tests/ReflectionOnly/System.Runtime.Serialization.Json.ReflectionOnly.Tests.csproj @@ -13,6 +13,9 @@ + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.Runtime.Serialization.Json/tests/System.Runtime.Serialization.Json.Tests.csproj b/src/libraries/System.Runtime.Serialization.Json/tests/System.Runtime.Serialization.Json.Tests.csproj index 9da2683c927..b317f148d2b 100644 --- a/src/libraries/System.Runtime.Serialization.Json/tests/System.Runtime.Serialization.Json.Tests.csproj +++ b/src/libraries/System.Runtime.Serialization.Json/tests/System.Runtime.Serialization.Json.Tests.csproj @@ -16,6 +16,9 @@ + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.Runtime/tests/CompareToTests.cs b/src/libraries/System.Runtime/tests/CompareToTests.cs index 5acc3cb1481..ff5ffbe6002 100644 --- a/src/libraries/System.Runtime/tests/CompareToTests.cs +++ b/src/libraries/System.Runtime/tests/CompareToTests.cs @@ -22,7 +22,7 @@ namespace System.Tests Assert.True(0 > false.CompareTo((object)true)); Assert.True(0 < true.CompareTo((object)false)); - Assert.Throws(() => false.CompareTo("hello")); + AssertExtensions.Throws(null, () => false.CompareTo("hello")); } [Fact] @@ -38,7 +38,7 @@ namespace System.Tests Assert.True(0 < byte.MaxValue.CompareTo((object)(byte)0)); Assert.True(0 > ((byte)0).CompareTo((object)(byte)1)); - Assert.Throws(() => ((byte)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((byte)0.CompareTo("hello"))); } [Fact] @@ -47,7 +47,7 @@ namespace System.Tests Assert.Equal(0, 'c'.CompareTo('c')); Assert.True(0 > 'a'.CompareTo('c')); Assert.True(0 < 'd'.CompareTo('c')); - Assert.Throws(() => 'x'.CompareTo("hello")); + AssertExtensions.Throws(null, () => 'x'.CompareTo("hello")); } [Fact] @@ -65,7 +65,7 @@ namespace System.Tests Assert.True(0 > ((decimal)0).CompareTo((object)(decimal)1)); Assert.True(0 < ((decimal)0).CompareTo((object)(decimal)-1)); - Assert.Throws(() => ((decimal)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((decimal)0.CompareTo("hello"))); } [Fact] @@ -83,7 +83,7 @@ namespace System.Tests Assert.True(0 > ((double)0).CompareTo((object)(double)1)); Assert.True(0 < ((double)0).CompareTo((object)(double)-1)); - Assert.Throws(() => ((double)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((double)0.CompareTo("hello"))); } [Fact] @@ -101,7 +101,7 @@ namespace System.Tests Assert.True(0 > ((short)0).CompareTo((object)(short)1)); Assert.True(0 < ((short)0).CompareTo((object)(short)-1)); - Assert.Throws(() => ((short)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((short)0.CompareTo("hello"))); } [Fact] @@ -119,7 +119,7 @@ namespace System.Tests Assert.True(0 > ((int)0).CompareTo((object)(int)1)); Assert.True(0 < ((int)0).CompareTo((object)(int)-1)); - Assert.Throws(() => ((int)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((int)0.CompareTo("hello"))); } [Fact] @@ -137,7 +137,7 @@ namespace System.Tests Assert.True(0 > ((long)0).CompareTo((object)(long)1)); Assert.True(0 < ((long)0).CompareTo((object)(long)-1)); - Assert.Throws(() => ((long)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((long)0.CompareTo("hello"))); } public static void FromSByte() @@ -154,7 +154,7 @@ namespace System.Tests Assert.True(0 > ((sbyte)0).CompareTo((object)(sbyte)1)); Assert.True(0 < ((sbyte)0).CompareTo((object)(sbyte)-1)); - Assert.Throws(() => ((sbyte)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((sbyte)0.CompareTo("hello"))); } [Fact] @@ -172,7 +172,7 @@ namespace System.Tests Assert.True(0 > ((float)0).CompareTo((object)(float)1)); Assert.True(0 < ((float)0).CompareTo((object)(float)-1)); - Assert.Throws(() => ((float)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((float)0.CompareTo("hello"))); } [Fact] @@ -188,7 +188,7 @@ namespace System.Tests Assert.True(0 < ushort.MaxValue.CompareTo((object)(ushort)0)); Assert.True(0 > ((ushort)0).CompareTo((object)(ushort)1)); - Assert.Throws(() => ((ushort)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((ushort)0.CompareTo("hello"))); } [Fact] @@ -204,7 +204,7 @@ namespace System.Tests Assert.True(0 < uint.MaxValue.CompareTo((object)(uint)0)); Assert.True(0 > ((uint)0).CompareTo((object)(uint)1)); - Assert.Throws(() => ((uint)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((uint)0.CompareTo("hello"))); } [Fact] @@ -220,7 +220,7 @@ namespace System.Tests Assert.True(0 < ulong.MaxValue.CompareTo((object)(ulong)0)); Assert.True(0 > ((ulong)0).CompareTo((object)(ulong)1)); - Assert.Throws(() => ((ulong)0.CompareTo("hello"))); + AssertExtensions.Throws(null, () => ((ulong)0.CompareTo("hello"))); } } } diff --git a/src/libraries/System.Runtime/tests/System/ArraySegmentTests.netcoreapp.cs b/src/libraries/System.Runtime/tests/System/ArraySegmentTests.netcoreapp.cs index 72362aee8e0..7ed13c52939 100644 --- a/src/libraries/System.Runtime/tests/System/ArraySegmentTests.netcoreapp.cs +++ b/src/libraries/System.Runtime/tests/System/ArraySegmentTests.netcoreapp.cs @@ -206,13 +206,13 @@ namespace System.Tests if (arraySegment.Any()) { // Destination not large enough - Assert.Throws(() => arraySegment.CopyTo(new int[count - 1])); - Assert.Throws(() => arraySegment.CopyTo(new int[count - 1], 0)); - Assert.Throws(() => arraySegment.CopyTo(new ArraySegment(new int[count - 1]))); + AssertExtensions.Throws("destinationArray", () => arraySegment.CopyTo(new int[count - 1])); + AssertExtensions.Throws("destinationArray", () => arraySegment.CopyTo(new int[count - 1], 0)); + AssertExtensions.Throws(null, () => arraySegment.CopyTo(new ArraySegment(new int[count - 1]))); // Don't write beyond the limits of the destination in cases where source.Count > destination.Count - Assert.Throws(() => arraySegment.CopyTo(new ArraySegment(new int[count], 1, 0))); // destination.Array can't fit source at destination.Offset - Assert.Throws(() => arraySegment.CopyTo(new ArraySegment(new int[count], 0, count - 1))); // destination.Array can fit source at destination.Offset, but destination can't + AssertExtensions.Throws(null, () => arraySegment.CopyTo(new ArraySegment(new int[count], 1, 0))); // destination.Array can't fit source at destination.Offset + AssertExtensions.Throws(null, () => arraySegment.CopyTo(new ArraySegment(new int[count], 0, count - 1))); // destination.Array can fit source at destination.Offset, but destination can't } } diff --git a/src/libraries/System.Runtime/tests/System/ArrayTests.cs b/src/libraries/System.Runtime/tests/System/ArrayTests.cs index 787ba977e33..e4a030b34d5 100644 --- a/src/libraries/System.Runtime/tests/System/ArrayTests.cs +++ b/src/libraries/System.Runtime/tests/System/ArrayTests.cs @@ -2868,12 +2868,12 @@ namespace System.Tests AssertExtensions.Throws("length", () => Array.Sort(new int[10], 0, -1)); // Index + length > list.Count - Assert.Throws(() => Array.Sort((Array)new int[10], 11, 0)); - Assert.Throws(() => Array.Sort(new int[10], 11, 0)); - Assert.Throws(() => Array.Sort((Array)new int[10], 10, 1)); - Assert.Throws(() => Array.Sort(new int[10], 10, 1)); - Assert.Throws(() => Array.Sort((Array)new int[10], 9, 2)); - Assert.Throws(() => Array.Sort(new int[10], 9, 2)); + AssertExtensions.Throws(null, () => Array.Sort((Array)new int[10], 11, 0)); + AssertExtensions.Throws(null, () => Array.Sort(new int[10], 11, 0)); + AssertExtensions.Throws(null, () => Array.Sort((Array)new int[10], 10, 1)); + AssertExtensions.Throws(null, () => Array.Sort(new int[10], 10, 1)); + AssertExtensions.Throws(null, () => Array.Sort((Array)new int[10], 9, 2)); + AssertExtensions.Throws(null, () => Array.Sort(new int[10], 9, 2)); } [Fact] diff --git a/src/libraries/System.Runtime/tests/System/Attributes.cs b/src/libraries/System.Runtime/tests/System/Attributes.cs index 638c4ecd342..035429c604e 100644 --- a/src/libraries/System.Runtime/tests/System/Attributes.cs +++ b/src/libraries/System.Runtime/tests/System/Attributes.cs @@ -251,7 +251,7 @@ namespace System.Tests element = typeof(AttributeGetCustomAttributes).Assembly; ; Assert.Throws(() => Attribute.GetCustomAttribute(element, attributeType)); attributeType = typeof(myClass); - Assert.Throws(() => Attribute.GetCustomAttribute(element, attributeType)); + AssertExtensions.Throws(null, () => Attribute.GetCustomAttribute(element, attributeType)); attributeType = typeof(Attribute); Assert.Throws(() => Attribute.GetCustomAttribute(element, attributeType)); @@ -293,7 +293,7 @@ namespace System.Tests element = typeof(AttributeGetCustomAttributes).Assembly; ; Assert.Throws(() => Attribute.GetCustomAttribute(element, attributeType, false)); attributeType = typeof(myClass); - Assert.Throws(() => Attribute.GetCustomAttribute(element, attributeType, true)); + AssertExtensions.Throws(null, () => Attribute.GetCustomAttribute(element, attributeType, true)); attributeType = typeof(Attribute); Assert.Throws(() => Attribute.GetCustomAttribute(element, attributeType, true)); @@ -330,7 +330,7 @@ namespace System.Tests element = typeof(TestClass).GetMethod("method1"); Assert.Throws(() => (ObsoleteAttribute)Attribute.GetCustomAttribute(element, attributeType)); attributeType = typeof(object); - Assert.Throws(() => Attribute.GetCustomAttribute(element, attributeType)); + AssertExtensions.Throws(null, () => Attribute.GetCustomAttribute(element, attributeType)); Assert.Throws(() => Attribute.GetCustomAttribute(typeof(Attribute).GetMethod("GetCustomAttribute"), typeof(Attribute))); @@ -367,7 +367,7 @@ namespace System.Tests element = typeof(TestClass).GetMethod("method1"); Assert.Throws(() => (ObsoleteAttribute)Attribute.GetCustomAttribute(element, attributeType, false)); attributeType = typeof(object); - Assert.Throws(() => Attribute.GetCustomAttribute(element, attributeType, false)); + AssertExtensions.Throws(null, () => Attribute.GetCustomAttribute(element, attributeType, false)); Assert.Throws(() => Attribute.GetCustomAttribute(typeof(Attribute).GetMethod("GetCustomAttribute"), typeof(Attribute), false)); @@ -403,7 +403,7 @@ namespace System.Tests attributeType = null; Assert.Throws(() => (DebuggableAttribute)Attribute.GetCustomAttribute(clsType.Module, attributeType)); attributeType = typeof(object); - Assert.Throws(() => (DebuggableAttribute)Attribute.GetCustomAttribute(clsType.Module, attributeType)); + AssertExtensions.Throws(null, () => (DebuggableAttribute)Attribute.GetCustomAttribute(clsType.Module, attributeType)); } [Fact] @@ -436,7 +436,7 @@ namespace System.Tests attributeType = null; Assert.Throws(() => (DebuggableAttribute)Attribute.GetCustomAttribute(clsType.Module, attributeType, false)); attributeType = typeof(object); - Assert.Throws(() => (DebuggableAttribute)Attribute.GetCustomAttribute(clsType.Module, attributeType, false)); + AssertExtensions.Throws(null, () => (DebuggableAttribute)Attribute.GetCustomAttribute(clsType.Module, attributeType, false)); } [Fact] @@ -473,7 +473,7 @@ namespace System.Tests attributeType = null; Assert.Throws(() => (ArgumentUsageAttribute)Attribute.GetCustomAttribute(paramInfos[0], attributeType)); attributeType = typeof(object); - Assert.Throws(() => (ArgumentUsageAttribute)Attribute.GetCustomAttribute(paramInfos[0], attributeType)); + AssertExtensions.Throws(null, () => (ArgumentUsageAttribute)Attribute.GetCustomAttribute(paramInfos[0], attributeType)); } [Fact] @@ -512,7 +512,7 @@ namespace System.Tests attributeType = null; Assert.Throws(() => (ArgumentUsageAttribute)Attribute.GetCustomAttribute(paramInfos[0], attributeType, false)); attributeType = typeof(object); - Assert.Throws(() => (ArgumentUsageAttribute)Attribute.GetCustomAttribute(paramInfos[0], attributeType, false)); + AssertExtensions.Throws(null, () => (ArgumentUsageAttribute)Attribute.GetCustomAttribute(paramInfos[0], attributeType, false)); } } diff --git a/src/libraries/System.Runtime/tests/System/ByteTests.cs b/src/libraries/System.Runtime/tests/System/ByteTests.cs index de9764e57b7..3bfc218d26c 100644 --- a/src/libraries/System.Runtime/tests/System/ByteTests.cs +++ b/src/libraries/System.Runtime/tests/System/ByteTests.cs @@ -269,16 +269,16 @@ namespace System.Tests } [Theory] - [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses)] - [InlineData(unchecked((NumberStyles)0xFFFFFC00))] - public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style) + [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses, null)] + [InlineData(unchecked((NumberStyles)0xFFFFFC00), "style")] + public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style, string paramName) { byte result = 0; - Assert.Throws(() => byte.TryParse("1", style, null, out result)); + AssertExtensions.Throws(paramName, () => byte.TryParse("1", style, null, out result)); Assert.Equal(default(byte), result); - Assert.Throws(() => byte.Parse("1", style)); - Assert.Throws(() => byte.Parse("1", style, null)); + AssertExtensions.Throws(paramName, () => byte.Parse("1", style)); + AssertExtensions.Throws(paramName, () => byte.Parse("1", style, null)); } } } diff --git a/src/libraries/System.Runtime/tests/System/Collections/ObjectModel/CollectionTests.cs b/src/libraries/System.Runtime/tests/System/Collections/ObjectModel/CollectionTests.cs index 03120dd14e8..4e1fb2f82eb 100644 --- a/src/libraries/System.Runtime/tests/System/Collections/ObjectModel/CollectionTests.cs +++ b/src/libraries/System.Runtime/tests/System/Collections/ObjectModel/CollectionTests.cs @@ -207,9 +207,9 @@ namespace System.Collections.ObjectModel.Tests int[] intArray = new int[s_intArray.Length + targetIndex]; Assert.Throws(() => collection.CopyTo(null, 0)); - Assert.Throws(() => ((ICollection)collection).CopyTo(new int[s_intArray.Length, s_intArray.Length], 0)); + AssertExtensions.Throws(null, () => ((ICollection)collection).CopyTo(new int[s_intArray.Length, s_intArray.Length], 0)); Assert.Throws(() => collection.CopyTo(intArray, -1)); - Assert.Throws(() => collection.CopyTo(intArray, s_intArray.Length - 1)); + AssertExtensions.Throws("destinationArray", "", () => collection.CopyTo(intArray, s_intArray.Length - 1)); collection.CopyTo(intArray, targetIndex); for (int i = targetIndex; i < intArray.Length; i++) diff --git a/src/libraries/System.Runtime/tests/System/Collections/ObjectModel/ReadOnlyCollectionTests.cs b/src/libraries/System.Runtime/tests/System/Collections/ObjectModel/ReadOnlyCollectionTests.cs index 07b8270bcc4..21528f51bbf 100644 --- a/src/libraries/System.Runtime/tests/System/Collections/ObjectModel/ReadOnlyCollectionTests.cs +++ b/src/libraries/System.Runtime/tests/System/Collections/ObjectModel/ReadOnlyCollectionTests.cs @@ -93,9 +93,9 @@ namespace System.Collections.ObjectModel.Tests int[] intArray = new int[s_intArray.Length + targetIndex]; Assert.Throws(() => collection.CopyTo(null, 0)); - Assert.Throws(() => ((ICollection)collection).CopyTo(new int[s_intArray.Length, s_intArray.Length], 0)); + AssertExtensions.Throws(null, () => ((ICollection)collection).CopyTo(new int[s_intArray.Length, s_intArray.Length], 0)); Assert.Throws(() => collection.CopyTo(intArray, -1)); - Assert.Throws(() => collection.CopyTo(intArray, s_intArray.Length - 1)); + AssertExtensions.Throws("destinationArray", "", () => collection.CopyTo(intArray, s_intArray.Length - 1)); collection.CopyTo(intArray, targetIndex); for (int i = targetIndex; i < intArray.Length; i++) diff --git a/src/libraries/System.Runtime/tests/System/DateTimeTests.cs b/src/libraries/System.Runtime/tests/System/DateTimeTests.cs index fe3c6887a2b..f33b1f8ac52 100644 --- a/src/libraries/System.Runtime/tests/System/DateTimeTests.cs +++ b/src/libraries/System.Runtime/tests/System/DateTimeTests.cs @@ -894,7 +894,7 @@ namespace System.Tests string[] formats = new string[] { "f" }; IFormatProvider provider = new CultureInfo("en-US"); DateTimeStyles style = DateTimeStyles.AssumeLocal | DateTimeStyles.AssumeUniversal; - Assert.Throws(() => DateTime.ParseExact(strDateTime, formats, provider, style)); + AssertExtensions.Throws("style", () => DateTime.ParseExact(strDateTime, formats, provider, style)); } } } diff --git a/src/libraries/System.Runtime/tests/System/DelegateTests.cs b/src/libraries/System.Runtime/tests/System/DelegateTests.cs index 00740727ec5..ff19147a284 100644 --- a/src/libraries/System.Runtime/tests/System/DelegateTests.cs +++ b/src/libraries/System.Runtime/tests/System/DelegateTests.cs @@ -393,7 +393,7 @@ namespace System.Tests [Fact] public static void DynamicInvoke_OptionalParameterUnassingableFromMissing_WithMissingValue() { - Assert.Throws(() => (new OptionalStringParameter(StringMethod)).DynamicInvoke(new object[] { Type.Missing })); + AssertExtensions.Throws(null, () => (new OptionalStringParameter(StringMethod)).DynamicInvoke(new object[] { Type.Missing })); } [Fact] diff --git a/src/libraries/System.Runtime/tests/System/Int16Tests.cs b/src/libraries/System.Runtime/tests/System/Int16Tests.cs index c71abcf6cd6..66abc2ffbeb 100644 --- a/src/libraries/System.Runtime/tests/System/Int16Tests.cs +++ b/src/libraries/System.Runtime/tests/System/Int16Tests.cs @@ -285,16 +285,16 @@ namespace System.Tests } [Theory] - [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses)] - [InlineData(unchecked((NumberStyles)0xFFFFFC00))] - public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style) + [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses, null)] + [InlineData(unchecked((NumberStyles)0xFFFFFC00), "style")] + public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style, string paramName) { short result = 0; - Assert.Throws(() => short.TryParse("1", style, null, out result)); + AssertExtensions.Throws(paramName, () => short.TryParse("1", style, null, out result)); Assert.Equal(default(short), result); - Assert.Throws(() => short.Parse("1", style)); - Assert.Throws(() => short.Parse("1", style, null)); + AssertExtensions.Throws(paramName, () => short.Parse("1", style)); + AssertExtensions.Throws(paramName, () => short.Parse("1", style, null)); } } } diff --git a/src/libraries/System.Runtime/tests/System/Int32Tests.cs b/src/libraries/System.Runtime/tests/System/Int32Tests.cs index 0fb2084d571..03fd1e1280c 100644 --- a/src/libraries/System.Runtime/tests/System/Int32Tests.cs +++ b/src/libraries/System.Runtime/tests/System/Int32Tests.cs @@ -475,16 +475,16 @@ namespace System.Tests } [Theory] - [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses)] - [InlineData(unchecked((NumberStyles)0xFFFFFC00))] - public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style) + [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses, null)] + [InlineData(unchecked((NumberStyles)0xFFFFFC00), "style")] + public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style, string paramName) { int result = 0; - Assert.Throws(() => int.TryParse("1", style, null, out result)); + AssertExtensions.Throws(paramName, () => int.TryParse("1", style, null, out result)); Assert.Equal(default(int), result); - Assert.Throws(() => int.Parse("1", style)); - Assert.Throws(() => int.Parse("1", style, null)); + AssertExtensions.Throws(paramName, () => int.Parse("1", style)); + AssertExtensions.Throws(paramName, () => int.Parse("1", style, null)); } } } diff --git a/src/libraries/System.Runtime/tests/System/Int64Tests.cs b/src/libraries/System.Runtime/tests/System/Int64Tests.cs index 0d6db47e67e..ca87ca8b566 100644 --- a/src/libraries/System.Runtime/tests/System/Int64Tests.cs +++ b/src/libraries/System.Runtime/tests/System/Int64Tests.cs @@ -278,16 +278,16 @@ namespace System.Tests } [Theory] - [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses)] - [InlineData(unchecked((NumberStyles)0xFFFFFC00))] - public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style) + [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses, null)] + [InlineData(unchecked((NumberStyles)0xFFFFFC00), "style")] + public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style, string paramName) { long result = 0; - Assert.Throws(() => long.TryParse("1", style, null, out result)); + AssertExtensions.Throws(paramName, () => long.TryParse("1", style, null, out result)); Assert.Equal(default(long), result); - Assert.Throws(() => long.Parse("1", style)); - Assert.Throws(() => long.Parse("1", style, null)); + AssertExtensions.Throws(paramName, () => long.Parse("1", style)); + AssertExtensions.Throws(paramName, () => long.Parse("1", style, null)); } } } diff --git a/src/libraries/System.Runtime/tests/System/Reflection/AssemblyNameTests.cs b/src/libraries/System.Runtime/tests/System/Reflection/AssemblyNameTests.cs index 7f4740bdd0f..0da7b72ae25 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/AssemblyNameTests.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/AssemblyNameTests.cs @@ -81,7 +81,7 @@ namespace System.Reflection.Tests public static void GetAssemblyName() { AssertExtensions.Throws("assemblyFile", () => AssemblyName.GetAssemblyName(null)); - Assert.Throws(() => AssemblyName.GetAssemblyName(string.Empty)); + AssertExtensions.Throws("path", null, () => AssemblyName.GetAssemblyName(string.Empty)); Assert.Throws(() => AssemblyName.GetAssemblyName("IDontExist")); using (var tempFile = new TempFile(Path.GetTempFileName(), 42)) diff --git a/src/libraries/System.Runtime/tests/System/Reflection/AssemblyTests.cs b/src/libraries/System.Runtime/tests/System/Reflection/AssemblyTests.cs index 9b58f5a3a2e..41a1dcbda40 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/AssemblyTests.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/AssemblyTests.cs @@ -128,10 +128,10 @@ namespace System.Reflection.Tests public void AssemblyLoadFromStringNeg() { Assert.Throws(() => Assembly.Load((string)null)); - Assert.Throws(() => Assembly.Load(string.Empty)); + AssertExtensions.Throws(null, () => Assembly.Load(string.Empty)); string emptyCName = new string('\0', 1); - Assert.Throws(() => Assembly.Load(emptyCName)); + AssertExtensions.Throws(null, () => Assembly.Load(emptyCName)); } [Fact] @@ -186,7 +186,7 @@ namespace System.Reflection.Tests public void AssemblyReflectionOnlyLoadFromNeg() { Assert.Throws(() => Assembly.ReflectionOnlyLoad((string)null)); - Assert.Throws(() => Assembly.ReflectionOnlyLoad(string.Empty)); + AssertExtensions.Throws(null, () => Assembly.ReflectionOnlyLoad(string.Empty)); Assert.Throws(() => Assembly.ReflectionOnlyLoad((byte[])null)); } @@ -336,7 +336,7 @@ namespace System.Reflection.Tests [SkipOnTargetFramework(TargetFrameworkMonikers.Uap, "Assembly.LoadFile() not supported on UapAot")] public void LoadFile_NoSuchPath_ThrowsArgumentException() { - Assert.Throws(() => Assembly.LoadFile("System.Runtime.Tests.dll")); + AssertExtensions.Throws("path", null, () => Assembly.LoadFile("System.Runtime.Tests.dll")); } [Fact] @@ -455,7 +455,7 @@ namespace System.Reflection.Tests public void GetFile() { Assert.Throws(() => typeof(AssemblyTests).Assembly.GetFile(null)); - Assert.Throws(() => typeof(AssemblyTests).Assembly.GetFile("")); + AssertExtensions.Throws(null, () => typeof(AssemblyTests).Assembly.GetFile("")); Assert.Null(typeof(AssemblyTests).Assembly.GetFile("NonExistentfile.dll")); Assert.NotNull(typeof(AssemblyTests).Assembly.GetFile("System.Runtime.Tests.dll")); Assert.Equal(typeof(AssemblyTests).Assembly.GetFile("System.Runtime.Tests.dll").Name, typeof(AssemblyTests).Assembly.Location); @@ -670,7 +670,7 @@ namespace System.Reflection.Tests { Assembly a = typeof(G).Assembly; string s = typeof(G).AssemblyQualifiedName; - Assert.Throws(() => a.GetType(s, throwOnError: true, ignoreCase: false)); + AssertExtensions.Throws(null, () => a.GetType(s, throwOnError: true, ignoreCase: false)); } [Fact] diff --git a/src/libraries/System.Runtime/tests/System/Reflection/ConstructorInfoTests.cs b/src/libraries/System.Runtime/tests/System/Reflection/ConstructorInfoTests.cs index c38e703285b..912a40e6b3b 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/ConstructorInfoTests.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/ConstructorInfoTests.cs @@ -139,7 +139,7 @@ namespace System.Reflection.Tests ConstructorInfo[] cis = GetConstructors(typeof(ConstructorInfoInvokeSample)); //try to invoke Array ctors with one param ConstructorInfoInvokeSample obj = null; - Assert.Throws(() => { obj = (ConstructorInfoInvokeSample)cis[1].Invoke(new object[] { "hello" }); }); + AssertExtensions.Throws(null, () => { obj = (ConstructorInfoInvokeSample)cis[1].Invoke(new object[] { "hello" }); }); } [Fact] @@ -246,4 +246,4 @@ namespace System.Reflection.Tests y = p2; } }; -} \ No newline at end of file +} diff --git a/src/libraries/System.Runtime/tests/System/Reflection/PointerTests.cs b/src/libraries/System.Runtime/tests/System/Reflection/PointerTests.cs index 59afabaab35..1dd87be3d80 100644 --- a/src/libraries/System.Runtime/tests/System/Reflection/PointerTests.cs +++ b/src/libraries/System.Runtime/tests/System/Reflection/PointerTests.cs @@ -37,7 +37,7 @@ namespace System.Reflection.Tests [Fact] public void Box_NonPointerType() { - Assert.Throws(() => + AssertExtensions.Throws("ptr", () => { Pointer.Box((void*)0, typeof(int)); }); @@ -46,7 +46,7 @@ namespace System.Reflection.Tests [Fact] public void Unbox_Null() { - Assert.Throws(() => + AssertExtensions.Throws("ptr", () => { Pointer.Unbox(null); }); @@ -55,7 +55,7 @@ namespace System.Reflection.Tests [Fact] public void Unbox_NotPointer() { - Assert.Throws(() => + AssertExtensions.Throws("ptr", () => { Pointer.Unbox(new object()); }); @@ -109,7 +109,7 @@ namespace System.Reflection.Tests { var obj = new PointerHolder(); FieldInfo field = typeof(PointerHolder).GetField("field"); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { field.SetValue(obj, Pointer.Box(unchecked((void*)value), typeof(long*))); }); @@ -158,7 +158,7 @@ namespace System.Reflection.Tests { var obj = new PointerHolder(); PropertyInfo property = typeof(PointerHolder).GetProperty("Property"); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { property.SetValue(obj, Pointer.Box(unchecked((void*)value), typeof(long*))); }); @@ -205,7 +205,7 @@ namespace System.Reflection.Tests { var obj = new PointerHolder(); MethodInfo method = typeof(PointerHolder).GetMethod("Method"); - Assert.Throws(() => + AssertExtensions.Throws(null, () => { method.Invoke(obj, new[] { Pointer.Box(unchecked((void*)value), typeof(long*)), value }); }); diff --git a/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.netcoreapp.cs b/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.netcoreapp.cs index 7619ec00923..9899fc705e1 100644 --- a/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.netcoreapp.cs +++ b/src/libraries/System.Runtime/tests/System/Runtime/CompilerServices/RuntimeHelpersTests.netcoreapp.cs @@ -44,7 +44,7 @@ namespace System.Runtime.CompilerServices.Tests { AssertExtensions.Throws("type", () => RuntimeHelpers.GetUninitializedObject(null)); - Assert.Throws(() => RuntimeHelpers.GetUninitializedObject(typeof(string))); // special type + AssertExtensions.Throws(null, () => RuntimeHelpers.GetUninitializedObject(typeof(string))); // special type Assert.Throws(() => RuntimeHelpers.GetUninitializedObject(typeof(System.IO.Stream))); // abstract type Assert.Throws(() => RuntimeHelpers.GetUninitializedObject(typeof(System.Collections.IEnumerable))); // interface Assert.Throws(() => RuntimeHelpers.GetUninitializedObject(typeof(System.Collections.Generic.List<>))); // generic definition diff --git a/src/libraries/System.Runtime/tests/System/SByteTests.cs b/src/libraries/System.Runtime/tests/System/SByteTests.cs index cd8f1a36ef0..85f9cece0d5 100644 --- a/src/libraries/System.Runtime/tests/System/SByteTests.cs +++ b/src/libraries/System.Runtime/tests/System/SByteTests.cs @@ -300,16 +300,16 @@ namespace System.Tests } [Theory] - [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses)] - [InlineData(unchecked((NumberStyles)0xFFFFFC00))] - public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style) + [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses, null)] + [InlineData(unchecked((NumberStyles)0xFFFFFC00), "style")] + public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style, string paramName) { sbyte result = 0; - Assert.Throws(() => sbyte.TryParse("1", style, null, out result)); + AssertExtensions.Throws(paramName, () => sbyte.TryParse("1", style, null, out result)); Assert.Equal(default(sbyte), result); - Assert.Throws(() => sbyte.Parse("1", style)); - Assert.Throws(() => sbyte.Parse("1", style, null)); + AssertExtensions.Throws(paramName, () => sbyte.Parse("1", style)); + AssertExtensions.Throws(paramName, () => sbyte.Parse("1", style, null)); } } } diff --git a/src/libraries/System.Runtime/tests/System/String.SplitTests.cs b/src/libraries/System.Runtime/tests/System/String.SplitTests.cs index 2932923f1e2..1789c6bef94 100644 --- a/src/libraries/System.Runtime/tests/System/String.SplitTests.cs +++ b/src/libraries/System.Runtime/tests/System/String.SplitTests.cs @@ -32,22 +32,22 @@ namespace System.Tests const StringSplitOptions optionsTooLow = StringSplitOptions.None - 1; const StringSplitOptions optionsTooHigh = StringSplitOptions.RemoveEmptyEntries + 1; - Assert.Throws(() => value.Split(',', optionsTooLow)); - Assert.Throws(() => value.Split(',', optionsTooHigh)); - Assert.Throws(() => value.Split(',', count, optionsTooLow)); - Assert.Throws(() => value.Split(',', count, optionsTooHigh)); - Assert.Throws(() => value.Split(new[] { ',' }, optionsTooLow)); - Assert.Throws(() => value.Split(new[] { ',' }, optionsTooHigh)); - Assert.Throws(() => value.Split(new[] { ',' }, count, optionsTooLow)); - Assert.Throws(() => value.Split(new[] { ',' }, count, optionsTooHigh)); - Assert.Throws(() => value.Split(",", optionsTooLow)); - Assert.Throws(() => value.Split(",", optionsTooHigh)); - Assert.Throws(() => value.Split(",", count, optionsTooLow)); - Assert.Throws(() => value.Split(",", count, optionsTooHigh)); - Assert.Throws(() => value.Split(new[] { "," }, optionsTooLow)); - Assert.Throws(() => value.Split(new[] { "," }, optionsTooHigh)); - Assert.Throws(() => value.Split(new[] { "," }, count, optionsTooLow)); - Assert.Throws(() => value.Split(new[] { "," }, count, optionsTooHigh)); + AssertExtensions.Throws(null, () => value.Split(',', optionsTooLow)); + AssertExtensions.Throws(null, () => value.Split(',', optionsTooHigh)); + AssertExtensions.Throws(null, () => value.Split(',', count, optionsTooLow)); + AssertExtensions.Throws(null, () => value.Split(',', count, optionsTooHigh)); + AssertExtensions.Throws(null, () => value.Split(new[] { ',' }, optionsTooLow)); + AssertExtensions.Throws(null, () => value.Split(new[] { ',' }, optionsTooHigh)); + AssertExtensions.Throws(null, () => value.Split(new[] { ',' }, count, optionsTooLow)); + AssertExtensions.Throws(null, () => value.Split(new[] { ',' }, count, optionsTooHigh)); + AssertExtensions.Throws(null, () => value.Split(",", optionsTooLow)); + AssertExtensions.Throws(null, () => value.Split(",", optionsTooHigh)); + AssertExtensions.Throws(null, () => value.Split(",", count, optionsTooLow)); + AssertExtensions.Throws(null, () => value.Split(",", count, optionsTooHigh)); + AssertExtensions.Throws(null, () => value.Split(new[] { "," }, optionsTooLow)); + AssertExtensions.Throws(null, () => value.Split(new[] { "," }, optionsTooHigh)); + AssertExtensions.Throws(null, () => value.Split(new[] { "," }, count, optionsTooLow)); + AssertExtensions.Throws(null, () => value.Split(new[] { "," }, count, optionsTooHigh)); } [Fact] diff --git a/src/libraries/System.Runtime/tests/System/Threading/WaitHandleTests.cs b/src/libraries/System.Runtime/tests/System/Threading/WaitHandleTests.cs index 528492c63d4..c9442d00dde 100644 --- a/src/libraries/System.Runtime/tests/System/Threading/WaitHandleTests.cs +++ b/src/libraries/System.Runtime/tests/System/Threading/WaitHandleTests.cs @@ -90,7 +90,7 @@ namespace System.Threading.Tests wh[0] = new Mutex(false, "test"); wh[1] = new Mutex(false, "test"); - Assert.Throws(() => WaitHandle.WaitAll(wh)); + AssertExtensions.Throws(null, () => WaitHandle.WaitAll(wh)); } [Fact] diff --git a/src/libraries/System.Runtime/tests/System/TupleTests.cs b/src/libraries/System.Runtime/tests/System/TupleTests.cs index 9b08c064634..afdf6cefaeb 100644 --- a/src/libraries/System.Runtime/tests/System/TupleTests.cs +++ b/src/libraries/System.Runtime/tests/System/TupleTests.cs @@ -649,7 +649,7 @@ namespace System.Tests var b = Tuple.Create(testClassB); Assert.True(a.Equals(b)); - Assert.Throws(() => ((IComparable)a).CompareTo(b)); + AssertExtensions.Throws(null, () => ((IComparable)a).CompareTo(b)); Assert.Equal(a.GetHashCode(), b.GetHashCode()); Assert.True(((IStructuralEquatable)a).Equals(b, TestEqualityComparer.Instance)); Assert.Equal(5, ((IStructuralComparable)a).CompareTo(b, TestComparer.Instance)); diff --git a/src/libraries/System.Runtime/tests/System/TypeTests.cs b/src/libraries/System.Runtime/tests/System/TypeTests.cs index 1ea18f10ef9..002e9e60622 100644 --- a/src/libraries/System.Runtime/tests/System/TypeTests.cs +++ b/src/libraries/System.Runtime/tests/System/TypeTests.cs @@ -168,7 +168,7 @@ namespace System.Tests [InlineData(typeof(IList<>))] public static void GetArrayRank_Invalid(Type t) { - Assert.Throws(() => t.GetArrayRank()); + AssertExtensions.Throws(null, () => t.GetArrayRank()); } [Theory] diff --git a/src/libraries/System.Runtime/tests/System/TypedReferenceTests.cs b/src/libraries/System.Runtime/tests/System/TypedReferenceTests.cs index 51189e57035..6f44d359678 100644 --- a/src/libraries/System.Runtime/tests/System/TypedReferenceTests.cs +++ b/src/libraries/System.Runtime/tests/System/TypedReferenceTests.cs @@ -54,9 +54,9 @@ namespace System.Tests Type dataType = data.GetType(); Assert.Throws(() => { TypedReference.MakeTypedReference(null, dataType.GetFields()); }); Assert.Throws(() => { TypedReference.MakeTypedReference(data, null); }); - Assert.Throws(() => { TypedReference.MakeTypedReference(data, Array.Empty()); }); - Assert.Throws(() => { TypedReference.MakeTypedReference(data, new FieldInfo[] { dataType.GetField("oneStruct"), null }); }); - Assert.Throws(() => { TypedReference.MakeTypedReference(data, new FieldInfo[] { dataType.GetField("oneStruct"), typeof(OneStruct).GetField("b") }); }); + AssertExtensions.Throws(null, () => { TypedReference.MakeTypedReference(data, Array.Empty()); }); + AssertExtensions.Throws(null, () => { TypedReference.MakeTypedReference(data, new FieldInfo[] { dataType.GetField("oneStruct"), null }); }); + AssertExtensions.Throws(null, () => { TypedReference.MakeTypedReference(data, new FieldInfo[] { dataType.GetField("oneStruct"), typeof(OneStruct).GetField("b") }); }); } [Fact] diff --git a/src/libraries/System.Runtime/tests/System/UInt16Tests.cs b/src/libraries/System.Runtime/tests/System/UInt16Tests.cs index 8cbc534fa66..b3699927b96 100644 --- a/src/libraries/System.Runtime/tests/System/UInt16Tests.cs +++ b/src/libraries/System.Runtime/tests/System/UInt16Tests.cs @@ -266,16 +266,16 @@ namespace System.Tests } [Theory] - [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses)] - [InlineData(unchecked((NumberStyles)0xFFFFFC00))] - public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style) + [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses, null)] + [InlineData(unchecked((NumberStyles)0xFFFFFC00), "style")] + public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style, string paramName) { ushort result = 0; - Assert.Throws(() => ushort.TryParse("1", style, null, out result)); + AssertExtensions.Throws(paramName, () => ushort.TryParse("1", style, null, out result)); Assert.Equal(default(ushort), result); - Assert.Throws(() => ushort.Parse("1", style)); - Assert.Throws(() => ushort.Parse("1", style, null)); + AssertExtensions.Throws(paramName, () => ushort.Parse("1", style)); + AssertExtensions.Throws(paramName, () => ushort.Parse("1", style, null)); } } } diff --git a/src/libraries/System.Runtime/tests/System/UInt32Tests.cs b/src/libraries/System.Runtime/tests/System/UInt32Tests.cs index 1a91f437acb..ab6f80960f1 100644 --- a/src/libraries/System.Runtime/tests/System/UInt32Tests.cs +++ b/src/libraries/System.Runtime/tests/System/UInt32Tests.cs @@ -268,16 +268,16 @@ namespace System.Tests } [Theory] - [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses)] - [InlineData(unchecked((NumberStyles)0xFFFFFC00))] - public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style) + [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses, null)] + [InlineData(unchecked((NumberStyles)0xFFFFFC00), "style")] + public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style, string paramName) { uint result = 0; - Assert.Throws(() => uint.TryParse("1", style, null, out result)); + AssertExtensions.Throws(paramName, () => uint.TryParse("1", style, null, out result)); Assert.Equal(default(uint), result); - Assert.Throws(() => uint.Parse("1", style)); - Assert.Throws(() => uint.Parse("1", style, null)); + AssertExtensions.Throws(paramName, () => uint.Parse("1", style)); + AssertExtensions.Throws(paramName, () => uint.Parse("1", style, null)); } } } diff --git a/src/libraries/System.Runtime/tests/System/UInt64Tests.cs b/src/libraries/System.Runtime/tests/System/UInt64Tests.cs index 33643dd2a68..e6fc44f96f8 100644 --- a/src/libraries/System.Runtime/tests/System/UInt64Tests.cs +++ b/src/libraries/System.Runtime/tests/System/UInt64Tests.cs @@ -267,16 +267,16 @@ namespace System.Tests } [Theory] - [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses)] - [InlineData(unchecked((NumberStyles)0xFFFFFC00))] - public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style) + [InlineData(NumberStyles.HexNumber | NumberStyles.AllowParentheses, null)] + [InlineData(unchecked((NumberStyles)0xFFFFFC00), "style")] + public static void TryParse_InvalidNumberStyle_ThrowsArgumentException(NumberStyles style, string paramName) { ulong result = 0; - Assert.Throws(() => ulong.TryParse("1", style, null, out result)); + AssertExtensions.Throws(paramName, () => ulong.TryParse("1", style, null, out result)); Assert.Equal(default(ulong), result); - Assert.Throws(() => ulong.Parse("1", style)); - Assert.Throws(() => ulong.Parse("1", style, null)); + AssertExtensions.Throws(paramName, () => ulong.Parse("1", style)); + AssertExtensions.Throws(paramName, () => ulong.Parse("1", style, null)); } } } diff --git a/src/libraries/System.Runtime/tests/System/Uri.CreateStringTests.cs b/src/libraries/System.Runtime/tests/System/Uri.CreateStringTests.cs index 8483b389830..795cc83f1bb 100644 --- a/src/libraries/System.Runtime/tests/System/Uri.CreateStringTests.cs +++ b/src/libraries/System.Runtime/tests/System/Uri.CreateStringTests.cs @@ -1015,13 +1015,13 @@ namespace System.Tests [Fact] public void Create_String_InvalidUriKind_ThrowsArgumentException() { - Assert.Throws(() => new Uri("http://host", UriKind.RelativeOrAbsolute - 1)); - Assert.Throws(() => new Uri("http://host", UriKind.Relative + 1)); + AssertExtensions.Throws(null, () => new Uri("http://host", UriKind.RelativeOrAbsolute - 1)); + AssertExtensions.Throws(null, () => new Uri("http://host", UriKind.Relative + 1)); Uri uri = null; - Assert.Throws(() => Uri.TryCreate("http://host", UriKind.RelativeOrAbsolute - 1, out uri)); + AssertExtensions.Throws(null, () => Uri.TryCreate("http://host", UriKind.RelativeOrAbsolute - 1, out uri)); Assert.Null(uri); - Assert.Throws(() => Uri.TryCreate("http://host", UriKind.Relative + 1, out uri)); + AssertExtensions.Throws(null, () => Uri.TryCreate("http://host", UriKind.Relative + 1, out uri)); Assert.Null(uri); } diff --git a/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_Constructor.cs b/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_Constructor.cs index 8d1433cbe1d..94451d3437e 100644 --- a/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_Constructor.cs +++ b/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_Constructor.cs @@ -59,56 +59,56 @@ namespace System.Security.AccessControl.Tests // test case 1: SACL is not null, SACL.IsContainer is true, but isContainer parameter is false sacl = new SystemAcl(true, true, 10); - Assert.Throws(() => + AssertExtensions.Throws("systemAcl", () => { sd = new CommonSecurityDescriptor(false, true, ControlFlags.SystemAclPresent, null, null, sacl, null); }); // test case 2: SACL is not null, SACL.IsContainer is false, but isContainer parameter is true sacl = new SystemAcl(false, true, 10); - Assert.Throws(() => + AssertExtensions.Throws("systemAcl", () => { sd = new CommonSecurityDescriptor(true, true, ControlFlags.SystemAclPresent, null, null, sacl, null); }); // test case 3: DACL is not null, DACL.IsContainer is true, but isContainer parameter is false dacl = new DiscretionaryAcl(true, true, 10); - Assert.Throws(() => + AssertExtensions.Throws("discretionaryAcl", () => { sd = new CommonSecurityDescriptor(false, true, ControlFlags.DiscretionaryAclPresent, null, null, null, dacl); }); // test case 4: DACL is not null, DACL.IsContainer is false, but isContainer parameter is true dacl = new DiscretionaryAcl(false, true, 10); - Assert.Throws(() => + AssertExtensions.Throws("discretionaryAcl", () => { sd = new CommonSecurityDescriptor(true, true, ControlFlags.DiscretionaryAclPresent, null, null, null, dacl); }); // test case 5: SACL is not null, SACL.IsDS is true, but isDS parameter is false sacl = new SystemAcl(true, true, 10); - Assert.Throws(() => + AssertExtensions.Throws("systemAcl", () => { sd = new CommonSecurityDescriptor(true, false, ControlFlags.SystemAclPresent, null, null, sacl, null); }); // test case 6: SACL is not null, SACL.IsDS is false, but isDS parameter is true sacl = new SystemAcl(true, false, 10); - Assert.Throws(() => + AssertExtensions.Throws("systemAcl", () => { sd = new CommonSecurityDescriptor(true, true, ControlFlags.SystemAclPresent, null, null, sacl, null); }); // test case 7: DACL is not null, DACL.IsDS is true, but isDS parameter is false dacl = new DiscretionaryAcl(true, true, 10); - Assert.Throws(() => + AssertExtensions.Throws("discretionaryAcl", () => { sd = new CommonSecurityDescriptor(true, false, ControlFlags.DiscretionaryAclPresent, null, null, null, dacl); }); // test case 8: DACL is not null, DACL.IsDS is false, but isDS parameter is true dacl = new DiscretionaryAcl(true, false, 10); - Assert.Throws(() => + AssertExtensions.Throws("discretionaryAcl", () => { sd = new CommonSecurityDescriptor(true, true, ControlFlags.DiscretionaryAclPresent, null, null, null, dacl); }); @@ -207,4 +207,4 @@ namespace System.Security.AccessControl.Tests return result; } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_CreateFromBinaryForm.cs b/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_CreateFromBinaryForm.cs index 3609d051673..ba917a6cb59 100644 --- a/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_CreateFromBinaryForm.cs +++ b/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_CreateFromBinaryForm.cs @@ -65,7 +65,7 @@ namespace System.Security.AccessControl.Tests }); // case 5: ControlFlags.SelfRelative is not set - Assert.Throws(() => + AssertExtensions.Throws(null, () => { byte[] binaryForm = new byte[24]; for (int i = 0; i < binaryForm.Length; i++) @@ -84,7 +84,7 @@ namespace System.Security.AccessControl.Tests }); // Case 7, an array of garbage - Assert.Throws(() => + AssertExtensions.Throws(null, () => { byte[] binaryForm = { 1, 0, 0, 128, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }; commonSecurityDescriptor = new CommonSecurityDescriptor(false, false, binaryForm, 0); @@ -118,4 +118,4 @@ namespace System.Security.AccessControl.Tests Assert.True(String.Compare(verifierSddl, resultSddlForm, StringComparison.CurrentCultureIgnoreCase) == 0); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_CreateFromSddlForm.cs b/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_CreateFromSddlForm.cs index 59cf2811c10..8c55238ccdd 100644 --- a/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_CreateFromSddlForm.cs +++ b/src/libraries/System.Security.AccessControl/tests/CommonSecurityDescriptor/CommonSecurityDescriptor_CreateFromSddlForm.cs @@ -46,35 +46,35 @@ namespace System.Security.AccessControl.Tests }); // Case 3, sddl form owner symbol exists but no content - Assert.Throws(() => + AssertExtensions.Throws("sddlForm", () => { commonSecurityDescriptor = new CommonSecurityDescriptor(false, false, "O:G:SYD:AI(A;ID;FR;;;BA)S:AI(AU;IDFA;FR;;;BA)"); // expect to throw exception but not }); // Case 4, sddl form group symbol exists but no content - Assert.Throws(() => + AssertExtensions.Throws("sddlForm", () => { commonSecurityDescriptor = new CommonSecurityDescriptor(false, false, "O:LAG:D:AI(A;ID;FR;;;BA)S:AI(AU;IDFA;FR;;;BA)"); // expect to throw exception but not }); // Case 5, garbage string sddl - Assert.Throws(() => + AssertExtensions.Throws("sddlForm", () => { commonSecurityDescriptor = new CommonSecurityDescriptor(false, false, "ABCDEFGHIJKLMNOPQ"); // expect to throw exception but not }); // Case 7, sddl form with invalid owner sid - Assert.Throws(() => + AssertExtensions.Throws("sddlForm", () => { commonSecurityDescriptor = new CommonSecurityDescriptor(false, false, "O:XXG:D:AI(A;ID;FR;;;BA)S:AI(AU;IDFA;FR;;;BA)"); // expect to throw exception but not }); // Case 8, sddl form with invalid group sid - Assert.Throws(() => + AssertExtensions.Throws("sddlForm", () => { commonSecurityDescriptor = new CommonSecurityDescriptor(false, false, "O:LAG:YYD:AI(A;ID;FR;;;BA)S:AI(AU;IDFA;FR;;;BA)"); // expect to throw exception but not diff --git a/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_AddAccess.cs b/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_AddAccess.cs index cbf69c84c3d..dc3876d10f4 100644 --- a/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_AddAccess.cs +++ b/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_AddAccess.cs @@ -102,7 +102,7 @@ namespace System.Security.AccessControl.Tests byte[] opaque = null; //Case 1, non-Container, but InheritanceFlags is not None - Assert.Throws(() => + AssertExtensions.Throws("inheritanceFlags", () => { isContainer = false; isDS = false; @@ -115,7 +115,7 @@ namespace System.Security.AccessControl.Tests }); //Case 2, non-Container, but PropagationFlags is not None - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = false; isDS = false; @@ -129,7 +129,7 @@ namespace System.Security.AccessControl.Tests }); //Case 3, Container, InheritanceFlags is None, PropagationFlags is InheritOnly - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = true; isDS = false; @@ -143,7 +143,7 @@ namespace System.Security.AccessControl.Tests }); //Case 4, Container, InheritanceFlags is None, PropagationFlags is NoPropagateInherit - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = true; isDS = false; @@ -157,7 +157,7 @@ namespace System.Security.AccessControl.Tests }); //Case 5, Container, InheritanceFlags is None, PropagationFlags is NoPropagateInherit | InheritOnly - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = true; isDS = false; @@ -171,7 +171,7 @@ namespace System.Security.AccessControl.Tests }); //Case 6, accessMask = 0 - Assert.Throws(() => + AssertExtensions.Throws("accessMask", () => { isContainer = true; isDS = false; @@ -232,7 +232,7 @@ namespace System.Security.AccessControl.Tests //bug# 288116 - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = true; isDS = false; @@ -342,4 +342,4 @@ namespace System.Security.AccessControl.Tests } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_RemoveAccess.cs b/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_RemoveAccess.cs index d565f3bfef4..9d34f1b6e6b 100644 --- a/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_RemoveAccess.cs +++ b/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_RemoveAccess.cs @@ -141,7 +141,7 @@ namespace System.Security.AccessControl.Tests //Case 3, accessMask = 0 - Assert.Throws(() => + AssertExtensions.Throws("accessMask", () => { isContainer = true; isDS = false; @@ -239,4 +239,4 @@ namespace System.Security.AccessControl.Tests } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_RemoveAccessSpecific.cs b/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_RemoveAccessSpecific.cs index e4ef54b0c60..e42cfbe34fe 100644 --- a/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_RemoveAccessSpecific.cs +++ b/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_RemoveAccessSpecific.cs @@ -128,7 +128,7 @@ namespace System.Security.AccessControl.Tests //Case 3, accessMask = 0 - Assert.Throws(() => + AssertExtensions.Throws("accessMask", () => { isContainer = true; isDS = false; @@ -224,4 +224,4 @@ namespace System.Security.AccessControl.Tests }); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_SetAccess.cs b/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_SetAccess.cs index 301a0d79d3e..1f724f6b710 100644 --- a/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_SetAccess.cs +++ b/src/libraries/System.Security.AccessControl/tests/DiscretionaryAcl/DiscretionaryAcl_SetAccess.cs @@ -87,7 +87,7 @@ namespace System.Security.AccessControl.Tests GenericAce gAce = null; byte[] opaque = null; //Case 1, non-Container, but InheritanceFlags is not None - Assert.Throws(() => + AssertExtensions.Throws("inheritanceFlags", () => { isContainer = false; isDS = false; @@ -101,7 +101,7 @@ namespace System.Security.AccessControl.Tests }); //Case 2, non-Container, but PropagationFlags is not None - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = false; isDS = false; @@ -134,7 +134,7 @@ namespace System.Security.AccessControl.Tests //Case 4, accessMask = 0 - Assert.Throws(() => + AssertExtensions.Throws("accessMask", () => { isContainer = true; isDS = false; @@ -303,4 +303,4 @@ namespace System.Security.AccessControl.Tests }); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.AccessControl/tests/RawAcl/RawAcl_CreateFromBinaryForm.cs b/src/libraries/System.Security.AccessControl/tests/RawAcl/RawAcl_CreateFromBinaryForm.cs index bf169f137a1..e01d16484e6 100644 --- a/src/libraries/System.Security.AccessControl/tests/RawAcl/RawAcl_CreateFromBinaryForm.cs +++ b/src/libraries/System.Security.AccessControl/tests/RawAcl/RawAcl_CreateFromBinaryForm.cs @@ -220,7 +220,7 @@ namespace System.Security.AccessControl.Tests aceFlag = 0; binaryForm = new byte[65536]; - Assert.Throws(() => + AssertExtensions.Throws("binaryForm", () => { revision = 127; capacity = 1; diff --git a/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_AddAudit.cs b/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_AddAudit.cs index 922bb974002..2bda59dce30 100644 --- a/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_AddAudit.cs +++ b/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_AddAudit.cs @@ -109,7 +109,7 @@ namespace System.Security.AccessControl.Tests }); //Case 2, SystemAudit Ace but non AuditFlags - Assert.Throws(() => + AssertExtensions.Throws("auditFlags", () => { isContainer = false; isDS = false; @@ -121,7 +121,7 @@ namespace System.Security.AccessControl.Tests }); //Case 3, 0 accessMask - Assert.Throws(() => + AssertExtensions.Throws("accessMask", () => { isContainer = false; isDS = false; @@ -133,7 +133,7 @@ namespace System.Security.AccessControl.Tests }); //Case 4, non-Container, but InheritanceFlags is not None - Assert.Throws(() => + AssertExtensions.Throws("inheritanceFlags", () => { isContainer = false; isDS = false; @@ -145,7 +145,7 @@ namespace System.Security.AccessControl.Tests }); //Case 5, non-Container, but PropagationFlags is not None - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = false; isDS = false; @@ -157,7 +157,7 @@ namespace System.Security.AccessControl.Tests }); //Case 6, Container, but InheritanceFlags is None, but PropagationFlags is InheritOnly - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = true; isDS = false; @@ -169,7 +169,7 @@ namespace System.Security.AccessControl.Tests }); //Case 7, Container, but InheritanceFlags is None, but PropagationFlags is NoPropagateInherit - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = true; isDS = false; @@ -181,7 +181,7 @@ namespace System.Security.AccessControl.Tests }); //Case 8, Container, but InheritanceFlags is None, but PropagationFlags is NoPropagateInherit | InheritOnly - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = true; isDS = false; @@ -262,4 +262,4 @@ namespace System.Security.AccessControl.Tests }); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_RemoveAudit.cs b/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_RemoveAudit.cs index 2b2764d8a8f..fb2b9fd8313 100644 --- a/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_RemoveAudit.cs +++ b/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_RemoveAudit.cs @@ -118,7 +118,7 @@ namespace System.Security.AccessControl.Tests }); //Case 2, SystemAudit Ace but non AuditFlags - Assert.Throws(() => + AssertExtensions.Throws("auditFlags", () => { isContainer = false; isDS = false; @@ -130,7 +130,7 @@ namespace System.Security.AccessControl.Tests }); //Case 3, 0 accessMask - Assert.Throws(() => + AssertExtensions.Throws("accessMask", () => { isContainer = false; isDS = false; @@ -201,4 +201,4 @@ namespace System.Security.AccessControl.Tests // Non-canonical ACLs cannot be modified } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_RemoveAuditSpecific.cs b/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_RemoveAuditSpecific.cs index f0a3e54df56..dcd398a0b9d 100644 --- a/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_RemoveAuditSpecific.cs +++ b/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_RemoveAuditSpecific.cs @@ -132,7 +132,7 @@ new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(si //Case 3, accessMask = 0 - Assert.Throws(() => + AssertExtensions.Throws("accessMask", () => { isContainer = true; isDS = false; @@ -150,7 +150,7 @@ new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(si //Case 4, Audit Qualifier None - Assert.Throws(() => + AssertExtensions.Throws("auditFlags", () => { isContainer = true; isDS = false; @@ -212,4 +212,4 @@ new SecurityIdentifier(Utils.TranslateStringConstFormatSidToStandardFormatSid(si }); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_SetAudit.cs b/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_SetAudit.cs index 55f89130750..b027e27e51e 100644 --- a/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_SetAudit.cs +++ b/src/libraries/System.Security.AccessControl/tests/SystemAcl/SystemAcl_SetAudit.cs @@ -95,7 +95,7 @@ namespace System.Security.AccessControl.Tests }); //Case 2, SystemAudit Ace but non AuditFlags - Assert.Throws(() => + AssertExtensions.Throws("auditFlags", () => { isContainer = false; isDS = false; @@ -107,7 +107,7 @@ namespace System.Security.AccessControl.Tests }); //Case 3, 0 accessMask - Assert.Throws(() => + AssertExtensions.Throws("accessMask", () => { isContainer = false; isDS = false; @@ -119,7 +119,7 @@ namespace System.Security.AccessControl.Tests }); //Case 4, non-Container, but InheritanceFlags is not None - Assert.Throws(() => + AssertExtensions.Throws("inheritanceFlags", () => { isContainer = false; isDS = false; @@ -131,7 +131,7 @@ namespace System.Security.AccessControl.Tests //Case 5, non-Container, but PropagationFlags is not None - Assert.Throws(() => + AssertExtensions.Throws("propagationFlags", () => { isContainer = false; isDS = false; @@ -213,4 +213,4 @@ namespace System.Security.AccessControl.Tests }); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.Cryptography.Algorithms/tests/DSACreateTests.cs b/src/libraries/System.Security.Cryptography.Algorithms/tests/DSACreateTests.cs index c18ba66509c..cd18bc0b0c1 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/tests/DSACreateTests.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/tests/DSACreateTests.cs @@ -88,7 +88,7 @@ namespace System.Security.Cryptography.Algorithms.Tests parameters.X = null; parameters.Y = null; - Assert.Throws(() => DSA.Create(parameters)); + AssertExtensions.Throws(null, () => DSA.Create(parameters)); } } } diff --git a/src/libraries/System.Security.Cryptography.Algorithms/tests/InvalidUsageTests.cs b/src/libraries/System.Security.Cryptography.Algorithms/tests/InvalidUsageTests.cs index 589f46a911d..3f1aca23711 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/tests/InvalidUsageTests.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/tests/InvalidUsageTests.cs @@ -17,9 +17,9 @@ namespace System.Security.Cryptography.Hashing.Algorithms.Tests Assert.Throws(() => hmac.ExposedHashCore(null, 0, 0)); AssertExtensions.Throws("offset", "inputOffset", () => hmac.ExposedHashCore(new byte[1], -1, 1)); AssertExtensions.Throws("count", null, () => hmac.ExposedHashCore(new byte[1], 0, -1)); - Assert.Throws(() => hmac.ExposedHashCore(new byte[1], 0, 2)); - Assert.Throws(() => hmac.ExposedHashCore(new byte[2], 1, 2)); - Assert.Throws(() => hmac.ExposedHashCore(new byte[1], Int32.MaxValue, Int32.MaxValue)); + AssertExtensions.Throws(null, () => hmac.ExposedHashCore(new byte[1], 0, 2)); + AssertExtensions.Throws(null, () => hmac.ExposedHashCore(new byte[2], 1, 2)); + AssertExtensions.Throws(null, () => hmac.ExposedHashCore(new byte[1], Int32.MaxValue, Int32.MaxValue)); } } diff --git a/src/libraries/System.Security.Cryptography.Algorithms/tests/RSACreateTests.cs b/src/libraries/System.Security.Cryptography.Algorithms/tests/RSACreateTests.cs index f78d8c2fc3d..913a3279190 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/tests/RSACreateTests.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/tests/RSACreateTests.cs @@ -76,7 +76,7 @@ namespace System.Security.Cryptography.Algorithms.Tests parameters.Exponent = null; if (RSA.Create() is RSACng && PlatformDetection.IsFullFramework) - Assert.Throws(() => RSA.Create(parameters)); + AssertExtensions.Throws(null, () => RSA.Create(parameters)); else Assert.Throws(() => RSA.Create(parameters)); } diff --git a/src/libraries/System.Security.Cryptography.Algorithms/tests/RandomNumberGeneratorTests.cs b/src/libraries/System.Security.Cryptography.Algorithms/tests/RandomNumberGeneratorTests.cs index ac6c12631b7..e458a11e49e 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/tests/RandomNumberGeneratorTests.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/tests/RandomNumberGeneratorTests.cs @@ -262,7 +262,7 @@ namespace System.Security.Cryptography.RNG.Tests AssertExtensions.Throws("data", () => rng.GetBytes(null, 0, 0)); AssertExtensions.Throws("offset", () => rng.GetBytes(Array.Empty(), -1, 0)); AssertExtensions.Throws("count", () => rng.GetBytes(Array.Empty(), 0, -1)); - Assert.Throws(() => rng.GetBytes(Array.Empty(), 0, 1)); + AssertExtensions.Throws(null, () => rng.GetBytes(Array.Empty(), 0, 1)); // GetBytes(null) covered in test NullInput() } diff --git a/src/libraries/System.Security.Cryptography.Algorithms/tests/Rfc2898Tests.cs b/src/libraries/System.Security.Cryptography.Algorithms/tests/Rfc2898Tests.cs index e867eb1febb..1b240bf994f 100644 --- a/src/libraries/System.Security.Cryptography.Algorithms/tests/Rfc2898Tests.cs +++ b/src/libraries/System.Security.Cryptography.Algorithms/tests/Rfc2898Tests.cs @@ -39,19 +39,19 @@ namespace System.Security.Cryptography.DeriveBytesTests [Fact] public static void Ctor_EmptySalt() { - Assert.Throws(() => new Rfc2898DeriveBytes(TestPassword, Array.Empty(), DefaultIterationCount)); + AssertExtensions.Throws("salt", null, () => new Rfc2898DeriveBytes(TestPassword, Array.Empty(), DefaultIterationCount)); } [Fact] public static void Ctor_DiminishedSalt() { - Assert.Throws(() => new Rfc2898DeriveBytes(TestPassword, new byte[7], DefaultIterationCount)); + AssertExtensions.Throws("salt", null, () => new Rfc2898DeriveBytes(TestPassword, new byte[7], DefaultIterationCount)); } [Fact] public static void Ctor_GenerateZeroSalt() { - Assert.Throws(() => new Rfc2898DeriveBytes(TestPassword, 0)); + AssertExtensions.Throws("saltSize", null, () => new Rfc2898DeriveBytes(TestPassword, 0)); } [Fact] @@ -65,7 +65,7 @@ namespace System.Security.Cryptography.DeriveBytesTests [Fact] public static void Ctor_GenerateDiminishedSalt() { - Assert.Throws(() => new Rfc2898DeriveBytes(TestPassword, 7)); + AssertExtensions.Throws("saltSize", null, () => new Rfc2898DeriveBytes(TestPassword, 7)); } [Fact] diff --git a/src/libraries/System.Security.Cryptography.Cng/tests/ECDsaCngTests.cs b/src/libraries/System.Security.Cryptography.Cng/tests/ECDsaCngTests.cs index 0621d5a8196..a2e924f2952 100644 --- a/src/libraries/System.Security.Cryptography.Cng/tests/ECDsaCngTests.cs +++ b/src/libraries/System.Security.Cryptography.Cng/tests/ECDsaCngTests.cs @@ -112,7 +112,7 @@ namespace System.Security.Cryptography.Cng.Tests { using (RSACng rsaCng = new RSACng()) { - Assert.Throws(() => new ECDsaCng(rsaCng.Key)); + AssertExtensions.Throws("key", () => new ECDsaCng(rsaCng.Key)); } } diff --git a/src/libraries/System.Security.Cryptography.Cng/tests/HandleTests.cs b/src/libraries/System.Security.Cryptography.Cng/tests/HandleTests.cs index c2519b646e7..ada15fe64e4 100644 --- a/src/libraries/System.Security.Cryptography.Cng/tests/HandleTests.cs +++ b/src/libraries/System.Security.Cryptography.Cng/tests/HandleTests.cs @@ -59,9 +59,9 @@ namespace System.Security.Cryptography.Cng.Tests Assert.True(closedAndInvalid.IsInvalid, "closedAndInvalid.IsInvalid"); // Tests - Assert.Throws(() => new SafeNCryptKeyHandle(IntPtr.Zero, openButInvalid)); - Assert.Throws(() => new SafeNCryptKeyHandle(IntPtr.Zero, closedButValid)); - Assert.Throws(() => new SafeNCryptKeyHandle(IntPtr.Zero, closedAndInvalid)); + AssertExtensions.Throws("parentHandle", () => new SafeNCryptKeyHandle(IntPtr.Zero, openButInvalid)); + AssertExtensions.Throws("parentHandle", () => new SafeNCryptKeyHandle(IntPtr.Zero, closedButValid)); + AssertExtensions.Throws("parentHandle", () => new SafeNCryptKeyHandle(IntPtr.Zero, closedAndInvalid)); } } diff --git a/src/libraries/System.Security.Cryptography.Csp/tests/CspParametersTests.cs b/src/libraries/System.Security.Cryptography.Csp/tests/CspParametersTests.cs index 07e37cf56e7..bd1b5e21e66 100644 --- a/src/libraries/System.Security.Cryptography.Csp/tests/CspParametersTests.cs +++ b/src/libraries/System.Security.Cryptography.Csp/tests/CspParametersTests.cs @@ -28,11 +28,10 @@ namespace System.Security.Cryptography.Csp.Tests CspParameters cspParameters = new CspParameters(); // Unmapped values (> 0xFF) throw - Assert.Throws(() => cspParameters.Flags = (CspProviderFlags)0x0100); + AssertExtensions.Throws(null, "value", () => cspParameters.Flags = (CspProviderFlags)0x0100); // Unmapped values (> 0xFF) throw, even when combined with known values. - Assert.Throws( - () => cspParameters.Flags = (CspProviderFlags)0x0100 | CspProviderFlags.NoPrompt); + AssertExtensions.Throws(null, "value", () => cspParameters.Flags = (CspProviderFlags)0x0100 | CspProviderFlags.NoPrompt); } [Fact] diff --git a/src/libraries/System.Security.Cryptography.Csp/tests/PasswordDeriveBytesTests.cs b/src/libraries/System.Security.Cryptography.Csp/tests/PasswordDeriveBytesTests.cs index 2c1f6d35355..74a2d20b157 100644 --- a/src/libraries/System.Security.Cryptography.Csp/tests/PasswordDeriveBytesTests.cs +++ b/src/libraries/System.Security.Cryptography.Csp/tests/PasswordDeriveBytesTests.cs @@ -196,7 +196,7 @@ namespace System.Security.Cryptography.DeriveBytesTests { using (var deriveBytes = new PasswordDeriveBytes(TestPassword, s_testSalt)) { - Assert.Throws(() => deriveBytes.GetBytes(0)); + AssertExtensions.Throws("", () => deriveBytes.GetBytes(0)); } } diff --git a/src/libraries/System.Security.Cryptography.Encoding/tests/AsnEncodedDataCollectionTests.cs b/src/libraries/System.Security.Cryptography.Encoding/tests/AsnEncodedDataCollectionTests.cs index e09d8a3b23d..18f9e068db6 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/tests/AsnEncodedDataCollectionTests.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/tests/AsnEncodedDataCollectionTests.cs @@ -122,7 +122,7 @@ namespace System.Security.Cryptography.Encoding.Tests AsnEncodedData[] a = new AsnEncodedData[3]; Assert.Throws(() => c.CopyTo(a, -1)); Assert.Throws(() => c.CopyTo(a, 3)); - Assert.Throws(() => c.CopyTo(a, 1)); + AssertExtensions.Throws("destinationArray", null, () => c.CopyTo(a, 1)); if (PlatformDetection.IsNonZeroLowerBoundArraySupported) { diff --git a/src/libraries/System.Security.Cryptography.Encoding/tests/OidCollectionTests.cs b/src/libraries/System.Security.Cryptography.Encoding/tests/OidCollectionTests.cs index 3d499a9816d..81a35622945 100644 --- a/src/libraries/System.Security.Cryptography.Encoding/tests/OidCollectionTests.cs +++ b/src/libraries/System.Security.Cryptography.Encoding/tests/OidCollectionTests.cs @@ -93,7 +93,7 @@ namespace System.Security.Cryptography.Encoding.Tests [Fact] public void CopyTo_Throws() { - ValidateCopyToThrows((collection, array, index) => collection.CopyTo(array, index)); + ValidateCopyToThrows((collection, array, index) => collection.CopyTo(array, index), paramName: "destinationArray"); } [Fact] @@ -102,14 +102,15 @@ namespace System.Security.Cryptography.Encoding.Tests ValidateCopyToThrows((collection, array, index) => ((ICollection)collection).CopyTo(array, index), c => { ICollection ic = c; - Assert.Throws(() => ic.CopyTo(new Oid[4, 3], 0)); + AssertExtensions.Throws(null, () => ic.CopyTo(new Oid[4, 3], 0)); Assert.Throws(() => ic.CopyTo(new string[10], 0)); - }); + }, paramName: null); } private static void ValidateCopyToThrows( Action copyTo, - Action additionalValidation = null) + Action additionalValidation = null, + string paramName = null) { var item1 = new Oid(Sha1Oid, Sha1Name); var item2 = new Oid(Sha256Oid, Sha256Name); @@ -121,7 +122,7 @@ namespace System.Security.Cryptography.Encoding.Tests Assert.Throws(() => copyTo(c, null, 0)); Assert.Throws(() => copyTo(c, null, -1)); Assert.Throws(() => copyTo(c, new Oid[10], -1)); - Assert.Throws(() => copyTo(c, new Oid[10], 7)); + AssertExtensions.Throws(paramName, null, () => copyTo(c, new Oid[10], 7)); Assert.Throws(() => copyTo(c, new Oid[10], 1000)); additionalValidation?.Invoke(c); diff --git a/src/libraries/System.Security.Cryptography.OpenSsl/tests/DsaOpenSslTests.cs b/src/libraries/System.Security.Cryptography.OpenSsl/tests/DsaOpenSslTests.cs index c91edc6bf30..d94b2dc6b99 100644 --- a/src/libraries/System.Security.Cryptography.OpenSsl/tests/DsaOpenSslTests.cs +++ b/src/libraries/System.Security.Cryptography.OpenSsl/tests/DsaOpenSslTests.cs @@ -75,7 +75,7 @@ namespace System.Security.Cryptography.OpenSsl.Tests { } - Assert.Throws(() => new DSAOpenSsl(pkey)); + AssertExtensions.Throws("pkeyHandle", () => new DSAOpenSsl(pkey)); } } @@ -84,7 +84,7 @@ namespace System.Security.Cryptography.OpenSsl.Tests { using (SafeEvpPKeyHandle pkey = new SafeEvpPKeyHandle(IntPtr.Zero, false)) { - Assert.Throws(() => new DSAOpenSsl(pkey)); + AssertExtensions.Throws("pkeyHandle", () => new DSAOpenSsl(pkey)); } } diff --git a/src/libraries/System.Security.Cryptography.OpenSsl/tests/EcDsaOpenSslTests.cs b/src/libraries/System.Security.Cryptography.OpenSsl/tests/EcDsaOpenSslTests.cs index 5299c3ada0d..4051b802980 100644 --- a/src/libraries/System.Security.Cryptography.OpenSsl/tests/EcDsaOpenSslTests.cs +++ b/src/libraries/System.Security.Cryptography.OpenSsl/tests/EcDsaOpenSslTests.cs @@ -220,7 +220,7 @@ namespace System.Security.Cryptography.EcDsa.OpenSsl.Tests { } - Assert.Throws(() => new ECDsaOpenSsl(pkey)); + AssertExtensions.Throws("pkeyHandle", () => new ECDsaOpenSsl(pkey)); } } @@ -229,7 +229,7 @@ namespace System.Security.Cryptography.EcDsa.OpenSsl.Tests { using (SafeEvpPKeyHandle pkey = new SafeEvpPKeyHandle(IntPtr.Zero, false)) { - Assert.Throws(() => new ECDsaOpenSsl(pkey)); + AssertExtensions.Throws("pkeyHandle", () => new ECDsaOpenSsl(pkey)); } } diff --git a/src/libraries/System.Security.Cryptography.OpenSsl/tests/RsaOpenSslTests.cs b/src/libraries/System.Security.Cryptography.OpenSsl/tests/RsaOpenSslTests.cs index f70b22394fa..e97137741aa 100644 --- a/src/libraries/System.Security.Cryptography.OpenSsl/tests/RsaOpenSslTests.cs +++ b/src/libraries/System.Security.Cryptography.OpenSsl/tests/RsaOpenSslTests.cs @@ -75,7 +75,7 @@ namespace System.Security.Cryptography.OpenSsl.Tests { } - Assert.Throws(() => new RSAOpenSsl(pkey)); + AssertExtensions.Throws("pkeyHandle", () => new RSAOpenSsl(pkey)); } } @@ -84,7 +84,7 @@ namespace System.Security.Cryptography.OpenSsl.Tests { using (SafeEvpPKeyHandle pkey = new SafeEvpPKeyHandle(IntPtr.Zero, false)) { - Assert.Throws(() => new RSAOpenSsl(pkey)); + AssertExtensions.Throws("pkeyHandle", () => new RSAOpenSsl(pkey)); } } diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs index ee3f7e5d0cd..f00fcb8c99f 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/CmsRecipientCollectionTests.cs @@ -160,14 +160,14 @@ namespace System.Security.Cryptography.Pkcs.Tests Assert.Throws(() => c.CopyTo(null, 0)); Assert.Throws(() => c.CopyTo(a, -1)); Assert.Throws(() => c.CopyTo(a, 3)); - Assert.Throws(() => c.CopyTo(a, 1)); + AssertExtensions.Throws(null, () => c.CopyTo(a, 1)); ICollection ic = c; Assert.Throws(() => ic.CopyTo(null, 0)); Assert.Throws(() => ic.CopyTo(a, -1)); Assert.Throws(() => ic.CopyTo(a, 3)); - Assert.Throws(() => ic.CopyTo(a, 1)); - Assert.Throws(() => ic.CopyTo(new CmsRecipient[2, 2], 1)); + AssertExtensions.Throws(null, () => ic.CopyTo(a, 1)); + AssertExtensions.Throws(null, () => ic.CopyTo(new CmsRecipient[2, 2], 1)); Assert.Throws(() => ic.CopyTo(new int[10], 1)); if (PlatformDetection.IsNonZeroLowerBoundArraySupported) diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs index c33bcdacd75..c84d3f31f58 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/CryptographicAttributeObjectCollectionTests.cs @@ -152,14 +152,14 @@ namespace System.Security.Cryptography.Pkcs.Tests Assert.Throws(() => c.CopyTo(null, 0)); Assert.Throws(() => c.CopyTo(a, -1)); Assert.Throws(() => c.CopyTo(a, 3)); - Assert.Throws(() => c.CopyTo(a, 1)); + AssertExtensions.Throws(null, () => c.CopyTo(a, 1)); ICollection ic = c; Assert.Throws(() => ic.CopyTo(null, 0)); Assert.Throws(() => ic.CopyTo(a, -1)); Assert.Throws(() => ic.CopyTo(a, 3)); - Assert.Throws(() => ic.CopyTo(a, 1)); - Assert.Throws(() => ic.CopyTo(new CryptographicAttributeObject[2, 2], 0)); + AssertExtensions.Throws(null, () => ic.CopyTo(a, 1)); + AssertExtensions.Throws(null, () => ic.CopyTo(new CryptographicAttributeObject[2, 2], 0)); Assert.Throws(() => ic.CopyTo(new int[10], 0)); if (PlatformDetection.IsNonZeroLowerBoundArraySupported) diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/Pkcs9AttributeTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/Pkcs9AttributeTests.cs index 2be317a8dd9..a1d2be92adf 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/Pkcs9AttributeTests.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/Pkcs9AttributeTests.cs @@ -57,7 +57,7 @@ namespace System.Security.Cryptography.Pkcs.Tests AsnEncodedData a = new AsnEncodedData(oid, new byte[3]); object ign; - Assert.Throws(() => ign = new Pkcs9AttributeObject(a)); + AssertExtensions.Throws("oid.Value", () => ign = new Pkcs9AttributeObject(a)); } [Fact] @@ -74,7 +74,7 @@ namespace System.Security.Cryptography.Pkcs.Tests Pkcs9AttributeObject p = new Pkcs9AttributeObject(); byte[] rawData = "041e4d00790020004400650073006300720069007000740069006f006e000000".HexToByteArray(); AsnEncodedData a = new AsnEncodedData(Oids.DocumentName, rawData); - Assert.Throws(() => p.CopyFrom(a)); + AssertExtensions.Throws(null, () => p.CopyFrom(a)); } [Fact] diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs index 7b7be6e3b9b..2743d1d6375 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/RecipientInfoCollectionTests.cs @@ -114,16 +114,16 @@ namespace System.Security.Cryptography.Pkcs.Tests RecipientInfo[] recipients = new RecipientInfo[6]; col.CopyTo(recipients, 3); - Assert.Throws(() => col.CopyTo(recipients, 4)); + AssertExtensions.Throws("destinationArray", null, () => col.CopyTo(recipients, 4)); Assert.Throws(() => col.CopyTo(recipients, -1)); Assert.Throws(() => col.CopyTo(recipients, 6)); ICollection ic = col; - Assert.Throws(() => ic.CopyTo(recipients, 4)); + AssertExtensions.Throws(null, () => ic.CopyTo(recipients, 4)); Assert.Throws(() => ic.CopyTo(recipients, -1)); Assert.Throws(() => ic.CopyTo(recipients, 6)); Assert.Throws(() => ic.CopyTo(recipients, 6)); - Assert.Throws(() => ic.CopyTo(new RecipientInfo[2, 2], 0)); + AssertExtensions.Throws(null, () => ic.CopyTo(new RecipientInfo[2, 2], 0)); } [Fact] @@ -136,7 +136,7 @@ namespace System.Security.Cryptography.Pkcs.Tests RecipientInfo[] recipients = new RecipientInfo[6]; col.CopyTo(recipients, 3); - Assert.Throws(() => col.CopyTo(recipients, 4)); + AssertExtensions.Throws(null, () => col.CopyTo(recipients, 4)); Assert.Throws(() => col.CopyTo(recipients, -1)); Assert.Throws(() => col.CopyTo(recipients, 6)); diff --git a/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj b/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj index 11e8cd7f7f5..b93ebb44d0a 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/System.Security.Cryptography.Pkcs.Tests.csproj @@ -38,6 +38,9 @@ + + Common\System\AssertExtensions.cs + diff --git a/src/libraries/System.Security.Cryptography.Primitives/tests/CryptoStream.cs b/src/libraries/System.Security.Cryptography.Primitives/tests/CryptoStream.cs index f0f6fab807a..1171efe8afc 100644 --- a/src/libraries/System.Security.Cryptography.Primitives/tests/CryptoStream.cs +++ b/src/libraries/System.Security.Cryptography.Primitives/tests/CryptoStream.cs @@ -15,9 +15,9 @@ namespace System.Security.Cryptography.Encryption.Tests.Asymmetric public static void Ctor() { var transform = new IdentityTransform(1, 1, true); - Assert.Throws(() => new CryptoStream(new MemoryStream(), transform, (CryptoStreamMode)12345)); - Assert.Throws(() => new CryptoStream(new MemoryStream(new byte[0], writable: false), transform, CryptoStreamMode.Write)); - Assert.Throws(() => new CryptoStream(new CryptoStream(new MemoryStream(new byte[0]), transform, CryptoStreamMode.Write), transform, CryptoStreamMode.Read)); + AssertExtensions.Throws(null, () => new CryptoStream(new MemoryStream(), transform, (CryptoStreamMode)12345)); + AssertExtensions.Throws(null, "stream", () => new CryptoStream(new MemoryStream(new byte[0], writable: false), transform, CryptoStreamMode.Write)); + AssertExtensions.Throws(null, "stream", () => new CryptoStream(new CryptoStream(new MemoryStream(new byte[0]), transform, CryptoStreamMode.Write), transform, CryptoStreamMode.Read)); } [Theory] @@ -51,7 +51,7 @@ namespace System.Security.Cryptography.Encryption.Tests.Asymmetric Assert.Throws(() => encryptStream.Write(new byte[0], -1, 0)); Assert.Throws(() => encryptStream.Write(new byte[0], 0, -1)); Assert.Throws(() => encryptStream.Write(new byte[0], 0, -1)); - Assert.Throws(() => encryptStream.Write(new byte[3], 1, 4)); + AssertExtensions.Throws(null, () => encryptStream.Write(new byte[3], 1, 4)); byte[] toWrite = Encoding.UTF8.GetBytes(LoremText); @@ -104,7 +104,7 @@ namespace System.Security.Cryptography.Encryption.Tests.Asymmetric Assert.Throws(() => decryptStream.Read(new byte[0], -1, 0)); Assert.Throws(() => decryptStream.Read(new byte[0], 0, -1)); Assert.Throws(() => decryptStream.Read(new byte[0], 0, -1)); - Assert.Throws(() => decryptStream.Read(new byte[3], 1, 4)); + AssertExtensions.Throws(null, () => decryptStream.Read(new byte[3], 1, 4)); using (StreamReader reader = new StreamReader(decryptStream)) { diff --git a/src/libraries/System.Security.Cryptography.Primitives/tests/SimpleHashAlgorithmTest.cs b/src/libraries/System.Security.Cryptography.Primitives/tests/SimpleHashAlgorithmTest.cs index 3593f365839..530c71d2358 100644 --- a/src/libraries/System.Security.Cryptography.Primitives/tests/SimpleHashAlgorithmTest.cs +++ b/src/libraries/System.Security.Cryptography.Primitives/tests/SimpleHashAlgorithmTest.cs @@ -122,9 +122,9 @@ namespace System.Security.Cryptography.Hashing.Tests { Assert.Throws(() => hash.ComputeHash((byte[])null, 0, 0)); Assert.Throws(() => hash.ComputeHash(s_tenBytes, -1, 0)); - Assert.Throws(() => hash.ComputeHash(s_tenBytes, 0, -1)); - Assert.Throws(() => hash.ComputeHash(s_tenBytes, 0, 11)); - Assert.Throws(() => hash.ComputeHash(s_tenBytes, 9, 2)); + AssertExtensions.Throws(null, () => hash.ComputeHash(s_tenBytes, 0, -1)); + AssertExtensions.Throws(null, () => hash.ComputeHash(s_tenBytes, 0, 11)); + AssertExtensions.Throws(null, () => hash.ComputeHash(s_tenBytes, 9, 2)); hash.Dispose(); diff --git a/src/libraries/System.Security.Cryptography.Primitives/tests/System.Security.Cryptography.Primitives.Tests.csproj b/src/libraries/System.Security.Cryptography.Primitives/tests/System.Security.Cryptography.Primitives.Tests.csproj index 8cb94859601..9490a4224bb 100644 --- a/src/libraries/System.Security.Cryptography.Primitives/tests/System.Security.Cryptography.Primitives.Tests.csproj +++ b/src/libraries/System.Security.Cryptography.Primitives/tests/System.Security.Cryptography.Primitives.Tests.csproj @@ -24,6 +24,9 @@ CommonTest\System\IO\PositionValueStream.cs + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/tests/CollectionTests.cs b/src/libraries/System.Security.Cryptography.X509Certificates/tests/CollectionTests.cs index e0c60a2741c..56dee9af45a 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/tests/CollectionTests.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/tests/CollectionTests.cs @@ -468,10 +468,10 @@ namespace System.Security.Cryptography.X509Certificates.Tests string bogus = "Bogus"; - Assert.Throws(() => il[0] = bogus); - Assert.Throws(() => il.Add(bogus)); - Assert.Throws(() => il.Remove(bogus)); - Assert.Throws(() => il.Insert(0, bogus)); + AssertExtensions.Throws("value", () => il[0] = bogus); + AssertExtensions.Throws("value", () => il.Add(bogus)); + AssertExtensions.Throws("value", () => il.Remove(bogus)); + AssertExtensions.Throws("value", () => il.Insert(0, bogus)); } } @@ -953,7 +953,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests cc.Remove(c2); Assert.Equal(0, cc.Count); - Assert.Throws(() => cc.Remove(c2)); + AssertExtensions.Throws(null, () => cc.Remove(c2)); IList il = new X509CertificateCollection(new X509Certificate[] { c1, c2 }); @@ -964,7 +964,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests il.Remove(c2); Assert.Equal(0, il.Count); - Assert.Throws(() => il.Remove(c2)); + AssertExtensions.Throws(null, () => il.Remove(c2)); } } @@ -1045,7 +1045,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests // Add c1Clone back // End state: { c1, c2 } => { c2, c1Clone } cc = new X509Certificate2Collection(array); - Assert.Throws(() => cc.RemoveRange(new X509Certificate2[] { c1Clone, c1, c2 })); + AssertExtensions.Throws(null, () => cc.RemoveRange(new X509Certificate2[] { c1Clone, c1, c2 })); Assert.Equal(2, cc.Count); Assert.Same(c2, cc[0]); Assert.Same(c1Clone, cc[1]); @@ -1106,7 +1106,7 @@ namespace System.Security.Cryptography.X509Certificates.Tests c1, c2, }; - Assert.Throws(() => cc.RemoveRange(collection)); + AssertExtensions.Throws(null, () => cc.RemoveRange(collection)); Assert.Equal(2, cc.Count); Assert.Same(c2, cc[0]); Assert.Same(c1Clone, cc[1]); diff --git a/src/libraries/System.Security.Cryptography.X509Certificates/tests/CtorTests.cs b/src/libraries/System.Security.Cryptography.X509Certificates/tests/CtorTests.cs index bbe093e4a9c..cb73a8baef9 100644 --- a/src/libraries/System.Security.Cryptography.X509Certificates/tests/CtorTests.cs +++ b/src/libraries/System.Security.Cryptography.X509Certificates/tests/CtorTests.cs @@ -280,11 +280,11 @@ namespace System.Security.Cryptography.X509Certificates.Tests public static void TestNullConstructorArguments() { Assert.Throws(() => new X509Certificate2((string)null)); - Assert.Throws(() => new X509Certificate2(IntPtr.Zero)); - Assert.Throws(() => new X509Certificate2((byte[])null, (string)null)); - Assert.Throws(() => new X509Certificate2(Array.Empty(), (string)null)); - Assert.Throws(() => new X509Certificate2((byte[])null, (string)null, X509KeyStorageFlags.DefaultKeySet)); - Assert.Throws(() => new X509Certificate2(Array.Empty(), (string)null, X509KeyStorageFlags.DefaultKeySet)); + AssertExtensions.Throws("handle", () => new X509Certificate2(IntPtr.Zero)); + AssertExtensions.Throws("rawData", () => new X509Certificate2((byte[])null, (string)null)); + AssertExtensions.Throws("rawData", () => new X509Certificate2(Array.Empty(), (string)null)); + AssertExtensions.Throws("rawData", () => new X509Certificate2((byte[])null, (string)null, X509KeyStorageFlags.DefaultKeySet)); + AssertExtensions.Throws("rawData", () => new X509Certificate2(Array.Empty(), (string)null, X509KeyStorageFlags.DefaultKeySet)); // A null string password does not throw using (new X509Certificate2(TestData.MsCertificate, (string)null)) { } diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/EncryptionPropertyCollectionTest.cs b/src/libraries/System.Security.Cryptography.Xml/tests/EncryptionPropertyCollectionTest.cs index 6c9293f6530..19d9e86f142 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/EncryptionPropertyCollectionTest.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/EncryptionPropertyCollectionTest.cs @@ -231,7 +231,7 @@ namespace System.Security.Cryptography.Xml.Tests encPropertyCollection.Add(new EncryptionProperty()); } EncryptionProperty[] encPropertyArray = new EncryptionProperty[1]; - Assert.Throws(() => encPropertyCollection.CopyTo(encPropertyArray, 0)); + AssertExtensions.Throws("destinationArray", "", () => encPropertyCollection.CopyTo(encPropertyArray, 0)); } [Fact] diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDecryptionTransformTest.cs b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDecryptionTransformTest.cs index af09d9efa85..adcc6dcb148 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDecryptionTransformTest.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDecryptionTransformTest.cs @@ -163,7 +163,7 @@ namespace System.Security.Cryptography.Xml.Tests doc.LoadXml(xml); transform.LoadInput(doc); - Assert.Throws(() => transform.GetOutput(typeof(string))); + AssertExtensions.Throws("type", () => transform.GetOutput(typeof(string))); } [Fact] diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigBase64TransformTest.cs b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigBase64TransformTest.cs index 6fd5e669a65..262f92cea30 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigBase64TransformTest.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigBase64TransformTest.cs @@ -178,7 +178,7 @@ namespace System.Security.Cryptography.Xml.Tests public void UnsupportedOutput() { XmlDocument doc = new XmlDocument(); - Assert.Throws(() => transform.GetOutput(doc.GetType())); + AssertExtensions.Throws("type", () => transform.GetOutput(doc.GetType())); } } } diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs index e78f0506aae..fd5366f0930 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigC14NTransformTest.cs @@ -140,7 +140,7 @@ namespace System.Security.Cryptography.Xml.Tests { XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); byte[] bad = { 0xBA, 0xD }; - Assert.Throws(() => transform.LoadInput(bad)); + AssertExtensions.Throws("obj", () => transform.LoadInput(bad)); } [Fact] @@ -148,7 +148,7 @@ namespace System.Security.Cryptography.Xml.Tests { XmlDsigC14NTransform transform = new XmlDsigC14NTransform(); XmlDocument doc = new XmlDocument(); - Assert.Throws(() => transform.GetOutput(doc.GetType())); + AssertExtensions.Throws("type", () => transform.GetOutput(doc.GetType())); } [Fact] diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs index f0b0257ae6f..d5889ac43fa 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigC14NWithCommentsTransformTest.cs @@ -56,7 +56,7 @@ namespace System.Security.Cryptography.Xml.Tests public void LoadInput_UnsupportedType(object input) { XmlDsigC14NWithCommentsTransform xmlDsigC14NWithCommentsTransform = new XmlDsigC14NWithCommentsTransform(); - Assert.Throws(() => xmlDsigC14NWithCommentsTransform.LoadInput(input)); + AssertExtensions.Throws("obj", () => xmlDsigC14NWithCommentsTransform.LoadInput(input)); } [Theory] @@ -65,7 +65,7 @@ namespace System.Security.Cryptography.Xml.Tests public void GetOutput_UnsupportedType(Type type) { XmlDsigC14NWithCommentsTransform xmlDsigC14NWithCommentsTransform = new XmlDsigC14NWithCommentsTransform(); - Assert.Throws(() => xmlDsigC14NWithCommentsTransform.GetOutput(type)); + AssertExtensions.Throws("type", () => xmlDsigC14NWithCommentsTransform.GetOutput(type)); } [Fact] diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs index c803d6c390e..26f82ffab6e 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigExcC14NTransformTest.cs @@ -280,14 +280,14 @@ namespace System.Security.Cryptography.Xml.Tests public void LoadInputWithUnsupportedType() { byte[] bad = { 0xBA, 0xD }; - Assert.Throws(() => transform.LoadInput(bad)); + AssertExtensions.Throws("obj", () => transform.LoadInput(bad)); } [Fact] public void UnsupportedOutput() { XmlDocument doc = new XmlDocument(); - Assert.Throws(() => transform.GetOutput(doc.GetType())); + AssertExtensions.Throws("type", () => transform.GetOutput(doc.GetType())); } [Fact] diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigXPathTransformTest.cs b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigXPathTransformTest.cs index 1cad2c6f1ff..d088954f33e 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigXPathTransformTest.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigXPathTransformTest.cs @@ -212,7 +212,7 @@ namespace System.Security.Cryptography.Xml.Tests public void UnsupportedOutput() { XmlDocument doc = new XmlDocument(); - Assert.Throws(() => transform.GetOutput(doc.GetType())); + AssertExtensions.Throws("type", () => transform.GetOutput(doc.GetType())); } [Fact] diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs index 3842e36f420..90abb4928ce 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/XmlDsigXsltTransformTest.cs @@ -302,7 +302,7 @@ namespace System.Security.Cryptography.Xml.Tests public void UnsupportedOutput() { XmlDocument doc = new XmlDocument(); - Assert.Throws(() => transform.GetOutput(doc.GetType())); + AssertExtensions.Throws("type", () => transform.GetOutput(doc.GetType())); } } } diff --git a/src/libraries/System.Security.Cryptography.Xml/tests/XmlLicenseTransformTest.cs b/src/libraries/System.Security.Cryptography.Xml/tests/XmlLicenseTransformTest.cs index b7135d5ff36..0f6e6114ddb 100644 --- a/src/libraries/System.Security.Cryptography.Xml/tests/XmlLicenseTransformTest.cs +++ b/src/libraries/System.Security.Cryptography.Xml/tests/XmlLicenseTransformTest.cs @@ -155,7 +155,7 @@ namespace System.Security.Cryptography.Xml.Tests [Fact] public void GetOutput_InvalidType() { - Assert.Throws(() => transform.GetOutput(typeof(string))); + AssertExtensions.Throws("type", () => transform.GetOutput(typeof(string))); } [Fact] diff --git a/src/libraries/System.Security.Permissions/tests/PrincipalPermissionTests.cs b/src/libraries/System.Security.Permissions/tests/PrincipalPermissionTests.cs index 2f4bbef0cde..a51905b15ab 100644 --- a/src/libraries/System.Security.Permissions/tests/PrincipalPermissionTests.cs +++ b/src/libraries/System.Security.Permissions/tests/PrincipalPermissionTests.cs @@ -122,7 +122,7 @@ namespace System.Security.Permissions.Tests SecurityElement se2 = new SecurityElement("IInvalidPermission", se.Text); se2.AddAttribute("class", se.Attribute("class")); se2.AddAttribute("version", se.Attribute("version")); - Assert.Throws(() => p.FromXml(se2)); + AssertExtensions.Throws(null, () => p.FromXml(se2)); } [Fact] @@ -134,7 +134,7 @@ namespace System.Security.Permissions.Tests SecurityElement se2 = new SecurityElement(se.Tag, se.Text); se2.AddAttribute("class", se.Attribute("class")); se2.AddAttribute("version", "2"); - Assert.Throws(() => p.FromXml(se2)); + AssertExtensions.Throws(null, () => p.FromXml(se2)); } [Fact] @@ -201,7 +201,7 @@ namespace System.Security.Permissions.Tests { PrincipalPermission p1 = new PrincipalPermission("user", null); EnvironmentPermission ep2 = new EnvironmentPermission(PermissionState.Unrestricted); - Assert.Throws(() => p1.Union(ep2)); + AssertExtensions.Throws("System.Security.Permissions.PrincipalPermission", () => p1.Union(ep2)); } [Fact] @@ -286,7 +286,7 @@ namespace System.Security.Permissions.Tests { PrincipalPermission p1 = new PrincipalPermission("user", null); EnvironmentPermission ep2 = new EnvironmentPermission(PermissionState.Unrestricted); - Assert.Throws(() => p1.Intersect(ep2)); + AssertExtensions.Throws("System.Security.Permissions.PrincipalPermission", () => p1.Intersect(ep2)); } [Fact] @@ -351,7 +351,7 @@ namespace System.Security.Permissions.Tests { PrincipalPermission p1 = new PrincipalPermission("user", null); EnvironmentPermission ep2 = new EnvironmentPermission(PermissionState.Unrestricted); - Assert.Throws(() => p1.IsSubsetOf(ep2)); + AssertExtensions.Throws("System.Security.Permissions.PrincipalPermission", () => p1.IsSubsetOf(ep2)); } } -} \ No newline at end of file +} diff --git a/src/libraries/System.Security.Permissions/tests/SecurityElementTests.cs b/src/libraries/System.Security.Permissions/tests/SecurityElementTests.cs index 928fc9433c6..4f8221d5576 100644 --- a/src/libraries/System.Security.Permissions/tests/SecurityElementTests.cs +++ b/src/libraries/System.Security.Permissions/tests/SecurityElementTests.cs @@ -237,14 +237,14 @@ namespace System.Security.Permissions.Tests public void AddAttribute_Name_Invalid() { SecurityElement elem = CreateElement(); - Assert.Throws(() => elem.AddAttribute("", "valid")); + AssertExtensions.Throws(null, () => elem.AddAttribute("", "valid")); } [Fact] public void AddAttribute_Value_Invalid() { SecurityElement elem = CreateElement(); - Assert.Throws(() => elem.AddAttribute("valid", "invalid\"")); + AssertExtensions.Throws(null, () => elem.AddAttribute("valid", "invalid\"")); } [Fact] @@ -260,7 +260,7 @@ namespace System.Security.Permissions.Tests public void AddAttribute_InvalidValue3() { SecurityElement elem = CreateElement(); - Assert.Throws(() => elem.AddAttribute("valid", "")); + AssertExtensions.Throws(null, () => elem.AddAttribute("valid", "")); } [Fact] @@ -268,7 +268,7 @@ namespace System.Security.Permissions.Tests { SecurityElement elem = CreateElement(); elem.AddAttribute("valid", "first time"); - Assert.Throws(() => elem.AddAttribute("valid", "second time")); + AssertExtensions.Throws(null, () => elem.AddAttribute("valid", "second time")); } [Fact] @@ -316,7 +316,7 @@ namespace System.Security.Permissions.Tests SecurityElement elem = CreateElement(); Hashtable h = elem.Attributes; h.Add("", "valid"); - Assert.Throws(() => elem.Attributes = h); + AssertExtensions.Throws(null, () => elem.Attributes = h); } [Fact] diff --git a/src/libraries/System.Security.Permissions/tests/System.Security.Permissions.Tests.csproj b/src/libraries/System.Security.Permissions/tests/System.Security.Permissions.Tests.csproj index 2288f2250f1..f1e9ea44aba 100644 --- a/src/libraries/System.Security.Permissions/tests/System.Security.Permissions.Tests.csproj +++ b/src/libraries/System.Security.Permissions/tests/System.Security.Permissions.Tests.csproj @@ -27,6 +27,9 @@ + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.Security.Principal.Windows/tests/System.Security.Principal.Windows.Tests.csproj b/src/libraries/System.Security.Principal.Windows/tests/System.Security.Principal.Windows.Tests.csproj index 91f6f07fcfc..fd3fefacdd5 100644 --- a/src/libraries/System.Security.Principal.Windows/tests/System.Security.Principal.Windows.Tests.csproj +++ b/src/libraries/System.Security.Principal.Windows/tests/System.Security.Principal.Windows.Tests.csproj @@ -10,6 +10,9 @@ + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.Security.Principal.Windows/tests/WellKnownSidTypeTests.cs b/src/libraries/System.Security.Principal.Windows/tests/WellKnownSidTypeTests.cs index dd957c06afb..daf2cc26793 100644 --- a/src/libraries/System.Security.Principal.Windows/tests/WellKnownSidTypeTests.cs +++ b/src/libraries/System.Security.Principal.Windows/tests/WellKnownSidTypeTests.cs @@ -143,7 +143,7 @@ public class WellKnownSidTypeTests public void CreatingSecurityIdentifierOutsideWellKnownSidTypeDefinedRangeThrowsException(WellKnownSidType sidType) { var currentDomainSid = WindowsIdentity.GetCurrent().Owner.AccountDomainSid; - Assert.Throws(() => new SecurityIdentifier(sidType, currentDomainSid)); + AssertExtensions.Throws("sidType", () => new SecurityIdentifier(sidType, currentDomainSid)); } [Fact] diff --git a/src/libraries/System.ServiceProcess.ServiceController/tests/System.ServiceProcess.ServiceController.Tests/ServiceControllerTests.cs b/src/libraries/System.ServiceProcess.ServiceController/tests/System.ServiceProcess.ServiceController.Tests/ServiceControllerTests.cs index bbdcf074d58..250a0bb91f4 100644 --- a/src/libraries/System.ServiceProcess.ServiceController/tests/System.ServiceProcess.ServiceController.Tests/ServiceControllerTests.cs +++ b/src/libraries/System.ServiceProcess.ServiceController/tests/System.ServiceProcess.ServiceController.Tests/ServiceControllerTests.cs @@ -123,7 +123,7 @@ namespace System.ServiceProcess.Tests var controller = new ServiceController(_testService.TestServiceName, _testService.TestMachineName); AssertExpectedProperties(controller); - Assert.Throws(() => { var c = new ServiceController(_testService.TestServiceName, ""); }); + AssertExtensions.Throws(null, () => { var c = new ServiceController(_testService.TestServiceName, ""); }); } [ConditionalFact(nameof(RunningWithElevatedPrivileges))] diff --git a/src/libraries/System.Text.Encoding.CodePages/tests/EncodingCodePages.cs b/src/libraries/System.Text.Encoding.CodePages/tests/EncodingCodePages.cs index a058eaca7f1..fe9e099adf5 100644 --- a/src/libraries/System.Text.Encoding.CodePages/tests/EncodingCodePages.cs +++ b/src/libraries/System.Text.Encoding.CodePages/tests/EncodingCodePages.cs @@ -472,7 +472,7 @@ namespace System.Text.Tests foreach (object[] mapping in CodePageInfo()) { Assert.Throws(() => Encoding.GetEncoding((int)mapping[0])); - Assert.Throws(() => Encoding.GetEncoding((string)mapping[2])); + AssertExtensions.Throws("name", () => Encoding.GetEncoding((string)mapping[2])); } // Currently the class EncodingInfo isn't present in corefx, so this checks none of the code pages are present. diff --git a/src/libraries/System.Text.Encoding.CodePages/tests/System.Text.Encoding.CodePages.Tests.csproj b/src/libraries/System.Text.Encoding.CodePages/tests/System.Text.Encoding.CodePages.Tests.csproj index 94457ad1d37..10be8f1e68e 100644 --- a/src/libraries/System.Text.Encoding.CodePages/tests/System.Text.Encoding.CodePages.Tests.csproj +++ b/src/libraries/System.Text.Encoding.CodePages/tests/System.Text.Encoding.CodePages.Tests.csproj @@ -9,6 +9,9 @@ + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.Text.Encoding/tests/Decoder/DecoderReset.cs b/src/libraries/System.Text.Encoding/tests/Decoder/DecoderReset.cs index e841f74ee93..e6fad9d26dc 100644 --- a/src/libraries/System.Text.Encoding/tests/Decoder/DecoderReset.cs +++ b/src/libraries/System.Text.Encoding/tests/Decoder/DecoderReset.cs @@ -48,7 +48,7 @@ namespace System.Text.Tests bytes[i] = (byte)i; } - Assert.Throws(() => + AssertExtensions.Throws("chars", () => { decoder.GetChars(bytes, 0, bytes.Length, chars, chars.Length - 1, false); }); @@ -56,7 +56,7 @@ namespace System.Text.Tests decoder.GetChars(bytes, 0, bytes.Length, chars, 0, false); - Assert.Throws(() => + AssertExtensions.Throws("chars", () => { decoder.GetChars(bytes, 0, bytes.Length, chars, chars.Length - 1, true); }); diff --git a/src/libraries/System.Text.Encoding/tests/Fallback/DecoderReplacementFallbackTests.cs b/src/libraries/System.Text.Encoding/tests/Fallback/DecoderReplacementFallbackTests.cs index 200eac7bc0d..8474df5ca41 100644 --- a/src/libraries/System.Text.Encoding/tests/Fallback/DecoderReplacementFallbackTests.cs +++ b/src/libraries/System.Text.Encoding/tests/Fallback/DecoderReplacementFallbackTests.cs @@ -37,12 +37,12 @@ namespace System.Text.Tests AssertExtensions.Throws("replacement", () => new DecoderReplacementFallback(null)); // Invalid surrogate pair - Assert.Throws(() => new DecoderReplacementFallback("\uD800")); - Assert.Throws(() => new DecoderReplacementFallback("\uD800a")); - Assert.Throws(() => new DecoderReplacementFallback("\uDC00")); - Assert.Throws(() => new DecoderReplacementFallback("a\uDC00")); - Assert.Throws(() => new DecoderReplacementFallback("\uDC00\uDC00")); - Assert.Throws(() => new DecoderReplacementFallback("\uD800\uD800")); + AssertExtensions.Throws(null, () => new DecoderReplacementFallback("\uD800")); + AssertExtensions.Throws(null, () => new DecoderReplacementFallback("\uD800a")); + AssertExtensions.Throws(null, () => new DecoderReplacementFallback("\uDC00")); + AssertExtensions.Throws(null, () => new DecoderReplacementFallback("a\uDC00")); + AssertExtensions.Throws(null, () => new DecoderReplacementFallback("\uDC00\uDC00")); + AssertExtensions.Throws(null, () => new DecoderReplacementFallback("\uD800\uD800")); } public static IEnumerable Equals_TestData() diff --git a/src/libraries/System.Text.Encoding/tests/Fallback/EncoderReplacementFallbackTests.cs b/src/libraries/System.Text.Encoding/tests/Fallback/EncoderReplacementFallbackTests.cs index 0d5628f69e2..f95529302ce 100644 --- a/src/libraries/System.Text.Encoding/tests/Fallback/EncoderReplacementFallbackTests.cs +++ b/src/libraries/System.Text.Encoding/tests/Fallback/EncoderReplacementFallbackTests.cs @@ -37,12 +37,12 @@ namespace System.Text.Tests AssertExtensions.Throws("replacement", () => new EncoderReplacementFallback(null)); // Invalid surrogate pair - Assert.Throws(() => new EncoderReplacementFallback("\uD800")); - Assert.Throws(() => new EncoderReplacementFallback("\uD800a")); - Assert.Throws(() => new EncoderReplacementFallback("\uDC00")); - Assert.Throws(() => new EncoderReplacementFallback("a\uDC00")); - Assert.Throws(() => new EncoderReplacementFallback("\uDC00\uDC00")); - Assert.Throws(() => new EncoderReplacementFallback("\uD800\uD800")); + AssertExtensions.Throws(null, () => new EncoderReplacementFallback("\uD800")); + AssertExtensions.Throws(null, () => new EncoderReplacementFallback("\uD800a")); + AssertExtensions.Throws(null, () => new EncoderReplacementFallback("\uDC00")); + AssertExtensions.Throws(null, () => new EncoderReplacementFallback("a\uDC00")); + AssertExtensions.Throws(null, () => new EncoderReplacementFallback("\uDC00\uDC00")); + AssertExtensions.Throws(null, () => new EncoderReplacementFallback("\uD800\uD800")); } public static IEnumerable Equals_TestData() diff --git a/src/libraries/System.Text.RegularExpressions/tests/CaptureCollectionTests.netcoreapp.cs b/src/libraries/System.Text.RegularExpressions/tests/CaptureCollectionTests.netcoreapp.cs index 5e606a12f26..045f25d3463 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/CaptureCollectionTests.netcoreapp.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/CaptureCollectionTests.netcoreapp.cs @@ -130,8 +130,8 @@ namespace System.Text.RegularExpressions.Tests ICollection collection = CreateCollection(); AssertExtensions.Throws("array", () => collection.CopyTo((Capture[])null, 0)); AssertExtensions.Throws("arrayIndex", () => collection.CopyTo(new Capture[1], -1)); - Assert.Throws(() => collection.CopyTo(new Capture[1], 0)); - Assert.Throws(() => collection.CopyTo(new Capture[1], 1)); + AssertExtensions.Throws(null, () => collection.CopyTo(new Capture[1], 0)); + AssertExtensions.Throws(null, () => collection.CopyTo(new Capture[1], 1)); AssertExtensions.Throws("arrayIndex", () => collection.CopyTo(new Capture[1], 2)); } diff --git a/src/libraries/System.Text.RegularExpressions/tests/GroupCollectionTests.netcoreapp.cs b/src/libraries/System.Text.RegularExpressions/tests/GroupCollectionTests.netcoreapp.cs index 733b63ab8b2..2b1f06a867c 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/GroupCollectionTests.netcoreapp.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/GroupCollectionTests.netcoreapp.cs @@ -127,8 +127,8 @@ namespace System.Text.RegularExpressions.Tests ICollection collection = CreateCollection(); AssertExtensions.Throws("array", () => collection.CopyTo(null, 0)); AssertExtensions.Throws("arrayIndex", () => collection.CopyTo(new Group[1], -1)); - Assert.Throws(() => collection.CopyTo(new Group[1], 0)); - Assert.Throws(() => collection.CopyTo(new Group[1], 1)); + AssertExtensions.Throws(null, () => collection.CopyTo(new Group[1], 0)); + AssertExtensions.Throws(null, () => collection.CopyTo(new Group[1], 1)); AssertExtensions.Throws("arrayIndex", () => collection.CopyTo(new Group[1], 2)); } diff --git a/src/libraries/System.Text.RegularExpressions/tests/MatchCollectionTests.netcoreapp.cs b/src/libraries/System.Text.RegularExpressions/tests/MatchCollectionTests.netcoreapp.cs index c4120da59db..08a9c90b89d 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/MatchCollectionTests.netcoreapp.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/MatchCollectionTests.netcoreapp.cs @@ -124,9 +124,9 @@ namespace System.Text.RegularExpressions.Tests ICollection collection = CreateCollection(); Assert.Throws(() => collection.CopyTo(null, 0)); Assert.Throws(() => collection.CopyTo(new Match[1], -1)); - Assert.Throws(() => collection.CopyTo(new Match[1], 0)); - Assert.Throws(() => collection.CopyTo(new Match[1], 1)); - Assert.Throws(() => collection.CopyTo(new Match[1], 2)); + AssertExtensions.Throws("destinationArray", () => collection.CopyTo(new Match[1], 0)); + AssertExtensions.Throws("destinationArray", () => collection.CopyTo(new Match[1], 1)); + AssertExtensions.Throws("destinationArray", () => collection.CopyTo(new Match[1], 2)); } [Fact] diff --git a/src/libraries/System.Text.RegularExpressions/tests/Regex.Ctor.Tests.cs b/src/libraries/System.Text.RegularExpressions/tests/Regex.Ctor.Tests.cs index 5f563d00ef7..16d121ee7d2 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/Regex.Ctor.Tests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/Regex.Ctor.Tests.cs @@ -254,7 +254,7 @@ namespace System.Text.RegularExpressions.Tests [InlineData("?((a)a|b", RegexOptions.None)] public void Ctor_InvalidPattern(string pattern, RegexOptions options) { - Assert.Throws(() => new Regex(pattern, options)); + AssertExtensions.Throws(null, () => new Regex(pattern, options)); } [Theory] diff --git a/src/libraries/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs b/src/libraries/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs index 6f33aa4f274..765f2e01474 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/Regex.Match.Tests.cs @@ -752,7 +752,7 @@ namespace System.Text.RegularExpressions.Tests [InlineData("(?()|||||)")] public void Match_InvalidPattern(string pattern) { - Assert.Throws(() => Regex.Match("input", pattern)); + AssertExtensions.Throws(null, () => Regex.Match("input", pattern)); } [Fact] diff --git a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_AllocateNativeOverlappedTests.cs b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_AllocateNativeOverlappedTests.cs index e6b93ac3307..3f9ce322077 100644 --- a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_AllocateNativeOverlappedTests.cs +++ b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_AllocateNativeOverlappedTests.cs @@ -83,7 +83,7 @@ public partial class ThreadPoolBoundHandleTests { using(ThreadPoolBoundHandle handle = CreateThreadPoolBoundHandle()) { - Assert.Throws(() => handle.AllocateNativeOverlapped((_, __, ___) => { }, new object(), new NonBlittableType() { s = "foo" })); + AssertExtensions.Throws(null, () => handle.AllocateNativeOverlapped((_, __, ___) => { }, new object(), new NonBlittableType() { s = "foo" })); } } @@ -131,7 +131,7 @@ public partial class ThreadPoolBoundHandleTests }; using(ThreadPoolBoundHandle handle = CreateThreadPoolBoundHandle()) { - Assert.Throws(() => handle.AllocateNativeOverlapped((_, __, ___) => { }, new object(), array)); + AssertExtensions.Throws(null, () => handle.AllocateNativeOverlapped((_, __, ___) => { }, new object(), array)); } } @@ -277,7 +277,7 @@ public partial class ThreadPoolBoundHandleTests { NativeOverlapped* overlapped = handle.AllocateNativeOverlapped(preAlloc); - Assert.Throws(() => + AssertExtensions.Throws("preAllocated", () => { handle.AllocateNativeOverlapped(preAlloc); }); diff --git a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_FreeNativeOverlappedTests.cs b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_FreeNativeOverlappedTests.cs index 8ec2b4b6d20..18777796754 100644 --- a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_FreeNativeOverlappedTests.cs +++ b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_FreeNativeOverlappedTests.cs @@ -41,7 +41,7 @@ public partial class ThreadPoolBoundHandleTests using (ThreadPoolBoundHandle handle2 = CreateThreadPoolBoundHandle()) { - Assert.Throws(() => + AssertExtensions.Throws("overlapped", () => { handle2.FreeNativeOverlapped(overlapped); }); diff --git a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_PreAllocatedOverlappedTests.cs b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_PreAllocatedOverlappedTests.cs index 41715d9e4f0..447185832ed 100644 --- a/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_PreAllocatedOverlappedTests.cs +++ b/src/libraries/System.Threading.Overlapped/tests/ThreadPoolBoundHandle_PreAllocatedOverlappedTests.cs @@ -43,7 +43,7 @@ public partial class ThreadPoolBoundHandleTests [Fact] public unsafe void PreAllocatedOverlapped_NonBlittableTypeAsPinData_Throws() { - Assert.Throws(() => new PreAllocatedOverlapped((_, __, ___) => { }, new object(), new NonBlittableType() { s = "foo" })); + AssertExtensions.Throws(null, () => new PreAllocatedOverlapped((_, __, ___) => { }, new object(), new NonBlittableType() { s = "foo" })); // Make sure the PreAllocatedOverlapped finalizer does the right thing in the case where the .ctor failed. GC.Collect(); @@ -75,7 +75,7 @@ public partial class ThreadPoolBoundHandleTests new NonBlittableType() { s = "foo" }, new byte[5], }; - Assert.Throws(() => new PreAllocatedOverlapped((_, __, ___) => { }, new object(), array)); + AssertExtensions.Throws(null, () => new PreAllocatedOverlapped((_, __, ___) => { }, new object(), array)); // Make sure the PreAllocatedOverlapped finalizer does the right thing in the case where the .ctor failed. GC.Collect(); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/BatchedJoinBlockTests.cs b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/BatchedJoinBlockTests.cs index a34bc39405f..3d3c84f4833 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/BatchedJoinBlockTests.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/BatchedJoinBlockTests.cs @@ -52,15 +52,15 @@ namespace System.Threading.Tasks.Dataflow.Tests { Assert.Throws(() => new BatchedJoinBlock(-1)); Assert.Throws(() => new BatchedJoinBlock(2, null)); - Assert.Throws(() => new BatchedJoinBlock(2, new GroupingDataflowBlockOptions { Greedy = false })); - Assert.Throws(() => new BatchedJoinBlock(2, new GroupingDataflowBlockOptions { BoundedCapacity = 2 })); + AssertExtensions.Throws("dataflowBlockOptions", () => new BatchedJoinBlock(2, new GroupingDataflowBlockOptions { Greedy = false })); + AssertExtensions.Throws("dataflowBlockOptions", () => new BatchedJoinBlock(2, new GroupingDataflowBlockOptions { BoundedCapacity = 2 })); Assert.Throws(() => ((IDataflowBlock)new BatchedJoinBlock(2)).Fault(null)); Assert.Throws(() => new BatchedJoinBlock(2).Target1.Fault(null)); Assert.Throws(() => new BatchedJoinBlock(-1)); Assert.Throws(() => new BatchedJoinBlock(2, null)); - Assert.Throws(() => new BatchedJoinBlock(2, new GroupingDataflowBlockOptions { Greedy = false })); - Assert.Throws(() => new BatchedJoinBlock(2, new GroupingDataflowBlockOptions { BoundedCapacity = 2 })); + AssertExtensions.Throws("dataflowBlockOptions", () => new BatchedJoinBlock(2, new GroupingDataflowBlockOptions { Greedy = false })); + AssertExtensions.Throws("dataflowBlockOptions", () => new BatchedJoinBlock(2, new GroupingDataflowBlockOptions { BoundedCapacity = 2 })); Assert.Throws(() => ((IDataflowBlock)new BatchedJoinBlock(2)).Fault(null)); DataflowTestHelpers.TestArgumentsExceptions(new BatchedJoinBlock(1)); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/BroadcastBlockTests.cs b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/BroadcastBlockTests.cs index c47c4d581af..3f612b75003 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/BroadcastBlockTests.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/BroadcastBlockTests.cs @@ -33,9 +33,9 @@ namespace System.Threading.Tasks.Dataflow.Tests public void TestArgumentExceptions() { Assert.Throws(() => new BroadcastBlock(i => i, null)); - Assert.Throws(() => + AssertExtensions.Throws("messageHeader", () => ((ITargetBlock)new BroadcastBlock(null)).OfferMessage(default(DataflowMessageHeader), 0, null, consumeToAccept: false)); - Assert.Throws(() => + AssertExtensions.Throws("consumeToAccept", () => ((ITargetBlock)new BroadcastBlock(null)).OfferMessage(new DataflowMessageHeader(1), 0, null, consumeToAccept: true)); DataflowTestHelpers.TestArgumentsExceptions(new BroadcastBlock(i => i)); } diff --git a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowBlockExtensionTests.cs b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowBlockExtensionTests.cs index acd7a9266cc..7e89973e9d2 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowBlockExtensionTests.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowBlockExtensionTests.cs @@ -14,7 +14,7 @@ namespace System.Threading.Tasks.Dataflow.Tests [Fact] public void TestDataflowMessageHeader() { - Assert.Throws(() => new DataflowMessageHeader(0)); + AssertExtensions.Throws("id", () => new DataflowMessageHeader(0)); Assert.False(new DataflowMessageHeader().IsValid); Assert.True(new DataflowMessageHeader(1).IsValid); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowTestHelper.cs b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowTestHelper.cs index e86ae0c4945..4c5962c2140 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowTestHelper.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/DataflowTestHelper.cs @@ -63,22 +63,22 @@ namespace System.Threading.Tasks.Dataflow.Tests bool consumed; Assert.Throws(() => source.ConsumeMessage(validMessageHeader, invalidTarget, out consumed)); - Assert.Throws(() => source.ConsumeMessage(invalidMessageHeader, validTarget, out consumed)); - Assert.Throws(() => source.ConsumeMessage(invalidMessageHeader, invalidTarget, out consumed)); + AssertExtensions.Throws("messageHeader", () => source.ConsumeMessage(invalidMessageHeader, validTarget, out consumed)); + AssertExtensions.Throws("messageHeader", () => source.ConsumeMessage(invalidMessageHeader, invalidTarget, out consumed)); Assert.Throws(() => source.ReserveMessage(validMessageHeader, invalidTarget)); - Assert.Throws(() => source.ReserveMessage(invalidMessageHeader, validTarget)); - Assert.Throws(() => source.ReserveMessage(invalidMessageHeader, invalidTarget)); + AssertExtensions.Throws("messageHeader", () => source.ReserveMessage(invalidMessageHeader, validTarget)); + AssertExtensions.Throws("messageHeader", () => source.ReserveMessage(invalidMessageHeader, invalidTarget)); Assert.Throws(() => source.ReleaseReservation(validMessageHeader, invalidTarget)); - Assert.Throws(() => source.ReleaseReservation(invalidMessageHeader, validTarget)); - Assert.Throws(() => source.ReleaseReservation(invalidMessageHeader, invalidTarget)); + AssertExtensions.Throws("messageHeader", () => source.ReleaseReservation(invalidMessageHeader, validTarget)); + AssertExtensions.Throws("messageHeader", () => source.ReleaseReservation(invalidMessageHeader, invalidTarget)); } internal static void TestOfferMessage_ArgumentValidation(ITargetBlock target) { - Assert.Throws(() => target.OfferMessage(default(DataflowMessageHeader), default(T), new BufferBlock(), false)); - Assert.Throws(() => target.OfferMessage(default(DataflowMessageHeader), default(T), null, false)); - Assert.Throws(() => target.OfferMessage(new DataflowMessageHeader(1), default(T), null, true)); + AssertExtensions.Throws("messageHeader", () => target.OfferMessage(default(DataflowMessageHeader), default(T), new BufferBlock(), false)); + AssertExtensions.Throws("messageHeader", () => target.OfferMessage(default(DataflowMessageHeader), default(T), null, false)); + AssertExtensions.Throws("consumeToAccept", () => target.OfferMessage(new DataflowMessageHeader(1), default(T), null, true)); } internal static void TestOfferMessage_AcceptsDataDirectly(ITargetBlock target, int messages = 3) diff --git a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/JoinBlockTests.cs b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/JoinBlockTests.cs index a6c9434aa02..ef303ce2e84 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/JoinBlockTests.cs +++ b/src/libraries/System.Threading.Tasks.Dataflow/tests/Dataflow/JoinBlockTests.cs @@ -65,8 +65,8 @@ namespace System.Threading.Tasks.Dataflow.Tests Assert.Throws(() => { var ignored = new JoinBlock().Target1.Completion; }); Assert.Throws(() => { var ignored = new JoinBlock().Target3.Completion; }); Assert.Throws(() => new JoinBlock().Target1.Fault(null)); - Assert.Throws(() => new JoinBlock().Target1.OfferMessage(default(DataflowMessageHeader), 1, null, false)); - Assert.Throws(() => new JoinBlock().Target1.OfferMessage(new DataflowMessageHeader(1), 1, null, true)); + AssertExtensions.Throws("messageHeader", () => new JoinBlock().Target1.OfferMessage(default(DataflowMessageHeader), 1, null, false)); + AssertExtensions.Throws("consumeToAccept", () => new JoinBlock().Target1.OfferMessage(new DataflowMessageHeader(1), 1, null, true)); DataflowTestHelpers.TestArgumentsExceptions>(new JoinBlock()); DataflowTestHelpers.TestArgumentsExceptions>(new JoinBlock()); diff --git a/src/libraries/System.Threading.Tasks.Dataflow/tests/System.Threading.Tasks.Dataflow.Tests.csproj b/src/libraries/System.Threading.Tasks.Dataflow/tests/System.Threading.Tasks.Dataflow.Tests.csproj index 1c8adef64f9..e6bae024865 100644 --- a/src/libraries/System.Threading.Tasks.Dataflow/tests/System.Threading.Tasks.Dataflow.Tests.csproj +++ b/src/libraries/System.Threading.Tasks.Dataflow/tests/System.Threading.Tasks.Dataflow.Tests.csproj @@ -24,6 +24,9 @@ + + Common\System\AssertExtensions.cs + Common\System\Diagnostics\Tracing\TestEventListener.cs diff --git a/src/libraries/System.Threading.Tasks.Parallel/tests/ParallelForTests.cs b/src/libraries/System.Threading.Tasks.Parallel/tests/ParallelForTests.cs index dfe06287829..32a4353857e 100644 --- a/src/libraries/System.Threading.Tasks.Parallel/tests/ParallelForTests.cs +++ b/src/libraries/System.Threading.Tasks.Parallel/tests/ParallelForTests.cs @@ -32,7 +32,7 @@ namespace System.Threading.Tasks.Tests AssertExtensions.Throws("parallelOptions", () => Parallel.Invoke((ParallelOptions)null, () => { })); AssertExtensions.Throws("actions", () => Parallel.Invoke(options, null)); - Assert.Throws(() => Parallel.Invoke(options, (Action)null)); + AssertExtensions.Throws(null, () => Parallel.Invoke(options, (Action)null)); CancellationTokenSource cts = new CancellationTokenSource(); options.CancellationToken = cts.Token; diff --git a/src/libraries/System.Threading.Tasks/tests/System.Runtime.CompilerServices/TaskAwaiterTests.cs b/src/libraries/System.Threading.Tasks/tests/System.Runtime.CompilerServices/TaskAwaiterTests.cs index efea704f3bd..e4b12e36c87 100644 --- a/src/libraries/System.Threading.Tasks/tests/System.Runtime.CompilerServices/TaskAwaiterTests.cs +++ b/src/libraries/System.Threading.Tasks/tests/System.Runtime.CompilerServices/TaskAwaiterTests.cs @@ -182,14 +182,14 @@ namespace System.Threading.Tasks.Tests Task task = Task.FromException(exception); // Task.GetAwaiter and Task.GetAwaiter - Assert.Same(exception, Assert.Throws(() => ((Task)task).GetAwaiter().GetResult())); - Assert.Same(exception, Assert.Throws(() => task.GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => ((Task)task).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => task.GetAwaiter().GetResult())); // w/ ConfigureAwait false and true - Assert.Same(exception, Assert.Throws(() => ((Task)task).ConfigureAwait(false).GetAwaiter().GetResult())); - Assert.Same(exception, Assert.Throws(() => ((Task)task).ConfigureAwait(true).GetAwaiter().GetResult())); - Assert.Same(exception, Assert.Throws(() => task.ConfigureAwait(false).GetAwaiter().GetResult())); - Assert.Same(exception, Assert.Throws(() => task.ConfigureAwait(true).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => ((Task)task).ConfigureAwait(false).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => ((Task)task).ConfigureAwait(true).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => task.ConfigureAwait(false).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => task.ConfigureAwait(true).GetAwaiter().GetResult())); } [Fact] @@ -201,14 +201,14 @@ namespace System.Threading.Tasks.Tests Task task = tcs.Task; // Task.GetAwaiter and Task.GetAwaiter - Assert.Same(exception, Assert.Throws(() => ((Task)task).GetAwaiter().GetResult())); - Assert.Same(exception, Assert.Throws(() => task.GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => ((Task)task).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => task.GetAwaiter().GetResult())); // w/ ConfigureAwait false and true - Assert.Same(exception, Assert.Throws(() => ((Task)task).ConfigureAwait(false).GetAwaiter().GetResult())); - Assert.Same(exception, Assert.Throws(() => ((Task)task).ConfigureAwait(true).GetAwaiter().GetResult())); - Assert.Same(exception, Assert.Throws(() => task.ConfigureAwait(false).GetAwaiter().GetResult())); - Assert.Same(exception, Assert.Throws(() => task.ConfigureAwait(true).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => ((Task)task).ConfigureAwait(false).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => ((Task)task).ConfigureAwait(true).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => task.ConfigureAwait(false).GetAwaiter().GetResult())); + Assert.Same(exception, AssertExtensions.Throws(null, () => task.ConfigureAwait(true).GetAwaiter().GetResult())); } [Fact] diff --git a/src/libraries/System.Threading.Tasks/tests/System.Threading.Tasks.Tests.csproj b/src/libraries/System.Threading.Tasks/tests/System.Threading.Tasks.Tests.csproj index 309bc201128..04caa71bc96 100644 --- a/src/libraries/System.Threading.Tasks/tests/System.Threading.Tasks.Tests.csproj +++ b/src/libraries/System.Threading.Tasks/tests/System.Threading.Tasks.Tests.csproj @@ -52,6 +52,9 @@ CommonTest\System\Threading\ThreadPoolHelpers.cs + + Common\System\AssertExtensions.cs + diff --git a/src/libraries/System.Threading.Tasks/tests/Task/TaskRtTests_Core.cs b/src/libraries/System.Threading.Tasks/tests/Task/TaskRtTests_Core.cs index a2db51d7b4a..308982d9b82 100644 --- a/src/libraries/System.Threading.Tasks/tests/Task/TaskRtTests_Core.cs +++ b/src/libraries/System.Threading.Tasks/tests/Task/TaskRtTests_Core.cs @@ -1323,7 +1323,7 @@ namespace System.Threading.Tasks.Tests public static void RunTaskWaitAllTests() { Assert.Throws(() => Task.WaitAll((Task[])null)); - Assert.Throws(() => Task.WaitAll(new Task[] { null })); + AssertExtensions.Throws(null, () => Task.WaitAll(new Task[] { null })); Assert.Throws(() => Task.WaitAll(new Task[] { Task.Factory.StartNew(() => { }) }, -2)); Assert.Throws(() => Task.WaitAll(new Task[] { Task.Factory.StartNew(() => { }) }, TimeSpan.FromMilliseconds(-2))); diff --git a/src/libraries/System.Threading.Thread/tests/System.Threading.Thread.Tests.csproj b/src/libraries/System.Threading.Thread/tests/System.Threading.Thread.Tests.csproj index 45a5c815836..f8fe4f8c0b3 100644 --- a/src/libraries/System.Threading.Thread/tests/System.Threading.Thread.Tests.csproj +++ b/src/libraries/System.Threading.Thread/tests/System.Threading.Thread.Tests.csproj @@ -15,6 +15,9 @@ + + Common\System\AssertExtensions.cs + Common\System\PlatformDetection.cs diff --git a/src/libraries/System.Threading.Thread/tests/ThreadTests.cs b/src/libraries/System.Threading.Thread/tests/ThreadTests.cs index 0b9660a3229..ba15b4708e5 100644 --- a/src/libraries/System.Threading.Thread/tests/ThreadTests.cs +++ b/src/libraries/System.Threading.Thread/tests/ThreadTests.cs @@ -601,7 +601,7 @@ namespace System.Threading.Threads.Tests { // AllocateNamedDataSlot allocates slot = Thread.AllocateNamedDataSlot(slotName); - Assert.Throws(() => Thread.AllocateNamedDataSlot(slotName)); + AssertExtensions.Throws(null, () => Thread.AllocateNamedDataSlot(slotName)); slot2 = Thread.AllocateNamedDataSlot(slotName2); Assert.NotEqual(slot, slot2); VerifyLocalDataSlot(slot); diff --git a/src/libraries/System.Threading/tests/EventWaitHandleTests.cs b/src/libraries/System.Threading/tests/EventWaitHandleTests.cs index aa5218e0cd2..832f8d6d359 100644 --- a/src/libraries/System.Threading/tests/EventWaitHandleTests.cs +++ b/src/libraries/System.Threading/tests/EventWaitHandleTests.cs @@ -23,14 +23,14 @@ namespace System.Threading.Tests [Fact] public void Ctor_InvalidMode() { - Assert.Throws(() => new EventWaitHandle(true, (EventResetMode)12345)); + AssertExtensions.Throws(null, () => new EventWaitHandle(true, (EventResetMode)12345)); } [PlatformSpecific(TestPlatforms.Windows)] // names aren't supported on Unix [Fact] public void Ctor_InvalidNames() { - Assert.Throws(() => new EventWaitHandle(true, EventResetMode.AutoReset, new string('a', 1000))); + AssertExtensions.Throws("name", null, () => new EventWaitHandle(true, EventResetMode.AutoReset, new string('a', 1000))); } [PlatformSpecific(TestPlatforms.AnyUnix)] // names aren't supported on Unix @@ -145,8 +145,8 @@ namespace System.Threading.Tests public void OpenExisting_InvalidNames_Windows() { AssertExtensions.Throws("name", () => EventWaitHandle.OpenExisting(null)); - Assert.Throws(() => EventWaitHandle.OpenExisting(string.Empty)); - Assert.Throws(() => EventWaitHandle.OpenExisting(new string('a', 10000))); + AssertExtensions.Throws("name", null, () => EventWaitHandle.OpenExisting(string.Empty)); + AssertExtensions.Throws("name", null, () => EventWaitHandle.OpenExisting(new string('a', 10000))); } [PlatformSpecific(TestPlatforms.Windows)] // OpenExisting not supported on Unix diff --git a/src/libraries/System.Threading/tests/MutexTests.cs b/src/libraries/System.Threading/tests/MutexTests.cs index 531d2ca897d..7d2344c76d0 100644 --- a/src/libraries/System.Threading/tests/MutexTests.cs +++ b/src/libraries/System.Threading/tests/MutexTests.cs @@ -41,7 +41,7 @@ namespace System.Threading.Tests [Fact] public void Ctor_InvalidName() { - Assert.Throws(() => new Mutex(false, new string('a', 1000))); + AssertExtensions.Throws("name", null, () => new Mutex(false, new string('a', 1000))); } [Fact] @@ -132,8 +132,8 @@ namespace System.Threading.Tests public void OpenExisting_InvalidNames() { AssertExtensions.Throws("name", () => Mutex.OpenExisting(null)); - Assert.Throws(() => Mutex.OpenExisting(string.Empty)); - Assert.Throws(() => Mutex.OpenExisting(new string('a', 10000))); + AssertExtensions.Throws("name", null, () => Mutex.OpenExisting(string.Empty)); + AssertExtensions.Throws("name", null, () => Mutex.OpenExisting(new string('a', 10000))); } [Fact] diff --git a/src/libraries/System.Threading/tests/SemaphoreTests.cs b/src/libraries/System.Threading/tests/SemaphoreTests.cs index 13302d862ed..7d88d428926 100644 --- a/src/libraries/System.Threading/tests/SemaphoreTests.cs +++ b/src/libraries/System.Threading/tests/SemaphoreTests.cs @@ -61,26 +61,26 @@ namespace System.Threading.Tests AssertExtensions.Throws("initialCount", () => new Semaphore(-1, 1)); AssertExtensions.Throws("initialCount", () => new Semaphore(-2, 1)); AssertExtensions.Throws("maximumCount", () => new Semaphore(0, 0)); - Assert.Throws(() => new Semaphore(2, 1)); + AssertExtensions.Throws(null, () => new Semaphore(2, 1)); AssertExtensions.Throws("initialCount", () => new Semaphore(-1, 1, null)); AssertExtensions.Throws("initialCount", () => new Semaphore(-2, 1, null)); AssertExtensions.Throws("maximumCount", () => new Semaphore(0, 0, null)); - Assert.Throws(() => new Semaphore(2, 1, null)); + AssertExtensions.Throws(null, () => new Semaphore(2, 1, null)); AssertExtensions.Throws("initialCount", () => new Semaphore(-1, 1, "CtorSemaphoreTest", out createdNew)); AssertExtensions.Throws("initialCount", () => new Semaphore(-2, 1, "CtorSemaphoreTest", out createdNew)); AssertExtensions.Throws("maximumCount", () => new Semaphore(0, 0, "CtorSemaphoreTest", out createdNew)); - Assert.Throws(() => new Semaphore(2, 1, "CtorSemaphoreTest", out createdNew)); + AssertExtensions.Throws(null, () => new Semaphore(2, 1, "CtorSemaphoreTest", out createdNew)); } [PlatformSpecific(TestPlatforms.Windows)] // named semaphores aren't supported on Unix [Fact] public void Ctor_InvalidNames() { - Assert.Throws(() => new Semaphore(0, 1, new string('a', 10000))); + AssertExtensions.Throws("name", null, () => new Semaphore(0, 1, new string('a', 10000))); bool createdNew; - Assert.Throws(() => new Semaphore(0, 1, new string('a', 10000), out createdNew)); + AssertExtensions.Throws("name", null, () => new Semaphore(0, 1, new string('a', 10000), out createdNew)); } [Fact] @@ -213,8 +213,8 @@ namespace System.Threading.Tests public void OpenExisting_InvalidNames_Windows() { AssertExtensions.Throws("name", () => Semaphore.OpenExisting(null)); - Assert.Throws(() => Semaphore.OpenExisting(string.Empty)); - Assert.Throws(() => Semaphore.OpenExisting(new string('a', 10000))); + AssertExtensions.Throws("name", null, () => Semaphore.OpenExisting(string.Empty)); + AssertExtensions.Throws("name", null, () => Semaphore.OpenExisting(new string('a', 10000))); } [PlatformSpecific(TestPlatforms.Windows)] // named semaphores aren't supported on Unix diff --git a/src/libraries/System.Threading/tests/SpinLockTests.cs b/src/libraries/System.Threading/tests/SpinLockTests.cs index 923eb6c843f..680a361852a 100644 --- a/src/libraries/System.Threading/tests/SpinLockTests.cs +++ b/src/libraries/System.Threading/tests/SpinLockTests.cs @@ -307,7 +307,7 @@ namespace System.Threading.Tests { SpinLock slock = new SpinLock(); bool isTaken = true; - Assert.Throws(() => slock.Enter(ref isTaken)); + AssertExtensions.Throws(null, () => slock.Enter(ref isTaken)); // Failure Case: Enter didn't throw AE when isTaken is true slock = new SpinLock(false); diff --git a/src/libraries/System.Transactions.Local/tests/TransactionScopeTest.cs b/src/libraries/System.Transactions.Local/tests/TransactionScopeTest.cs index 72dadc1a7cd..1838ba4961b 100644 --- a/src/libraries/System.Transactions.Local/tests/TransactionScopeTest.cs +++ b/src/libraries/System.Transactions.Local/tests/TransactionScopeTest.cs @@ -999,7 +999,7 @@ namespace System.Transactions.Tests [Fact] public void ExplicitTransaction12() { - Assert.Throws(() => + AssertExtensions.Throws("asyncResult", () => { CommittableTransaction ct = new CommittableTransaction(); diff --git a/src/libraries/System.ValueTuple/tests/System.ValueTuple.Tests.csproj b/src/libraries/System.ValueTuple/tests/System.ValueTuple.Tests.csproj index b0fb644dc24..f43c2518b49 100644 --- a/src/libraries/System.ValueTuple/tests/System.ValueTuple.Tests.csproj +++ b/src/libraries/System.ValueTuple/tests/System.ValueTuple.Tests.csproj @@ -17,6 +17,9 @@ + + Common\System\AssertExtensions.cs + CommonTest\System\PlatformDetection.cs diff --git a/src/libraries/System.ValueTuple/tests/ValueTupleTests.cs b/src/libraries/System.ValueTuple/tests/ValueTupleTests.cs index 7181596d78d..a3e82638d63 100644 --- a/src/libraries/System.ValueTuple/tests/ValueTupleTests.cs +++ b/src/libraries/System.ValueTuple/tests/ValueTupleTests.cs @@ -283,7 +283,7 @@ namespace System.Tests internal void TestCompareToThrows() { ValueTuple ValueTupleB = new ValueTuple((int)10000); - Assert.Throws(() => ((IComparable)valueTuple).CompareTo(ValueTupleB)); + AssertExtensions.Throws("other", () => ((IComparable)valueTuple).CompareTo(ValueTupleB)); } } @@ -755,7 +755,7 @@ namespace System.Tests var b = ValueTuple.Create(testClassB); Assert.True(a.Equals(b)); - Assert.Throws(() => ((IComparable)a).CompareTo(b)); + AssertExtensions.Throws(null, () => ((IComparable)a).CompareTo(b)); Assert.Equal(a.GetHashCode(), b.GetHashCode()); Assert.True(((IStructuralEquatable)a).Equals(b, TestEqualityComparer.Instance)); Assert.Equal(5, ((IStructuralComparable)a).CompareTo(b, DummyTestComparer.Instance)); @@ -773,7 +773,7 @@ namespace System.Tests Assert.Equal(0, a.CompareTo(new ValueTuple())); Assert.Equal(1, ((IStructuralComparable)a).CompareTo(null, DummyTestComparer.Instance)); - Assert.Throws(() => ((IStructuralComparable)a).CompareTo("string", DummyTestComparer.Instance)); + AssertExtensions.Throws("other", () => ((IStructuralComparable)a).CompareTo("string", DummyTestComparer.Instance)); Assert.Equal("(1, 2, 3, 4, 5, 6, 7, )", CreateLong(1, 2, 3, 4, 5, 6, 7, new ValueTuple()).ToString()); #if netcoreapp @@ -794,7 +794,7 @@ namespace System.Tests IStructuralComparable sc = (IStructuralComparable)c; Assert.Equal(1, sc.CompareTo(null, DummyTestComparer.Instance)); - Assert.Throws(() => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); + AssertExtensions.Throws("other", () => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(3), TestComparer.Instance)); @@ -826,7 +826,7 @@ namespace System.Tests IStructuralComparable sc = (IStructuralComparable)c; Assert.Equal(1, sc.CompareTo(null, DummyTestComparer.Instance)); - Assert.Throws(() => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); + AssertExtensions.Throws("other", () => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(1, 3), TestComparer.Instance)); @@ -860,7 +860,7 @@ namespace System.Tests IStructuralComparable sc = (IStructuralComparable)c; Assert.Equal(1, sc.CompareTo(null, DummyTestComparer.Instance)); - Assert.Throws(() => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); + AssertExtensions.Throws("other", () => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(1, 3, 1), TestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(1, 1, 3), TestComparer.Instance)); @@ -897,7 +897,7 @@ namespace System.Tests IStructuralComparable sc = (IStructuralComparable)c; Assert.Equal(1, sc.CompareTo(null, DummyTestComparer.Instance)); - Assert.Throws(() => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); + AssertExtensions.Throws("other", () => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(3, 1, 1, 1), TestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(1, 3, 1, 1), TestComparer.Instance)); @@ -938,7 +938,7 @@ namespace System.Tests IStructuralComparable sc = (IStructuralComparable)c; Assert.Equal(1, sc.CompareTo(null, DummyTestComparer.Instance)); - Assert.Throws(() => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); + AssertExtensions.Throws("other", () => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(3, 1, 1, 1, 1), TestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(1, 3, 1, 1, 1), TestComparer.Instance)); @@ -982,7 +982,7 @@ namespace System.Tests IStructuralComparable sc = (IStructuralComparable)c; Assert.Equal(1, sc.CompareTo(null, DummyTestComparer.Instance)); - Assert.Throws(() => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); + AssertExtensions.Throws("other", () => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(3, 1, 1, 1, 1, 1), TestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(1, 3, 1, 1, 1, 1), TestComparer.Instance)); @@ -1029,7 +1029,7 @@ namespace System.Tests IStructuralComparable sc = (IStructuralComparable)c; Assert.Equal(1, sc.CompareTo(null, DummyTestComparer.Instance)); - Assert.Throws(() => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); + AssertExtensions.Throws("other", () => ((IStructuralComparable)sc).CompareTo("string", DummyTestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(3, 1, 1, 1, 1, 1, 1), TestComparer.Instance)); Assert.Equal(1, sc.CompareTo(ValueTuple.Create(1, 3, 1, 1, 1, 1, 1), TestComparer.Instance)); @@ -1097,7 +1097,7 @@ namespace System.Tests IStructuralComparable sc = t; Assert.Equal(1, sc.CompareTo(null, DummyTestComparer.Instance)); - Assert.Throws(() => sc.CompareTo("string", DummyTestComparer.Instance)); + AssertExtensions.Throws("other", () => sc.CompareTo("string", DummyTestComparer.Instance)); Assert.Equal(1, sc.CompareTo(CreateLong(3, 1, 1, 1, 1, 1, 1, ValueTuple.Create(1)), TestComparer.Instance)); Assert.Equal(1, sc.CompareTo(CreateLong(1, 3, 1, 1, 1, 1, 1, ValueTuple.Create(1)), TestComparer.Instance));