Esempio n. 1
0
        protected virtual void AddToCollection(IList collection, int numberOfItemsToAdd)
        {
            int seed = 9600;

            while (collection.Count < numberOfItemsToAdd)
            {
                object toAdd = CreateT(seed++);
                while (collection.Contains(toAdd) || InvalidValues.Contains(toAdd))
                {
                    toAdd = CreateT(seed++);
                }
                collection.Add(toAdd);
            }
        }
        protected override void AddToCollection(ICollection <T> collection, int numberOfItemsToAdd)
        {
            int      seed = 9600;
            ISet <T> set  = (ISet <T>)collection;

            while (set.Count < numberOfItemsToAdd)
            {
                T toAdd = CreateT(seed++);
                while (set.Contains(toAdd) || (InvalidValues != Array.Empty <T>() && InvalidValues.Contains(toAdd, GetIEqualityComparer())))
                {
                    toAdd = CreateT(seed++);
                }
                set.Add(toAdd);
            }
        }
Esempio n. 3
0
 public void ICollection_Generic_Remove_DefaultValueContainedInCollection(int count)
 {
     if (!IsReadOnly && DefaultValueAllowed && !InvalidValues.Contains(default(T)))
     {
         var seed       = count * 21;
         var collection = GenericICollectionFactory(count);
         var value      = default(T);
         if (!collection.Contains(value))
         {
             collection.Add(value);
             count++;
         }
         Assert.True(collection.Remove(value));
         Assert.Equal(count - 1, collection.Count);
     }
 }
Esempio n. 4
0
        public void ICollection_Generic_Remove_NonDefaultValueNotContainedInCollection(int count)
        {
            if (IsReadOnly)
            {
                return;
            }
            var seed       = count * 251;
            var collection = GenericICollectionFactory(count);
            var value      = CreateT(seed++);

            while (collection.Contains(value) || InvalidValues.Contains(value))
            {
                value = CreateT(seed++);
            }
            Assert.False(collection.Remove(value));
            Assert.Equal(count, collection.Count);
        }
        protected override void AddToCollection(ICollection <KeyValuePair <TKey, TValue> > collection, int numberOfItemsToAdd)
        {
            Assert.False(IsReadOnly);
            var seed         = 12353;
            var casted       = (IDictionary <TKey, TValue>)collection;
            var initialCount = casted.Count;

            while (casted.Count - initialCount < numberOfItemsToAdd)
            {
                var toAdd = CreateT(seed++);
                while (casted.ContainsKey(toAdd.Key) || InvalidValues.Contains(toAdd))
                {
                    toAdd = CreateT(seed++);
                }
                collection.Add(toAdd);
            }
        }