Пример #1
0
        public void GetPostByIDCachesForOneMinute()
        {
            FakeCache          cache = new FakeCache();
            FakePostRepository inner = new FakePostRepository();

            CachingPostRepository repository = new CachingPostRepository(inner, cache);

            repository.GetPost(Guid.NewGuid());

            Assert.Equal(TimeSpan.FromMinutes(1), cache.Cache.Single().Duration);
        }
Пример #2
0
        public void GetPostByNameReturnsInnerPost()
        {
            FakeCache          cache = new FakeCache();
            FakePostRepository inner = new FakePostRepository();

            CachingPostRepository repository = new CachingPostRepository(inner, cache);

            Post post = repository.GetPost("area", "slug");

            Assert.Equal("area", post.Area.Name);
            Assert.Equal("slug", post.Slug);
        }
Пример #3
0
        public void GetPostByIDSetsPostInCache()
        {
            FakeCache          cache = new FakeCache();
            FakePostRepository inner = new FakePostRepository();

            CachingPostRepository repository = new CachingPostRepository(inner, cache);

            Guid postID = Guid.NewGuid();

            Post actual = repository.GetPost(postID);

            Assert.Equal(postID, ((Post)cache.Cache.Single().Item).ID);
        }
Пример #4
0
        public void GetPostByIDReturnsPostFromInner()
        {
            FakeCache          cache = new FakeCache();
            FakePostRepository inner = new FakePostRepository();

            CachingPostRepository repository = new CachingPostRepository(inner, cache);

            Guid postID = Guid.NewGuid();

            Post actual = repository.GetPost(postID);

            Assert.Equal(postID, actual.ID);
        }
Пример #5
0
        public void GetPostByNameCachesInnerPost()
        {
            FakeCache          cache = new FakeCache();
            FakePostRepository inner = new FakePostRepository();

            CachingPostRepository repository = new CachingPostRepository(inner, cache);

            repository.GetPost("area", "slug");

            Assert.Equal("area", ((Post)cache.Cache.Single().Item).Area.Name);
            Assert.Equal("slug", ((Post)cache.Cache.Single().Item).Slug);
            Assert.Equal("Post:Area:area:Slug:slug", cache.Cache.Single().Key);
            Assert.Equal(TimeSpan.FromMinutes(1), cache.Cache.Single().Duration);
        }
Пример #6
0
        public void GetPostByIDSetsCacheKey()
        {
            FakeCache          cache = new FakeCache();
            FakePostRepository inner = new FakePostRepository();

            CachingPostRepository repository = new CachingPostRepository(inner, cache);

            Guid postID = Guid.NewGuid();

            Post actual = repository.GetPost(postID);

            string expectedKey = string.Format("Post:ID:{0}", postID.ToString());

            Assert.Equal(expectedKey, cache.Cache.Single().Key);
        }
Пример #7
0
        public void GetPostReturnsItemFromCache()
        {
            FakeCache          cache = new FakeCache();
            FakePostRepository inner = new FakePostRepository();

            CachingPostRepository repository = new CachingPostRepository(inner, cache);

            Post cachedPost = new Post();

            cache.Add("Post:Area:area:Slug:slug", cachedPost, TimeSpan.FromMinutes(1));

            Post actualPost = repository.GetPost("area", "slug");

            Assert.Same(cachedPost, actualPost);
        }
Пример #8
0
        public void GetPostByIDReturnsItemFromCache()
        {
            FakeCache          cache = new FakeCache();
            FakePostRepository inner = new FakePostRepository();

            CachingPostRepository repository = new CachingPostRepository(inner, cache);

            Guid   postID      = Guid.NewGuid();
            string expectedKey = string.Format("Post:ID:{0}", postID.ToString());

            cache.Cache.Add(new FakeCache.FakeCacheEntry()
            {
                Item = new Post()
                {
                    ID = postID
                }, Key = expectedKey
            });

            Post actual = repository.GetPost(postID);

            Assert.Same(cache.Cache.Single().Item, actual);
        }