Skip to content

Commit ad01286

Browse files
authored
Tests | Move various unit tests to UnitTests project (#3458)
* Move SqlVectorTest, adjust namespace * Replace LocalAppContextSwitchesTests * Move SqlBufferTests * Remove unnecessary reflection from SqlBufferTests * Add descriptions to SqlBufferTests * Move SqlCommandSetTest * Remove unnecessary reflection from SqlCommandSetTest * Act on messages * Add descriptions to SqlCommandSetTests * Rename SqlBufferTests to align with standard * Adhere to project code style: namespace statements * Remove redundant using statement * Add missing license statement * Remove all internal reflection on SqlCommandSetTest * Remove unnecessary validation logic (and covering test)
1 parent 7584037 commit ad01286

File tree

10 files changed

+327
-509
lines changed

10 files changed

+327
-509
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommandSet.cs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal SqlCommandSet() : base()
3030
_commandList = new List<SqlBatchCommand>();
3131
}
3232

33-
private SqlCommand BatchCommand
33+
internal SqlCommand BatchCommand
3434
{
3535
get
3636
{
@@ -45,7 +45,7 @@ private SqlCommand BatchCommand
4545

4646
internal int CommandCount => CommandList.Count;
4747

48-
private List<SqlBatchCommand> CommandList
48+
internal List<SqlBatchCommand> CommandList
4949
{
5050
get
5151
{
@@ -98,24 +98,16 @@ internal void Append(SqlCommand command)
9898
{
9999
ADP.CheckArgumentNull(command, nameof(command));
100100
SqlClientEventSource.Log.TryTraceEvent("SqlCommandSet.Append | API | Object Id {0}, Command '{1}', Parameter Count {2}", ObjectID, command.ObjectID, command.Parameters.Count);
101+
102+
// SqlCommandSet only supports commands of type Text or StoredProcedure. This aligns with SqlCommand (validated by its CommandType setter.)
103+
Debug.Assert(command.CommandType is CommandType.Text or CommandType.StoredProcedure);
104+
101105
string cmdText = command.CommandText;
102106
if (string.IsNullOrEmpty(cmdText))
103107
{
104108
throw ADP.CommandTextRequired(nameof(Append));
105109
}
106110

107-
CommandType commandType = command.CommandType;
108-
switch (commandType)
109-
{
110-
case CommandType.Text:
111-
case CommandType.StoredProcedure:
112-
break;
113-
case CommandType.TableDirect:
114-
throw SQL.NotSupportedCommandType(commandType);
115-
default:
116-
throw ADP.InvalidCommandType(commandType);
117-
}
118-
119111
SqlParameterCollection parameters = null;
120112

121113
SqlParameterCollection collection = command.Parameters;
@@ -279,7 +271,7 @@ internal bool GetBatchedAffected(int commandIdentifier, out int recordsAffected,
279271
internal int GetParameterCount(int commandIndex)
280272
=> CommandList[commandIndex].Parameters.Count;
281273

282-
private void ValidateCommandBehavior(string method, CommandBehavior behavior)
274+
internal void ValidateCommandBehavior(string method, CommandBehavior behavior)
283275
{
284276
if (0 != (behavior & ~(CommandBehavior.SequentialAccess | CommandBehavior.CloseConnection)))
285277
{

src/Microsoft.Data.SqlClient/tests/FunctionalTests/LocalAppContextSwitchesTests.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.FunctionalTests.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@
3030
<Compile Include="MultipartIdentifierTests.cs" />
3131
<Compile Include="MultiplexerTests.cs" />
3232
<Compile Include="SqlAuthenticationProviderTest.cs" />
33-
<Compile Include="SqlBufferTests.cs" />
3433
<Compile Include="SqlClientLoggerTest.cs" />
35-
<Compile Include="SqlCommandSetTest.cs" />
36-
<Compile Include="LocalAppContextSwitchesTests.cs" />
3734
<Compile Include="SqlConfigurableRetryLogicTest.cs" />
3835
<Compile Include="SqlCommandBuilderTest.cs" />
3936
<Compile Include="SqlBulkCopyTest.cs" />

src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlBufferTests.cs

Lines changed: 0 additions & 253 deletions
This file was deleted.

0 commit comments

Comments
 (0)