public void TestReturn() { var recycler = new Recycler <Dummy>(() => new Dummy()); Assert.AreEqual(0, recycler.TotalCount); Assert.AreEqual(0, recycler.UnusedCount); recycler.Precook(2); Assert.AreEqual(2, recycler.TotalCount); Assert.AreEqual(2, recycler.UnusedCount); var dummy = recycler.GetNext(); Assert.AreEqual(2, recycler.TotalCount); Assert.AreEqual(1, recycler.UnusedCount); Assert.IsTrue(dummy.IsAlive); recycler.Return(dummy); Assert.AreEqual(2, recycler.TotalCount); Assert.AreEqual(2, recycler.UnusedCount); Assert.IsFalse(dummy.IsAlive); dummy = recycler.GetNext(); Assert.AreEqual(2, recycler.TotalCount); Assert.AreEqual(1, recycler.UnusedCount); Assert.IsTrue(dummy.IsAlive); dummy.ReturnToRecycler(); Assert.AreEqual(2, recycler.TotalCount); Assert.AreEqual(2, recycler.UnusedCount); Assert.IsFalse(dummy.IsAlive); }
public void TestGetNext() { var recycler = new Recycler <Dummy>(() => new Dummy()); Assert.AreEqual(0, recycler.TotalCount); Assert.AreEqual(0, recycler.UnusedCount); var dummy = recycler.GetNext(); Assert.IsTrue(dummy.IsAlive); Assert.AreSame(recycler, dummy.Recycler); Assert.AreEqual(1, recycler.TotalCount); Assert.AreEqual(0, recycler.UnusedCount); var dummy2 = recycler.GetNext(); Assert.IsTrue(dummy2.IsAlive); Assert.AreSame(recycler, dummy2.Recycler); Assert.AreEqual(2, recycler.TotalCount); Assert.AreEqual(0, recycler.UnusedCount); Assert.AreNotSame(dummy2, dummy); }