public void TryGetValue_WithValueNotInCache_ReturnsFalse()
        {
            var cache     = new Cache <object, string>();
            var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create());
            var key       = new object();

            string value;
            var    result = decorator.TryGetValue(key, out value);

            Assert.That(result, Is.False);
            Assert.That(value, Is.Null);
        }
        public void TryGetValue_AfterTokenWasInvalidated_RefreshesRevision_ReturnsFalse()
        {
            var cache     = new Cache <object, string>();
            var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create());
            var key       = new object();

            decorator.InvalidationToken.Invalidate();

            cache.Add(key, "Value");
            string valueOnFirstCall;
            var    resultOnFirstCall = decorator.TryGetValue(key, out valueOnFirstCall);

            Assert.That(resultOnFirstCall, Is.False);
            Assert.That(valueOnFirstCall, Is.Null);

            cache.Add(key, "Value2");
            string valueOnSecondCall;
            var    resultOnSecondCall = decorator.TryGetValue(key, out valueOnSecondCall);

            Assert.That(resultOnSecondCall, Is.True);
            Assert.That(valueOnSecondCall, Is.EqualTo("Value2"));
        }
        public void TryGetValue_WithValueInCache_ReturnsTrueAndSetsOutValue()
        {
            var cache     = new Cache <object, string>();
            var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create());
            var key       = new object();

            cache.Add(key, "Value");

            string value;
            var    result = decorator.TryGetValue(key, out value);

            Assert.That(result, Is.True);
            Assert.That(value, Is.EqualTo("Value"));
        }
        public void Clear_RefreshesRevision()
        {
            var cache     = new Cache <object, string>();
            var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create());

            decorator.InvalidationToken.Invalidate();
            ((ICache <object, string>)decorator).Clear();
            var key = new object();

            cache.Add(key, "Value");

            string value;
            var    result = decorator.TryGetValue(key, out value);

            Assert.That(result, Is.True);
            Assert.That(value, Is.EqualTo("Value"));
        }
        public void TryGetValue_AfterTokenWasInvalidated_ReturnsFalse()
        {
            var cache     = new Cache <object, string>();
            var decorator = new InvalidationTokenBasedCacheDecorator <object, string> (cache, InvalidationToken.Create());
            var key       = new object();

            cache.Add(key, "Value");

            decorator.InvalidationToken.Invalidate();

            string value;
            var    result = decorator.TryGetValue(key, out value);

            Assert.That(result, Is.False);
            Assert.That(value, Is.Null);

            string cachedValue;
            bool   cachedResult = cache.TryGetValue(key, out cachedValue);

            Assert.That(cachedResult, Is.False);
        }