Example #1
0
 public void IList_Generic_Insert_NegativeIndex_ThrowsArgumentOutOfRangeException(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list     = GenericIListFactory(count);
         T             validAdd = CreateT(0);
         Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(-1, validAdd));
         Assert.Throws <ArgumentOutOfRangeException>(() => list.Insert(int.MinValue, validAdd));
         Assert.Equal(count, list.Count);
     }
 }
Example #2
0
        /// <summary>
        /// Returns a set of ModifyEnumerable delegates that modify the enumerable passed to them.
        /// </summary>
        protected override SCG.IEnumerable <ModifyEnumerable> GetModifyEnumerables(ModifyOperation operations)
        {
            foreach (var item in base.GetModifyEnumerables(operations))
            {
                yield return(item);
            }

            if (!AddRemoveClear_ThrowsNotSupported && (operations & ModifyOperation.Insert) == ModifyOperation.Insert)
            {
                yield return((SCG.IEnumerable <T> enumerable) =>
                {
                    SCG.IList <T> casted = ((SCG.IList <T>)enumerable);
                    if (casted.Count > 0)
                    {
                        casted.Insert(0, CreateT(12));
                        return true;
                    }
                    return false;
                });
            }
            if (!AddRemoveClear_ThrowsNotSupported && (operations & ModifyOperation.Remove) == ModifyOperation.Remove)
            {
                yield return((SCG.IEnumerable <T> enumerable) =>
                {
                    SCG.IList <T> casted = ((SCG.IList <T>)enumerable);
                    if (casted.Count > 0)
                    {
                        casted.RemoveAt(0);
                        return true;
                    }
                    return false;
                });
            }
        }
Example #3
0
 public void IList_Generic_Insert_ToReadOnlyList(int count)
 {
     if (IsReadOnly || AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list = GenericIListFactory(count);
         Assert.Throws <NotSupportedException>(() => list.Insert(count / 2, CreateT(321432)));
         Assert.Equal(count, list.Count);
     }
 }
Example #4
0
 public void IList_Generic_Insert_InvalidValue(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         Assert.All(InvalidValues, value =>
         {
             SCG.IList <T> list = GenericIListFactory(count);
             Assert.Throws <ArgumentException>(() => list.Insert(count / 2, value));
         });
     }
 }
Example #5
0
 public void IList_Generic_Insert_DuplicateValues(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported && DuplicateValuesAllowed)
     {
         SCG.IList <T> list  = GenericIListFactory(count);
         T             value = CreateT(123452);
         if (AddRemoveClear_ThrowsNotSupported)
         {
             Assert.Throws <NotSupportedException>(() => list.Insert(0, value));
         }
         else
         {
             list.Insert(0, value);
             list.Insert(1, value);
             Assert.Equal(value, list[0]);
             Assert.Equal(value, list[1]);
             Assert.Equal(count + 2, list.Count);
         }
     }
 }
Example #6
0
 public void IList_Generic_Insert_FirstItemToDefaultValue(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported && DefaultValueAllowed)
     {
         SCG.IList <T> list  = GenericIListFactory(count);
         T             value = default(T);
         list.Insert(0, value);
         Assert.Equal(value, list[0]);
         Assert.Equal(count + 1, list.Count);
     }
 }
Example #7
0
 public void IList_Generic_Insert_IndexGreaterThanListCount_Appends(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list     = GenericIListFactory(count);
         T             validAdd = CreateT(12350);
         list.Insert(count, validAdd);
         Assert.Equal(count + 1, list.Count);
         Assert.Equal(validAdd, list[count]);
     }
 }
Example #8
0
 public void IList_Generic_Insert_LastItemToNonDefaultValue(int count)
 {
     if (!IsReadOnly && !AddRemoveClear_ThrowsNotSupported)
     {
         SCG.IList <T> list      = GenericIListFactory(count);
         T             value     = CreateT(123452);
         int           lastIndex = count > 0 ? count - 1 : 0;
         list.Insert(lastIndex, value);
         Assert.Equal(value, list[lastIndex]);
         Assert.Equal(count + 1, list.Count);
     }
 }