Example #1
0
        public void IndexOfNonSqlParameter()
        {
            SqlCommand            command    = new SqlCommand();
            DbParameterCollection collection = command.Parameters;

            Assert.Throws <InvalidCastException>(() => collection.IndexOf(new NotASqlParameter()));
        }
Example #2
0
        public void BasicOperationsTest()
        {
            SqlCommand            command    = new SqlCommand();
            DbParameterCollection collection = command.Parameters;
            SqlParameter          firstParam = new SqlParameter();

            // Add
            int index = collection.Add(firstParam);

            Assert.Equal(0, index);

            // Get
            Assert.Same(firstParam, collection[index]);
            Assert.Equal(0, collection.IndexOf(firstParam));
            Assert.Equal(-1, collection.IndexOf(new SqlParameter()));
            Assert.Equal(-1, collection.IndexOf(null));

            // Insert
            SqlParameter secondParam = new SqlParameter();

            collection.Insert(0, secondParam);
            Assert.Same(secondParam, collection[0]);
            Assert.Same(firstParam, collection[1]);

            // Replace
            SqlParameter thirdParam = new SqlParameter();

            collection[1] = thirdParam;
            Assert.Same(thirdParam, collection[1]);

            // Remove
            collection.Remove(secondParam);
            Assert.Equal(1, collection.Count);
            Assert.Same(thirdParam, collection[0]);

            // Clear
            collection.Clear();
            Assert.Equal(0, collection.Count);
        }
 public override int IndexOf(string parameterName)
 {
     return(m_parameters.IndexOf(parameterName));
 }
 public override int IndexOf(string parameterName)
 {
     return(_parameterCollection.IndexOf(parameterName));
 }