@@ -1398,45 +1398,67 @@ public void TestReadOnlyColumnMetadata()
13981398 }
13991399
14001400 [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureSynapse ) ) ]
1401- [ InlineData ( nameof ( SqlCommandBuilder . GetInsertCommand ) , null ) ]
1402- [ InlineData ( nameof ( SqlCommandBuilder . GetInsertCommand ) , true ) ]
1403- [ InlineData ( nameof ( SqlCommandBuilder . GetInsertCommand ) , false ) ]
1404- [ InlineData ( nameof ( SqlCommandBuilder . GetUpdateCommand ) , null ) ]
1405- [ InlineData ( nameof ( SqlCommandBuilder . GetUpdateCommand ) , true ) ]
1406- [ InlineData ( nameof ( SqlCommandBuilder . GetUpdateCommand ) , false ) ]
1407- [ InlineData ( nameof ( SqlCommandBuilder . GetDeleteCommand ) , null ) ]
1408- [ InlineData ( nameof ( SqlCommandBuilder . GetDeleteCommand ) , false ) ]
1409- [ InlineData ( nameof ( SqlCommandBuilder . GetDeleteCommand ) , true ) ]
1410- public void VerifyGetCommand ( string methodName , bool ? useColumnsForParameterNames )
1401+ [ InlineData ( null ) ]
1402+ [ InlineData ( false ) ]
1403+ [ InlineData ( true ) ]
1404+ public void VerifyDeleteCommand ( bool ? useColumnsForParameterNames )
14111405 {
1412- using ( SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) )
1406+ if ( useColumnsForParameterNames . HasValue )
14131407 {
1414- connection . Open ( ) ;
1415- using ( SqlDataAdapter dataAdapter = new SqlDataAdapter ( "SELECT * FROM dbo.Customers" , connection ) )
1416- {
1417- using ( SqlCommandBuilder commandBuilder = new SqlCommandBuilder ( dataAdapter ) )
1418- {
1419- object [ ] parameters = null ;
1420- Type [ ] parameterTypes = null ;
1421- if ( useColumnsForParameterNames != null )
1422- {
1423- parameters = new object [ ] { useColumnsForParameterNames } ;
1424- parameterTypes = new Type [ ] { typeof ( bool ) } ;
1425- }
1426- else
1427- {
1428- parameters = new object [ ] { } ;
1429- parameterTypes = new Type [ ] { } ;
1430- }
1408+ VerifyGetCommand ( commandBuilder => commandBuilder . GetDeleteCommand ( useColumnsForParameterNames . Value ) ) ;
1409+ }
1410+ else
1411+ {
1412+ VerifyGetCommand ( commandBuilder => commandBuilder . GetDeleteCommand ( ) ) ;
1413+ }
1414+ }
14311415
1432- MethodInfo method = commandBuilder . GetType ( ) . GetMethod ( methodName , parameterTypes ) ;
1433- using ( SqlCommand cmd = ( SqlCommand ) method . Invoke ( commandBuilder , parameters ) )
1434- {
1435- Assert . NotNull ( cmd ) ;
1436- }
1437- }
1438- }
1416+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureSynapse ) ) ]
1417+ [ InlineData ( null ) ]
1418+ [ InlineData ( false ) ]
1419+ [ InlineData ( true ) ]
1420+ public void VerifyInsertCommand ( bool ? useColumnsForParameterNames )
1421+ {
1422+ if ( useColumnsForParameterNames . HasValue )
1423+ {
1424+ VerifyGetCommand ( commandBuilder => commandBuilder . GetInsertCommand ( useColumnsForParameterNames . Value ) ) ;
1425+ }
1426+ else
1427+ {
1428+ VerifyGetCommand ( commandBuilder => commandBuilder . GetInsertCommand ( ) ) ;
1429+ }
1430+ }
1431+
1432+ [ ConditionalTheory ( typeof ( DataTestUtility ) , nameof ( DataTestUtility . AreConnStringsSetup ) , nameof ( DataTestUtility . IsNotAzureSynapse ) ) ]
1433+ [ InlineData ( null ) ]
1434+ [ InlineData ( false ) ]
1435+ [ InlineData ( true ) ]
1436+ public void VerifyUpdateCommand ( bool ? useColumnsForParameterNames )
1437+ {
1438+ if ( useColumnsForParameterNames . HasValue )
1439+ {
1440+ VerifyGetCommand ( commandBuilder => commandBuilder . GetUpdateCommand ( useColumnsForParameterNames . Value ) ) ;
14391441 }
1442+ else
1443+ {
1444+ VerifyGetCommand ( commandBuilder => commandBuilder . GetUpdateCommand ( ) ) ;
1445+ }
1446+ }
1447+
1448+ private static void VerifyGetCommand ( Func < SqlCommandBuilder , SqlCommand > getFunc )
1449+ {
1450+ // Arrange
1451+ using SqlConnection connection = new SqlConnection ( DataTestUtility . TCPConnectionString ) ;
1452+ connection . Open ( ) ;
1453+
1454+ using SqlDataAdapter dataAdapter = new SqlDataAdapter ( "SELECT * FROM dbo.Customers" , connection ) ;
1455+ using SqlCommandBuilder commandBuilder = new SqlCommandBuilder ( dataAdapter ) ;
1456+
1457+ // Act
1458+ using SqlCommand command = getFunc ( commandBuilder ) ;
1459+
1460+ // Assert
1461+ Assert . NotNull ( command ) ;
14401462 }
14411463
14421464 #region Utility_Methods
0 commit comments