Exemplo n.º 1
0
        public void TryAdd()
        {
            const string value = "value";

            var sharedList = new SharedList <string>(LockingStrategy);

            bool doInsert = false;

            using (ISharedCollectionLock l = sharedList.GetReadLock())
            {
                if (!sharedList.Contains(value))
                {
                    doInsert = true;
                }
            }

            if (doInsert)
            {
                using (ISharedCollectionLock l = sharedList.GetWriteLock())
                {
                    if (!sharedList.Contains(value))
                    {
                        sharedList.Add(value);
                    }
                }
            }

            CollectionAssert.AreEqual(new List <string> {
                value
            }, sharedList.BackingList);
        }
Exemplo n.º 2
0
        public void DisposedWriteLockDeniesRead()
        {
            var d = new SharedList <string>(LockingStrategy);

            ISharedCollectionLock l = d.GetWriteLock();

            l.Dispose();

            d.Contains("foo");
        }
Exemplo n.º 3
0
        public void DisposedWriteLockDeniesRead()
        {
            var d = new SharedList <string>(this.LockingStrategy);

            ISharedCollectionLock l = d.GetWriteLock();

            l.Dispose();

            Assert.Throws <ReadLockRequiredException>(() => d.Contains("foo"));
        }