public void CacheUsesCachedValuesAfterTheyAreComputed() { var computeCounts = new Dictionary <int, int>(); object factory(int value) { if (!computeCounts.ContainsKey(value)) { computeCounts[value] = 0; } ++computeCounts[value]; return(computeCounts[value]); } var projection = Projection.CacheOnFirstUse(3, Projection.CreateUsingFuncAdaptor(factory)); Assert.AreEqual(1, projection[0]); Assert.AreEqual(1, projection[0]); Assert.AreEqual(1, projection[0]); Assert.AreEqual(1, projection[1]); Assert.AreEqual(1, projection[1]); Assert.AreEqual(1, projection[1]); Assert.AreEqual(1, projection[2]); Assert.AreEqual(1, projection[2]); Assert.AreEqual(1, projection[2]); }
public void CacheDoesNotInvokeProjectionOnCreation() { var invoked = false; object factory(int value) { invoked = true; return(value); }; var projection = Projection.CacheOnFirstUse( 3, Projection.CreateUsingFuncAdaptor(factory)); Assert.IsFalse(invoked); }
public void CacheThrowsWithNegativeArgument() { Assert.ThrowsException <ArgumentOutOfRangeException>( () => Projection.CacheOnFirstUse(-1, Projection.Identity <int>())); }
public void CacheThrowsWithNullArgument() { Assert.ThrowsException <ArgumentNullException>( () => Projection.CacheOnFirstUse <object>(1, null)); }