コード例 #1
0
        public void CustomObjectSaveTest()
        {
            _cache = new FileCache();

            //create custom object
            CustomObjB customBefore = new CustomObjB()
            {
                Num = 5,
                obj = new CustomObjA()
                {
                    Name = "test"
                }
            };

            CacheItem item = new CacheItem("foo")
            {
                Value      = customBefore,
                RegionName = "foobar"
            };

            //set it
            _cache.Set(item, new CacheItemPolicy());

            //now get it back
            CacheItem fromCache = _cache.GetCacheItem("foo", "foobar");

            //pulling twice increases code coverage
            fromCache = _cache.GetCacheItem("foo", "foobar");

            var customAfter = fromCache.Value as CustomObjB;

            customAfter.Should().BeEquivalentTo(customBefore);
        }
コード例 #2
0
ファイル: FileCacheTest.cs プロジェクト: simonthum/FileCache
        public void CustomObjectSaveTest()
        {
            FileCache target = new FileCache();

            //create custom object
            CustomObjB custom = new CustomObjB()
            {
                Num = 5,
                obj = new CustomObjA()
                {
                    Name = "test"
                }
            };

            CacheItem item = new CacheItem("foo")
            {
                Value      = custom,
                RegionName = "foobar"
            };

            //set it
            target.Set(item, new CacheItemPolicy());

            //now get it back
            CacheItem fromCache = target.GetCacheItem("foo", "foobar");

            //pulling twice increases code coverage
            fromCache = target.GetCacheItem("foo", "foobar");
            custom    = null;
            custom    = fromCache.Value as CustomObjB;
            Assert.IsNotNull(custom);
            Assert.IsNotNull(custom.obj);
            Assert.AreEqual(custom.Num, 5);
            Assert.AreEqual(custom.obj.Name, "test");
        }