{
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)
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;
}
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
{
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
{
}
else
{
- AssertExtensions.Throws<TNetCoreExceptionType>(paramName, action);
+ AssertExtensions.Throws<TNetCoreExceptionType>(expectedParamName, action);
}
}
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
+using System.Globalization;
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()
{
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;
}
}
}
// 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
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;
});
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 =
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)}\')"
+ );
+ }
}
}
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)}\')"
+ );
+ }
}
}
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)}\')"
+ );
+ }
}
}
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())
CmsSigner signer = new CmsSigner();
AssertExtensions.Throws<ArgumentException>(
- paramName: null,
+ expectedParamName: null,
() => signer.SignerIdentifierType = invalidType);
}
}