Skip to content

Commit 7045eea

Browse files
committed
Add descriptions to SqlCommandSetTests
1 parent b415d5e commit 7045eea

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

src/Microsoft.Data.SqlClient/tests/UnitTests/Microsoft/Data/SqlClient/SqlCommandSetTest.cs

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,17 @@
66

77
namespace Microsoft.Data.SqlClient.UnitTests
88
{
9+
/// <summary>
10+
/// Provides unit tests for verifying the behavior of the SqlCommandSet class.
11+
/// </summary>
912
public class SqlCommandSetTest
1013
{
14+
/// <summary>
15+
/// Verifies that key properties throw an ObjectDisposedException after the SqlCommandSet has been disposed.
16+
/// </summary>
17+
/// <remarks>
18+
/// These properties are private, requiring reflection to access.
19+
/// </remarks>
1120
[Theory]
1221
[InlineData("BatchCommand")]
1322
[InlineData("CommandList")]
@@ -20,6 +29,9 @@ public void GetDisposedProperty_Throws(string propertyName)
2029
Assert.Contains("disposed", ex.Message, StringComparison.OrdinalIgnoreCase);
2130
}
2231

32+
/// <summary>
33+
/// Verifies that adding a SqlCommand with an empty CommandText to a SqlCommandSet throws an InvalidOperationException.
34+
/// </summary>
2335
[Fact]
2436
public void AppendCommandWithEmptyString_Throws()
2537
{
@@ -30,20 +42,24 @@ public void AppendCommandWithEmptyString_Throws()
3042
Assert.Contains("CommandText property has not been initialized", ex.Message, StringComparison.OrdinalIgnoreCase);
3143
}
3244

33-
public static IEnumerable<object[]> CommandTypeData()
34-
{
35-
yield return [CommandType.TableDirect];
36-
yield return [(CommandType)5];
37-
}
38-
45+
/// <summary>
46+
/// Returns a set of invalid CommandType values.
47+
/// </summary>
48+
/// <see cref="AppendBadCommandType_Throws(CommandType)"/>
49+
/// <remarks>
50+
/// .NET Framework puts system enums in the Global Assembly Cache (GAC), and xUnit refuses to serialize enums that live there.
51+
/// We make these system enum values a method, then disable enumeration of the test data to avoid warnings on the console when running tests.
52+
/// </remarks>
53+
public static TheoryData<CommandType> CommandTypeData()
54+
=> new(CommandType.TableDirect, (CommandType)5);
55+
56+
/// <summary>
57+
/// Verifies that adding a SqlCommand with an invalid CommandType to a SqlCommandSet throws an ArgumentOutOfRangeException.
58+
/// </summary>
3959
[Theory]
4060
[MemberData(
4161
nameof(CommandTypeData)
4262
#if NETFRAMEWORK
43-
// .NET Framework puts system enums in something called the Global
44-
// Assembly Cache (GAC), and xUnit refuses to serialize enums that
45-
// live there. So for .NET Framework, we disable enumeration of the
46-
// test data to avoid warnings on the console when running tests.
4763
, DisableDiscoveryEnumeration = true
4864
#endif
4965
)]
@@ -56,6 +72,9 @@ public void AppendBadCommandType_Throws(CommandType commandType)
5672
Assert.Contains("CommandType", ex.Message, StringComparison.OrdinalIgnoreCase);
5773
}
5874

75+
/// <summary>
76+
/// Verifies that adding a SqlCommand containing a SqlParameter with an invalid name to a SqlCommandSet throws an ArgumentException.
77+
/// </summary>
5978
[Fact]
6079
public void AppendBadParameterName_Throws()
6180
{
@@ -68,6 +87,9 @@ public void AppendBadParameterName_Throws()
6887
Assert.Contains("not valid", ex.Message, StringComparison.OrdinalIgnoreCase);
6988
}
7089

90+
/// <summary>
91+
/// Verifies that a SqlParameter containing an array round-trips through a SqlCommandSet correctly.
92+
/// </summary>
7193
[Theory]
7294
[InlineData(new byte[] { 1, 2, 3 })]
7395
[InlineData(new char[] { '1', '2', '3' })]
@@ -84,6 +106,9 @@ public void AppendParameterArrayWithSize(object array)
84106
Assert.Equal(2, result.Size);
85107
}
86108

109+
/// <summary>
110+
/// Verifies that a SqlParameter containing a scalar value round-trips through a SqlCommandSet correctly.
111+
/// </summary>
87112
[Fact]
88113
public void GetParameter()
89114
{
@@ -98,6 +123,10 @@ public void GetParameter()
98123
Assert.Equal("value", (string)result.Value);
99124
}
100125

126+
/// <summary>
127+
/// Verifies that SqlCommandSet.GetParameterCount returns the correct number of parameters for a command
128+
/// at the correct index.
129+
/// </summary>
101130
[Fact]
102131
public void GetParameterCount()
103132
{
@@ -112,6 +141,9 @@ public void GetParameterCount()
112141
Assert.Equal(2, count);
113142
}
114143

144+
/// <summary>
145+
/// Verifies that SqlCommandSet.ValidateCommandBehavior throws an ArgumentOutOfRangeException when an invalid CommandBehavior is specified.
146+
/// </summary>
115147
[Fact]
116148
public void InvalidCommandBehaviorValidateCommandBehavior_Throws()
117149
{
@@ -121,6 +153,9 @@ public void InvalidCommandBehaviorValidateCommandBehavior_Throws()
121153
Assert.Contains("CommandBehavior", ex.Message, StringComparison.OrdinalIgnoreCase);
122154
}
123155

156+
/// <summary>
157+
/// Verifies that SqlCommandSet.ValidateCommandBehavior throws an ArgumentOutOfRangeException when a valid but unsupported CommandBehavior is specified.
158+
/// </summary>
124159
[Fact]
125160
public void NotSupportedCommandBehaviorValidateCommandBehavior_Throws()
126161
{

0 commit comments

Comments
 (0)