Skip to content

Commit a97cd89

Browse files
committed
SqlMetaData resolution in common MDS project
Rewrite VerifyGetCommand in adapter test to no longer use reflection/dynamic invocation
1 parent e5663e2 commit a97cd89

3 files changed

Lines changed: 66 additions & 37 deletions

File tree

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,9 +1049,10 @@
10491049
<Link>Resources\ILLink.Substitutions.xml</Link>
10501050
</EmbeddedResource>
10511051

1052+
<!-- Used by SqlMetaDataFactory to construct its DataSet -->
10521053
<EmbeddedResource Include="$(CommonSourceRoot)Resources\Microsoft.Data.SqlClient.SqlMetaData.xml">
10531054
<Link>Resources\Microsoft.Data.SqlCLient.SqlMetaData.xml</Link>
1054-
<LogicalName>Microsoft.Data.SqlClient.SqlMetaData.xml</LogicalName> <!-- @TODO: How necessary is this? -->
1055+
<LogicalName>Microsoft.Data.SqlClient.SqlMetaData.xml</LogicalName>
10551056
</EmbeddedResource>
10561057

10571058
<!-- Base strings in English -->

src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,15 @@
8181
<!-- the app context switch in their csproj. This file only applies to netcore on windows. -->
8282
<!-- This file does not support pre-processor directives, so it must be conditionally -->
8383
<!-- included into the build. -->
84-
<EmbeddedResource Include="Resources/ILLink.Substitutions.xml"
84+
<EmbeddedResource Include="Resources\ILLink.Substitutions.xml"
8585
Condition="'$(NormalizedTargetOs)' == 'windows_nt' AND '$(TargetFramework)' != 'net462'" />
8686

87+
<!-- Used by SqlMetaDataFactory to construct its DataSet -->
88+
<EmbeddedResource Include="Resources\Microsoft.Data.SqlClient.SqlMetaData.xml">
89+
<Link>Resources\Microsoft.Data.SqlCLient.SqlMetaData.xml</Link>
90+
<LogicalName>Microsoft.Data.SqlClient.SqlMetaData.xml</LogicalName>
91+
</EmbeddedResource>
92+
8793
<!-- Base strings in English -->
8894
<EmbeddedResource Update="Resources\Strings.resx">
8995
<LogicalName>Microsoft.Data.SqlClient.Resources.Strings.resources</LogicalName>

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

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)