Exemple #1
0
        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]);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 public void CacheThrowsWithNegativeArgument()
 {
     Assert.ThrowsException <ArgumentOutOfRangeException>(
         () => Projection.CacheOnFirstUse(-1, Projection.Identity <int>()));
 }
Exemple #4
0
 public void CacheThrowsWithNullArgument()
 {
     Assert.ThrowsException <ArgumentNullException>(
         () => Projection.CacheOnFirstUse <object>(1, null));
 }