Example #1
0
    public void DisposableObjectPool_DisposeAndReturn_DisposesObject()
    {
        // Arrange
        var pool = new DisposableObjectPool <DisposableObject>(new DefaultPooledObjectPolicy <DisposableObject>());
        var obj  = pool.Get();

        // Act
        pool.Dispose();
        pool.Return(obj);

        // Assert
        Assert.True(obj.IsDisposed);
    }
Example #2
0
    public void DisposableObjectPoolWithOneElement_Dispose_ObjectDisposed()
    {
        // Arrange
        var pool = new DisposableObjectPool <DisposableObject>(new DefaultPooledObjectPolicy <DisposableObject>());
        var obj  = pool.Get();

        pool.Return(obj);

        // Act
        pool.Dispose();

        // Assert
        Assert.True(obj.IsDisposed);
    }
Example #3
0
    public void DisposableObjectPool_DisposeAndGet_ThrowsObjectDisposed()
    {
        // Arrange
        var pool = new DisposableObjectPool <DisposableObject>(new DefaultPooledObjectPolicy <DisposableObject>());
        var obj1 = pool.Get();
        var obj2 = pool.Get();

        pool.Return(obj1);
        pool.Return(obj2);

        // Act
        pool.Dispose();

        // Assert
        Assert.Throws <ObjectDisposedException>(() => pool.Get());
    }
Example #4
0
    public void DisposableObjectPoolWithTwoElements_Dispose_ObjectsDisposed()
    {
        // Arrange
        var pool = new DisposableObjectPool <DisposableObject>(new DefaultPooledObjectPolicy <DisposableObject>());
        var obj1 = pool.Get();
        var obj2 = pool.Get();

        pool.Return(obj1);
        pool.Return(obj2);

        // Act
        pool.Dispose();

        // Assert
        Assert.True(obj1.IsDisposed);
        Assert.True(obj2.IsDisposed);
    }