상속: IPostRepository
예제 #1
0
        public void ShouldHaveTenPosts()
        {
            IPostRepository repo = new PostRepository(new BlogContext());

            var posts = repo.RetrieveAll();

            posts.Count().Should().Be(10);
        }
예제 #2
0
        public void BetweenDates()
        {
            IPostRepository repo = new PostRepository(new BlogContext());

            var criteria = new PostCriteria(new DateTime(2012, 1, 3), new DateTime(2012, 1, 7), String.Empty);

            var posts = repo.Retrieve(criteria, Order<Post>.ByDescending(post => post.PublishDate));

            posts.Count().Should().Be(4);
        }
예제 #3
0
        public void ByTitle()
        {
            IPostRepository repo = new PostRepository(new BlogContext());

            var criteria = new PostCriteria(null, null, "9");

            var posts = repo.Retrieve(criteria, Order<Post>.ByDescending(post => post.PublishDate));

            posts.Count().Should().Be(1);
            posts.First().Title.Should().Be("Post Title 9");
        }
        private int CreatePost(string title, string text, DateTime published)
        {
            IPostRepository repo = new PostRepository(new BlogContext());

            var post = new Post
                           {
                               Title = title,
                               Text = text,
                               PublishDate = published
                           };

            return repo.Save(post);
        }
        public void StoreAndRetrievePost()
        {
            IPostRepository repo = new PostRepository(new BlogContext());

            var r = new Random();
            var title = "Post Title " + r.Next();
            var text = "Text of Post " + r.Next();
            var publishDate = new DateTime(2012, 1, 1).AddDays(r.Next(10));

            var id = CreatePost(title, text, publishDate);

            var post = repo.Retrieve(id);

            post.Title.Should().Be(title);
            post.Text.Should().Be(text);
            post.PublishDate.Should().Be(publishDate);
        }
예제 #6
0
        private int CreatePost(string title, string text, DateTime published, params Comment[] comments)
        {
            IPostRepository repo = new PostRepository(new BlogContext());

            var post = new Post
                           {
                               Title = title,
                               Text = text,
                               PublishDate = published
                           };

            post.Comments = new Collection<Comment>();

            foreach(var comment in comments)
            {
                post.Comments.Add(new Comment() { Text = comment.Text, Author = comment.Author});
            }

            return repo.Save(post);
        }