public void TestOutputHtmlFragment() { const string input = "This is the html body"; const string expected = "<html><body>This is the html body<br/></body></html>"; const string expected2 = "This is the html body<br/>"; var converter = new TextToHtml(); string result; result = converter.Convert(input); Assert.AreEqual(expected, result); converter.OutputHtmlFragment = true; result = converter.Convert(input); Assert.AreEqual(expected2, result); }
public void TestSimpleTextWithUrlsToHtml() { const string expected = "Check out <a href=\"http://www.xamarin.com\">http://www.xamarin.com</a> - it's amazing!<br/>"; string text = "Check out http://www.xamarin.com - it's amazing!" + Environment.NewLine; var converter = new TextToHtml(); var result = converter.Convert(text); Assert.AreEqual(expected, result); }
public void TestArgumentExceptions() { var converter = new TextToHtml(); var reader = new StringReader(""); var writer = new StringWriter(); Assert.AreEqual(TextFormat.Plain, converter.InputFormat); Assert.AreEqual(TextFormat.Html, converter.OutputFormat); Assert.IsFalse(converter.DetectEncodingFromByteOrderMark); Assert.IsFalse(converter.OutputHtmlFragment); Assert.IsNull(converter.Footer); Assert.IsNull(converter.Header); Assert.AreEqual(HeaderFooterFormat.Text, converter.FooterFormat); Assert.AreEqual(HeaderFooterFormat.Text, converter.HeaderFormat); Assert.Throws <ArgumentNullException> (() => converter.Convert((TextReader)null, writer)); Assert.Throws <ArgumentNullException> (() => converter.Convert(reader, (TextWriter)null)); }
public void TestSimpleTextToHtml() { const string expected = "This is some sample text. This is line #1.<br/>" + "This is line #2.<br/>" + "And this is line #3.<br/>"; string text = "This is some sample text. This is line #1." + Environment.NewLine + "This is line #2." + Environment.NewLine + "And this is line #3." + Environment.NewLine; var converter = new TextToHtml(); var result = converter.Convert(text); Assert.AreEqual(expected, result); }
public void TestEmoji() { var expected = "<html><body>😱<br/></body></html>"; var buffer = Encoding.ASCII.GetBytes("=F0=9F=98=B1"); var decoder = new QuotedPrintableDecoder(); var length = decoder.EstimateOutputLength(buffer.Length); var decoded = new byte[length]; var n = decoder.Decode(buffer, 0, buffer.Length, decoded); var emoji = Encoding.UTF8.GetString(decoded, 0, n); var converter = new TextToHtml(); var result = converter.Convert(emoji); Assert.AreEqual(expected, result); }
private void SetTextToHtml(TextPart entity) { var beforeAfter = GetBeforeAfterFormatWrapper(UIStrings.TextToHtmlFormatWrapper); var converter = new TextToHtml { Header = $"{UIStrings.MarkOfTheWeb}{Environment.NewLine}{beforeAfter.Before}", HeaderFormat = HeaderFooterFormat.Html, Footer = beforeAfter.After, FooterFormat = HeaderFooterFormat.Html }; _body = converter.Convert(entity.Text); }
public void TestArgumentExceptions() { var converter = new TextToHtml(); var reader = new StringReader(""); var writer = new StringWriter(); Assert.Throws <ArgumentNullException> (() => converter.InputEncoding = null); Assert.Throws <ArgumentNullException> (() => converter.OutputEncoding = null); Assert.Throws <ArgumentOutOfRangeException> (() => converter.InputStreamBufferSize = -1); Assert.Throws <ArgumentOutOfRangeException> (() => converter.OutputStreamBufferSize = -1); Assert.Throws <ArgumentNullException> (() => converter.Convert(null)); Assert.Throws <ArgumentNullException> (() => converter.Convert((Stream)null, Stream.Null)); Assert.Throws <ArgumentNullException> (() => converter.Convert(Stream.Null, (Stream)null)); Assert.Throws <ArgumentNullException> (() => converter.Convert((TextReader)null, Stream.Null)); Assert.Throws <ArgumentNullException> (() => converter.Convert(Stream.Null, (TextWriter)null)); Assert.Throws <ArgumentNullException> (() => converter.Convert((TextReader)null, writer)); Assert.Throws <ArgumentNullException> (() => converter.Convert(reader, (TextWriter)null)); Assert.Throws <ArgumentNullException> (() => converter.Convert(new StreamReader(Stream.Null), (Stream)null)); Assert.Throws <ArgumentNullException> (() => converter.Convert((Stream)null, new StreamWriter(Stream.Null))); Assert.Throws <ArgumentNullException> (() => converter.Convert(new StreamReader(Stream.Null), (TextWriter)null)); }
public void TestHeaderFooter() { const string input = "This is the html body"; const string header = "This is the header"; const string footer = "This is the footer"; var expected = "<html><body>" + header + "<br/>" + input + "<br/>" + footer + "<br/></body></html>"; var converter = new TextToHtml { HeaderFormat = HeaderFooterFormat.Text, Header = header, FooterFormat = HeaderFooterFormat.Text, Footer = footer }; var result = converter.Convert(input); Assert.AreEqual(expected, result); }
public void TestDecreasingQuoteLevels() { string expected = "<blockquote><blockquote><blockquote><blockquote><blockquote><blockquote>Thou villainous ill-breeding spongy dizzy-eyed reeky elf-skinned pigeon-egg!<br/>" + "</blockquote>Thou artless swag-bellied milk-livered dismal-dreaming idle-headed scut!<br/>" + "</blockquote>Thou errant folly-fallen spleeny reeling-ripe unmuzzled ratsbane!<br/>" + "</blockquote>Henceforth, the coding style is to be strictly enforced, including the use of only upper case.<br/>" + "</blockquote>I've noticed a lack of adherence to the coding styles, of late.<br/>" + "</blockquote>Any complaints?<br/>" + "</blockquote>"; string text = ">>>>>> Thou villainous ill-breeding spongy dizzy-eyed reeky elf-skinned pigeon-egg!" + Environment.NewLine + ">>>>> Thou artless swag-bellied milk-livered dismal-dreaming idle-headed scut!" + Environment.NewLine + ">>>> Thou errant folly-fallen spleeny reeling-ripe unmuzzled ratsbane!" + Environment.NewLine + ">>> Henceforth, the coding style is to be strictly enforced, including the use of only upper case." + Environment.NewLine + ">> I've noticed a lack of adherence to the coding styles, of late." + Environment.NewLine + "> Any complaints?" + Environment.NewLine; var converter = new TextToHtml { OutputHtmlFragment = true }; var result = converter.Convert(text); Assert.AreEqual(expected, result); }