Esempio n. 1
0
        public async Task TestNonEqualObjectsWithEqualToStringAsync()
        {
            var value = "value";
            var obj1  = new CustomCacheKey(new ObjectEqualToString(1), "test", true);
            var obj2  = new CustomCacheKey(new ObjectEqualToString(2), "test", true);

            var cache = GetDefaultCache();

            await(cache.PutAsync(obj1, value, CancellationToken.None));
            Assert.That(await(cache.GetAsync(obj1, CancellationToken.None)), Is.EqualTo(value), "Unable to retrieved cached object for key obj1");
            Assert.That(await(cache.GetAsync(obj2, CancellationToken.None)), Is.EqualTo(value), "Unable to retrieved cached object for key obj2");
            await(cache.RemoveAsync(obj1, CancellationToken.None));
        }
Esempio n. 2
0
        public async Task TestEqualObjectsWithDifferentHashCodeAsync()
        {
            var value = "value";
            var obj1  = new CustomCacheKey(1, "test", false);
            var obj2  = new CustomCacheKey(1, "test", false);

            var cache = GetDefaultCache();

            await(cache.PutAsync(obj1, value, CancellationToken.None));
            Assert.That(await(cache.GetAsync(obj1, CancellationToken.None)), Is.EqualTo(value), "Unable to retrieved cached object for key obj1");
            Assert.That(await(cache.GetAsync(obj2, CancellationToken.None)), Is.EqualTo(value), "Unable to retrieved cached object for key obj2");
            await(cache.RemoveAsync(obj1, CancellationToken.None));
        }
Esempio n. 3
0
        public void TestEqualObjectsWithDifferentHashCode()
        {
            var value = "value";
            var obj1  = new CustomCacheKey(1, "test", false);
            var obj2  = new CustomCacheKey(1, "test", false);

            var cache = GetDefaultCache();

            cache.Put(obj1, value);
            Assert.That(cache.Get(obj1), Is.EqualTo(value), "Unable to retrieved cached object for key obj1");
            Assert.That(cache.Get(obj2), Is.EqualTo(value), "Unable to retrieved cached object for key obj2");
            cache.Remove(obj1);
        }
Esempio n. 4
0
        public void TestNonEqualObjectsWithEqualToString()
        {
            var value = "value";
            var obj1  = new CustomCacheKey(new ObjectEqualToString(1), "test", true);
            var obj2  = new CustomCacheKey(new ObjectEqualToString(2), "test", true);

            var cache = GetDefaultCache();

            cache.Put(obj1, value);
            Assert.That(cache.Get(obj1), Is.EqualTo(value), "Unable to retrieved cached object for key obj1");
            Assert.That(cache.Get(obj2), Is.EqualTo(value), "Unable to retrieved cached object for key obj2");
            cache.Remove(obj1);
        }
Esempio n. 5
0
        public async Task TestNonEqualObjectsWithEqualToStringUseHashCodeAsync()
        {
            var value = "value";
            var obj1  = new CustomCacheKey(new ObjectEqualToString(1), "test", true);
            var obj2  = new CustomCacheKey(new ObjectEqualToString(2), "test", true);

            var props         = GetDefaultProperties();
            var cacheProvider = ProviderBuilder();

            props[RedisEnvironment.AppendHashcode] = "true";
            cacheProvider.Start(props);
            var cache = cacheProvider.BuildCache(DefaultRegion, props);

            await(cache.PutAsync(obj1, value, CancellationToken.None));
            Assert.That(await(cache.GetAsync(obj1, CancellationToken.None)), Is.EqualTo(value), "Unable to retrieved cached object for key obj1");
            Assert.That(await(cache.GetAsync(obj2, CancellationToken.None)), Is.Null, "Unexpectedly found a cache entry for key obj2 after obj1 put");
            await(cache.RemoveAsync(obj1, CancellationToken.None));
        }
Esempio n. 6
0
        public async Task TestEqualObjectsWithDifferentHashCodeAndUseHashCodeRegionConfigurationAsync()
        {
            var value = "value";
            var obj1  = new CustomCacheKey(1, "test", false);
            var obj2  = new CustomCacheKey(1, "test", false);

            var props         = GetDefaultProperties();
            var cacheProvider = ProviderBuilder();

            cacheProvider.Start(props);
            props["append-hashcode"] = "true";
            var cache = cacheProvider.BuildCache(DefaultRegion, props);

            await(cache.PutAsync(obj1, value, CancellationToken.None));
            Assert.That(await(cache.GetAsync(obj1, CancellationToken.None)), Is.EqualTo(value), "Unable to retrieved cached object for key obj1");
            Assert.That(await(cache.GetAsync(obj2, CancellationToken.None)), Is.Null, "The hash code should be used in the cache key");
            await(cache.RemoveAsync(obj1, CancellationToken.None));
        }
Esempio n. 7
0
        public void TestEqualObjectsWithDifferentHashCodeAndUseHashCodeGlobalConfiguration()
        {
            var value = "value";
            var obj1  = new CustomCacheKey(1, "test", false);
            var obj2  = new CustomCacheKey(1, "test", false);

            var props         = GetDefaultProperties();
            var cacheProvider = ProviderBuilder();

            props[RedisEnvironment.AppendHashcode] = "true";
            cacheProvider.Start(props);
            var cache = cacheProvider.BuildCache(DefaultRegion, props);

            cache.Put(obj1, value);
            Assert.That(cache.Get(obj1), Is.EqualTo(value), "Unable to retrieved cached object for key obj1");
            Assert.That(cache.Get(obj2), Is.Null, "The hash code should be used in the cache key");
            cache.Remove(obj1);
        }