Fix and re-enable outerloop test on OLEDB (dotnet/corefx#38024)
authorMaryam Ariyan <maryam.ariyan@microsoft.com>
Thu, 4 Jul 2019 18:00:02 +0000 (11:00 -0700)
committerGitHub <noreply@github.com>
Thu, 4 Jul 2019 18:00:02 +0000 (11:00 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/477abf147d8860fae35f975fddafb2711ee42bd4

src/libraries/Common/tests/CoreFx.Private.TestUtilities/System/AssertExtensions.cs
src/libraries/System.Data.OleDb/tests/Helpers.cs
src/libraries/System.Data.OleDb/tests/OleDbCommandBuilderTests.cs
src/libraries/System.Data.OleDb/tests/OleDbCommandTests.cs
src/libraries/System.Security.Cryptography.Pkcs/tests/SignedCms/CmsSignerTests.cs

index f09b4ee..dec6f7a 100644 (file)
@@ -15,10 +15,10 @@ namespace System
     {
         private static bool IsFullFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework");
 
-        public static void Throws<T>(Action action, string message)
+        public static void Throws<T>(Action action, string expectedMessage)
             where T : Exception
         {
-            Assert.Equal(Assert.Throws<T>(action).Message, message);
+            Assert.Equal(expectedMessage, Assert.Throws<T>(action).Message);
         }
 
         public static void Throws<T>(string netCoreParamName, string netFxParamName, Action action)
@@ -57,12 +57,12 @@ namespace System
             Assert.Equal(expectedParamName, exception.ParamName);
         }
 
-        public static T Throws<T>(string paramName, Action action)
+        public static T Throws<T>(string expectedParamName, Action action)
             where T : ArgumentException
         {
             T exception = Assert.Throws<T>(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<T>(string paramName, Func<object> testCode)
+        public static T Throws<T>(string expectedParamName, Func<object> testCode)
             where T : ArgumentException
         {
             T exception = Assert.Throws<T>(testCode);
 
-            Assert.Equal(paramName, exception.ParamName);
+            Assert.Equal(expectedParamName, exception.ParamName);
 
             return exception;
         }
 
-        public static async Task<T> ThrowsAsync<T>(string paramName, Func<Task> testCode)
+        public static async Task<T> ThrowsAsync<T>(string expectedParamName, Func<Task> testCode)
             where T : ArgumentException
         {
             T exception = await Assert.ThrowsAsync<T>(testCode);
 
-            Assert.Equal(paramName, exception.ParamName);
+            Assert.Equal(expectedParamName, exception.ParamName);
 
             return exception;
         }
 
-        public static void Throws<TNetCoreExceptionType, TNetFxExceptionType>(string paramName, Action action)
+        public static void Throws<TNetCoreExceptionType, TNetFxExceptionType>(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<TNetCoreExceptionType>(paramName, action);
+                AssertExtensions.Throws<TNetCoreExceptionType>(expectedParamName, action);
             }
         }
 
index 087f92a..b475540 100644 (file)
@@ -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<object> providerNames = new List<object>();
                 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;
             }
         }
     }
index 9759e41..52f81fa 100644 (file)
@@ -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<ArgumentNullException>(
-                        () => builder.QuoteIdentifier(null, command.Connection), 
-                        $"Value cannot be null.\r\nParameter name: unquotedIdentifier");
-
-                    AssertExtensions.Throws<ArgumentNullException>(
-                        () => builder.UnquoteIdentifier(null, command.Connection), 
-                        $"Value cannot be null.\r\nParameter name: quotedIdentifier");
+                    if (PlatformDetection.IsFullFramework)
+                    {
+                        AssertExtensions.Throws<ArgumentNullException>(
+                            () => builder.QuoteIdentifier(null, command.Connection), 
+                            $"Value cannot be null.\r\nParameter name: unquotedIdentifier");
+
+                        AssertExtensions.Throws<ArgumentNullException>(
+                            () => builder.UnquoteIdentifier(null, command.Connection), 
+                            $"Value cannot be null.\r\nParameter name: quotedIdentifier");
+                    }
+                    else
+                    {
+                        AssertExtensions.Throws<ArgumentNullException>(
+                            () => builder.QuoteIdentifier(null, command.Connection), 
+                            $"Value cannot be null. (Parameter \'unquotedIdentifier\')");
+
+                        AssertExtensions.Throws<ArgumentNullException>(
+                            () => 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 =
index 4493ec0..ebc6e95 100644 (file)
@@ -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<ArgumentOutOfRangeException>(
-                    () => cmd.UpdatedRowSource = (UpdateRowSource)InvalidValue, 
-                    $"The {nameof(UpdateRowSource)} enumeration value, {InvalidValue}, is invalid.\r\nParameter name: {nameof(UpdateRowSource)}"
-                );
+                if (PlatformDetection.IsFullFramework)
+                {
+                    AssertExtensions.Throws<ArgumentOutOfRangeException>(
+                        () => cmd.UpdatedRowSource = (UpdateRowSource)InvalidValue, 
+                        $"The {nameof(UpdateRowSource)} enumeration value, {InvalidValue}, is invalid.\r\nParameter name: {nameof(UpdateRowSource)}"
+                    );
+                }
+                else
+                {
+                    AssertExtensions.Throws<ArgumentOutOfRangeException>(
+                        () => 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<ArgumentException>(
-                    () => cmd.CommandTimeout = InvalidValue, 
-                    $"Invalid CommandTimeout value {InvalidValue}; the value must be >= 0.\r\nParameter name: {nameof(cmd.CommandTimeout)}"
-                );
+                if (PlatformDetection.IsFullFramework)
+                {
+                    AssertExtensions.Throws<ArgumentException>(
+                        () => cmd.CommandTimeout = InvalidValue, 
+                        $"Invalid CommandTimeout value {InvalidValue}; the value must be >= 0.\r\nParameter name: {nameof(cmd.CommandTimeout)}"
+                    );
+                }
+                else
+                {
+                    AssertExtensions.Throws<ArgumentException>(
+                        () => 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<ArgumentOutOfRangeException>(
-                    () => cmd.CommandType = (CommandType)InvalidValue, 
-                    $"The CommandType enumeration value, {InvalidValue}, is invalid.\r\nParameter name: {nameof(cmd.CommandType)}"
-                );
+                if (PlatformDetection.IsFullFramework)
+                {
+                    AssertExtensions.Throws<ArgumentOutOfRangeException>(
+                        () => cmd.CommandType = (CommandType)InvalidValue, 
+                        $"The CommandType enumeration value, {InvalidValue}, is invalid.\r\nParameter name: {nameof(cmd.CommandType)}"
+                    );
+                }
+                else
+                {
+                    AssertExtensions.Throws<ArgumentOutOfRangeException>(
+                        () => 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<ArgumentNullException>(
-                    () => command.Parameters.Add(null), 
-                    $"The {nameof(OleDbParameterCollection)} only accepts non-null {nameof(OleDbParameter)} type objects.\r\nParameter name: value"
-                );
+                if (PlatformDetection.IsFullFramework)
+                {
+                    AssertExtensions.Throws<ArgumentNullException>(
+                        () => command.Parameters.Add(null), 
+                        $"The {nameof(OleDbParameterCollection)} only accepts non-null {nameof(OleDbParameter)} type objects.\r\nParameter name: value"
+                    );
+                }
+                else
+                {
+                    AssertExtensions.Throws<ArgumentNullException>(
+                        () => 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())
index 90f6179..9893cf2 100644 (file)
@@ -17,7 +17,7 @@ namespace System.Security.Cryptography.Pkcs.Tests
             CmsSigner signer = new CmsSigner();
 
             AssertExtensions.Throws<ArgumentException>(
-                paramName: null,
+                expectedParamName: null,
                 () => signer.SignerIdentifierType = invalidType);
         }
     }