예제 #1
0
        public static MockCacheKey Create(string userId)
        {
            var mockCacheKey = new MockCacheKey();

            mockCacheKey.SetParams("user-id", userId);
            return(mockCacheKey);
        }
예제 #2
0
        public void should_get_key_when_not_set_param()
        {
            var cacheKey = MockCacheKey.Create().Apps;


            Assert.Equal("mock:#apps", cacheKey.ToString());
        }
예제 #3
0
        public void should_get_right_sequencekey_key_when_set_two_params()
        {
            var cacheKey = MockCacheKey.Create("123", "abc").Apps;


            Assert.Equal("mock:&user-id=123&client-id=abc#apps", cacheKey.ToString());
        }
예제 #4
0
        public void should_get_key_include_param_and_name_when_set_param_and_name()
        {
            var mockCacheKey = MockCacheKey.Create("123").Apps;

            var key = mockCacheKey.ToString();

            Assert.Equal("mock:&user-id=123#apps", key);
        }
예제 #5
0
        public void when_key_not_exist_should_return_null()
        {
            var memoryCache = BuildMemoryCache();
            var key         = MockCacheKey.Create("123").Apps;

            var cacheValue = memoryCache.Get(key);

            Assert.Null(cacheValue);
        }
예제 #6
0
        public static MockCacheKey Create(string userId, string clientId)
        {
            var mockCacheKey = new MockCacheKey();

            mockCacheKey.SetParams(new Dictionary <string, string>
            {
                ["user-id"]   = userId,
                ["client-id"] = clientId,
            });
            return(mockCacheKey);
        }
예제 #7
0
        public void when_key_exist_should_retunt_cache()
        {
            var memoryCache = BuildMemoryCache();
            var key         = MockCacheKey.Create("123").Apps;

            memoryCache.Set(key, "abc");

            var cacheValue = memoryCache.Get(key);

            Assert.Equal("abc", cacheValue);
        }
예제 #8
0
        public void when_remove_key_should_retunt_null()
        {
            var memoryCache = BuildMemoryCache();
            var key         = MockCacheKey.Create("123").Apps;

            memoryCache.Set(key, "abc");

            memoryCache.Delete(key);

            var cacheValue = memoryCache.Get(key);

            Assert.Null(cacheValue);
        }
예제 #9
0
        public void when_cache_is_timeout_should_retunt_null()
        {
            _clock.Now = DateTimeOffset.Parse("2017-09-19 17:16:16");

            var memoryCache = BuildMemoryCache();
            var key         = MockCacheKey.Create("123").Apps;

            memoryCache.Set(key, "abc", TimeSpan.FromHours(1));


            _clock.Now = DateTimeOffset.Parse("2017-09-20 17:16:16");
            var cacheValue = memoryCache.Get(key);

            Assert.Null(cacheValue);
        }
예제 #10
0
        public void when_remove_key_by_prefix_should_retunt_null()
        {
            var memoryCache = BuildMemoryCache();
            var key         = MockCacheKey.Create("123");
            var keyPrefix   = key.Prefix;

            memoryCache.Set(key.Apps, "app");
            memoryCache.Set(key.Profile, "profile");

            memoryCache.Delete(keyPrefix, true);

            var cacheValueOfApps    = memoryCache.Get(key.Apps);
            var cacheValueOfProfile = memoryCache.Get(key.Profile);

            Assert.Null(cacheValueOfApps);
            Assert.Null(cacheValueOfProfile);
        }
예제 #11
0
        public void should_throw_ArgumentNullException_when_not_set_name()
        {
            var mockCacheKey = MockCacheKey.Create("123");

            Assert.Throws <ArgumentNullException>(() => mockCacheKey.ToString());
        }