Example #1
0
        public void DataItemBuiltInDataPooling()
        {
            Guid guid1   = Guid.NewGuid();
            var  value1a = new DataItem <Guid>(guid1);
            var  value1b = new DataItem <Guid>(guid1);

            Assert.AreEqual <DataItem <Guid> >(value1a, value1b);
            Assert.IsFalse(Object.ReferenceEquals(value1a, value1b));
            Assert.IsTrue(Object.ReferenceEquals(value1a.PoolValue, value1b.PoolValue));
            DataItem <Guid> .ClearPool();

            var value1c = new DataItem <Guid>(guid1);
            var value1d = new DataItem <Guid>(guid1);

            // pool cleared - new values c,d are not same pool values as a,b
            Assert.IsTrue(Object.ReferenceEquals(value1a.PoolValue, value1b.PoolValue));
            Assert.IsTrue(Object.ReferenceEquals(value1c.PoolValue, value1d.PoolValue));
            Assert.IsFalse(Object.ReferenceEquals(value1c.PoolValue, value1b.PoolValue));
            // repool the old items - now a,b,c,d should all be same pool value
            value1a.Repool();
            value1b.Repool();
            Assert.IsTrue(Object.ReferenceEquals(value1a.PoolValue, value1b.PoolValue));
            Assert.IsTrue(Object.ReferenceEquals(value1c.PoolValue, value1d.PoolValue));
            Assert.IsTrue(Object.ReferenceEquals(value1c.PoolValue, value1b.PoolValue));
        }