|
| 1 | +namespace Belin.Sql; |
| 2 | + |
| 3 | +using System.Data; |
| 4 | + |
| 5 | +/// <summary> |
| 6 | +/// Tests the features of the <see cref="ParameterCollection"/> class. |
| 7 | +/// </summary> |
| 8 | +[TestClass] |
| 9 | +public sealed class ParameterCollectionTests { |
| 10 | + |
| 11 | + [TestMethod] |
| 12 | + public void Constructor() { |
| 13 | + var collection = new ParameterCollection(); |
| 14 | + IsEmpty(collection); |
| 15 | + |
| 16 | + collection = new("?1", 123, DbType.Int32); |
| 17 | + HasCount(1, collection); |
| 18 | + |
| 19 | + var parameter = collection.First(); |
| 20 | + AreEqual("?1", parameter.Name); |
| 21 | + AreEqual(123, parameter.Value); |
| 22 | + AreEqual(DbType.Int32, parameter.DbType); |
| 23 | + |
| 24 | + collection = new(("?1", 123, DbType.Int32), ("@Key", "Unique", DbType.AnsiString)); |
| 25 | + HasCount(2, collection); |
| 26 | + |
| 27 | + parameter = collection.Last(); |
| 28 | + AreEqual("@Key", parameter.Name); |
| 29 | + AreEqual("Unique", parameter.Value); |
| 30 | + AreEqual(DbType.AnsiString, parameter.DbType); |
| 31 | + } |
| 32 | + |
| 33 | + [TestMethod] |
| 34 | + public void Contains() { |
| 35 | + var collection = new ParameterCollection("@Key"); |
| 36 | + IsTrue(collection.Contains("Key")); |
| 37 | + IsTrue(collection.Contains("@Key")); |
| 38 | + IsFalse(collection.Contains("Foo")); |
| 39 | + IsFalse(collection.Contains("@Foo")); |
| 40 | + } |
| 41 | + |
| 42 | + [TestMethod] |
| 43 | + public void IndexOf() { |
| 44 | + var collection = new ParameterCollection(("?1", 123), ("@Key", "Unique")); |
| 45 | + AreEqual(1, collection.IndexOf("Key")); |
| 46 | + AreEqual(1, collection.IndexOf("@Key")); |
| 47 | + AreEqual(-1, collection.IndexOf("Foo")); |
| 48 | + AreEqual(-1, collection.IndexOf("@Foo")); |
| 49 | + } |
| 50 | + |
| 51 | + [TestMethod] |
| 52 | + public void RemoveAt() { |
| 53 | + var collection = new ParameterCollection(("?1", 123), ("@Key", "Unique")); |
| 54 | + HasCount(2, collection); |
| 55 | + |
| 56 | + collection.RemoveAt("Key"); |
| 57 | + HasCount(1, collection); |
| 58 | + Throws<ArgumentOutOfRangeException>(() => collection.RemoveAt("Foo")); |
| 59 | + collection.RemoveAt("?1"); |
| 60 | + IsEmpty(collection); |
| 61 | + } |
| 62 | +} |
0 commit comments