Example #1
0
            public void ReturnsFalseOnANewList()
            {
                var list = new DeletableObjectList <TestDeletable>();

                var returnValue = list.Remove(new TestDeletable());

                returnValue.Should().BeFalse();
            }
Example #2
0
            public void ThrowsOnNull()
            {
                var list = new DeletableObjectList <TestDeletable>();

                Action addingNull = () => list.Add(null);

                Assert.Throws <ArgumentNullException>(addingNull);
            }
Example #3
0
            public void ReturnsFalseOnANewList()
            {
                var list = new DeletableObjectList <TestDeletable>();

                var returnValue = list.Remove(new TestDeletable());

                Assert.False(returnValue);
            }
Example #4
0
            public void AddsObjectToList()
            {
                var list      = new DeletableObjectList <TestDeletable>();
                var deletable = new TestDeletable();

                list.Add(deletable);

                Assert.Equal(deletable, list.Single());
            }
Example #5
0
            public void DoesNotThrowAfterDisposingEnumerator()
            {
                var list       = new DeletableObjectList <TestDeletable>();
                var enumerator = list.GetEnumerator();

                enumerator.Dispose();

                CallMethod(list);
            }
Example #6
0
            public void AddsObjectToList()
            {
                var list      = new DeletableObjectList <TestDeletable>();
                var deletable = new TestDeletable();

                list.Add(deletable);

                list.Should().ContainSingle().Which.Should().Be(deletable);
            }
Example #7
0
            public void ThrowsIfEnumerating()
            {
                var list = new DeletableObjectList <TestDeletable>();

                list.GetEnumerator();

                Action callingWhileEnumerating = () => CallMethod(list);

                Assert.Throws <InvalidOperationException>(callingWhileEnumerating);
            }
Example #8
0
        createPopulatedList(int itemsToAdd)
        {
            var list  = new DeletableObjectList <TestDeletable>();
            var items = getDeletables(itemsToAdd);

            foreach (var item in items)
            {
                list.Add(item);
            }
            return(list, items);
        }
Example #9
0
            public void CanAddMultipleItems(int itemsToAdd)
            {
                var list  = new DeletableObjectList <TestDeletable>();
                var items = getDeletables(itemsToAdd);

                foreach (var item in items)
                {
                    list.Add(item);
                }

                list.Should().BeEquivalentTo(items, withExactSameItems);
            }
Example #10
0
            public void DoesNotThrowIfAllEnumeratorsAreDisposed()
            {
                var list        = new DeletableObjectList <TestDeletable>();
                var enumerators = Enumerable.Range(0, 20).Select(i => list.GetEnumerator()).ToList();

                foreach (var enumerator in enumerators)
                {
                    enumerator.Dispose();
                }

                CallMethod(list);
            }
Example #11
0
            public void CanAddMultipleItems(int itemsToAdd)
            {
                var list  = new DeletableObjectList <TestDeletable>();
                var items = getDeletables(itemsToAdd);

                foreach (var item in items)
                {
                    list.Add(item);
                }

                Assert.True(items.SequenceEqual(list));
            }
Example #12
0
        private DeletableObjectList <T> getList <T>()
            where T : class, IDeletable
        {
            object list;

            if (lists.TryGetValue(typeof(T), out list))
            {
                return((DeletableObjectList <T>)list);
            }

            var l = new DeletableObjectList <T>();

            lists.Add(typeof(T), l);
            return(l);
        }
Example #13
0
        public DeletableObjectList <T> GetList <T>()
            where T : class, IDeletable
        {
            object list;

            if (this.lists.TryGetValue(typeof(T), out list))
            {
                return((DeletableObjectList <T>)list);
            }

            var l = new DeletableObjectList <T>();

            this.lists.Add(typeof(T), l);
            return(l);
        }
Example #14
0
            public void ThrowsIfAtLeastOneEnumeratorIsNotDisposed()
            {
                var list                = new DeletableObjectList <TestDeletable>();
                var enumerators         = Enumerable.Range(0, 20).Select(i => list.GetEnumerator()).ToList();
                var arbitraryEnumerator = enumerators[7];

                foreach (var enumerator in enumerators.Except(new [] { arbitraryEnumerator }))
                {
                    enumerator.Dispose();
                }

                Action callingWhileEnumerating = () => CallMethod(list);

                Assert.Throws <InvalidOperationException>(callingWhileEnumerating);
            }
Example #15
0
            public void IsAccurateWhenAddingAndRemoving(PositiveInt itemsToAdd, int randomSeed)
            {
                var itemCount = itemsToAdd.Get;
                var random    = new System.Random(randomSeed);
                var list      = new DeletableObjectList <TestDeletable>();

                foreach (var i in Enumerable.Range(1, itemCount))
                {
                    list.Add(new TestDeletable());
                    Assert.Equal(i, list.ApproximateCount);
                }

                foreach (var i in Enumerable.Range(1, itemCount))
                {
                    list.Remove(list.RandomElement(random));
                    Assert.Equal(itemCount - i, list.ApproximateCount);
                }
            }
Example #16
0
        public void AddToList(DeletableObjectList <T> list)
        {
            if (this.List != null)
            {
                return;
            }

            this.List    = list;
            this.Deleted = false;

            if (list.Last != null)
            {
                this.Prev      = list.Last;
                this.Prev.Next = (T)this;
            }

            this.ChangingList = true;
            list.Add((T)this);
            this.ChangingList = false;
        }
Example #17
0
            public void CreatesEmptyListForZeroValue()
            {
                var list = new DeletableObjectList <IDeletable>(0);

                Assert.Empty(list);
            }
Example #18
0
            public void IsZeroForEmptyList()
            {
                var list = new DeletableObjectList <TestDeletable>();

                Assert.Equal(0, list.ApproximateCount);
            }
Example #19
0
            public void CreatesEmptyList()
            {
                var list = new DeletableObjectList <IDeletable>();

                Assert.Empty(list);
            }
Example #20
0
 protected override void CallMethod(DeletableObjectList <TestDeletable> list) => list.ForceCompact();
Example #21
0
 protected override void CallMethod(DeletableObjectList <TestDeletable> list) => list.TrimExcess();
Example #22
0
            public void CreatesEmptyListForPositiveValues(int count)
            {
                var list = new DeletableObjectList <IDeletable>(count);

                list.Should().BeEmpty();
            }
Example #23
0
            public void ThrowsForNegativeValues(int count)
            {
                Action createListWithNegativeValue = () => _ = new DeletableObjectList <IDeletable>(-count);

                createListWithNegativeValue.Should().Throw <ArgumentOutOfRangeException>();
            }
Example #24
0
            public void DoesNotThrowForEmptyList()
            {
                var list = new DeletableObjectList <TestDeletable>();

                CallMethod(list);
            }
Example #25
0
            public void DoesNotThrowForEmptyList()
            {
                var list = new DeletableObjectList <TestDeletable>();

                list.Clear();
            }
Example #26
0
            public void CreatesEmptyListForPositiveValues(int count)
            {
                var list = new DeletableObjectList <IDeletable>(count);

                Assert.Empty(list);
            }
Example #27
0
 protected override void CallMethod(DeletableObjectList <TestDeletable> list)
 => list.Add(new TestDeletable());
Example #28
0
 protected override void CallMethod(DeletableObjectList <TestDeletable> list)
 => list.Remove(list.RandomElement(random));
Example #29
0
 protected abstract void CallMethod(DeletableObjectList <TestDeletable> list);
Example #30
0
 protected override void CallMethod(DeletableObjectList <TestDeletable> list)
 => list.Clear();