Example #1
0
 public override void AddRange(Array values)
 {
     if (_dbParameterCollection != null)
     {
         _dbParameterCollection.AddRange(values);
     }
     else
     {
         foreach (var value in values)
         {
             Add(value);
         }
     }
 }
Example #2
0
        public void AddNonSqlParameter()
        {
            SqlCommand            command    = new SqlCommand();
            DbParameterCollection collection = command.Parameters;

            Assert.Throws <ArgumentNullException>(() => collection.Add(null));
            Assert.Throws <InvalidCastException>(() => collection.Add(new NotASqlParameter()));
            Assert.Throws <ArgumentNullException>(() => collection.Insert(0, null));
            Assert.Throws <InvalidCastException>(() => collection.Insert(0, new NotASqlParameter()));
            Assert.Throws <InvalidCastException>(() => collection.AddRange(new object[] { new SqlParameter(), new NotASqlParameter() }));
            Assert.Equal(0, collection.Count);

            collection.Add(new SqlParameter());
            Assert.Throws <ArgumentNullException>(() => collection[0] = null);
            Assert.Throws <InvalidCastException>(() => collection[0]  = new NotASqlParameter());
        }
Example #3
0
        public void AddDuplicate()
        {
            SqlCommand            command    = new SqlCommand();
            DbParameterCollection collection = command.Parameters;
            SqlParameter          firstParam = new SqlParameter();

            collection.Add(firstParam);

            Assert.Throws <ArgumentException>(() => collection.Add(firstParam));
            Assert.Throws <ArgumentException>(() => collection.Insert(1, firstParam));
            Assert.Throws <ArgumentException>(() => collection.AddRange(new object[] { new SqlParameter(), firstParam }));
            // Back-compat:
            // Checking for duplications happens while adding items to the collection, so we have one item added before the exception is thrown
            Assert.Equal(2, collection.Count);

            // Setting the item to its current index should succeed
            collection[0] = firstParam;
            Assert.Throws <ArgumentException>(() => collection[1] = firstParam);
        }
Example #4
0
        public static DbParameterCollection AddRange(this DbParameterCollection collection, params object[] values)
        {
            collection.AddRange(values);

            return(collection);
        }
Example #5
0
 /// <summary>
 /// Adds a sequence of parameters to a parameter collection.
 /// </summary>
 /// <param name="this">The parameter collection to which to add the parameters.</param>
 /// <param name="parameters">The parameters to add.</param>
 public static void AddRange(this DbParameterCollection @this, IEnumerable <DbParameter> parameters)
 {
     @this.AddRange(parameters.ToArray());
 }
 public override void AddRange(Array values)
 {
     m_parameters.AddRange(values);
 }