Upgrade Microsoft Data SqlClient
This commit is contained in:
@@ -69,6 +69,30 @@ namespace Sacs.UnitTests.Net.Standard.Base.Dbas
|
||||
Assert.That(connection.ConnectionString, Is.EqualTo(config.ConnectionString));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OpenOdbcDatabase_CreatesSqlConnectionWithExpectedSecuritySettings()
|
||||
{
|
||||
SacsDatabaseConsole.OdbcConfig config = new SacsDatabaseConsole.OdbcConfig
|
||||
{
|
||||
Dbms = DbmsType.MsSql,
|
||||
Location = "MsSql:db.example.test\\Inventory",
|
||||
User = "test-user",
|
||||
Password = "test-password"
|
||||
};
|
||||
|
||||
SacsDatabase database = SacsDatabaseConsole.OpenOdbcDatabase(config);
|
||||
using SqlConnection connection = (SqlConnection)database.CreateConnection();
|
||||
SqlConnectionStringBuilder settings = new SqlConnectionStringBuilder(connection.ConnectionString);
|
||||
|
||||
Assert.That(settings.DataSource, Is.EqualTo("db.example.test"));
|
||||
Assert.That(settings.InitialCatalog, Is.EqualTo("Inventory"));
|
||||
Assert.That(settings.UserID, Is.EqualTo("test-user"));
|
||||
Assert.That(settings.Password, Is.EqualTo("test-password"));
|
||||
Assert.That(settings.IntegratedSecurity, Is.False);
|
||||
Assert.That(settings.Encrypt, Is.EqualTo(SqlConnectionEncryptOption.Mandatory));
|
||||
Assert.That(settings.TrustServerCertificate, Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateDataAdapter_ReturnsOdbcAdapter()
|
||||
{
|
||||
@@ -194,6 +218,59 @@ namespace Sacs.UnitTests.Net.Standard.Base.Dbas
|
||||
Is.EqualTo(new[] { DbType.Int16, DbType.Int32, DbType.Int64, DbType.Byte, DbType.Single, DbType.Double, DbType.Decimal, DbType.Boolean, DbType.Guid, DbType.DateTime, DbType.Binary }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddCommandParameter_CreatesSqlValuesWithExpectedTypesAndOrder()
|
||||
{
|
||||
ParameterTestItem item = new ParameterTestItem();
|
||||
Guid identifier = Guid.Parse("024f2943-12a6-46be-88cf-49980f81e603");
|
||||
byte[] data = new byte[] { 1, 2, 3 };
|
||||
using SqlCommand command = new SqlCommand();
|
||||
|
||||
item.AddParameter(command, "@Text", "value");
|
||||
item.AddParameter(command, "@Short", (short)12);
|
||||
item.AddParameter(command, "@Integer", 34);
|
||||
item.AddParameter(command, "@Long", 56L);
|
||||
item.AddParameter(command, "@Byte", (byte)78);
|
||||
item.AddParameter(command, "@Single", 90.1f);
|
||||
item.AddParameter(command, "@Double", 23.4d);
|
||||
item.AddParameter(command, "@Decimal", 78.9m);
|
||||
item.AddParameter(command, "@Boolean", true);
|
||||
item.AddParameter(command, "@Identifier", identifier);
|
||||
item.AddParameter(command, "@Data", data);
|
||||
|
||||
Assert.That(command.Parameters.Cast<SqlParameter>().Select(parameter => parameter.ParameterName),
|
||||
Is.EqualTo(new[] { "@Text", "@Short", "@Integer", "@Long", "@Byte", "@Single", "@Double", "@Decimal", "@Boolean", "@Identifier", "@Data" }));
|
||||
Assert.That(command.Parameters.Cast<SqlParameter>().Select(parameter => parameter.DbType),
|
||||
Is.EqualTo(new[] { DbType.String, DbType.Int16, DbType.Int32, DbType.Int64, DbType.Byte, DbType.Single, DbType.Double, DbType.Decimal, DbType.Boolean, DbType.Guid, DbType.Binary }));
|
||||
Assert.That(command.Parameters[0].Value, Is.EqualTo("value"));
|
||||
Assert.That(command.Parameters[9].Value, Is.EqualTo(identifier));
|
||||
Assert.That(command.Parameters[10].Value, Is.SameAs(data));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AddCommandParameter_CreatesTypedSqlNulls()
|
||||
{
|
||||
ParameterTestItem item = new ParameterTestItem();
|
||||
using SqlCommand command = new SqlCommand();
|
||||
|
||||
item.AddParameter<short?>(command, "@Short", null);
|
||||
item.AddParameter<int?>(command, "@Integer", null);
|
||||
item.AddParameter<long?>(command, "@Long", null);
|
||||
item.AddParameter<byte?>(command, "@Byte", null);
|
||||
item.AddParameter<float?>(command, "@Single", null);
|
||||
item.AddParameter<double?>(command, "@Double", null);
|
||||
item.AddParameter<decimal?>(command, "@Decimal", null);
|
||||
item.AddParameter<bool?>(command, "@Boolean", null);
|
||||
item.AddParameter<Guid?>(command, "@Identifier", null);
|
||||
item.AddParameter<DateTime?>(command, "@Date", null);
|
||||
item.AddParameter<byte[]>(command, "@Data", null);
|
||||
|
||||
Assert.That(command.Parameters.Cast<SqlParameter>().Select(parameter => parameter.Value),
|
||||
Is.All.EqualTo(DBNull.Value));
|
||||
Assert.That(command.Parameters.Cast<SqlParameter>().Select(parameter => parameter.DbType),
|
||||
Is.EqualTo(new[] { DbType.Int16, DbType.Int32, DbType.Int64, DbType.Byte, DbType.Single, DbType.Double, DbType.Decimal, DbType.Boolean, DbType.Guid, DbType.DateTime2, DbType.Binary }));
|
||||
}
|
||||
|
||||
// --- The End ---
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user