Example #1
0
        public void TestSoftCacheValue()
        {
            bool wasStrong = CacheValue <object> .FutureInstancesWillBeStrong;

            CacheValue <object> .SetStrength(CacheValueStrength.Soft);

            assertFalse("setStrength(SOFT).futureInstancesWillBeStrong()",
                        CacheValue <object> .FutureInstancesWillBeStrong);
            CacheValue <Object> sv = CacheValue <object> .GetInstance(this);

            assertFalse("soft CacheValue not isNull()", sv.IsNull);
            Object v = sv.Get();

            assertTrue("soft CacheValue get()==same or null", v == this || v == null);
            assertTrue("soft CacheValue reset==same", sv.ResetIfCleared(this) == this);
            if (wasStrong)
            {
                CacheValue <object> .SetStrength(CacheValueStrength.Strong);
            }
        }
Example #2
0
        public void TestStrongCacheValue()
        {
            bool wasStrong = CacheValue <object> .FutureInstancesWillBeStrong;

            CacheValue <object> .SetStrength(CacheValueStrength.Strong);

            assertTrue("setStrength(STRONG).futureInstancesWillBeStrong()",
                       CacheValue <object> .FutureInstancesWillBeStrong);
            CacheValue <Object> sv = CacheValue <Object> .GetInstance(this);

            assertFalse("strong CacheValue not isNull()", sv.IsNull);
            assertTrue("strong CacheValue get()==same", sv.Get() == this);
            // A strong CacheValue never changes value.
            // The implementation does not check that the new value is equal to the old one,
            // or even of equal type, so it does not matter which new value we pass in.
            assertTrue("strong CacheValue reset==same", sv.ResetIfCleared("") == this);
            if (!wasStrong)
            {
                CacheValue <object> .SetStrength(CacheValueStrength.Soft);
            }
        }