Esempio n. 1
0
        public void GetCommentSegmentWithContext()
        {
            var commentID = 22;

            using (var db = new VoatDataContext())
            {
                var nestedcomment = db.Comment.Where(x => x.SubmissionID == _unitSubmissionID && x.Content.Contains("Path 1:1:1:1:1")).FirstOrDefault();
                if (nestedcomment == null)
                {
                    Assert.Fail("Can not find expected comment in database");
                }
                commentID = nestedcomment.ID;
            }

            var user = TestHelper.SetPrincipal("TestUser01");
            var q    = new QueryCommentContext(_unitSubmissionID, commentID, 0, CommentSortAlgorithm.New);
            var r    = q.Execute();

            Assert.IsNotNull(r, "Query returned null");

            string        expectedPath = "Path 1";
            NestedComment comment      = r.Comments.First();

            for (int i = 0; i < 5; i++)
            {
                Assert.IsNotNull(comment, "looping comment was null");
                Assert.IsTrue(comment.Content.EndsWith(expectedPath), $"Expected path to end with {expectedPath}, but got {comment.Content}");
                comment = comment.Children != null?comment.Children.Comments.FirstOrDefault() : null;

                expectedPath += ":1";
            }
        }
Esempio n. 2
0
        protected void VerifyCommentIsProtected(int submissionID, int commentID, string userName = null)
        {
            IPrincipal user = null;

            if (!String.IsNullOrEmpty(userName))
            {
                user = TestHelper.SetPrincipal(userName);
            }

            //verify comment segment hides user name
            var q = new QueryCommentContext(submissionID, commentID).SetUserContext(user);
            var r = q.Execute();

            Assert.IsNotNull(r, "Query response is null");
            Assert.IsNotNull(r.Comments, "Comment segment is null");

            VerifyCommentSegmentIsAnonProtected(r);
            var comment = r.Comments.FirstOrDefault();

            if (!String.IsNullOrEmpty(userName))
            {
                Assert.IsTrue(comment.IsOwner, $"Expected user {userName} to be submitter on comment {comment.ID}");
            }

            //Ensure direct comment is protected
            var q2 = new QueryComment(commentID, CachePolicy.None);
            var r2 = q2.Execute();

            Assert.IsNotNull(r2, "Query 2 response is null");
            EnsureAnonIsProtected(r2);

            //Ensure stream comment is protected
            var options = new SearchOptions();

            options.StartDate = r2.CreationDate.AddMinutes(-5);
            var q3 = new QueryComments(r2.Subverse, options, CachePolicy.None);
            var r3 = q3.Execute();

            Assert.IsNotNull(r3, "Expecting stream endpoint to return comment");
            Assert.AreNotEqual(0, r3.Count(), "Expected at least 1 comment to be returned");
            foreach (var c in r3)
            {
                EnsureAnonIsProtected(c);
            }
        }
Esempio n. 3
0
        public void CommentContext_Anon()
        {
            int commentID = 0;

            using (var db = new VoatDataContext())
            {
                var nestedcomment = db.Comment.Where(x => x.SubmissionID == _submissionID).OrderByDescending(x => x.ID).FirstOrDefault();
                if (nestedcomment == null)
                {
                    Assert.Fail("Can not find expected comment in database");
                }
                commentID = nestedcomment.ID;
            }

            var user = TestHelper.SetPrincipal("TestUser01");
            var q    = new QueryCommentContext(_submissionID, commentID, 0, CommentSortAlgorithm.New);
            var r    = q.Execute();

            Assert.IsNotNull(r, "Query returned null");

            VerifyCommentSegmentIsAnonProtected(r);
        }