public void GuideMLTranslatorTests_ConvertPlainText_HttpToClickableLink_Basic()
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
            string guideML;

            guideML = guideMLTranslator.ConvertPlainText("http://www.bbc.co.uk/");
            Assert.AreEqual("<LINK HREF=\"http://www.bbc.co.uk/\">http://www.bbc.co.uk/</LINK>", guideML);

            guideML = guideMLTranslator.ConvertPlainText("Check out some nonsense here: http://www.bbc.co.uk/dna/mb606/A123");
            Assert.AreEqual("Check out some nonsense here: <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK>", guideML);

            guideML = guideMLTranslator.ConvertPlainText("http1 = http://www.bbc.co.uk/dna/mb606/A123 http2 http://www.bbc.co.uk/dna/mb606/A456");
            Assert.AreEqual("http1 = <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK> http2 <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A456\">http://www.bbc.co.uk/dna/mb606/A456</LINK>", guideML);

            guideML = guideMLTranslator.ConvertPlainText("http1 = http://www.bbc.co.uk/dna/mb606/A123 http2 http://www.bbc.co.uk/dna/mb606/A456 http 3 = http://www.bbc.co.uk/dna/mb606/789 more text");
            Assert.AreEqual("http1 = <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK> http2 <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A456\">http://www.bbc.co.uk/dna/mb606/A456</LINK> http 3 = <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/789\">http://www.bbc.co.uk/dna/mb606/789</LINK> more text", guideML);

            guideML = guideMLTranslator.ConvertPlainText("http://www.bbc.co.uk/dna/mb606 is a good site.");
            Assert.AreEqual("<LINK HREF=\"http://www.bbc.co.uk/dna/mb606\">http://www.bbc.co.uk/dna/mb606</LINK> is a good site.", guideML);

            guideML = guideMLTranslator.ConvertPlainText("Some text?");
            Assert.AreEqual("Some text?", guideML);
        }
        public void GuideMLTranslatorTests_ConvertPlainText_CRsToBRs()
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
            string guideML;

            guideML = guideMLTranslator.ConvertPlainText("A sentence. \r\n Another sentence.");
            Assert.AreEqual("A sentence. <BR /> Another sentence.", guideML);

            guideML = guideMLTranslator.ConvertPlainText("A sentence. \n Another sentence.");
            Assert.AreEqual("A sentence. <BR /> Another sentence.", guideML);

            guideML = guideMLTranslator.ConvertPlainText("A sentence. \r\n\r\n\r\n Another sentence.");
            Assert.AreEqual("A sentence. <BR /><BR /><BR /> Another sentence.", guideML);

            guideML = guideMLTranslator.ConvertPlainText("A sentence. \n\n\n Another sentence.");
            Assert.AreEqual("A sentence. <BR /><BR /><BR /> Another sentence.", guideML);

            guideML = guideMLTranslator.ConvertPlainText("A sentence. \'test\' Another sentence.");
            Assert.AreEqual("A sentence. \'test\' Another sentence.", guideML);
        }
        public void GuideMLTranslatorTests_ConvertPlainText_HttpToClickableLink_InvalidLength()
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
            string guideML;

            guideML = guideMLTranslator.ConvertPlainText("A long url http://www.reallylongurlsareusbecausewecan.con/onceuponatime/inaland/far/far/far/away/gremlin/Thepurposebehindgreekingistoforceyourreviewerstoignorethetextandjustfocusonthedesignelementsonthepage/everydesignerhasexperiencedthereviewsessionwherethereviewersfound13typosinthesampletextthatwasusedordecidedthatthe10-wordmarketingtextreallyshouldbe12/Andsoon/Andsoon/thiscanbereallyfrustratingwhenyouretryingtodecidebetweena2-columnlayoutanda3-columnlayout/ButonceyourepasttheinitialdesignphasetheGreektextshouldbereplacedwithcontentthatisasclosetowhatwillreallybethereasyoucanpossiblyget/becausetextonWebpagesismeanttoberead/Greekedtextwillforcereviewerstoignorethefactthatthecolumnissowideornarrowthatthescan-lineisimpossible/Orthatthefontsizeistoosmallformostpeopletoread/Thatsbecausetheyarentreadingit/OnonesiteIworkedontherewasspaceforapproximately50charactersinthisonesectionofthepage/Butthedatafeedthatdeliveredthatcontentwasa128characterelement/Wedecidedtoalwayscutthefeedoffatawordendjustbeforecharacter46andaddblahblah is here.");
            Assert.AreEqual("A long url http://www.reallylongurlsareusbecausewecan.con/onceuponatime/inaland/far/far/far/away/gremlin/Thepurposebehindgreekingistoforceyourreviewerstoignorethetextandjustfocusonthedesignelementsonthepage/everydesignerhasexperiencedthereviewsessionwherethereviewersfound13typosinthesampletextthatwasusedordecidedthatthe10-wordmarketingtextreallyshouldbe12/Andsoon/Andsoon/thiscanbereallyfrustratingwhenyouretryingtodecidebetweena2-columnlayoutanda3-columnlayout/ButonceyourepasttheinitialdesignphasetheGreektextshouldbereplacedwithcontentthatisasclosetowhatwillreallybethereasyoucanpossiblyget/becausetextonWebpagesismeanttoberead/Greekedtextwillforcereviewerstoignorethefactthatthecolumnissowideornarrowthatthescan-lineisimpossible/Orthatthefontsizeistoosmallformostpeopletoread/Thatsbecausetheyarentreadingit/OnonesiteIworkedontherewasspaceforapproximately50charactersinthisonesectionofthepage/Butthedatafeedthatdeliveredthatcontentwasa128characterelement/Wedecidedtoalwayscutthefeedoffatawordendjustbeforecharacter46andaddblahblah is here.", guideML);
        }
 public void GuideMLTranslatorTests_ConvertPlainText_HttpToClickableLink_NullInput()
 {
     GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
     string guideML = null;
     try
     {
         guideML = guideMLTranslator.ConvertPlainText(guideML);
         Assert.AreEqual("", guideML);
     }
     catch (NullReferenceException ex)
     {
         Assert.IsTrue(ex is NullReferenceException, "Was expecting NullReferenceException but got " + ex.GetType());
     }
 }
        public void GuideMLTranslatorTests_ConvertPlainText_HttpToClickableLink_EmptyStrings()
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
            string guideML;

            guideML = guideMLTranslator.ConvertPlainText("There are known knowns; there are things we know we know.");
            Assert.AreEqual("There are known knowns; there are things we know we know.", guideML);

            guideML = guideMLTranslator.ConvertPlainText("There are known unknowns http; that is to say we know there are some things we do not know.");
            Assert.AreEqual("There are known unknowns http; that is to say we know there are some things we do not know.", guideML);

            guideML = guideMLTranslator.ConvertPlainText("But there are also unknown unknowns -- www.cbsnews.com/blogs/2006/11/09/publiceye/entry2165872.shtml -- the ones we don't know we don't know.");
            Assert.AreEqual("But there are also unknown unknowns -- www.cbsnews.com/blogs/2006/11/09/publiceye/entry2165872.shtml -- the ones we don't know we don't know.", guideML);

            guideML = guideMLTranslator.ConvertPlainText(String.Empty);
            Assert.AreEqual("", guideML);
        }
        public void GuideMLTranslatorTests_ConvertPlainText_HttpToClickableLink_Terminators()
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
            string guideML;

            guideML = guideMLTranslator.ConvertPlainText("http://www.bbc.co.uk/dna/mb606. Another sentance.");
            Assert.AreEqual("<LINK HREF=\"http://www.bbc.co.uk/dna/mb606\">http://www.bbc.co.uk/dna/mb606</LINK>. Another sentance.", guideML);

            guideML = guideMLTranslator.ConvertPlainText("First sentance http://www.bbc.co.uk/dna/mb606? Second sentance.");
            Assert.AreEqual("First sentance <LINK HREF=\"http://www.bbc.co.uk/dna/mb606\">http://www.bbc.co.uk/dna/mb606</LINK>? Second sentance.", guideML);

            guideML = guideMLTranslator.ConvertPlainText("The following link is in brackets (http://www.bbc.co.uk/dna/mb606).");
            Assert.AreEqual("The following link is in brackets (<LINK HREF=\"http://www.bbc.co.uk/dna/mb606\">http://www.bbc.co.uk/dna/mb606</LINK>).", guideML);

            guideML = guideMLTranslator.ConvertPlainText("Another link is in brackets (http://www.bbc.co.uk/dna/mb606/).");
            Assert.AreEqual("Another link is in brackets (<LINK HREF=\"http://www.bbc.co.uk/dna/mb606/\">http://www.bbc.co.uk/dna/mb606/</LINK>).", guideML);

            guideML = guideMLTranslator.ConvertPlainText("http1 = http://www.bbc.co.uk/dna/mb606/A123, something else");
            Assert.AreEqual("http1 = <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK>, something else", guideML);

            guideML = guideMLTranslator.ConvertPlainText("http1 = http://www.bbc.co.uk/dna/mb606/A123. Something else");
            Assert.AreEqual("http1 = <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK>. Something else", guideML);

            guideML = guideMLTranslator.ConvertPlainText("http1 = @http://www.bbc.co.uk/dna/mb606/A123@ Something else");
            Assert.AreEqual("http1 = @<LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK>@ Something else", guideML);

            guideML = guideMLTranslator.ConvertPlainText("http1 = \"http://www.bbc.co.uk/dna/mb606/A123\",|{^ Something else");
            Assert.AreEqual("http1 = \"<LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK>\",|{^ Something else", guideML);
        }
示例#7
0
 /// <summary>
 /// Marks-up a piece of plain text.
 /// </summary>
 /// <param name="text">String to convert from plain text to GuideML</param>
 /// <returns>Converted string</returns>
 public static string ConvertPlainText(string text)
 {
     GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
     string guideML = String.Empty;
     guideML = guideMLTranslator.ConvertPlainText(text);
     return guideML;
 }