Ejemplo n.º 1
0
        public void TestMultiCacheWith3ItemsThen5()
        {
            Assert.AreEqual(0, cache1.Hits);
            Assert.AreEqual(0, cache1.Misses);

            var service  = new MultiService();
            var results1 = service.GetItems(new[] { "k1", "k2", "k3" });

            Assert.AreEqual(0, cache1.Hits);
            Assert.AreEqual(3, cache1.Misses);
            LinqAssert.Count(results1, 3);
            LinqAssert.Any(results1, r => r.Id == "k1");
            LinqAssert.Any(results1, r => r.Id == "k2");
            LinqAssert.Any(results1, r => r.Id == "k3");

            var results2 = service.GetItems(new[] { "k5", "k2", "k1", "k4", "k3" });

            Assert.AreEqual(3, cache1.Hits);
            Assert.AreEqual(5, cache1.Misses);
            LinqAssert.Count(results2, 5);
            LinqAssert.Any(results2, r => r.Id == "k1");
            LinqAssert.Any(results2, r => r.Id == "k2");
            LinqAssert.Any(results2, r => r.Id == "k3");
            LinqAssert.Any(results2, r => r.Id == "k4");
            LinqAssert.Any(results2, r => r.Id == "k5");
        }
Ejemplo n.º 2
0
        public void TestMultiCacheWith3ItemsGuidKey()
        {
            Assert.AreEqual(0, cache1.Hits);
            Assert.AreEqual(0, cache1.Misses);

            var id1 = Guid.NewGuid();
            var id2 = Guid.NewGuid();
            var id3 = Guid.NewGuid();

            var service = new MultiService2();
            var results = service.GetItems(new[] { id1, id2, id3 });

            Assert.AreEqual(0, cache1.Hits);
            Assert.AreEqual(3, cache1.Misses);
            LinqAssert.Count(results, 3);
            LinqAssert.Any(results, r => r.Id == id1);
            LinqAssert.Any(results, r => r.Id == id2);
            LinqAssert.Any(results, r => r.Id == id3);

            results = service.GetItems(new[] { id1, id2, id3 });

            Assert.AreEqual(3, cache1.Hits);
            Assert.AreEqual(3, cache1.Misses);
            LinqAssert.Count(results, 3);
            LinqAssert.Any(results, r => r.Id == id1);
            LinqAssert.Any(results, r => r.Id == id2);
            LinqAssert.Any(results, r => r.Id == id3);
        }
Ejemplo n.º 3
0
        public void TestReadAppConfig()
        {
            var config = ConfigurationManager.GetSection("PubComp/CacheConfig") as IList <ConfigNode>;

            Assert.IsNotNull(config);

            Assert.AreEqual(15, config.Count);
            LinqAssert.Count(config.OfType <CacheConfig>(), 4);
            LinqAssert.Count(config.OfType <RemoveConfig>(), 5);
            LinqAssert.Count(config.OfType <ConnectionStringConfig>(), 4);
            LinqAssert.Count(config.OfType <NotifierConfig>(), 2);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Add &&
                           c.Name == "cacheFromConfig1" &&
                           c is CacheConfig);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Add &&
                           c.Name == "cacheFromConfig2" &&
                           c is NoCacheConfig);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Add &&
                           c.Name == "cacheFromConfig2" &&
                           c is MockNoCacheConfig &&
                           ((MockNoCacheConfig)c).Policy != null &&
                           ((MockNoCacheConfig)c).Policy.SlidingExpiration.HasValue &&
                           ((MockNoCacheConfig)c).Policy.SlidingExpiration?.Minutes == 15 &&
                           ((MockNoCacheConfig)c).Policy.AbsoluteExpiration.HasValue == false &&
                           ((MockNoCacheConfig)c).Policy.ExpirationFromAdd.HasValue == false);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Remove &&
                           c.Name == "cacheFromConfig2" &&
                           c is RemoveConfig);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Add &&
                           c.Name == "cacheFromConfig3" &&
                           c is CacheConfig &&
                           ((CacheConfig)c).CreateCache() is NoCache);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Remove &&
                           c.Name == "cacheFromConfig3" &&
                           c is RemoveConfig);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Remove &&
                           c.Name == "cacheFromConfig4" &&
                           c is RemoveConfig);
        }
Ejemplo n.º 4
0
        public void TestKeyGeneration_CacheList()
        {
            Assert.AreEqual(0, cache1.Hits);
            Assert.AreEqual(0, cache1.Misses);

            var service = new MultiService();
            var results = service.GetItems(new[] { "k1", "k2", "k3" });

            Assert.AreEqual(0, cache1.Hits);
            Assert.AreEqual(3, cache1.Misses);
            LinqAssert.Count(results, 3);
            LinqAssert.Any(results, r => r.Id == "k1");
            LinqAssert.Any(results, r => r.Id == "k2");
            LinqAssert.Any(results, r => r.Id == "k3");

            results = service.GetItems(new[] { "k1", "k2", "k3" });

            Assert.AreEqual(3, cache1.Hits);
            Assert.AreEqual(3, cache1.Misses);
            LinqAssert.Count(results, 3);
            LinqAssert.Any(results, r => r.Id == "k1");
            LinqAssert.Any(results, r => r.Id == "k2");
            LinqAssert.Any(results, r => r.Id == "k3");

            // Note: must use List<string>, not string[] here in order to get correct key
            var key = CacheKey.GetKey(() => service.GetItems(new List <string> {
                "k2"
            }));

            cache1.Clear(key);

            results = service.GetItems(new[] { "k1" });
            Assert.AreEqual(4, cache1.Hits);
            Assert.AreEqual(3, cache1.Misses);
            LinqAssert.Count(results, 1);
            LinqAssert.Any(results, r => r.Id == "k1");

            results = service.GetItems(new[] { "k2" });
            Assert.AreEqual(4, cache1.Hits);
            Assert.AreEqual(4, cache1.Misses);
            LinqAssert.Count(results, 1);
            LinqAssert.Any(results, r => r.Id == "k2");

            results = service.GetItems(new[] { "k1", "k2", "k3" });

            Assert.AreEqual(7, cache1.Hits);
            Assert.AreEqual(4, cache1.Misses);
            LinqAssert.Count(results, 3);
            LinqAssert.Any(results, r => r.Id == "k1");
            LinqAssert.Any(results, r => r.Id == "k2");
            LinqAssert.Any(results, r => r.Id == "k3");
        }
Ejemplo n.º 5
0
        public void TestReadAppConfig()
        {
            var config = ConfigurationManager.GetSection("PubComp/CacheConfig") as IList <CacheConfig>;

            Assert.IsNotNull(config);
            Assert.AreEqual(7, config.Count);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Add &&
                           c.Name == "cacheFromConfig1" &&
                           c is NoCacheConfig);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Add &&
                           c.Name == "cacheFromConfig2" &&
                           c is NoCacheConfig);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Remove &&
                           c.Name == "cacheFromConfig2" &&
                           c is NoCacheConfig);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Add &&
                           c.Name == "cacheFromConfig2" &&
                           c is MockNoCacheConfig &&
                           ((MockNoCacheConfig)c).Policy != null &&
                           ((MockNoCacheConfig)c).Policy.SlidingExpiration.HasValue &&
                           ((MockNoCacheConfig)c).Policy.SlidingExpiration.Value.Minutes == 15 &&
                           ((MockNoCacheConfig)c).Policy.AbsoluteExpiration.HasValue == false &&
                           ((MockNoCacheConfig)c).Policy.ExpirationFromAdd.HasValue == false);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Add &&
                           c.Name == "cacheFromConfig3" &&
                           c is NoCacheConfig);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Remove &&
                           c.Name == "cacheFromConfig3" &&
                           c is NoCacheConfig);

            LinqAssert.Any(config, c =>
                           c.Action == ConfigAction.Remove &&
                           c.Name == "cacheFromConfig4" &&
                           c is NoCacheConfig);
        }