diff --git a/src/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs b/src/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs index f09b4ee68e3a..dec6f7af745e 100644 --- a/src/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs +++ b/src/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs @@ -15,10 +15,10 @@ public static class AssertExtensions { private static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework"); - public static void Throws(Action action, string message) + public static void Throws(Action action, string expectedMessage) where T : Exception { - Assert.Equal(Assert.Throws(action).Message, message); + Assert.Equal(expectedMessage, Assert.Throws(action).Message); } public static void Throws(string netCoreParamName, string netFxParamName, Action action) @@ -57,12 +57,12 @@ public static void Throws(string netCoreParamName, string netFxParamName, Fun Assert.Equal(expectedParamName, exception.ParamName); } - public static T Throws(string paramName, Action action) + public static T Throws(string expectedParamName, Action action) where T : ArgumentException { T exception = Assert.Throws(action); - Assert.Equal(paramName, exception.ParamName); + Assert.Equal(expectedParamName, exception.ParamName); return exception; } @@ -75,27 +75,27 @@ public static T Throws(Action action) return exception; } - public static T Throws(string paramName, Func testCode) + public static T Throws(string expectedParamName, Func testCode) where T : ArgumentException { T exception = Assert.Throws(testCode); - Assert.Equal(paramName, exception.ParamName); + Assert.Equal(expectedParamName, exception.ParamName); return exception; } - public static async Task ThrowsAsync(string paramName, Func testCode) + public static async Task ThrowsAsync(string expectedParamName, Func testCode) where T : ArgumentException { T exception = await Assert.ThrowsAsync(testCode); - Assert.Equal(paramName, exception.ParamName); + Assert.Equal(expectedParamName, exception.ParamName); return exception; } - public static void Throws(string paramName, Action action) + public static void Throws(string expectedParamName, Action action) where TNetCoreExceptionType : ArgumentException where TNetFxExceptionType : Exception { @@ -106,7 +106,7 @@ public static void Throws(string par if (typeof(ArgumentException).IsAssignableFrom(typeof(TNetFxExceptionType))) { Exception exception = Assert.Throws(typeof(TNetFxExceptionType), action); - Assert.Equal(paramName, ((ArgumentException)exception).ParamName); + Assert.Equal(expectedParamName, ((ArgumentException)exception).ParamName); } else { @@ -115,7 +115,7 @@ public static void Throws(string par } else { - AssertExtensions.Throws(paramName, action); + AssertExtensions.Throws(expectedParamName, action); } } diff --git a/src/System.Data.OleDb/tests/Helpers.cs b/src/System.Data.OleDb/tests/Helpers.cs index 087f92abf5c5..b4755406d186 100644 --- a/src/System.Data.OleDb/tests/Helpers.cs +++ b/src/System.Data.OleDb/tests/Helpers.cs @@ -2,6 +2,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Generic; +using System.Globalization; namespace System.Data.OleDb.Tests { @@ -20,6 +21,7 @@ private class Nested public static readonly string ProviderName; public static Nested Instance => s_instance; private static readonly Nested s_instance = new Nested(); + private const string ExpectedProviderName = @"Microsoft.ACE.OLEDB.12.0"; private Nested() { } static Nested() { @@ -29,13 +31,15 @@ static Nested() List providerNames = new List(); foreach (DataRow row in table.Rows) { - providerNames.Add(row[providersRegistered]); + providerNames.Add((string)row[providersRegistered]); } - string providerName = PlatformDetection.Is32BitProcess ? - @"Microsoft.Jet.OLEDB.4.0" : - @"Microsoft.ACE.OLEDB.12.0"; - IsAvailable = false; // ActiveIssue #37823 // providerNames.Contains(providerName); - ProviderName = IsAvailable ? providerName : null; + // skip if x86 or if the expected driver not available + IsAvailable = !PlatformDetection.Is32BitProcess && providerNames.Contains(ExpectedProviderName); + if (!CultureInfo.CurrentCulture.Name.Equals("en-US", StringComparison.OrdinalIgnoreCase)) + { + IsAvailable = false; // ActiveIssue: https://github.com/dotnet/corefx/issues/38737 + } + ProviderName = IsAvailable ? ExpectedProviderName : null; } } } diff --git a/src/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs b/src/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs index 9759e41a9452..52f81fa30245 100644 --- a/src/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs +++ b/src/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs @@ -2,8 +2,10 @@ // 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.Diagnostics; using System.IO; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using Xunit; namespace System.Data.OleDb.Tests @@ -90,13 +92,26 @@ public void QuoteUnquoteIdentifier_Null_Throws() command.CommandText = @"SELECT * FROM " + tableName; using (var builder = (OleDbCommandBuilder)OleDbFactory.Instance.CreateCommandBuilder()) { - AssertExtensions.Throws( - () => builder.QuoteIdentifier(null, command.Connection), - $"Value cannot be null.\r\nParameter name: unquotedIdentifier"); - - AssertExtensions.Throws( - () => builder.UnquoteIdentifier(null, command.Connection), - $"Value cannot be null.\r\nParameter name: quotedIdentifier"); + if (PlatformDetection.IsFullFramework) + { + AssertExtensions.Throws( + () => builder.QuoteIdentifier(null, command.Connection), + $"Value cannot be null.\r\nParameter name: unquotedIdentifier"); + + AssertExtensions.Throws( + () => builder.UnquoteIdentifier(null, command.Connection), + $"Value cannot be null.\r\nParameter name: quotedIdentifier"); + } + else + { + AssertExtensions.Throws( + () => builder.QuoteIdentifier(null, command.Connection), + $"Value cannot be null. (Parameter \'unquotedIdentifier\')"); + + AssertExtensions.Throws( + () => builder.UnquoteIdentifier(null, command.Connection), + $"Value cannot be null. (Parameter \'quotedIdentifier\')"); + } } command.CommandType = CommandType.Text; }); @@ -154,7 +169,22 @@ private void RunTest(Action testAction, [CallerMemberName] Firstname NVARCHAR(5), Lastname NVARCHAR(40), Nickname NVARCHAR(30))"; - command.ExecuteNonQuery(); + try + { + command.ExecuteNonQuery(); + } + catch (SEHException sehEx) + { + Console.WriteLine($"Code: {sehEx.ErrorCode}"); + Exception baseException = sehEx.GetBaseException(); + Debug.Assert(baseException != null); + Console.WriteLine($"Base Exception error code : {baseException.HResult}"); + Console.WriteLine($"Base Exception message : {baseException}"); + Console.WriteLine($"Base Inner Exception: {sehEx.InnerException}"); + + // This exception is not expected. So rethrow to indicate test failure. + throw; + } Assert.True(File.Exists(Path.Combine(TestDirectory, tableName))); command.CommandText = diff --git a/src/System.Data.OleDb/tests/OleDbCommandTests.cs b/src/System.Data.OleDb/tests/OleDbCommandTests.cs index 4493ec09b009..ebc6e95eb14a 100644 --- a/src/System.Data.OleDb/tests/OleDbCommandTests.cs +++ b/src/System.Data.OleDb/tests/OleDbCommandTests.cs @@ -21,10 +21,20 @@ public void UpdatedRowSource_SetInvalidValue_Throws() Assert.Equal(UpdateRowSource.Both, cmd.UpdatedRowSource); cmd.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord; Assert.Equal(UpdateRowSource.FirstReturnedRecord, cmd.UpdatedRowSource); - AssertExtensions.Throws( - () => cmd.UpdatedRowSource = (UpdateRowSource)InvalidValue, - $"The {nameof(UpdateRowSource)} enumeration value, {InvalidValue}, is invalid.\r\nParameter name: {nameof(UpdateRowSource)}" - ); + if (PlatformDetection.IsFullFramework) + { + AssertExtensions.Throws( + () => cmd.UpdatedRowSource = (UpdateRowSource)InvalidValue, + $"The {nameof(UpdateRowSource)} enumeration value, {InvalidValue}, is invalid.\r\nParameter name: {nameof(UpdateRowSource)}" + ); + } + else + { + AssertExtensions.Throws( + () => cmd.UpdatedRowSource = (UpdateRowSource)InvalidValue, + $"The {nameof(UpdateRowSource)} enumeration value, {InvalidValue}, is invalid. (Parameter \'{nameof(UpdateRowSource)}\')" + ); + } } } @@ -34,10 +44,20 @@ public void CommandTimeout_SetInvalidValue_Throws() const int InvalidValue = -1; using (var cmd = new OleDbCommand(default, connection, transaction)) { - AssertExtensions.Throws( - () => cmd.CommandTimeout = InvalidValue, - $"Invalid CommandTimeout value {InvalidValue}; the value must be >= 0.\r\nParameter name: {nameof(cmd.CommandTimeout)}" - ); + if (PlatformDetection.IsFullFramework) + { + AssertExtensions.Throws( + () => cmd.CommandTimeout = InvalidValue, + $"Invalid CommandTimeout value {InvalidValue}; the value must be >= 0.\r\nParameter name: {nameof(cmd.CommandTimeout)}" + ); + } + else + { + AssertExtensions.Throws( + () => cmd.CommandTimeout = InvalidValue, + $"Invalid CommandTimeout value {InvalidValue}; the value must be >= 0. (Parameter \'{nameof(cmd.CommandTimeout)}\')" + ); + } } } @@ -61,10 +81,20 @@ public void CommandType_SetInvalidValue_Throws() const int InvalidValue = 0; using (var cmd = (OleDbCommand)OleDbFactory.Instance.CreateCommand()) { - AssertExtensions.Throws( - () => cmd.CommandType = (CommandType)InvalidValue, - $"The CommandType enumeration value, {InvalidValue}, is invalid.\r\nParameter name: {nameof(cmd.CommandType)}" - ); + if (PlatformDetection.IsFullFramework) + { + AssertExtensions.Throws( + () => cmd.CommandType = (CommandType)InvalidValue, + $"The CommandType enumeration value, {InvalidValue}, is invalid.\r\nParameter name: {nameof(cmd.CommandType)}" + ); + } + else + { + AssertExtensions.Throws( + () => cmd.CommandType = (CommandType)InvalidValue, + $"The CommandType enumeration value, {InvalidValue}, is invalid. (Parameter \'{nameof(cmd.CommandType)}\')" + ); + } } } @@ -149,10 +179,20 @@ public void Prepare_InsertMultipleItems_UseTableDirectToVerify() public void Parameters_AddNullParameter_Throws() { RunTest((command, tableName) => { - AssertExtensions.Throws( - () => command.Parameters.Add(null), - $"The {nameof(OleDbParameterCollection)} only accepts non-null {nameof(OleDbParameter)} type objects.\r\nParameter name: value" - ); + if (PlatformDetection.IsFullFramework) + { + AssertExtensions.Throws( + () => command.Parameters.Add(null), + $"The {nameof(OleDbParameterCollection)} only accepts non-null {nameof(OleDbParameter)} type objects.\r\nParameter name: value" + ); + } + else + { + AssertExtensions.Throws( + () => command.Parameters.Add(null), + $"The {nameof(OleDbParameterCollection)} only accepts non-null {nameof(OleDbParameter)} type objects. (Parameter \'value\')" + ); + } command.CommandText = "SELECT * FROM " + tableName + " WHERE NumPlants = ?"; command.Parameters.Add(new OleDbParameter("@p1", 7)); using (OleDbDataReader reader = command.ExecuteReader()) diff --git a/src/System.Security.Cryptography.Pkcs/tests/SignedCms/CmsSignerTests.cs b/src/System.Security.Cryptography.Pkcs/tests/SignedCms/CmsSignerTests.cs index 90f617994b55..9893cf2853f1 100644 --- a/src/System.Security.Cryptography.Pkcs/tests/SignedCms/CmsSignerTests.cs +++ b/src/System.Security.Cryptography.Pkcs/tests/SignedCms/CmsSignerTests.cs @@ -17,7 +17,7 @@ public static void SignerIdentifierType_InvalidValues(SubjectIdentifierType inva CmsSigner signer = new CmsSigner(); AssertExtensions.Throws( - paramName: null, + expectedParamName: null, () => signer.SignerIdentifierType = invalidType); } }