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(); }
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(); }
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); }