コード例 #1
0
        public void CanGetAndReleasePooledList()
        {
            var pooled = Pooling.GetList <int>();

            Assert.That(pooled.List, Is.Not.Null);
            Assert.That(() => pooled.Dispose(), Throws.Nothing);
        }
コード例 #2
0
        public void ReleasingMultipleTimesThrows()
        {
            var pooled = Pooling.GetList <int>();

            Assert.That(() => pooled.Dispose(), Throws.Nothing);
            Assert.That(() => pooled.Dispose(), Throws.InvalidOperationException);
        }
コード例 #3
0
        public void CanGetAndReleaseInDifferentOrder()
        {
            var pooled  = Pooling.GetList <int>();
            var pooled2 = Pooling.GetList <int>();

            Assert.That(() => pooled2.Dispose(), Throws.Nothing);
            Assert.That(() => pooled.Dispose(), Throws.Nothing);
        }
コード例 #4
0
        public void MultipleGetResultsInDifferentPooledLists()
        {
            var pooled  = Pooling.GetList <int>();
            var pooled2 = Pooling.GetList <int>();

            Assert.That(pooled.List, Is.Not.SameAs(pooled2.List));
            Assert.That(() => pooled2.Dispose(), Throws.Nothing);
            Assert.That(() => pooled.Dispose(), Throws.Nothing);
        }
コード例 #5
0
        public void ReleasingAPooledListClearsIt()
        {
            const int count  = 5;
            var       pooled = Pooling.GetList <int>();
            var       list   = pooled.List;

            Assert.That(list.Count, Is.EqualTo(0));
            for (var i = 0; i < count; ++i)
            {
                list.Add(i);
            }

            Assert.That(list.Count, Is.EqualTo(count));
            Assert.That(() => pooled.Dispose(), Throws.Nothing);
            Assert.That(list.Count, Is.EqualTo(0));
        }
コード例 #6
0
        public void PooledListAreIndeedPooled()
        {
            var releasedPools = new HashSet <List <int> >();

            using (var pooled = Pooling.GetList <int>())
                using (var pooled2 = Pooling.GetList <int>())
                    using (var pooled3 = Pooling.GetList <int>())
                    {
                        releasedPools.Add(pooled.List);
                        releasedPools.Add(pooled2.List);
                        releasedPools.Add(pooled3.List);
                    }

            using (var pooled = Pooling.GetList <int>())
                using (var pooled2 = Pooling.GetList <int>())
                    using (var pooled3 = Pooling.GetList <int>())
                    {
                        Assert.That(releasedPools, Contains.Item(pooled.List));
                        Assert.That(releasedPools, Contains.Item(pooled2.List));
                        Assert.That(releasedPools, Contains.Item(pooled3.List));
                    }
        }
コード例 #7
0
        public void GetAndReleaseClearList()
        {
            var list = new List <int> {
                0, 1, 2, 3, 4, 5
            };
            List <int> hackerList;

            using (var pooled = list.ToPooledList())
            {
                hackerList = pooled.List;
                Assert.That(list, Is.EqualTo(pooled.List));
                Assert.That(list, Is.Not.SameAs(pooled.List));
            }
            Assert.That(hackerList.Count, Is.EqualTo(0));
            hackerList.AddRange(list);
            Assert.That(hackerList.Count, Is.EqualTo(list.Count));

            using (var pooled = Pooling.GetList <int>())
            {
                // This relies on the fact that we internally uses a stack, so getting a new one will re-use the last returned one.
                Assert.That(pooled.List, Is.SameAs(hackerList));
                Assert.That(hackerList.Count, Is.EqualTo(0));
            }
        }