Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion BUILDGUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ Manual Tests require the below setup to run:
|SupportsFileStream | (Optional) Whether or not FileStream is enabled on SQL Server| `true` OR `false`|
|UseManagedSNIOnWindows | (Optional) Enables testing with Managed SNI on Windows| `true` OR `false`|
|IsAzureSynpase | (Optional) When set to 'true', test suite runs compatible tests for Azure Synapse/Parallel Data Warehouse. | `true` OR `false`|

|MakecertPath | The full path to makecert.exe. This is not required if the path is present in the PATH environment variable. | `D:\\escaped\\absolute\\path\\to\\makecert.exe` |
### Commands to run Manual Tests:

- Windows (`netfx x86`):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
[PlatformSpecific(TestPlatforms.Windows)]
public class CspProviderExt
{
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
[ClassData(typeof(AEConnectionStringProvider))]
public void TestKeysFromCertificatesCreatedWithMultipleCryptoProviders(string connectionString)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ internal static void CreateCertificate(string certificateName, string certificat
Assert.False(string.IsNullOrWhiteSpace(certificateName), "FAILED: certificateName should not be null or empty.");
Assert.False(string.IsNullOrWhiteSpace(certificateLocation), "FAILED: certificateLocation should not be null or empty.");

ProcessStartInfo processStartInfo = new ProcessStartInfo(@"makecert");
string makecertPath = string.IsNullOrEmpty(DataTestUtility.MakecertPath) ? "makecert" : DataTestUtility.MakecertPath;
ProcessStartInfo processStartInfo = new ProcessStartInfo(makecertPath);
processStartInfo.Arguments = string.Format(@"-n ""CN={0}"" -pe -sr {1} -r -eku 1.3.6.1.5.5.8.2.2,1.3.6.1.4.1.311.10.3.11 -ss my -sky exchange -sp ""{2}"" -sy {3} -len 2048 -a sha256",
certificateName,
certificateLocation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class DataTestUtility
public static readonly bool UseManagedSNIOnWindows = false;
public static readonly bool IsAzureSynapse = false;
public static Uri AKVBaseUri = null;
public static readonly string MakecertPath = null;

public static readonly string DNSCachingConnString = null;
public static readonly string DNSCachingServerCR = null; // this is for the control ring
Expand Down Expand Up @@ -95,6 +96,7 @@ static DataTestUtility()
IsDNSCachingSupportedTR = c.IsDNSCachingSupportedTR;
EnclaveAzureDatabaseConnString = c.EnclaveAzureDatabaseConnString;
UserManagedIdentityClientId = c.UserManagedIdentityClientId;
MakecertPath = c.MakecertPath;

System.Net.ServicePointManager.SecurityProtocol |= System.Net.SecurityProtocolType.Tls12;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public class AdapterTest
public AdapterTest()
{
// create random name for temp tables
_randomGuid = Guid.NewGuid().ToString();
_tempTable = Environment.MachineName + "_" + _randomGuid;
_tempTable = DataTestUtility.GetUniqueName("AdapterTest");
_tempTable = _tempTable.Replace('-', '_');

_randomGuid = Guid.NewGuid().ToString();
_tempKey = "employee_id_key_" + Environment.TickCount.ToString() + _randomGuid;
_tempKey = _tempKey.Replace('-', '_');

Expand Down Expand Up @@ -179,15 +179,15 @@ public void PrepUnprepTest()
public void SqlVariantTest()
{
string tableName = DataTestUtility.GenerateObjectName();
try
// good test for null values and unicode strings
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmd = new SqlCommand(null, conn))
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
{
ExecuteNonQueryCommand("CREATE TABLE " + tableName + " (c0_bigint bigint, c1_variant sql_variant)");

// good test for null values and unicode strings
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmd = new SqlCommand(null, conn))
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
try
{
ExecuteNonQueryCommand("CREATE TABLE " + tableName + " (c0_bigint bigint, c1_variant sql_variant)");

cmd.Connection.Open();

// the ORDER BY clause tests that we correctly ignore the ORDER token
Expand Down Expand Up @@ -263,10 +263,10 @@ public void SqlVariantTest()
}
}
}
}
finally
{
ExecuteNonQueryCommand("DROP TABLE " + tableName);
finally
{
DataTestUtility.DropTable(conn, tableName);
}
}
}

Expand Down Expand Up @@ -659,7 +659,7 @@ public void UpdateTest()
}
finally
{
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
DataTestUtility.DropTable(conn, _tempTable);
}
}
}
Expand Down Expand Up @@ -757,7 +757,7 @@ public void BulkUpdateTest()
}
finally
{
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
DataTestUtility.DropTable(conn, _tempTable);
}
}
}
Expand All @@ -768,33 +768,35 @@ public void BulkUpdateTest()
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public void UpdateRefreshTest()
{
string identTableName = DataTestUtility.GetUniqueName("ID_");
string createIdentTable =
"CREATE TABLE ID_" + _tempTable + "(id int IDENTITY," +
$"CREATE TABLE {identTableName} (id int IDENTITY," +
"LastName nvarchar(50) NULL," +
"Firstname nvarchar(50) NULL)";

string spName = DataTestUtility.GetUniqueName("sp_insert", withBracket: false);
string spCreateInsert =
"CREATE PROCEDURE sp_insert" + _tempTable +
$"CREATE PROCEDURE {spName}" +
"(@FirstName nvarchar(50), @LastName nvarchar(50), @id int OUTPUT) " +
"AS INSERT INTO " + _tempTable + " (FirstName, LastName) " +
"VALUES (@FirstName, @LastName); " +
"SELECT @id=@@IDENTITY";

string spDropInsert = "DROP PROCEDURE sp_insert" + _tempTable;
string spDropInsert = $"DROP PROCEDURE {spName}";
bool dropSP = false;

using (SqlDataAdapter adapter = new SqlDataAdapter())
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmd = new SqlCommand(null, conn))
using (SqlCommand temp = new SqlCommand("SELECT id, LastName, FirstName into " + _tempTable + " from ID_" + _tempTable, conn))
using (SqlCommand temp = new SqlCommand("SELECT id, LastName, FirstName into " + _tempTable + $" from {identTableName}", conn))
using (SqlCommand tableClean = new SqlCommand("", conn))
{
ExecuteNonQueryCommand(createIdentTable);
try
{
adapter.InsertCommand = new SqlCommand()
{
CommandText = "sp_insert" + _tempTable,
CommandText = spName,
CommandType = CommandType.StoredProcedure
};
adapter.InsertCommand.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.NVarChar, 50, "FirstName"));
Expand Down Expand Up @@ -851,9 +853,9 @@ public void UpdateRefreshTest()
{
if (dropSP)
{
ExecuteNonQueryCommand(spDropInsert);
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
ExecuteNonQueryCommand("DROP TABLE ID_" + _tempTable);
DataTestUtility.DropStoredProcedure(conn, spName);
DataTestUtility.DropTable(conn, _tempTable);
DataTestUtility.DropTable(conn, identTableName);
}
}
}
Expand All @@ -873,18 +875,18 @@ public void UpdateNullTest()
"VALUES (@val_cvarbin, @val_cimage)";
bool dropSP = false;

try
{
ExecuteNonQueryCommand(createTable);
ExecuteNonQueryCommand(createSP);
dropSP = true;

using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmdInsert = new SqlCommand(procName, conn))
using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn))
using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn))
using (SqlDataAdapter adapter = new SqlDataAdapter())
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmdInsert = new SqlCommand(procName, conn))
using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn))
using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn))
using (SqlDataAdapter adapter = new SqlDataAdapter())
{
try
{
ExecuteNonQueryCommand(createTable);
ExecuteNonQueryCommand(createSP);
dropSP = true;
conn.Open();

cmdInsert.CommandType = CommandType.StoredProcedure;
Expand All @@ -905,13 +907,13 @@ public void UpdateNullTest()
DataTestUtility.AssertEqualsWithDescription(DBNull.Value, ds.Tables[0].Rows[0][0], "Unexpected value.");
DataTestUtility.AssertEqualsWithDescription(DBNull.Value, ds.Tables[0].Rows[0][1], "Unexpected value.");
}
}
finally
{
if (dropSP)
finally
{
ExecuteNonQueryCommand("DROP PROCEDURE " + procName);
ExecuteNonQueryCommand("DROP TABLE " + tableName);
if (dropSP)
{
DataTestUtility.DropStoredProcedure(conn, procName);
DataTestUtility.DropTable(conn, tableName);
}
}
}
}
Expand All @@ -930,18 +932,18 @@ public void UpdateOffsetTest()
"VALUES (@val_cvarbin, @val_cimage)";
bool dropSP = false;

try
{
ExecuteNonQueryCommand(createTable);
ExecuteNonQueryCommand(createSP);
dropSP = true;

using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmdInsert = new SqlCommand(procName, conn))
using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn))
using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn))
using (SqlDataAdapter adapter = new SqlDataAdapter())
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmdInsert = new SqlCommand(procName, conn))
using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn))
using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn))
using (SqlDataAdapter adapter = new SqlDataAdapter())
{
try
{
ExecuteNonQueryCommand(createTable);
ExecuteNonQueryCommand(createSP);
dropSP = true;
conn.Open();

cmdInsert.CommandType = CommandType.StoredProcedure;
Expand Down Expand Up @@ -978,13 +980,13 @@ public void UpdateOffsetTest()
val = (byte[])(ds.Tables[0].Rows[0][1]);
Assert.True(ByteArraysEqual(expectedBytes2, val), "FAILED: Test 2: Unequal byte arrays.");
}
}
finally
{
if (dropSP)
finally
{
ExecuteNonQueryCommand("DROP PROCEDURE " + procName);
ExecuteNonQueryCommand("DROP TABLE " + tableName);
if (dropSP)
{
DataTestUtility.DropStoredProcedure(conn, procName);
DataTestUtility.DropTable(conn, tableName);
}
}
}
}
Expand Down Expand Up @@ -1069,7 +1071,7 @@ public void AutoGenUpdateTest()
}
finally
{
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
DataTestUtility.DropTable(conn, _tempTable);
}
}
}
Expand All @@ -1078,16 +1080,17 @@ public void AutoGenUpdateTest()
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
public void AutoGenErrorTest()
{
string identTableName = DataTestUtility.GetUniqueName("ID_");
string createIdentTable =
"CREATE TABLE ID_" + _tempTable + "(id int IDENTITY," +
$"CREATE TABLE {identTableName} (id int IDENTITY," +
"LastName nvarchar(50) NULL," +
"Firstname nvarchar(50) NULL)";

try
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmd = new SqlCommand($"SELECT * into {_tempTable} from {identTableName}", conn))
using (SqlDataAdapter adapter = new SqlDataAdapter())
{
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
using (SqlCommand cmd = new SqlCommand("SELECT * into " + _tempTable + " from ID_" + _tempTable, conn))
using (SqlDataAdapter adapter = new SqlDataAdapter())
try
{
ExecuteNonQueryCommand(createIdentTable);

Expand All @@ -1110,11 +1113,11 @@ public void AutoGenErrorTest()
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
adapter.Update(ds, _tempTable);
}
}
finally
{
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
ExecuteNonQueryCommand("DROP TABLE ID_" + _tempTable);
finally
{
DataTestUtility.DropTable(conn, _tempTable);
DataTestUtility.DropTable(conn, identTableName);
}
}
}

Expand Down Expand Up @@ -1206,7 +1209,7 @@ public void AutoGenBulkUpdateTest()
}
finally
{
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
DataTestUtility.DropTable(conn, _tempTable);
}
}
}
Expand Down Expand Up @@ -1319,6 +1322,48 @@ public void TestReadOnlyColumnMetadata()
}
}

[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
[InlineData(nameof(SqlCommandBuilder.GetInsertCommand), null)]
[InlineData(nameof(SqlCommandBuilder.GetInsertCommand), true)]
[InlineData(nameof(SqlCommandBuilder.GetInsertCommand), false)]
[InlineData(nameof(SqlCommandBuilder.GetUpdateCommand), null)]
[InlineData(nameof(SqlCommandBuilder.GetUpdateCommand), true)]
[InlineData(nameof(SqlCommandBuilder.GetUpdateCommand), false)]
[InlineData(nameof(SqlCommandBuilder.GetDeleteCommand), null)]
[InlineData(nameof(SqlCommandBuilder.GetDeleteCommand), false)]
[InlineData(nameof(SqlCommandBuilder.GetDeleteCommand), true)]
public void VerifyGetCommand(string methodName, bool? useColumnsForParameterNames)
{
using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
{
connection.Open();
using (SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * FROM dbo.Customers", connection))
{
using (SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter))
{
object[] parameters = null;
Type[] parameterTypes = null;
if (useColumnsForParameterNames != null)
{
parameters = new object[] { useColumnsForParameterNames };
parameterTypes = new Type[] { typeof(bool) };
}
else
{
parameters = new object[] { };
parameterTypes = new Type[] { };
}

MethodInfo method = commandBuilder.GetType().GetMethod(methodName, parameterTypes);
using (SqlCommand cmd = (SqlCommand)method.Invoke(commandBuilder, parameters))
{
Assert.NotNull(cmd);
}
}
}
}
}

#region Utility_Methods
private void CheckParameters(SqlCommand cmd, string expectedResults)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ static TcpDefaultForAzureTest()
public static void NonAzureNoProtocolConnectionTest()
{
builder.DataSource = InvalidHostname;
#if NETFRAMEWORK
CheckConnectionFailure(builder.ConnectionString, NP);
#else
CheckConnectionFailure(builder.ConnectionString, DataTestUtility.IsUsingManagedSNI() ? TCP : NP);
#endif
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Config
public bool IsDNSCachingSupportedTR = false; // this is for the tenant ring
public string EnclaveAzureDatabaseConnString = null;
public string UserManagedIdentityClientId = null;
public string MakecertPath = null;

public static Config Load(string configPath = @"config.json")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
"IsDNSCachingSupportedTR": false,
"IsAzureSynapse": false,
"EnclaveAzureDatabaseConnString": "",
"UserManagedIdentityClientId": ""
"UserManagedIdentityClientId": "",
"MakecertPath": ""
}