public void TestExecuteWithObjectAllItemsTaken() { var op = new ObjectPool <PoolItem>( () => new PoolItem(42, "The Hitchhiker's Guide to the Galaxy"), 100, 10); op.AcquireAllObjects(); op.ExecuteWithObject(item => item); }
public void TestNoAvailableItem() { var op = new ObjectPool <PoolItem>( () => new PoolItem(42, "The Hitchhiker's Guide to the Galaxy"), 100, 10); op.AcquireAllObjects(); Assert.AreEqual(0, op.AvailableTokenCount); op.AcquireObject(); }
public void TestAcquireAllAndRelease() { var op = new ObjectPool <PoolItem>( () => new PoolItem(42, "The Hitchhiker's Guide to the Galaxy"), 100, 10); var os = op.AcquireAllObjects().ToList(); Assert.AreEqual(0, op.AvailableTokenCount); Thread.Sleep(new Random().Next(10, 200)); os.ForEach(o => op.ReleaseObject(o)); Assert.AreEqual(100, op.AvailableTokenCount); }
public void TestReleaseObjectWithoutAcquiring() { var op = new ObjectPool <PoolItem>( () => new PoolItem(42, "The Hitchhiker's Guide to the Galaxy"), 100, 10); InvalidOperationException exception = null; try { op.ReleaseObject(new PoolItem(20, "ERROR ITEM")); } catch (InvalidOperationException ex) { exception = ex; } var os = op.AcquireAllObjects().ToList(); Assert.IsNotNull(exception); Assert.AreEqual(100, os.Count); Assert.AreEqual(0, os.Count(i => i.Number == 20 || i.Text == "ERROR ITEM")); }