예제 #1
0
    public void GetOrCreate_CallsCleanWhenReturningDirtyElement()
    {
        var pool = new ElementPool <Element>();

        pool.ReturnElement(new Element());

        bool isCalled = false;

        pool.GetOrCreateElement(() => new Element(), element => isCalled = true);

        isCalled.Should().BeTrue();
    }
예제 #2
0
    public void GetOrCreate_DoesNotCreateWhenContainingElement()
    {
        var pool = new ElementPool <Element>();

        pool.ReturnElement(new Element());

        bool isCalled = false;

        pool.GetOrCreateElement(() =>
        {
            isCalled = true;
            return(new Element());
        });

        isCalled.Should().BeFalse();
    }
예제 #3
0
    public void StoresMaximumAmountOfPooledElements()
    {
        var pool = new ElementPool <Element>(5);

        for (int i = 0; i < 10; i++)
        {
            pool.ReturnElement(new Element());
        }

        var callCount = 0;

        for (int i = 0; i < 10; i++)
        {
            pool.GetOrCreateElement(() =>
            {
                callCount++;
                return(new Element());
            });
        }

        callCount.Should().Be(5);
    }