From 57db927206cb28be3848df3ffc928260a4709e1d Mon Sep 17 00:00:00 2001 From: Maryam Ariyan Date: Thu, 4 Jul 2019 11:00:02 -0700 Subject: [PATCH] Fix and re-enable outerloop test on OLEDB (dotnet/corefx#38024) Commit migrated from https://github.com/dotnet/corefx/commit/477abf147d8860fae35f975fddafb2711ee42bd4 --- .../System/AssertExtensions.cs | 22 +++---- src/libraries/System.Data.OleDb/tests/Helpers.cs | 16 +++-- .../tests/OleDbCommandBuilderTests.cs | 46 +++++++++++--- .../System.Data.OleDb/tests/OleDbCommandTests.cs | 72 +++++++++++++++++----- .../tests/SignedCms/CmsSignerTests.cs | 2 +- 5 files changed, 116 insertions(+), 42 deletions(-) diff --git a/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs index f09b4ee..dec6f7a 100644 --- a/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs +++ b/src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs @@ -15,10 +15,10 @@ namespace System { 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 @@ namespace System 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 @@ namespace System 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 @@ namespace System 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 @@ namespace System } else { - AssertExtensions.Throws(paramName, action); + AssertExtensions.Throws(expectedParamName, action); } } diff --git a/src/libraries/System.Data.OleDb/tests/Helpers.cs b/src/libraries/System.Data.OleDb/tests/Helpers.cs index 087f92a..b475540 100644 --- a/src/libraries/System.Data.OleDb/tests/Helpers.cs +++ b/src/libraries/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 @@ namespace System.Data.OleDb.Tests 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 @@ namespace System.Data.OleDb.Tests 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/libraries/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs b/src/libraries/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs index 9759e41..52f81fa 100644 --- a/src/libraries/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs +++ b/src/libraries/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 @@ namespace System.Data.OleDb.Tests 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 @@ namespace System.Data.OleDb.Tests 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/libraries/System.Data.OleDb/tests/OleDbCommandTests.cs b/src/libraries/System.Data.OleDb/tests/OleDbCommandTests.cs index 4493ec0..ebc6e95 100644 --- a/src/libraries/System.Data.OleDb/tests/OleDbCommandTests.cs +++ b/src/libraries/System.Data.OleDb/tests/OleDbCommandTests.cs @@ -21,10 +21,20 @@ namespace System.Data.OleDb.Tests 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 @@ namespace System.Data.OleDb.Tests 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 @@ namespace System.Data.OleDb.Tests 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 @@ namespace System.Data.OleDb.Tests 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/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/CmsSignerTests.cs b/src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/CmsSignerTests.cs index 90f6179..9893cf28 100644 --- a/src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/CmsSignerTests.cs +++ b/src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/CmsSignerTests.cs @@ -17,7 +17,7 @@ namespace System.Security.Cryptography.Pkcs.Tests CmsSigner signer = new CmsSigner(); AssertExtensions.Throws( - paramName: null, + expectedParamName: null, () => signer.SignerIdentifierType = invalidType); } } -- 2.7.4