public void Lazily_creates_generators_as_requested_up_to_pool_size()
        {
            var property = CreateProperty();

            var factoryMock = new Mock <IValueGeneratorFactory>();

            factoryMock.Setup(m => m.Create(property)).Returns(() => new TemporaryValueGenerator());

            var pool = new ValueGeneratorPool(factoryMock.Object, property, poolSize: 3);

            factoryMock.Verify(m => m.Create(It.IsAny <Property>()), Times.Never);

            var generator1 = pool.GetGenerator();

            factoryMock.Verify(m => m.Create(It.IsAny <Property>()), Times.Once);
            factoryMock.Verify(m => m.Create(property), Times.Once);

            var generator2 = pool.GetGenerator();

            factoryMock.Verify(m => m.Create(It.IsAny <Property>()), Times.Exactly(2));
            factoryMock.Verify(m => m.Create(property), Times.Exactly(2));
            Assert.NotSame(generator1, generator2);

            var generator3 = pool.GetGenerator();

            factoryMock.Verify(m => m.Create(It.IsAny <Property>()), Times.Exactly(3));
            factoryMock.Verify(m => m.Create(property), Times.Exactly(3));
            Assert.NotSame(generator2, generator3);

            Assert.Same(generator1, pool.GetGenerator());
            Assert.Same(generator2, pool.GetGenerator());
            Assert.Same(generator3, pool.GetGenerator());
            Assert.Same(generator1, pool.GetGenerator());
            Assert.Same(generator2, pool.GetGenerator());
            Assert.Same(generator3, pool.GetGenerator());

            factoryMock.Verify(m => m.Create(It.IsAny <Property>()), Times.Exactly(3));
            factoryMock.Verify(m => m.Create(property), Times.Exactly(3));
        }
        public void Lazily_creates_generators_as_requested_up_to_pool_size()
        {
            var property = CreateProperty();

            var factoryMock = new Mock<IValueGeneratorFactory>();
            factoryMock.Setup(m => m.Create(property)).Returns(CreateValueGeneratorCallback);

            var pool = new ValueGeneratorPool(factoryMock.Object, property, poolSize: 3);

            factoryMock.Verify(m => m.Create(It.IsAny<Property>()), Times.Never);

            var generator1 = pool.GetGenerator();

            factoryMock.Verify(m => m.Create(It.IsAny<Property>()), Times.Once);
            factoryMock.Verify(m => m.Create(property), Times.Once);

            var generator2 = pool.GetGenerator();

            factoryMock.Verify(m => m.Create(It.IsAny<Property>()), Times.Exactly(2));
            factoryMock.Verify(m => m.Create(property), Times.Exactly(2));
            Assert.NotSame(generator1, generator2);

            var generator3 = pool.GetGenerator();

            factoryMock.Verify(m => m.Create(It.IsAny<Property>()), Times.Exactly(3));
            factoryMock.Verify(m => m.Create(property), Times.Exactly(3));
            Assert.NotSame(generator2, generator3);

            Assert.Same(generator1, pool.GetGenerator());
            Assert.Same(generator2, pool.GetGenerator());
            Assert.Same(generator3, pool.GetGenerator());
            Assert.Same(generator1, pool.GetGenerator());
            Assert.Same(generator2, pool.GetGenerator());
            Assert.Same(generator3, pool.GetGenerator());

            factoryMock.Verify(m => m.Create(It.IsAny<Property>()), Times.Exactly(3));
            factoryMock.Verify(m => m.Create(property), Times.Exactly(3));
        }