public void ShouldCreateRegionIfNotAlreadyThere()
        {
            var sut = new RegionedAppFabricSearchCache(cache, new AbsoluteCacheItemPolicyFactory(10), RegionName);

            var created = cache.CreateRegion(RegionName);

            Assert.IsFalse(created); // because the constructor should have already created the region
        }
        public void ShouldExpireAsPerPolicy()
        {
            var sut = new RegionedAppFabricSearchCache(cache, new AbsoluteCacheItemPolicyFactory(5), RegionName);

            var result = new SearchResult(new List<int> { 1, 2, 3 }, DateTime.Now, false, 0);

            sut.Add("bob", result);

            Thread.Sleep(TimeSpan.FromSeconds(8));

            var cached = sut.Get("bob", 1);

            Assert.IsNull(cached);
        }
        public void ShouldClearRegionOnCallingClear()
        {
            var sut = new RegionedAppFabricSearchCache(cache, new AbsoluteCacheItemPolicyFactory(150), RegionName);

            var result = new SearchResult(new List<int> { 1, 2, 3 }, DateTime.Now, false, 0);

            sut.Add("bob", result);

            sut.Clear();

            var cached = sut.Get("bob", 1);

            Assert.IsNull(cached);
        }
        public void ShouldNotExpireIfPolicySaysInfinite()
        {
            var sut = new RegionedAppFabricSearchCache(cache, new AbsoluteCacheItemPolicyFactory(ObjectCache.InfiniteAbsoluteExpiration.Second), RegionName);

            var result = new SearchResult(new List<int> { 1, 2, 3 }, DateTime.Now, false, 0);

            sut.Add("bob", result);

            Thread.Sleep(TimeSpan.FromSeconds(10));

            var cached = sut.Get("bob", 1);

            Assert.IsNotNull(cached);
        }
        public void ShouldSwallowKeyAlreadyExists()
        {
            var sut = new RegionedAppFabricSearchCache(cache, new AbsoluteCacheItemPolicyFactory(15), RegionName);

            var result = new SearchResult(new List<int> { 1, 2, 3 }, DateTime.Now, false, 0);

            sut.Add("bob", result);

            sut.Add("bob", result); // would throw DataCacheException(KeyAlreadyExists) usually

            Assert.IsTrue(true);
        }