예제 #1
0
        public void UpdatesTheCommentTree()
        {
            Comment a, b;

            TestingShared.CreateTwoComments(out a, out b);

            Comment c = new Comment {
                Id = 3
            };

            a.Replies.Comments.Add(c);
            Comment e = new Comment {
                Id = 5
            };

            a.Replies.Comments.Add(e);

            Comment d = new Comment {
                Id = 4
            };

            b.Replies.Comments.Add(d);

            _rh.MergeFrom(a, b);

            Assert.AreSame(c, a.Replies.Comments[0], "Should've kept the old comment in the comment tree.");
            Assert.AreSame(e, a.Replies.Comments[2], "Should've kept the old comment in the comment tree.");
            Assert.AreEqual(d, a.Replies.Comments[1], "Should've updated the comment tree with a new comment.");
        }
예제 #2
0
        public void MergesAllFullComments()
        {
            EntryPage target = TestingShared.GenerateEntryPage();
            EntryPage source = TestingShared.GenerateEntryPage(true);

            Comment[] commentsBefore = _rh.EnumerateAll(target.Replies)
                                       .ToArray();

            _rh.MergeFrom(target, source);

            Comment[] commentsAfter = _rh.EnumerateAll(target.Replies)
                                      .ToArray();

            // No objects replaced.
            for (int i = 0; i < commentsBefore.Length; i++)
            {
                Assert.AreSame(commentsBefore[i], commentsAfter[i]);
                Assert.IsTrue(
                    commentsAfter[i]
                    .IsFull
                    );
                Assert.IsTrue(
                    !string.IsNullOrWhiteSpace(
                        commentsAfter[i]
                        .Text
                        )
                    );
            }
        }
        public void TopAuthorCommentIsAdded()
        {
            EntryPage ep = new EntryPage();

            ep.Entry.Poster.Username = "******";

            Comment a = new Comment();

            TestingShared.SetIdAndUrls(a, 1, null);
            a.Poster.Username = "******";
            ep.Replies.Comments.Add(a);

            Comment aB = new Comment();

            TestingShared.SetIdAndUrls(aB, 2, a);
            aB.Poster.Username = "******";
            a.Replies.Comments.Add(aB);

            List <Comment[]> result = _picker.Pick(ep);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(
                1
                , result[0]
                .Length
                );
            Assert.AreSame(a, result[0][0]);
        }
        public void ParsesTestPage()
        {
            string content = TestingShared.GetFileContent("testpage_247911.xml");

            LayerParser p    = new LayerParser();
            EntryPage   page = p.ParseAsAnEntryPage(content);

            Assert.IsNotNull(page);
            Assert.IsNotNull(page.Replies);

            // Has userpic.
            Userpic userpic = page.Entry.PosterUserpic;

            Assert.IsNotNull(userpic);

            // Comment deserialization
            Comment firstComment = page.Replies.Comments[0];

            Assert.AreEqual(91506535, firstComment.Id);
            Assert.IsTrue(firstComment.IsFull, "By default a comment is treated as full.");

            Assert.AreEqual(new DateTime(2015, 6, 25, 15, 16, 50), firstComment.Date.Value);
            Assert.AreEqual("1", firstComment.Text);

            Comment innerComment = firstComment.Replies.Comments[0];

            Assert.AreEqual("http://galkovsky.livejournal.com/247911.html?thread=91589479#t91589479", innerComment.Url);

            // Entry text deserialization
            string entryText = page.Entry.Text;

            Assert.IsTrue(entryText.StartsWith("<p><center><img"));
        }
예제 #5
0
        public void ThrowsIfNewVersionIsOfDifferentId()
        {
            Comment a, b;

            TestingShared.CreateTwoComments(out a, out b);
            b.Id++;

            Assert.That(() => _rh.UpdateDirectDataWith(a, b), Throws.ArgumentException);
        }
        public void LoadHtml()
        {
            string content = TestingShared.GetFileContent("testpage_247911.xml");

            LayerParser.LayerParser p = new LayerParser.LayerParser();
            _html = p.ParseAsAnEntryPage(content)
                    .Entry.Text;
            _ex = new FileUrlExtractor();
        }
        public void EnsuresTargetCommentsPagesDataIsNull(bool startFromEmpty)
        {
            EntryPage target = startFromEmpty ? new EntryPage() : TestingShared.GenerateEntryPage();
            EntryPage source = TestingShared.GenerateEntryPage(true);

            _eph.AddData(target, source);

            Assert.IsTrue(CommentPages.IsEmpty(target.CommentPages));
        }
예제 #8
0
        public void ThrowsIfTargetAndSourceHaveDifferentIds()
        {
            Entry e1 = new Entry();
            Entry e2 = TestingShared.GenerateEntryPage()
                       .Entry;

            e1.Id = 1;
            e2.Id = 2;

            Assert.That(() => _eh.UpdateWith(e1, e2), Throws.ArgumentException);
        }
예제 #9
0
        public void DoesntThrowIfOneOfIdsIsZero()
        {
            Entry e1 = new Entry();
            Entry e2 = TestingShared.GenerateEntryPage()
                       .Entry;

            e1.Id = 0;
            e2.Id = 2;

            _eh.UpdateWith(e1, e2);
        }
        public void StoresUserpic()
        {
            string content = TestingShared.GetFileContent("testpage_247911.xml");

            LayerParser p    = new LayerParser();
            EntryPage   page = p.ParseAsAnEntryPage(content);

            page.Replies.Comments.Clear();

            string serialized = p.Serialize(page);

            Assert.IsTrue(serialized.Contains("<userpic "));
        }
        public void SelectsCommentsAsExpected()
        {
            EntryPage ep = TestingShared.GenerateEntryPage(true);

            List <Comment[]> result = _picker.Pick(ep);

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(
                3
                , result[0]
                .Length
                );
        }
예제 #12
0
        public void EmptyPageGetsAllDataWhenMergedInto()
        {
            Entry     e1 = new Entry();
            EntryPage p2 = TestingShared.GenerateEntryPage();

            e1.Id       = 1;
            p2.Entry.Id = 1;

            _eh.UpdateWith(e1, p2.Entry);

            Assert.That(e1.Text, Is.Not.Null.And.Not.Empty);
            Assert.That(e1.Subject, Is.Not.Null.And.Not.Empty);
            Assert.IsNotNull(e1.Date);
            Assert.AreNotEqual(default(long), e1.Id);
        }
        public void StoresUsername()
        {
            string content = TestingShared.GetFileContent("testpage_247911.xml");

            LayerParser p    = new LayerParser();
            EntryPage   page = p.ParseAsAnEntryPage(content);

            page.Replies.Comments.Clear();

            string serialized = p.Serialize(page);

            page = p.ParseAsAnEntryPage(serialized);

            Assert.That(page.Entry.Poster.Username, Is.Not.Null.And.Not.Empty);
        }
예제 #14
0
        public void InsertCommentsFromMiddlePages()
        {
            // Three original pages.
            EntryPage p1 = TestingShared.GenerateEntryPage(true, 0);
            EntryPage p2 = TestingShared.GenerateEntryPage(true, 50);
            EntryPage p3 = TestingShared.GenerateEntryPage(true, 100);

            _rh.MergeFrom(p1, p3);
            _rh.MergeFrom(p1, p2);

            Comment[] comments = _rh.EnumerateAll(p1.Replies)
                                 .ToArray();
            Assert.AreEqual(12, comments.Length, "Comments should've been added.");
            CollectionAssert.AllItemsAreUnique(comments.Select(z => z.Id));
            CollectionAssert.IsOrdered(comments.Select(z => z.Id));
        }
예제 #15
0
        public void UpdatesWithNewVersion()
        {
            Comment a, b;

            TestingShared.CreateTwoComments(out a, out b);

            object oldCollection = a.Replies.Comments;
            int    oldDepth      = a.Depth;
            string oldParentUrl  = a.ParentUrl;

            _rh.UpdateDirectDataWith(a, b);

            Assert.AreSame(oldCollection, a.Replies.Comments);
            Assert.AreEqual(oldDepth, a.Depth, "Should keep the depth.");
            Assert.AreEqual(b.Text, a.Text);
            Assert.AreEqual(b.Subject, a.Subject);
            Assert.AreEqual(b.PosterUserpic, a.PosterUserpic);
            Assert.AreEqual(oldParentUrl, a.ParentUrl);
            Assert.AreEqual(b.DateValue, a.DateValue);
        }
        public void ThrowsIfNoTargetSpecified()
        {
            EntryPage other = TestingShared.GenerateEntryPage();

            Assert.That(() => _eph.AddData(null, other), Throws.ArgumentNullException);
        }
        public void AddsComplexTreeAsTwoThreads(
            [Values(true, false)] bool firstLeafIsAuthor
            , [Values(true, false)] bool firstReplyIsTheSamePerson
            )
        {
            EntryPage ep = new EntryPage();

            ep.Entry.Poster.Username = "******";

            // Tree. Should become (B A C A), (X A).
            Comment a = new Comment();

            TestingShared.SetIdAndUrls(a, 1, null);
            a.Poster.Username = "******";
            ep.Replies.Comments.Add(a);

            Comment aB = new Comment();

            TestingShared.SetIdAndUrls(aB, 2, a);
            aB.Poster.Username = "******";
            a.Replies.Comments.Add(aB);

            Comment aBC = new Comment();

            TestingShared.SetIdAndUrls(aBC, 3, aB);
            aBC.Poster.Username = firstReplyIsTheSamePerson ? "B" : "C";
            aB.Replies.Comments.Add(aBC);

            Comment aBCD = new Comment();

            TestingShared.SetIdAndUrls(aBCD, 4, aBC);
            aBCD.Poster.Username = firstLeafIsAuthor ? "A" : "R";
            aBC.Replies.Comments.Add(aBCD);

            Comment aBE = new Comment();

            TestingShared.SetIdAndUrls(aBE, 5, aB);
            aBE.Poster.Username = "******";
            aB.Replies.Comments.Add(aBE);

            Comment aBEF = new Comment();

            TestingShared.SetIdAndUrls(aBEF, 6, aBE);
            aBEF.Poster.Username = "******";
            aBE.Replies.Comments.Add(aBEF);

            List <Comment[]> result = _picker.Pick(ep);

            if (firstLeafIsAuthor)
            {
                Assert.AreEqual(2, result.Count);
                CollectionAssert.AreEqual(new[] { a, aB, aBC, aBCD }, result[0]);
                CollectionAssert.AreEqual(new[] { aBE, aBEF }, result[1]);
            }
            else
            {
                if (firstReplyIsTheSamePerson)
                {
                    // We take a_b_c.
                    Assert.AreEqual(2, result.Count);
                    CollectionAssert.AreEqual(new[] { a, aB, aBC }, result[0]);
                    CollectionAssert.AreEqual(new[] { aBE, aBEF }, result[1]);
                }
                else
                {
                    // We don't take it. We don't care what he wrote.
                    Assert.AreEqual(1, result.Count);
                    CollectionAssert.AreEqual(new[] { a, aB, aBE, aBEF }, result[0]);
                }
            }
        }