Skip to content

Commit c944713

Browse files
author
Johnny Pham
authored
[3.1] Changes to run tests on 1es pipelines (#1552)
* 1es 3.1 * Update TcpDefaultForAzureTest.cs * Update CspProviderExt.cs
1 parent f89555d commit c944713

File tree

8 files changed

+125
-71
lines changed

8 files changed

+125
-71
lines changed

BUILDGUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ Manual Tests require the below setup to run:
122122
|SupportsFileStream | (Optional) Whether or not FileStream is enabled on SQL Server| `true` OR `false`|
123123
|UseManagedSNIOnWindows | (Optional) Enables testing with Managed SNI on Windows| `true` OR `false`|
124124
|IsAzureSynpase | (Optional) When set to 'true', test suite runs compatible tests for Azure Synapse/Parallel Data Warehouse. | `true` OR `false`|
125-
125+
|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` |
126126
### Commands to run Manual Tests:
127127

128128
- Windows (`netfx x86`):

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/CspProviderExt.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.Data.SqlClient.ManualTesting.Tests.AlwaysEncrypted
2323
[PlatformSpecific(TestPlatforms.Windows)]
2424
public class CspProviderExt
2525
{
26-
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
26+
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringSetupForAE))]
2727
[ClassData(typeof(AEConnectionStringProvider))]
2828
public void TestKeysFromCertificatesCreatedWithMultipleCryptoProviders(string connectionString)
2929
{

src/Microsoft.Data.SqlClient/tests/ManualTests/AlwaysEncrypted/TestFixtures/Setup/CertificateUtilityWin.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ internal static void CreateCertificate(string certificateName, string certificat
3131
Assert.False(string.IsNullOrWhiteSpace(certificateName), "FAILED: certificateName should not be null or empty.");
3232
Assert.False(string.IsNullOrWhiteSpace(certificateLocation), "FAILED: certificateLocation should not be null or empty.");
3333

34-
ProcessStartInfo processStartInfo = new ProcessStartInfo(@"makecert");
34+
string makecertPath = string.IsNullOrEmpty(DataTestUtility.MakecertPath) ? "makecert" : DataTestUtility.MakecertPath;
35+
ProcessStartInfo processStartInfo = new ProcessStartInfo(makecertPath);
3536
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",
3637
certificateName,
3738
certificateLocation,

src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public static class DataTestUtility
4848
public static readonly bool UseManagedSNIOnWindows = false;
4949
public static readonly bool IsAzureSynapse = false;
5050
public static Uri AKVBaseUri = null;
51+
public static readonly string MakecertPath = null;
5152

5253
public static readonly string DNSCachingConnString = null;
5354
public static readonly string DNSCachingServerCR = null; // this is for the control ring
@@ -95,6 +96,7 @@ static DataTestUtility()
9596
IsDNSCachingSupportedTR = c.IsDNSCachingSupportedTR;
9697
EnclaveAzureDatabaseConnString = c.EnclaveAzureDatabaseConnString;
9798
UserManagedIdentityClientId = c.UserManagedIdentityClientId;
99+
MakecertPath = c.MakecertPath;
98100

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

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/AdapterTest/AdapterTest.cs

Lines changed: 112 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public class AdapterTest
5454
public AdapterTest()
5555
{
5656
// create random name for temp tables
57-
_randomGuid = Guid.NewGuid().ToString();
58-
_tempTable = Environment.MachineName + "_" + _randomGuid;
57+
_tempTable = DataTestUtility.GetUniqueName("AdapterTest");
5958
_tempTable = _tempTable.Replace('-', '_');
6059

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

@@ -179,15 +179,15 @@ public void PrepUnprepTest()
179179
public void SqlVariantTest()
180180
{
181181
string tableName = DataTestUtility.GenerateObjectName();
182-
try
182+
// good test for null values and unicode strings
183+
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
184+
using (SqlCommand cmd = new SqlCommand(null, conn))
185+
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
183186
{
184-
ExecuteNonQueryCommand("CREATE TABLE " + tableName + " (c0_bigint bigint, c1_variant sql_variant)");
185-
186-
// good test for null values and unicode strings
187-
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
188-
using (SqlCommand cmd = new SqlCommand(null, conn))
189-
using (SqlDataAdapter sqlAdapter = new SqlDataAdapter())
187+
try
190188
{
189+
ExecuteNonQueryCommand("CREATE TABLE " + tableName + " (c0_bigint bigint, c1_variant sql_variant)");
190+
191191
cmd.Connection.Open();
192192

193193
// the ORDER BY clause tests that we correctly ignore the ORDER token
@@ -263,10 +263,10 @@ public void SqlVariantTest()
263263
}
264264
}
265265
}
266-
}
267-
finally
268-
{
269-
ExecuteNonQueryCommand("DROP TABLE " + tableName);
266+
finally
267+
{
268+
DataTestUtility.DropTable(conn, tableName);
269+
}
270270
}
271271
}
272272

@@ -659,7 +659,7 @@ public void UpdateTest()
659659
}
660660
finally
661661
{
662-
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
662+
DataTestUtility.DropTable(conn, _tempTable);
663663
}
664664
}
665665
}
@@ -757,7 +757,7 @@ public void BulkUpdateTest()
757757
}
758758
finally
759759
{
760-
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
760+
DataTestUtility.DropTable(conn, _tempTable);
761761
}
762762
}
763763
}
@@ -768,33 +768,35 @@ public void BulkUpdateTest()
768768
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
769769
public void UpdateRefreshTest()
770770
{
771+
string identTableName = DataTestUtility.GetUniqueName("ID_");
771772
string createIdentTable =
772-
"CREATE TABLE ID_" + _tempTable + "(id int IDENTITY," +
773+
$"CREATE TABLE {identTableName} (id int IDENTITY," +
773774
"LastName nvarchar(50) NULL," +
774775
"Firstname nvarchar(50) NULL)";
775776

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

783-
string spDropInsert = "DROP PROCEDURE sp_insert" + _tempTable;
785+
string spDropInsert = $"DROP PROCEDURE {spName}";
784786
bool dropSP = false;
785787

786788
using (SqlDataAdapter adapter = new SqlDataAdapter())
787789
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
788790
using (SqlCommand cmd = new SqlCommand(null, conn))
789-
using (SqlCommand temp = new SqlCommand("SELECT id, LastName, FirstName into " + _tempTable + " from ID_" + _tempTable, conn))
791+
using (SqlCommand temp = new SqlCommand("SELECT id, LastName, FirstName into " + _tempTable + $" from {identTableName}", conn))
790792
using (SqlCommand tableClean = new SqlCommand("", conn))
791793
{
792794
ExecuteNonQueryCommand(createIdentTable);
793795
try
794796
{
795797
adapter.InsertCommand = new SqlCommand()
796798
{
797-
CommandText = "sp_insert" + _tempTable,
799+
CommandText = spName,
798800
CommandType = CommandType.StoredProcedure
799801
};
800802
adapter.InsertCommand.Parameters.Add(new SqlParameter("@FirstName", SqlDbType.NVarChar, 50, "FirstName"));
@@ -851,9 +853,9 @@ public void UpdateRefreshTest()
851853
{
852854
if (dropSP)
853855
{
854-
ExecuteNonQueryCommand(spDropInsert);
855-
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
856-
ExecuteNonQueryCommand("DROP TABLE ID_" + _tempTable);
856+
DataTestUtility.DropStoredProcedure(conn, spName);
857+
DataTestUtility.DropTable(conn, _tempTable);
858+
DataTestUtility.DropTable(conn, identTableName);
857859
}
858860
}
859861
}
@@ -873,18 +875,18 @@ public void UpdateNullTest()
873875
"VALUES (@val_cvarbin, @val_cimage)";
874876
bool dropSP = false;
875877

876-
try
877-
{
878-
ExecuteNonQueryCommand(createTable);
879-
ExecuteNonQueryCommand(createSP);
880-
dropSP = true;
881878

882-
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
883-
using (SqlCommand cmdInsert = new SqlCommand(procName, conn))
884-
using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn))
885-
using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn))
886-
using (SqlDataAdapter adapter = new SqlDataAdapter())
879+
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
880+
using (SqlCommand cmdInsert = new SqlCommand(procName, conn))
881+
using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn))
882+
using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn))
883+
using (SqlDataAdapter adapter = new SqlDataAdapter())
884+
{
885+
try
887886
{
887+
ExecuteNonQueryCommand(createTable);
888+
ExecuteNonQueryCommand(createSP);
889+
dropSP = true;
888890
conn.Open();
889891

890892
cmdInsert.CommandType = CommandType.StoredProcedure;
@@ -905,13 +907,13 @@ public void UpdateNullTest()
905907
DataTestUtility.AssertEqualsWithDescription(DBNull.Value, ds.Tables[0].Rows[0][0], "Unexpected value.");
906908
DataTestUtility.AssertEqualsWithDescription(DBNull.Value, ds.Tables[0].Rows[0][1], "Unexpected value.");
907909
}
908-
}
909-
finally
910-
{
911-
if (dropSP)
910+
finally
912911
{
913-
ExecuteNonQueryCommand("DROP PROCEDURE " + procName);
914-
ExecuteNonQueryCommand("DROP TABLE " + tableName);
912+
if (dropSP)
913+
{
914+
DataTestUtility.DropStoredProcedure(conn, procName);
915+
DataTestUtility.DropTable(conn, tableName);
916+
}
915917
}
916918
}
917919
}
@@ -930,18 +932,18 @@ public void UpdateOffsetTest()
930932
"VALUES (@val_cvarbin, @val_cimage)";
931933
bool dropSP = false;
932934

933-
try
934-
{
935-
ExecuteNonQueryCommand(createTable);
936-
ExecuteNonQueryCommand(createSP);
937-
dropSP = true;
938935

939-
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
940-
using (SqlCommand cmdInsert = new SqlCommand(procName, conn))
941-
using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn))
942-
using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn))
943-
using (SqlDataAdapter adapter = new SqlDataAdapter())
936+
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
937+
using (SqlCommand cmdInsert = new SqlCommand(procName, conn))
938+
using (SqlCommand cmdSelect = new SqlCommand("select * from " + tableName, conn))
939+
using (SqlCommand tableClean = new SqlCommand("delete " + tableName, conn))
940+
using (SqlDataAdapter adapter = new SqlDataAdapter())
941+
{
942+
try
944943
{
944+
ExecuteNonQueryCommand(createTable);
945+
ExecuteNonQueryCommand(createSP);
946+
dropSP = true;
945947
conn.Open();
946948

947949
cmdInsert.CommandType = CommandType.StoredProcedure;
@@ -978,13 +980,13 @@ public void UpdateOffsetTest()
978980
val = (byte[])(ds.Tables[0].Rows[0][1]);
979981
Assert.True(ByteArraysEqual(expectedBytes2, val), "FAILED: Test 2: Unequal byte arrays.");
980982
}
981-
}
982-
finally
983-
{
984-
if (dropSP)
983+
finally
985984
{
986-
ExecuteNonQueryCommand("DROP PROCEDURE " + procName);
987-
ExecuteNonQueryCommand("DROP TABLE " + tableName);
985+
if (dropSP)
986+
{
987+
DataTestUtility.DropStoredProcedure(conn, procName);
988+
DataTestUtility.DropTable(conn, tableName);
989+
}
988990
}
989991
}
990992
}
@@ -1069,7 +1071,7 @@ public void AutoGenUpdateTest()
10691071
}
10701072
finally
10711073
{
1072-
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
1074+
DataTestUtility.DropTable(conn, _tempTable);
10731075
}
10741076
}
10751077
}
@@ -1078,16 +1080,17 @@ public void AutoGenUpdateTest()
10781080
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
10791081
public void AutoGenErrorTest()
10801082
{
1083+
string identTableName = DataTestUtility.GetUniqueName("ID_");
10811084
string createIdentTable =
1082-
"CREATE TABLE ID_" + _tempTable + "(id int IDENTITY," +
1085+
$"CREATE TABLE {identTableName} (id int IDENTITY," +
10831086
"LastName nvarchar(50) NULL," +
10841087
"Firstname nvarchar(50) NULL)";
10851088

1086-
try
1089+
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
1090+
using (SqlCommand cmd = new SqlCommand($"SELECT * into {_tempTable} from {identTableName}", conn))
1091+
using (SqlDataAdapter adapter = new SqlDataAdapter())
10871092
{
1088-
using (SqlConnection conn = new SqlConnection(DataTestUtility.TCPConnectionString))
1089-
using (SqlCommand cmd = new SqlCommand("SELECT * into " + _tempTable + " from ID_" + _tempTable, conn))
1090-
using (SqlDataAdapter adapter = new SqlDataAdapter())
1093+
try
10911094
{
10921095
ExecuteNonQueryCommand(createIdentTable);
10931096

@@ -1110,11 +1113,11 @@ public void AutoGenErrorTest()
11101113
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
11111114
adapter.Update(ds, _tempTable);
11121115
}
1113-
}
1114-
finally
1115-
{
1116-
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
1117-
ExecuteNonQueryCommand("DROP TABLE ID_" + _tempTable);
1116+
finally
1117+
{
1118+
DataTestUtility.DropTable(conn, _tempTable);
1119+
DataTestUtility.DropTable(conn, identTableName);
1120+
}
11181121
}
11191122
}
11201123

@@ -1206,7 +1209,7 @@ public void AutoGenBulkUpdateTest()
12061209
}
12071210
finally
12081211
{
1209-
ExecuteNonQueryCommand("DROP TABLE " + _tempTable);
1212+
DataTestUtility.DropTable(conn, _tempTable);
12101213
}
12111214
}
12121215
}
@@ -1319,6 +1322,48 @@ public void TestReadOnlyColumnMetadata()
13191322
}
13201323
}
13211324

1325+
[ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
1326+
[InlineData(nameof(SqlCommandBuilder.GetInsertCommand), null)]
1327+
[InlineData(nameof(SqlCommandBuilder.GetInsertCommand), true)]
1328+
[InlineData(nameof(SqlCommandBuilder.GetInsertCommand), false)]
1329+
[InlineData(nameof(SqlCommandBuilder.GetUpdateCommand), null)]
1330+
[InlineData(nameof(SqlCommandBuilder.GetUpdateCommand), true)]
1331+
[InlineData(nameof(SqlCommandBuilder.GetUpdateCommand), false)]
1332+
[InlineData(nameof(SqlCommandBuilder.GetDeleteCommand), null)]
1333+
[InlineData(nameof(SqlCommandBuilder.GetDeleteCommand), false)]
1334+
[InlineData(nameof(SqlCommandBuilder.GetDeleteCommand), true)]
1335+
public void VerifyGetCommand(string methodName, bool? useColumnsForParameterNames)
1336+
{
1337+
using (SqlConnection connection = new SqlConnection(DataTestUtility.TCPConnectionString))
1338+
{
1339+
connection.Open();
1340+
using (SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * FROM dbo.Customers", connection))
1341+
{
1342+
using (SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter))
1343+
{
1344+
object[] parameters = null;
1345+
Type[] parameterTypes = null;
1346+
if (useColumnsForParameterNames != null)
1347+
{
1348+
parameters = new object[] { useColumnsForParameterNames };
1349+
parameterTypes = new Type[] { typeof(bool) };
1350+
}
1351+
else
1352+
{
1353+
parameters = new object[] { };
1354+
parameterTypes = new Type[] { };
1355+
}
1356+
1357+
MethodInfo method = commandBuilder.GetType().GetMethod(methodName, parameterTypes);
1358+
using (SqlCommand cmd = (SqlCommand)method.Invoke(commandBuilder, parameters))
1359+
{
1360+
Assert.NotNull(cmd);
1361+
}
1362+
}
1363+
}
1364+
}
1365+
}
1366+
13221367
#region Utility_Methods
13231368
private void CheckParameters(SqlCommand cmd, string expectedResults)
13241369
{

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/TcpDefaultForAzureTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@ static TcpDefaultForAzureTest()
4141
public static void NonAzureNoProtocolConnectionTest()
4242
{
4343
builder.DataSource = InvalidHostname;
44+
#if NETFRAMEWORK
45+
CheckConnectionFailure(builder.ConnectionString, NP);
46+
#else
4447
CheckConnectionFailure(builder.ConnectionString, DataTestUtility.IsUsingManagedSNI() ? TCP : NP);
48+
#endif
4549
}
4650

4751
[Fact]

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/Config.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class Config
3737
public bool IsDNSCachingSupportedTR = false; // this is for the tenant ring
3838
public string EnclaveAzureDatabaseConnString = null;
3939
public string UserManagedIdentityClientId = null;
40+
public string MakecertPath = null;
4041

4142
public static Config Load(string configPath = @"config.json")
4243
{

src/Microsoft.Data.SqlClient/tests/tools/Microsoft.Data.SqlClient.TestUtilities/config.default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
"IsDNSCachingSupportedTR": false,
2626
"IsAzureSynapse": false,
2727
"EnclaveAzureDatabaseConnString": "",
28-
"UserManagedIdentityClientId": ""
28+
"UserManagedIdentityClientId": "",
29+
"MakecertPath": ""
2930
}

0 commit comments

Comments
 (0)