示例#1
0
        public void Test_Dispose_4()
        {
            Disposable disposable;
            PoolResourceHolder<Disposable> poolResourceHolder;
            var pool = new Pool<Disposable>(() => new Disposable(), AccessStrategy.LIFO, LoadingStrategy.Eager, 1);
            pool.Dispose();

            Assert.Throws<ObjectDisposedException>(() => pool.Acquire());
            Assert.Throws<ObjectDisposedException>(() => pool.AcquireHolder());
            Assert.Throws<ObjectDisposedException>(() => pool.TryAcquire(TimeSpan.FromDays(1), out disposable));
            Assert.Throws<ObjectDisposedException>(() => pool.TryAcquireHolder(TimeSpan.FromDays(1), out poolResourceHolder));
            Assert.Throws<ObjectDisposedException>(() => pool.TryAcquireImmediately(out disposable));
            Assert.Throws<ObjectDisposedException>(() => pool.TryAcquireHolderImmediately(out poolResourceHolder));

            // Асинхронные методы.
            try
            {
                pool.AcquireAsync().Wait();
                Assert.Fail("Must throw exception.");
            }
            catch (AggregateException error)
            {
                Assert.True(error.InnerExceptions.Single() is ObjectDisposedException);
            }
            try
            {
                pool.AcquireHolderAsync().Wait();
                Assert.Fail("Must throw exception.");
            }
            catch (AggregateException error)
            {
                Assert.True(error.InnerExceptions.Single() is ObjectDisposedException);
            }
        }