public void SingletonBorrowAndReturn() { MockEntity obj1 = SingleMockPool.Instance.Borrow(); MockEntity obj2 = SingleMockPool.Instance.Borrow(); MockEntity obj3 = SingleMockPool.Instance.Borrow(); Assert.AreEqual(3, SingleMockPool.Instance.WorkingCount); Assert.AreEqual(0, SingleMockPool.Instance.AvailableCount); SingleMockPool.Instance.Return(obj1); SingleMockPool.Instance.Return(obj2); SingleMockPool.Instance.Return(obj3); Assert.AreEqual(0, SingleMockPool.Instance.WorkingCount); Assert.AreEqual(3, SingleMockPool.Instance.AvailableCount); }
public void BorrowAndReturn() { MockEntityPool pool = new MockEntityPool(); MockEntity obj1 = pool.Borrow(); MockEntity obj2 = pool.Borrow(); MockEntity obj3 = pool.Borrow(); Assert.AreEqual(3, pool.WorkingCount); Assert.AreEqual(0, pool.AvailableCount); pool.Return(obj1); pool.Return(obj2); pool.Return(obj3); Assert.AreEqual(0, pool.WorkingCount); Assert.AreEqual(3, pool.AvailableCount); }
public void BorrowAndReturnOneInvalid() { MockEntityPool pool = new MockEntityPool(); MockEntity obj1 = pool.Borrow(); obj1.Id = 1; MockEntity obj2 = pool.Borrow(); obj2.Id = 2; MockEntity obj3 = pool.Borrow(); obj3.Id = 3; // Mark it as invalid so it will not be reused; obj2.Valid = false; pool.Return(obj2); MockEntity obj4 = pool.Borrow(); Assert.AreEqual(0, obj4.Id, "Id should be 0 because the item should be new, not from the pool."); }
public void BorrowAndReuseOneById() { MockEntityPool pool = new MockEntityPool(); MockEntity obj1 = pool.Borrow(); obj1.Id = 1; MockEntity obj2 = pool.Borrow(); obj2.Id = 2; MockEntity obj3 = pool.Borrow(); obj3.Id = 3; pool.Return(obj2); MockEntity obj4 = pool.Borrow(); Assert.AreEqual(3, pool.WorkingCount); Assert.AreEqual(0, pool.AvailableCount); Assert.AreEqual(2, obj4.Id, "Id should be 2 because the item should be from the pool." + "It should be the one that was returned."); }
public void BorrowAndReturnSameObjectMultipleTime() { MockEntityPool pool = new MockEntityPool(); MockEntity obj1 = pool.Borrow(); pool.Borrow(); pool.Borrow(); Assert.AreEqual(3, pool.WorkingCount); Assert.AreEqual(0, pool.AvailableCount); pool.Return(obj1); Assert.AreEqual(2, pool.WorkingCount); Assert.AreEqual(1, pool.AvailableCount); pool.Return(obj1); Assert.AreEqual(2, pool.WorkingCount); Assert.AreEqual(1, pool.AvailableCount); }