示例#1
0
        public void TryGetFoundResultTest()
        {
            const string prefix = "123123aawdawdsegsegsegawdf";
            const string key = "321awdawawdasefgsfgsegsegwd";

            var mCache = MemoryCache.Default;
            _objectCacheFactory.Setup(x => x.Create()).Returns(mCache).Verifiable();
            var fullKey = FullKey(prefix, key);
            var exp = new One();
            mCache.Add(fullKey, exp, DateTimeOffset.MaxValue);
            var cacher = new MemoryCacher<One>(_itemPolicyMock.Object, _objectCacheFactory.Object, prefix);
            One actual;
            var tryGetResult = cacher.TryGet(key, out actual);
            Assert.AreEqual(CacheTryGetResult.Found, tryGetResult);
            Assert.AreEqual(exp, actual);
        }
示例#2
0
        public void TryGetNullResultTest()
        {
            const string prefix = "123123aawdawdawdf";
            const string key = "321awdawawdawd";

            var mCache = MemoryCache.Default;
            _objectCacheFactory.Setup(x => x.Create()).Returns(mCache).Verifiable();

            var cacher = new MemoryCacher<One>(_itemPolicyMock.Object, _objectCacheFactory.Object, prefix);
            One actual;
            var tryGetResult = cacher.TryGet(key, out actual);
            Assert.AreEqual(CacheTryGetResult.NotFound, tryGetResult);
            Assert.IsNull(actual);
        }