public void LeaseSetsReturnAction() { var pool = new DefaultObjectPool <TestPooledObject>(() => new TestPooledObject(), 10, 0); var origLeased = pool.Lease(); origLeased.ReturnAction(origLeased); pool.Dispose(); Assert.AreNotSame(origLeased, pool.Lease()); }
public void DisposeCleansSharedPool() { var pool = new DefaultObjectPool <TestPooledObject>(() => new TestPooledObject(), 10, 0); var origLeased = pool.Lease(); pool.Return(origLeased); pool.Dispose(); Assert.AreNotSame(origLeased, pool.Lease()); }
public async Task PassivateFalseDoesNotPassivate() { var mockFoo = new Mock <IFoo>(); var factory = new Mock <IObjectPoolFactory <IFoo> >(); factory.Setup(x => x.Create()).Returns(mockFoo.Object); var sut = new DefaultObjectPool <IFoo>(factory.Object, objectPassivator: _ => false); var obj = await sut.GetObjectAsync(); obj.Dispose(); sut.Dispose(); mockFoo.Verify(x => x.Dispose(), Times.Never); }
public async Task DisposeThrowsActiveObjects() { var mockFactory = new Mock <IObjectPoolFactory <IFoo> >(); var mockFoo = new Mock <IFoo>(); mockFactory.Setup(x => x.Create()).Returns(mockFoo.Object); var sut = new DefaultObjectPool <IFoo>(mockFactory.Object); await sut.GetObjectAsync(); Action act = () => sut.Dispose(); act.Should().ThrowExactly <InvalidOperationException>().Which.Message.Should() .ContainEquivalentOf("1 active object(s)"); }
public async Task DisposeDisposesObjects() { var mockFactory = new Mock <IObjectPoolFactory <IFoo> >(); var mockFoo = new Mock <IFoo>(); mockFactory.Setup(x => x.Create()).Returns(mockFoo.Object); var sut = new DefaultObjectPool <IFoo>(mockFactory.Object, objectPassivator: _ => true); var proxy = await sut.GetObjectAsync(); proxy.Dispose(); sut.Dispose(); mockFoo.Verify(x => x.Dispose(), Times.AtLeastOnce); }