Ejemplo n.º 1
0
        public void TestDurableCacheWithComplicatedParameter()
        {
            var complexObject = new ComplexObject { Ints = { 5, 5, 5 } };

            var now = _cached.GetComplexObjectWithComplexParameterFifeenSecondCacheAbsoluteNinetySeconds(complexObject);
            Assert.Equal(complexObject.Ints, now.Ints);

            Thread.Sleep(new TimeSpan(0, 0, 0, 10, 500));

            var cached = _cached.GetComplexObjectWithComplexParameterFifeenSecondCacheAbsoluteNinetySeconds(complexObject);

            //Cache has been refreshed
            Assert.NotEqual(now.FourthDimension.Keys.First(), cached.FourthDimension.Keys.First());
            Assert.Equal(complexObject.Ints, cached.Ints);

            Thread.Sleep(new TimeSpan(0, 0, 5));

            var cached2 = _cached.GetComplexObjectWithComplexParameterFifeenSecondCacheAbsoluteNinetySeconds(complexObject);

            //Cache has not yet been refreshed
            Assert.Equal(cached.FourthDimension.Keys.First(), cached2.FourthDimension.Keys.First());
            Assert.Equal(complexObject.Ints, cached2.Ints);

            Thread.Sleep(new TimeSpan(0, 0, 0, 5, 500));

            var cached3 = _cached.GetComplexObjectWithComplexParameterFifeenSecondCacheAbsoluteNinetySeconds(complexObject);

            //Cache was resceduled
            Assert.NotEqual(cached2.FourthDimension.Keys.First(), cached3.FourthDimension.Keys.First());
            Assert.Equal(complexObject.Ints, cached3.Ints);

            //Check Trace to make sure cache stops refreshing
            Thread.Sleep(new TimeSpan(0, 0, 40));
        }
Ejemplo n.º 2
0
        public ComplexObject GetComplexObjectWithComplexParameterFifeenSecondCacheAbsoluteNinetySeconds(ComplexObject obj)
        {
            NumberOfCalls++;
            var newObject = new ComplexObject();

            newObject.Ints = obj.Ints;

            return newObject;
        }