8000 Add tests for DbParameter and DbParameterCollection. · mysql-net/AdoNetApiTest@200c994 · GitHub
[go: up one dir, main page]

Skip to content

Commit 200c994

Browse files
committed
Add tests for DbParameter and DbParameterCollection.
1 parent 6ee3dc9 commit 200c994

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed

src/AdoNet.Specification.Tests/ParameterTestBase.cs

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Data;
34
using System.Data.Common;
45
using Xunit;
@@ -169,5 +170,181 @@ public virtual void ParameterName_can_be_set_to_null()
169170
{
170171
Fixture.Factory.CreateParameter().ParameterName = null;
171172
}
173+
174+
[Fact]
175+
public virtual void ParameterName_default_is_empty_string()
176+
{
177+
Assert.Equal("", Fixture.Factory.CreateParameter().ParameterName);
178+
}
179+
180+
[Fact]
181+
public virtual void ParameterName_set_to_null_is_empty_string()
182+
{
183+
var parameter = Fixture.Factory.CreateParameter();
184+
parameter.ParameterName = null;
185+
Assert.Equal("", parameter.ParameterName);
186+
}
187+
188+
[Fact]
189+
public virtual void SourceColumn_can_be_set_to_null()
190+
{
191+
Fixture.Factory.CreateParameter().SourceColumn = null;
192+
}
193+
194+
[Fact]
195+
public virtual void SourceColumn_default_is_empty_string()
196+
{
197+
Assert.Equal("", Fixture.Factory.CreateParameter().SourceColumn);
198+
}
199+
200+
[Fact]
201+
public virtual void SourceColumn_set_to_null_is_empty_string()
202+
{
203+
var parameter = Fixture.Factory.CreateParameter();
204+
parameter.SourceColumn = null;
205+
Assert.Equal("", parameter.SourceColumn);
206+
}
207+
208+
[Fact]
209+
public virtual void ParameterCollection_Add_throws_for_null()
210+
{
211+
using (var command = Fixture.Factory.CreateCommand())
212+
{
213+
Assert.Throws<ArgumentNullException>(() => command.Parameters.Add(default));
214+
}
215+
}
216+
217+
[Fact]
218+
public virtual void ParameterCollection_string_indexer_setter_throws_for_null()
219+
{
220+
using (var command = Fixture.Factory.CreateCommand())
221+
{
222+
var parameter = command.CreateParameter();
223+
parameter.ParameterName = "@param";
224+
command.Parameters.Add(parameter);
225+
Assert.Throws<ArgumentNullException>(() => command.Parameters["@param"] = null);
226+
}
227+
}
228+
229+
[Fact]
230+
public virtual void ParameterCollection_int_indexer_setter_throws_for_null()
231+
{
232+
using (var command = Fixture.Factory.CreateCommand())
233+
{
234+
var parameter = command.CreateParameter();
235+
command.Parameters.Add(parameter);
236+
Assert.Throws<ArgumentNullException>(() => command.Parameters[0] = null);
237+
}
238+
}
239+
240+
[Fact]
241+
public virtual void ParameterCollection_IList_indexer_setter_throws_for_null()
242+
{
243+
using (var command = Fixture.Factory.CreateCommand())
244+
{
245+
var parameter = command.CreateParameter();
246+
command.Parameters.Add(parameter);
247+
Assert.Throws<ArgumentNullException>(() => ((IList) command.Parameters)[0] = null);
248+
}
249+
}
250+
251+
[Fact]
252+
public virtual void ParameterCollection_IDataParameterCollection_indexer_setter_throws_for_null()
253+
{
254+
using (var command = Fixture.Factory.CreateCommand())
255+
{
256+
var parameter = command.CreateParameter();
257+
parameter.ParameterName = "@param";
258+
command.Parameters.Add(parameter);
259+
Assert.Throws<ArgumentNullException>(() => ((IDataParameterCollection) command.Parameters)["@param"] = null);
260+
}
261+
}
262+
263+
[Fact]
264+
public virtual void ParameterCollection_Contains_object_returns_false_null()
265+
{
266+
using (var command = Fixture.Factory.CreateCommand())
267+
{
268+
Assert.False(command.Parameters.Contains(default(object)));
269+
}
270+
}
271+
272+
[Fact]
273+
public virtual void ParameterCollection_Contains_string_returns_false_for_null()
274+
{
275+
using (var command = Fixture.Factory.CreateCommand())
276+
{
277+
Assert.False(command.Parameters.Contains(default(string)));
278+
}
279+
}
280+
281+
[Fact]
282+
public virtual void ParameterCollection_IndexOf_object_returns_negative_one_for_null()
283+
{
284+
using (var command = Fixture.Factory.CreateCommand())
285+
{
286+
Assert.Equal(-1, command.Parameters.IndexOf(default(object)));
287+
}
288+
}
289+
290+
[Fact]
291+
public virtual void ParameterCollection_IndexOf_string_returns_negative_one_for_null()
292+
{
293+
using (var command = Fixture.Factory.CreateCommand())
294+
{
295+
Assert.Equal(-1, command.Parameters.IndexOf(default(string)));
296+
}
297+
}
298+
299+
[Fact]
300+
public virtual void ParameterCollection_Remove_throws_for_null()
301+
{
302+
using (var command = Fixture.Factory.CreateCommand())
303+
{
304+
Assert.Throws<ArgumentNullException>(() => command.Parameters.Remove(null));
305+
}
306+
}
307+
308+
[Fact]
309+
public virtual void ParameterCollection_RemoveAt_negative_one_throws()
310+
{
311+
using (var command = Fixture.Factory.CreateCommand())
312+
{
313+
Assert.Throws<ArgumentOutOfRangeException>(() => command.Parameters.RemoveAt(-1));
314+
}
315+
}
316+
317+
[Fact]
318+
public virtual void ParameterCollection_RemoveAt_zero_throws_when_empty()
319+
{
320+
using (var command = Fixture.Factory.CreateCommand())
321+
{
322+
Assert.Throws<ArgumentOutOfRangeException>(() => command.Parameters.RemoveAt(0));
323+
}
324+
}
325+
326+
[Fact]
327+
public virtual void ParameterCollection_Remove_succeeds()
328+
{
329+
using (var command = Fixture.Factory.CreateCommand())
330+
{
331+
var parameter = command.CreateParameter();
332+
command.Parameters.Add(parameter);
333+
command.Parameters.Remove(parameter);
334+
Assert.Empty(command.Parameters);
335+
}
336+
}
337+
338+
[Fact]
339+
public virtual void ParameterCollection_RemoveAt_succeeds()
340+
{
341+
using (var command = Fixture.Factory.CreateCommand())
342+
{
343+
var parameter = command.CreateParameter();
344+
command.Parameters.Add(parameter);
345+
command.Parameters.RemoveAt(0);
346+
Assert.Empty(command.Parameters);
347+
}
348+
}
172349
}
173350
}

0 commit comments

Comments
 (0)
0