Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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());
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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)");
        }
Ejemplo n.º 5
0
        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);
        }