public void ShouldCallRemoveItemOnCacheTwice()
        {
            CacheItem item1 = new CacheItem {
                Date = DateTime.Now
            };
            CacheItem item2 = new CacheItem {
                Date = DateTime.Now.AddDays(-1)
            };
            CacheItem item3 = new CacheItem {
                Date = DateTime.Now.AddDays(-3)
            };
            CacheItem item4 = new CacheItem {
                Date = DateTime.Now.AddDays(-2)
            };

            this.cache.CacheItems.Add("1", item1);
            this.cache.CacheItems.Add("2", item2);
            this.cache.CacheItems.Add("3", item3);
            this.cache.CacheItems.Add("4", item4);

            IPurgeStrategy purgeStrategy = new FifoPurgeStrategy();

            purgeStrategy.Purge(this.cache);

            Assert.AreEqual(2, this.cache.RemoveItemCalled.Count);
            Assert.IsTrue(this.cache.RemoveItemCalled["3"]);
            Assert.IsTrue(this.cache.RemoveItemCalled["4"]);
        }
        public void ShouldNotRaiseItemsPurgedEventWhenItemsAreNotPurged()
        {
            bool itemsPurgedRaised = false;

            IPurgeStrategy purgeStrategy = new FifoPurgeStrategy();

            purgeStrategy.ItemsPurged += (s, e) => itemsPurgedRaised = true;

            purgeStrategy.Purge(this.cache);

            Assert.IsFalse(itemsPurgedRaised);
        }
        public void ShouldRaiseItemsPurgedEventWhenItemsArePurged()
        {
            IEnumerable <string> itemsPurged = null;
            bool itemsPurgedRaised           = false;

            CacheItem item1 = new CacheItem {
                Date = DateTime.Now
            };
            CacheItem item2 = new CacheItem {
                Date = DateTime.Now.AddDays(-1)
            };
            CacheItem item3 = new CacheItem {
                Date = DateTime.Now.AddDays(-3)
            };
            CacheItem item4 = new CacheItem {
                Date = DateTime.Now.AddDays(-2)
            };

            this.cache.CacheItems.Add("1", item1);
            this.cache.CacheItems.Add("2", item2);
            this.cache.CacheItems.Add("3", item3);
            this.cache.CacheItems.Add("4", item4);

            IPurgeStrategy purgeStrategy = new FifoPurgeStrategy();

            purgeStrategy.ItemsPurged += (s, e) =>
            {
                itemsPurged       = e.Data;
                itemsPurgedRaised = true;
            };
            purgeStrategy.Purge(this.cache);

            Assert.IsTrue(itemsPurgedRaised);
            Assert.AreEqual(2, itemsPurged.Count());
            Assert.AreEqual("3", itemsPurged.ElementAt(0));
            Assert.AreEqual("4", itemsPurged.ElementAt(1));
        }