Exemplo n.º 1
0
        public virtual void Take()
        {
            // Arrange
            MockInnerPool.Setup(inner => inner.Take("state")).Returns("data");

            // Act
            var result = DecoratedPool.Take("state");

            // Assert
            Assert.Equal("data", result);
        }
Exemplo n.º 2
0
        public void Take_Inner_Returned_Null()
        {
            // Arrange
            MockInnerPool.Setup(inner => inner.Take(null)).Returns((string)null);

            // Act
            var result = DecoratedPool.Take(null);

            // Assert
            Assert.Null(result);
        }
Exemplo n.º 3
0
        public virtual void Clear()
        {
            // Arrange
            var succeed = RandomHelper.NextBoolean(g_random);

            MockInnerPool.Setup(inner => inner.Clear()).Returns(succeed);

            // Act
            var result = DecoratedPool.Clear();

            // Assert
            Assert.Equal(succeed, result);
        }
Exemplo n.º 4
0
        public void Return_Inner_Return_False()
        {
            // Arrange
            var item = RandomHelper.NextWord(g_random);

            MockInnerPool.Setup(inner => inner.Return(item)).Returns(false);

            // Act
            var result = DecoratedPool.Return(item);

            // Assert
            Assert.False(result);
        }
Exemplo n.º 5
0
        public virtual void Return_Already_Disposed()
        {
            // Arrange
            MockInnerPool.Setup(inner => inner.Dispose());
            MockManagedPool.Setup(managed => managed.Clear()).Returns(true);
            DecoratedPool.Dispose();

            // Act
            var result = DecoratedPool.Return(null);

            // Assert
            Assert.False(result);
        }
Exemplo n.º 6
0
        public void Return_More_Than_Taken()
        {
            // Arrange
            for (int i = 0; i < m_waitPool.Size; i++)
            {
                Return();
            }

            // Act
            var result = DecoratedPool.Return("data");

            // Assert
            Assert.False(result);
        }
Exemplo n.º 7
0
        public override void Return_Already_Disposed()
        {
            // Arrange
            MockInnerPool.Setup(inner => inner.Take(null)).Returns((string)null);
            MockInnerPool.Setup(inner => inner.Count).Returns(0);
            MockInnerPool.Setup(inner => inner.Dispose());
            DecoratedPool.Dispose();

            // Act
            var result = DecoratedPool.Return(null);

            // Assert
            Assert.False(result);
        }
Exemplo n.º 8
0
        public override void Return_Already_Disposed()
        {
            // Arrange
            var items = new Queue <string>(new string[] { "x", "x", null });

            MockInnerPool.Setup(inner => inner.Take(null)).Returns(items.Dequeue);
            MockInnerPool.Setup(inner => inner.Count).Returns(0);
            MockInnerPool.Setup(inner => inner.Dispose());
            DecoratedPool.Dispose();

            // Act
            var result = DecoratedPool.Return(null);

            // Assert
            Assert.False(result);
        }