コード例 #1
0
 public void BorrowTwiceReturnsDifferent()
 {
     using (var disposer1 = ReferenceSetPool <object> .Borrow())
     {
         using (var disposer2 = ReferenceSetPool <object> .Borrow())
         {
             Assert.AreNotSame(disposer1.Value, disposer2.Value);
         }
     }
 }
コード例 #2
0
        public void BorrowTwiceReturnsSame()
        {
            var value = (ConcurrentQueue <HashSet <object> >) typeof(ReferenceSetPool <object>).GetField("Pool", BindingFlags.Static | BindingFlags.NonPublic)
                        .GetValue(null);
            HashSet <object> temp;

            while (value.TryDequeue(out temp))
            {
            }
            HashSet <object> set;

            using (var disposer = ReferenceSetPool <object> .Borrow())
            {
                disposer.Value.Add(new object());
                set = disposer.Value;
            }

            using (var disposer = ReferenceSetPool <object> .Borrow())
            {
                CollectionAssert.IsEmpty(disposer.Value);
                Assert.AreSame(set, disposer.Value);
            }
        }