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

            guideML = guideMLTranslator.PlainTextToGuideML("http://www.bbc.co.uk/");
            DnaXmlValidator validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY><LINK HREF=\"http://www.bbc.co.uk/\">http://www.bbc.co.uk/</LINK></BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("Check out some nonsense here: http://www.bbc.co.uk/dna/mb606/A123");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>Check out some nonsense here: <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK></BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("http1 = http://www.bbc.co.uk/dna/mb606/A123 http2 http://www.bbc.co.uk/dna/mb606/A456");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>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></BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("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");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>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</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("http://www.bbc.co.uk/dna/mb606 is a good site.");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY><LINK HREF=\"http://www.bbc.co.uk/dna/mb606\">http://www.bbc.co.uk/dna/mb606</LINK> is a good site.</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("Some text?");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>Some text?</BODY></GUIDE>", guideML);
        }
        public void GuideMLTranslatorTests_PlainTextToGuideML_HttpToClickableLink_Terminators()
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator(); 
            string guideML;

            guideML = guideMLTranslator.PlainTextToGuideML("http://www.bbc.co.uk/dna/mb606. Another sentance.");
            DnaXmlValidator validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY><LINK HREF=\"http://www.bbc.co.uk/dna/mb606\">http://www.bbc.co.uk/dna/mb606</LINK>. Another sentance.</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("First sentance http://www.bbc.co.uk/dna/mb606? Second sentance.");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>First sentance <LINK HREF=\"http://www.bbc.co.uk/dna/mb606\">http://www.bbc.co.uk/dna/mb606</LINK>? Second sentance.</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("The following link is in brackets (http://www.bbc.co.uk/dna/mb606).");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>The following link is in brackets (<LINK HREF=\"http://www.bbc.co.uk/dna/mb606\">http://www.bbc.co.uk/dna/mb606</LINK>).</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("Another link is in brackets (http://www.bbc.co.uk/dna/mb606/).");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>Another link is in brackets (<LINK HREF=\"http://www.bbc.co.uk/dna/mb606/\">http://www.bbc.co.uk/dna/mb606/</LINK>).</BODY></GUIDE>", guideML);

			guideML = guideMLTranslator.PlainTextToGuideML("http1 = http://www.bbc.co.uk/dna/mb606/A123, something else");
			validator = new DnaXmlValidator(guideML, _schemaUri);
			validator.Validate();
			Assert.AreEqual("<GUIDE><BODY>http1 = <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK>, something else</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("http1 = http://www.bbc.co.uk/dna/mb606/A123. Something else");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>http1 = <LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK>. Something else</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("http1 = @http://www.bbc.co.uk/dna/mb606/A123@ Something else");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>http1 = @<LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK>@ Something else</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("http1 = \"http://www.bbc.co.uk/dna/mb606/A123\",|{^ Something else");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>http1 = \"<LINK HREF=\"http://www.bbc.co.uk/dna/mb606/A123\">http://www.bbc.co.uk/dna/mb606/A123</LINK>\",|{^ Something else</BODY></GUIDE>", guideML);
			
			// http://www.guardian.co.uk/alqaida/story/0,,2173071,00.html
			guideML = guideMLTranslator.PlainTextToGuideML("Guardian link: http://www.guardian.co.uk/alqaida/story/0,,2173071,00.html");
			validator = new DnaXmlValidator(guideML, _schemaUri);
			validator.Validate();
			Assert.AreEqual("<GUIDE><BODY>Guardian link: <LINK HREF=\"http://www.guardian.co.uk/alqaida/story/0,,2173071,00.html\">http://www.guardian.co.uk/alqaida/story/0,,2173071,00.html</LINK></BODY></GUIDE>", guideML);
        }
		public void PlainTextToGuideMLMixingLinksAndReturns()
		{
			GuideMLTranslator translator = new GuideMLTranslator();
			string guideML;

			guideML = translator.PlainTextToGuideML("1 < 2");
			Assert.AreEqual("<GUIDE><BODY>1 &lt; 2</BODY></GUIDE>", guideML);

			guideML = translator.PlainTextToGuideML("http://www.h2g2.com");
			Assert.AreEqual("<GUIDE><BODY><LINK HREF=\"http://www.h2g2.com\">http://www.h2g2.com</LINK></BODY></GUIDE>", guideML);

			guideML = translator.PlainTextToGuideML("http://www.h2g2.com/test?abc=1&bcd='2'");
			Assert.AreEqual("<GUIDE><BODY><LINK HREF=\"http://www.h2g2.com/test?abc=1&amp;bcd=&apos;2&apos;\">http://www.h2g2.com/test?abc=1&amp;bcd=&apos;2&apos;</LINK></BODY></GUIDE>", guideML);

			guideML = translator.PlainTextToGuideML("Testing URLs: http://www.h2g2.com\r\n");
			Assert.AreEqual("<GUIDE><BODY>Testing URLs: <LINK HREF=\"http://www.h2g2.com\">http://www.h2g2.com</LINK><BR /></BODY></GUIDE>",guideML);
		}
        public void GuideMLTranslatorTests_PlainTextToGuideML_CRsToBRs()
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
            string guideML;

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

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

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

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

            guideML = guideMLTranslator.PlainTextToGuideML("A sentence. \'test\' Another sentence.");
            Assert.AreEqual("<GUIDE><BODY>A sentence. \'test\' Another sentence.</BODY></GUIDE>", guideML);
        }
        public void GuideMLTranslatorTests_PlainTextToGuideML_HttpToClickableLink_InvalidLength()
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
            string guideML;

            guideML = guideMLTranslator.PlainTextToGuideML("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("<GUIDE><BODY>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.</BODY></GUIDE>", guideML);
        }
 public void GuideMLTranslatorTests_PlainTextToGuideML_HttpToClickableLink_NullInput()
 {
     GuideMLTranslator guideMLTranslator = new GuideMLTranslator(); 
     string guideML = null;
     try
     {
         guideML = guideMLTranslator.PlainTextToGuideML(guideML);
         Assert.AreEqual("<GUIDE><BODY></BODY></GUIDE>", guideML);
     }
     catch (NullReferenceException ex)
     {
         Assert.IsTrue(ex is NullReferenceException, "Was expecting NullReferenceException but got " + ex.GetType());
     }
 }
        public void GuideMLTranslatorTests_PlainTextToGuideML_HttpToClickableLink_EmptyStrings()
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator(); 
            string guideML;

            guideML = guideMLTranslator.PlainTextToGuideML("There are known knowns; there are things we know we know.");
            DnaXmlValidator validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>There are known knowns; there are things we know we know.</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("There are known unknowns http; that is to say we know there are some things we do not know.");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>There are known unknowns http; that is to say we know there are some things we do not know.</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML("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.");
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY>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.</BODY></GUIDE>", guideML);

            guideML = guideMLTranslator.PlainTextToGuideML(String.Empty);
            validator = new DnaXmlValidator(guideML, _schemaUri);
            validator.Validate();
            Assert.AreEqual("<GUIDE><BODY></BODY></GUIDE>", guideML);
        }
Exemple #8
0
        /// <summary>
        /// Converts a piece of plain text into GuideML.
        /// </summary>
        /// <param name="text">String to convert from plain text to GuideML</param>
        /// <returns>Converted string with &lt;GUIDE&gt;&lt;BODY&gt;</returns>
        public static string PlainTextToGuideML(string text)
        {
            GuideMLTranslator guideMLTranslator = new GuideMLTranslator();
            string guideML = String.Empty;
            guideML = guideMLTranslator.PlainTextToGuideML(text);

            return guideML;
        }