protected override IList NonGenericIListFactory(int count)
        {
            CiccioSet <string> collection = new CiccioSet <string>();
            int seed = 9600;

            while (collection.Count < count)
            {
                object toAdd = CreateT(seed++);
                collection.Add((string)toAdd);
            }
            return(collection);
        }
コード例 #2
0
        /// <summary>
        /// Will perform an Add or Insert on the given Collection depending on whether the
        /// insertIndex is null or not. If it is null, will Add, otherwise, will Insert.
        /// </summary>
        public void AddOrInsertItemTest(CiccioSet <string> collection, string itemToAdd, int?insertIndex = null)
        {
            INotifyPropertyChanged collectionPropertyChanged = collection;

            collectionPropertyChanged.PropertyChanged += Collection_PropertyChanged;
            _expectedPropertyChanged = new[]
            {
                new PropertyNameExpected(COUNT),
                //new PropertyNameExpected(ITEMARRAY)
            };

            collection.CollectionChanged += Collection_CollectionChanged;

            ExpectedCollectionChangedFired++;
            ExpectedAction   = NotifyCollectionChangedAction.Add;
            ExpectedNewItems = new string[] { itemToAdd };
            if (insertIndex.HasValue)
            {
                ExpectedNewStartingIndex = insertIndex.Value;
            }
            else
            {
                ExpectedNewStartingIndex = collection.Count;
            }
            ExpectedOldItems         = null;
            ExpectedOldStartingIndex = -1;

            int expectedCount = collection.Count + 1;

            if (insertIndex.HasValue)
            {
                //collection.Insert(insertIndex.Value, itemToAdd);
                //Assert.Equal(itemToAdd, collection[insertIndex.Value]);
            }
            else
            {
                collection.Add(itemToAdd);
                Assert.Equal(itemToAdd, collection.ToArray()[collection.Count - 1]);
            }

            Assert.Equal(expectedCount, collection.Count);
            Assert.Equal(ExpectedCollectionChangedFired, NumCollectionChangedFired);


            foreach (var item in _expectedPropertyChanged)
            {
                Assert.True(item.IsFound, "The propertychanged event should have fired for" + item.Name + ", since we just added an item");
            }

            collection.CollectionChanged -= Collection_CollectionChanged;
            collectionPropertyChanged.PropertyChanged -= Collection_PropertyChanged;
        }
コード例 #3
0
        public void Reentrancy_MultipleListeners_Throws()
        {
            bool handler1Called = false;
            bool handler2Called = false;

            var collection = new CiccioSet <int>();

            collection.CollectionChanged += (sender, e) => { handler1Called = true; };
            collection.CollectionChanged += (sender, e) =>
            {
                handler2Called = true;

                // More than one listener; throws.
                Assert.Throws <InvalidOperationException>(() => collection.Add(2));
            };
            collection.Add(1);

            Assert.True(handler1Called);
            Assert.True(handler2Called);
            Assert.Equal(1, collection.Count);
            Assert.Equal(1, collection.ToArray()[0]);
        }
コード例 #4
0
        public void Reentrancy_SingleListener_DoesNotThrow()
        {
            bool handlerCalled = false;

            var collection = new CiccioSet <int>();

            collection.CollectionChanged += (sender, e) =>
            {
                if (!handlerCalled)
                {
                    handlerCalled = true;

                    // Single listener; does not throw.
                    collection.Add(2);
                }
            };
            collection.Add(1);

            Assert.True(handlerCalled);
            Assert.Equal(2, collection.Count);
            Assert.Equal(1, collection.ToArray()[0]);
            Assert.Equal(2, collection.ToArray()[1]);
        }