@@ -16,27 +16,24 @@ public void GetDisposedProperty_Throws(string propertyName)
16
16
SqlCommandSet cmdSet = new ( ) ;
17
17
cmdSet . Dispose ( ) ;
18
18
19
- ObjectDisposedException ode = GetProperty_Throws < ObjectDisposedException > ( cmdSet , propertyName ) ;
20
- Assert . Contains ( "disposed" , ode . Message , StringComparison . OrdinalIgnoreCase ) ;
19
+ ObjectDisposedException ex = GetProperty_Throws < ObjectDisposedException > ( cmdSet , propertyName ) ;
20
+ Assert . Contains ( "disposed" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
21
21
}
22
22
23
23
[ Fact ]
24
24
public void AppendCommandWithEmptyString_Throws ( )
25
25
{
26
26
SqlCommandSet cmdSet = new ( ) ;
27
- SqlCommand cmd = new ( "" ) ;
27
+ using SqlCommand cmd = new ( "" ) ;
28
28
29
- InvalidOperationException ioe = Assert . Throws < InvalidOperationException > ( ( ) => cmdSet . Append ( cmd ) ) ;
30
- Assert . Contains ( "CommandText property has not been initialized" , ioe . Message , StringComparison . OrdinalIgnoreCase ) ;
29
+ InvalidOperationException ex = Assert . Throws < InvalidOperationException > ( ( ) => cmdSet . Append ( cmd ) ) ;
30
+ Assert . Contains ( "CommandText property has not been initialized" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
31
31
}
32
32
33
33
public static IEnumerable < object [ ] > CommandTypeData ( )
34
34
{
35
- return new object [ ] [ ]
36
- {
37
- new object [ ] { CommandType . TableDirect } ,
38
- new object [ ] { ( CommandType ) 5 }
39
- } ;
35
+ yield return [ CommandType . TableDirect ] ;
36
+ yield return [ ( CommandType ) 5 ] ;
40
37
}
41
38
42
39
[ Theory ]
@@ -53,22 +50,22 @@ public static IEnumerable<object[]> CommandTypeData()
53
50
public void AppendBadCommandType_Throws ( CommandType commandType )
54
51
{
55
52
SqlCommandSet cmdSet = new ( ) ;
56
- SqlCommand cmd = GenerateBadCommand ( commandType ) ;
53
+ using SqlCommand cmd = GenerateBadCommand ( commandType ) ;
57
54
58
- ArgumentOutOfRangeException aoore = Assert . Throws < ArgumentOutOfRangeException > ( ( ) => cmdSet . Append ( cmd ) ) ;
59
- Assert . Contains ( "CommandType" , aoore . Message , StringComparison . OrdinalIgnoreCase ) ;
55
+ ArgumentOutOfRangeException ex = Assert . Throws < ArgumentOutOfRangeException > ( ( ) => cmdSet . Append ( cmd ) ) ;
56
+ Assert . Contains ( "CommandType" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
60
57
}
61
58
62
59
[ Fact ]
63
60
public void AppendBadParameterName_Throws ( )
64
61
{
65
62
SqlCommandSet cmdSet = new ( ) ;
66
- SqlCommand cmd = new ( "Test" ) ;
63
+ using SqlCommand cmd = new ( "Test" ) ;
67
64
cmd . CommandType = CommandType . Text ;
68
65
cmd . Parameters . Add ( new SqlParameter ( "Test1;=" , "1" ) ) ;
69
66
70
- ArgumentException ae = Assert . Throws < ArgumentException > ( ( ) => cmdSet . Append ( cmd ) ) ;
71
- Assert . Contains ( "not valid" , ae . Message , StringComparison . OrdinalIgnoreCase ) ;
67
+ ArgumentException ex = Assert . Throws < ArgumentException > ( ( ) => cmdSet . Append ( cmd ) ) ;
68
+ Assert . Contains ( "not valid" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
72
69
}
73
70
74
71
[ Theory ]
@@ -77,11 +74,9 @@ public void AppendBadParameterName_Throws()
77
74
public void AppendParameterArrayWithSize ( object array )
78
75
{
79
76
SqlCommandSet cmdSet = new ( ) ;
80
- SqlCommand cmd = new ( "Test" ) ;
77
+ using SqlCommand cmd = new ( "Test" ) ;
81
78
cmd . CommandType = CommandType . StoredProcedure ;
82
- SqlParameter parameter = new ( "@array" , array ) ;
83
- parameter . Size = 2 ;
84
- cmd . Parameters . Add ( parameter ) ;
79
+ cmd . Parameters . Add ( new SqlParameter ( "@array" , array ) { Size = 2 } ) ;
85
80
cmdSet . Append ( cmd ) ;
86
81
SqlParameter result = cmdSet . GetParameter ( 0 , 0 ) ;
87
82
Assert . NotNull ( result ) ;
@@ -93,7 +88,7 @@ public void AppendParameterArrayWithSize(object array)
93
88
public void GetParameter ( )
94
89
{
95
90
SqlCommandSet cmdSet = new ( ) ;
96
- SqlCommand cmd = new ( "Test" ) ;
91
+ using SqlCommand cmd = new ( "Test" ) ;
97
92
cmd . CommandType = CommandType . Text ;
98
93
cmd . Parameters . Add ( new SqlParameter ( "@text" , "value" ) ) ;
99
94
cmdSet . Append ( cmd ) ;
@@ -107,7 +102,7 @@ public void GetParameter()
107
102
public void GetParameterCount ( )
108
103
{
109
104
SqlCommandSet cmdSet = new ( ) ;
110
- SqlCommand cmd = new ( "Test" ) ;
105
+ using SqlCommand cmd = new ( "Test" ) ;
111
106
cmd . CommandType = CommandType . Text ;
112
107
cmd . Parameters . Add ( new SqlParameter ( "@abc" , "1" ) ) ;
113
108
cmd . Parameters . Add ( new SqlParameter ( "@test" , "2" ) ) ;
@@ -122,17 +117,17 @@ public void InvalidCommandBehaviorValidateCommandBehavior_Throws()
122
117
{
123
118
SqlCommandSet cmdSet = new ( ) ;
124
119
125
- ArgumentOutOfRangeException aoore = InvokeMethod_Throws < ArgumentOutOfRangeException > ( cmdSet , "ValidateCommandBehavior" , "ExecuteNonQuery" , ( CommandBehavior ) 64 ) ;
126
- Assert . Contains ( "CommandBehavior" , aoore . Message , StringComparison . OrdinalIgnoreCase ) ;
120
+ ArgumentOutOfRangeException ex = InvokeMethod_Throws < ArgumentOutOfRangeException > ( cmdSet , "ValidateCommandBehavior" , "ExecuteNonQuery" , ( CommandBehavior ) 64 ) ;
121
+ Assert . Contains ( "CommandBehavior" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
127
122
}
128
123
129
124
[ Fact ]
130
125
public void NotSupportedCommandBehaviorValidateCommandBehavior_Throws ( )
131
126
{
132
127
SqlCommandSet cmdSet = new ( ) ;
133
128
134
- ArgumentOutOfRangeException aoore = InvokeMethod_Throws < ArgumentOutOfRangeException > ( cmdSet , "ValidateCommandBehavior" , "ExecuteNonQuery" , CommandBehavior . KeyInfo ) ;
135
- Assert . Contains ( "not supported" , aoore . Message , StringComparison . OrdinalIgnoreCase ) ;
129
+ ArgumentOutOfRangeException ex = InvokeMethod_Throws < ArgumentOutOfRangeException > ( cmdSet , "ValidateCommandBehavior" , "ExecuteNonQuery" , CommandBehavior . KeyInfo ) ;
130
+ Assert . Contains ( "not supported" , ex . Message , StringComparison . OrdinalIgnoreCase ) ;
136
131
}
137
132
138
133
#region private methods
@@ -168,7 +163,7 @@ private static T InvokeMethod_Throws<T>(SqlCommandSet instance, MethodInfo metho
168
163
} ) ;
169
164
}
170
165
171
- private SqlCommand GenerateBadCommand ( CommandType cType )
166
+ private static SqlCommand GenerateBadCommand ( CommandType cType )
172
167
{
173
168
SqlCommand cmd = new ( "Test" ) ;
174
169
// There's validation done on the CommandType property, but we need to create one that avoids the check for the test case.
0 commit comments