예제 #1
0
        public CommentDetail Get(CommentCriteria criteria)
        {
            var qUserComment = View <UserComment>().All();

            if (criteria.IDToInt > 0)
            {
                qUserComment = qUserComment.Where(w => w.ID == criteria.IDToInt);
            }

            var comment = qUserComment.SingleOrDefault();

            if (comment == null)
            {
                return(null);
            }

            var detail = new CommentDetail();

            MapProperty(comment, detail);

            return(detail);
        }
        public void VirtualCountEqualsTotalItems()
        {
            var comments = new Comment[12];

            for (int i = 0; i < 12; i++)
            {
                comments[i] = new Comment()
                {
                    Text = "This is comment " + i.ToString("D2"), Author = "Chuck Finley"
                };
            }

            var postId = CreatePost("Comments Test", "Comments Test", DateTime.Now, comments);

            var repo = new CommentRepository(new BlogContext());

            int virtualItemCount;
            int pageSize = 5;

            var criteria = new CommentCriteria()
            {
                PostId = postId
            };
            var order = Order <Comment> .By(c => c.Text);

            var page0 = repo.Retrieve(pageSize, 0, out virtualItemCount, criteria, order).ToList();

            virtualItemCount.Should().Be(12);

            var page1 = repo.Retrieve(pageSize, 1, out virtualItemCount, criteria, order).ToList();

            virtualItemCount.Should().Be(12);

            var page2 = repo.Retrieve(pageSize, 2, out virtualItemCount, criteria, order).ToList();

            virtualItemCount.Should().Be(12);
        }