public void ObjectPool_AcquireReleaseObject_CheckWithParallelObjectCreation_ShouldReturnObject() { //--------------Arrange------------------------------ TestClass expectedResult = new TestClass(); var objectPool = new ObjectPoolFactory <TestClass>().New(() => expectedResult, (instance) => false); Parallel.For(0, 1000, (i, loopState) => { //--------------Act---------------------------------- TestClass actualResult = objectPool.AcquireObject(); //--------------Assert------------------------------- Assert.AreEqual(expectedResult, actualResult); Assert.AreEqual(expectedResult.GetValue(i), actualResult.GetValue(i)); objectPool.ReleaseObject(actualResult); }); }
public void ObjectPool_Dispose_ShouldClearObjectList() { //--------------Arrange------------------------------ TestClass expectedResult = new TestClass(); var objectPool = new ObjectPoolFactory <TestClass>().New(() => expectedResult, (instance) => false); Parallel.For(0, 1000, (i, loopState) => { TestClass actualResult = objectPool.AcquireObject(); Assert.AreEqual(expectedResult, actualResult); Assert.AreEqual(expectedResult.GetValue(i), actualResult.GetValue(i)); objectPool.ReleaseObject(actualResult); }); //--------------Act---------------------------------- objectPool.Dispose(); //--------------Assert------------------------------- }