예제 #1
0
        public void GoodLink_FindLink(string linkText)
        {
            var linkDetector = new LinkDetectorService();
            var links        = linkDetector.DetectLinks(linkText);

            Assert.AreEqual(1, links.Count, "We should have found the link.");
        }
예제 #2
0
        public void BadLink_DontFindAnything(string linkText)
        {
            var linkDetector = new LinkDetectorService();
            var links        = linkDetector.DetectLinks(linkText);

            Assert.AreEqual(0, links.Count, "We shouldn't have found anything; Link found: " + (links.Count > 0 ? links.First().ToString() : ""));
        }
예제 #3
0
        public void FindRightLineNumber(int lineNumber)
        {
            string link         = "[Text](Link)";
            var    linkDetector = new LinkDetectorService();
            var    links        = linkDetector.DetectLinks(AddLinkAtLine(lineNumber, link));

            Assert.AreEqual(lineNumber, links.First().Lines.First(), "Got wrong line number");
        }
예제 #4
0
        public void LinkWithParentheses_FindLink(string link, string textAfterLink)
        {
            var fullText     = $"SomeTextBefore[Hi]({link}){textAfterLink}";
            var linkDetector = new LinkDetectorService();
            var links        = linkDetector.DetectLinks(fullText);

            Assert.AreEqual(link, links.First().Link, "Got wrong link");
        }
예제 #5
0
        public void OneLink_FindLink(string linkText, string link)
        {
            var fullText     = $"SomeTextBefore[{linkText}]({link})SomeTextAfter";
            var linkDetector = new LinkDetectorService();
            var links        = linkDetector.DetectLinks(fullText);

            Assert.AreEqual(1, links.Count, "We should have found a single link. Found " + links.Count);
            Assert.AreEqual(linkText, links.First().Text, "Got wrong link text");
            Assert.AreEqual(link.Trim(), links.First().Link, "Got wrong link");
        }
예제 #6
0
        public void TwoLinksOnSameLine_FindBoth()
        {
            string link1Text = "link1", link2Text = "link2";
            string link1 = "/link1", link2 = "#link2";
            var    fullText     = $"SomeTextBefore[{link1Text}]({link1})SomeTextAfter[{link2Text}]({link2})";
            var    linkDetector = new LinkDetectorService();
            var    links        = linkDetector.DetectLinks(fullText);

            Assert.IsTrue(links.Contains(new LinkDto(link1, link1Text, 1)), "Didn't find link1");
            Assert.IsTrue(links.Contains(new LinkDto(link2, link2Text, 1)), "Didn't find link2");
        }
예제 #7
0
        public void TwoLinksTheSame_FindBoth()
        {
            string link = "link", linkText = "linkText";
            var    line1        = $"SomeTextBefore[{linkText}]({link})SomeTextAfter";
            var    line2        = $"SomeTextBefore[{linkText}]({link})SomeTextAfter";
            var    linkDetector = new LinkDetectorService();
            var    links        = linkDetector.DetectLinks(new [] { line1, line2 });

            Assert.AreEqual(1, links.Count, "We should have only found one link (with 2 lines)");
            Assert.IsTrue(links.Contains(new LinkDto(link, linkText, 1)), "Didn't find the link");
            AssertAreSameLines(new List <int> {
                1, 2
            }, links.First().Lines);
        }