6
6
7
7
namespace Microsoft . Data . SqlClient . UnitTests
8
8
{
9
+ /// <summary>
10
+ /// Provides unit tests for verifying the behavior of the SqlCommandSet class.
11
+ /// </summary>
9
12
public class SqlCommandSetTest
10
13
{
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>
11
20
[ Theory ]
12
21
[ InlineData ( "BatchCommand" ) ]
13
22
[ InlineData ( "CommandList" ) ]
@@ -20,6 +29,9 @@ public void GetDisposedProperty_Throws(string propertyName)
20
29
Assert . Contains ( "disposed" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
21
30
}
22
31
32
+ /// <summary>
33
+ /// Verifies that adding a SqlCommand with an empty CommandText to a SqlCommandSet throws an InvalidOperationException.
34
+ /// </summary>
23
35
[ Fact ]
24
36
public void AppendCommandWithEmptyString_Throws ( )
25
37
{
@@ -30,20 +42,24 @@ public void AppendCommandWithEmptyString_Throws()
30
42
Assert . Contains ( "CommandText property has not been initialized" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
31
43
}
32
44
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>
39
59
[ Theory ]
40
60
[ MemberData (
41
61
nameof ( CommandTypeData )
42
62
#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.
47
63
, DisableDiscoveryEnumeration = true
48
64
#endif
49
65
) ]
@@ -56,6 +72,9 @@ public void AppendBadCommandType_Throws(CommandType commandType)
56
72
Assert . Contains ( "CommandType" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
57
73
}
58
74
75
+ /// <summary>
76
+ /// Verifies that adding a SqlCommand containing a SqlParameter with an invalid name to a SqlCommandSet throws an ArgumentException.
77
+ /// </summary>
59
78
[ Fact ]
60
79
public void AppendBadParameterName_Throws ( )
61
80
{
@@ -68,6 +87,9 @@ public void AppendBadParameterName_Throws()
68
87
Assert . Contains ( "not valid" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
69
88
}
70
89
90
+ /// <summary>
91
+ /// Verifies that a SqlParameter containing an array round-trips through a SqlCommandSet correctly.
92
+ /// </summary>
71
93
[ Theory ]
72
94
[ InlineData ( new byte [ ] { 1 , 2 , 3 } ) ]
73
95
[ InlineData ( new char [ ] { '1' , '2' , '3' } ) ]
@@ -84,6 +106,9 @@ public void AppendParameterArrayWithSize(object array)
84
106
Assert . Equal ( 2 , result . Size ) ;
85
107
}
86
108
109
+ /// <summary>
110
+ /// Verifies that a SqlParameter containing a scalar value round-trips through a SqlCommandSet correctly.
111
+ /// </summary>
87
112
[ Fact ]
88
113
public void GetParameter ( )
89
114
{
@@ -98,6 +123,10 @@ public void GetParameter()
98
123
Assert . Equal ( "value" , ( string ) result . Value ) ;
99
124
}
100
125
126
+ /// <summary>
127
+ /// Verifies that SqlCommandSet.GetParameterCount returns the correct number of parameters for a command
128
+ /// at the correct index.
129
+ /// </summary>
101
130
[ Fact ]
102
131
public void GetParameterCount ( )
103
132
{
@@ -112,6 +141,9 @@ public void GetParameterCount()
112
141
Assert . Equal ( 2 , count ) ;
113
142
}
114
143
144
+ /// <summary>
145
+ /// Verifies that SqlCommandSet.ValidateCommandBehavior throws an ArgumentOutOfRangeException when an invalid CommandBehavior is specified.
146
+ /// </summary>
115
147
[ Fact ]
116
148
public void InvalidCommandBehaviorValidateCommandBehavior_Throws ( )
117
149
{
@@ -121,6 +153,9 @@ public void InvalidCommandBehaviorValidateCommandBehavior_Throws()
121
153
Assert . Contains ( "CommandBehavior" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
122
154
}
123
155
156
+ /// <summary>
157
+ /// Verifies that SqlCommandSet.ValidateCommandBehavior throws an ArgumentOutOfRangeException when a valid but unsupported CommandBehavior is specified.
158
+ /// </summary>
124
159
[ Fact ]
125
160
public void NotSupportedCommandBehaviorValidateCommandBehavior_Throws ( )
126
161
{
0 commit comments