Exemplo n.º 1
0
        public void ShouldThrowExceptionWhenCacheLoaderReturnsNull()
        {
            CacheBuilder <string>     ref_cache_builder = new CacheBuilder <string>();
            LoadingCacheMock <string> ref_cache         =
                new LoadingCacheMock <string>(ref_cache_builder);

            CacheBuilder <long>     val_cache_builder = new CacheBuilder <long>();
            LoadingCacheMock <long> val_cache         =
                new LoadingCacheMock <long>(val_cache_builder);

            CacheLoader <string> ref_loader = new StringCacheLoader();

            try {
                ref_cache.Get("missing-ref-key", ref_loader);
            } catch (ExecutionException exception) {
                Assert.IsAssignableFrom <InvalidCacheLoadException>(
                    exception.InnerException);
            }

            CacheLoader <long> val_loader =
                CacheLoader <long> .From(delegate(string key) { return(default(long)); });

            Assert.DoesNotThrow(
                delegate() { val_cache.Get("missing-ref-key", val_loader); });
        }
Exemplo n.º 2
0
        public void ShouldLoadTheValueForMissingKey()
        {
            CacheBuilder <string>     cache_builder = new CacheBuilder <string>();
            LoadingCacheMock <string> cache         =
                new LoadingCacheMock <string>(cache_builder);

            CacheLoader <string> loader = new StringCacheLoader();
            string cached = cache.GetIfPresent("missing-key");

            Assert.IsNull(cached);

            cached = cache.Get("missing-key", loader);
            Assert.IsNotNull(cached);
        }
Exemplo n.º 3
0
        public void ShouldThrowExceptionWhenKeyIsNull()
        {
            CacheBuilder <string>     cache_builder = new CacheBuilder <string>();
            LoadingCacheMock <string> cache         =
                new LoadingCacheMock <string>(cache_builder);

            CacheLoader <string> loader = new StringCacheLoader();

            Assert.Throws <ArgumentNullException>(
                delegate() { cache.Get(null, loader); });

            Assert.Throws <ArgumentNullException>(
                delegate() { cache.GetIfPresent(null); });

            Assert.Throws <ArgumentNullException>(
                delegate() { cache.Put(null, string.Empty); });

            Assert.Throws <ArgumentNullException>(delegate() { cache.Remove(null); });
        }