Skip to content

Commit b415d5e

Browse files
committed
Act on messages
1 parent 7948fab commit b415d5e

File tree

1 file changed

+22
-27
lines changed

1 file changed

+22
-27
lines changed

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

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,24 @@ public void GetDisposedProperty_Throws(string propertyName)
1616
SqlCommandSet cmdSet = new();
1717
cmdSet.Dispose();
1818

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);
2121
}
2222

2323
[Fact]
2424
public void AppendCommandWithEmptyString_Throws()
2525
{
2626
SqlCommandSet cmdSet = new();
27-
SqlCommand cmd = new("");
27+
using SqlCommand cmd = new("");
2828

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);
3131
}
3232

3333
public static IEnumerable<object[]> CommandTypeData()
3434
{
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];
4037
}
4138

4239
[Theory]
@@ -53,22 +50,22 @@ public static IEnumerable<object[]> CommandTypeData()
5350
public void AppendBadCommandType_Throws(CommandType commandType)
5451
{
5552
SqlCommandSet cmdSet = new();
56-
SqlCommand cmd = GenerateBadCommand(commandType);
53+
using SqlCommand cmd = GenerateBadCommand(commandType);
5754

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);
6057
}
6158

6259
[Fact]
6360
public void AppendBadParameterName_Throws()
6461
{
6562
SqlCommandSet cmdSet = new();
66-
SqlCommand cmd = new("Test");
63+
using SqlCommand cmd = new("Test");
6764
cmd.CommandType = CommandType.Text;
6865
cmd.Parameters.Add(new SqlParameter("Test1;=", "1"));
6966

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);
7269
}
7370

7471
[Theory]
@@ -77,11 +74,9 @@ public void AppendBadParameterName_Throws()
7774
public void AppendParameterArrayWithSize(object array)
7875
{
7976
SqlCommandSet cmdSet = new();
80-
SqlCommand cmd = new("Test");
77+
using SqlCommand cmd = new("Test");
8178
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 });
8580
cmdSet.Append(cmd);
8681
SqlParameter result = cmdSet.GetParameter(0, 0);
8782
Assert.NotNull(result);
@@ -93,7 +88,7 @@ public void AppendParameterArrayWithSize(object array)
9388
public void GetParameter()
9489
{
9590
SqlCommandSet cmdSet = new();
96-
SqlCommand cmd = new("Test");
91+
using SqlCommand cmd = new("Test");
9792
cmd.CommandType = CommandType.Text;
9893
cmd.Parameters.Add(new SqlParameter("@text", "value"));
9994
cmdSet.Append(cmd);
@@ -107,7 +102,7 @@ public void GetParameter()
107102
public void GetParameterCount()
108103
{
109104
SqlCommandSet cmdSet = new();
110-
SqlCommand cmd = new("Test");
105+
using SqlCommand cmd = new("Test");
111106
cmd.CommandType = CommandType.Text;
112107
cmd.Parameters.Add(new SqlParameter("@abc", "1"));
113108
cmd.Parameters.Add(new SqlParameter("@test", "2"));
@@ -122,17 +117,17 @@ public void InvalidCommandBehaviorValidateCommandBehavior_Throws()
122117
{
123118
SqlCommandSet cmdSet = new();
124119

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);
127122
}
128123

129124
[Fact]
130125
public void NotSupportedCommandBehaviorValidateCommandBehavior_Throws()
131126
{
132127
SqlCommandSet cmdSet = new();
133128

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);
136131
}
137132

138133
#region private methods
@@ -168,7 +163,7 @@ private static T InvokeMethod_Throws<T>(SqlCommandSet instance, MethodInfo metho
168163
});
169164
}
170165

171-
private SqlCommand GenerateBadCommand(CommandType cType)
166+
private static SqlCommand GenerateBadCommand(CommandType cType)
172167
{
173168
SqlCommand cmd = new("Test");
174169
// 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

Comments
 (0)