public void MoveCssInline_NoStyle_DoesNotBreakImageWidthAttribute() { string input = "<html><head><style type=\"text/css\"></style></head>" + "<body><img style=\"width: 206px; height: 64px;\" src=\"http://localhost/left.gif\" height=\"64\" WIDTH=\"206\" border=\"0\"></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input); Assert.IsFalse(premailedOutput.Html.Contains("width=\"206px\"")); Assert.IsTrue(premailedOutput.Html.Contains("width=\"206\"")); }
public void AddAnalyticsTags_AddsTags() { const string input = @"<div><a href=""blah.com/someurl"">Some URL</a><a>No href</a></div><div><a href=""blah.com/someurl?extra=1"">Extra Stuff</a></div>"; const string expected = @"<html><head></head><body><div><a href=""blah.com/someurl?utm_source=source&utm_medium=medium&utm_campaign=campaign&utm_content=content"">Some URL</a><a>No href</a></div><div><a href=""blah.com/someurl?extra=1&utm_source=source&utm_medium=medium&utm_campaign=campaign&utm_content=content"">Extra Stuff</a></div></body></html>"; var premailedOutput = new PreMailer(input, HtmlParsingMode.Auto) .AddAnalyticsTags("source", "medium", "campaign", "content") .MoveCssInline(); Assert.IsTrue(expected == premailedOutput.Html); }
public void AddAnalyticsTags_AddsTagsBeforeAnchorTags() { const string input = @"<div><a href=""https://github.com/premailer/premailer#premailer-specific-css"">Premailer Specific CSS</a></div>"; const string expected = @"<html><head></head><body><div><a href=""https://github.com/premailer/premailer?utm_source=source&utm_medium=medium&utm_campaign=campaign&utm_content=content#premailer-specific-css"">Premailer Specific CSS</a></div></body></html>"; var premailedOutput = new PreMailer(input) .AddAnalyticsTags("source", "medium", "campaign", "content", "github.com") .MoveCssInline(); Assert.True(expected == premailedOutput.Html); }
public void AddAnalyticsTags_AddsTagsAndExcludesDomain() { const string input = @"<div><a href=""http://www.blah.com/someurl"">Some URL</a><a>No href</a></div><div><a href=""https://www.nomatch.com/someurl?extra=1"">Extra Stuff</a><a href=""{{Handlebars}}"">Don't Touch</a></div>"; const string expected = @"<html><head></head><body><div><a href=""http://www.blah.com/someurl?utm_source=source&utm_medium=medium&utm_campaign=campaign&utm_content=content"">Some URL</a><a>No href</a></div><div><a href=""https://www.nomatch.com/someurl?extra=1"">Extra Stuff</a><a href=""{{Handlebars}}"">Don't Touch</a></div></body></html>"; var premailedOutput = new PreMailer(input) .AddAnalyticsTags("source", "medium", "campaign", "content", "www.Blah.com") .MoveCssInline(); Assert.IsTrue(expected == premailedOutput.Html); }
public void MoveCssInline_UnsupportedPseudoSelector_AddsWarning() { string input = "<html><head><style type=\"text/css\">li:before { width: 42px; }</style></head><body><div><div class=\"target\">test</div></div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input); var warnings = premailedOutput.Warnings; Assert.IsTrue(warnings.Contains("PreMailer.Net is unable to process the pseudo class/element 'li:before' due to a limitation in CsQuery.")); }
public void MoveCssInline_LaterPositionStylesWithEqualSpecificityHasPrecedence_Nested_InSeparateBlocks() { string input1 = "<html><head><style type=\"text/css\">table.child td { color: #00F; } table.parent td { color: #00F; }</style><style type=\"text/css\">table.parent td { color: #0F0; }</style></head><body><table class=\"parent\"><tr><td><table class=\"child\"><tr><td>test</td></tr></table></td></tr></table></body></html>"; string input2 = "<html><head><style type=\"text/css\">table.parent td { color: #0F0; } table.child td { color: #0F0; }</style><style type=\"text/css\">table.child td { color: #00F; }</style></head><body><table class=\"parent\"><tr><td><table class=\"child\"><tr><td>test</td></tr></table></td></tr></table></body></html>"; var premailedOutput1 = PreMailer.MoveCssInline(input1, false); var premailedOutput2 = PreMailer.MoveCssInline(input2, false); Assert.IsTrue(premailedOutput1.Html.Contains("<td style=\"color: #0F0\">test</td>")); Assert.IsTrue(premailedOutput2.Html.Contains("<td style=\"color: #00F\">test</td>")); }
public void MoveCssInline_LaterPositionStylesWithEqualSpecificityHasPrecedence_InSameBlock() { string input1 = "<html><head><style type=\"text/css\">table.acolor td { color: #0F0; } table.bcolor td { color: #00F; }</style></head><body><table class=\"acolor bcolor\"><tr><td>test</td></tr></table></body></html>"; string input2 = "<html><head><style type=\"text/css\">table.bcolor td { color: #00F; } table.acolor td { color: #0F0; }</style></head><body><table class=\"acolor bcolor\"><tr><td>test</td></tr></table></body></html>"; var premailedOutput1 = PreMailer.MoveCssInline(input1, false); var premailedOutput2 = PreMailer.MoveCssInline(input2, false); Assert.Contains("<td style=\"color: #00F\">test</td>", premailedOutput1.Html); Assert.Contains("<td style=\"color: #0F0\">test</td>", premailedOutput2.Html); }
public static string ToHighLightFormat(this string str, string lng) { WirteCodeToFile(str, lng); WirteHighlightFile(); string htmlSource = File.ReadAllText(@"C:\Workspace\testmail.html"); var result = PreMailer.MoveCssInline(htmlSource); //result.Html; // Resultant HTML, with CSS in-lined. //result.Warnings; // string[] of any warnings that occurred during processing. return(File.ReadAllText(PathHighlight + "main.html")); }
public void MoveCssInline_CrazyCssSelector_DoesNotThrowError() { string input = "<html><head><style type=\"text/css\">li:crazy { width: 42px; }</style></head><body><ul><li>target</li><li>blargh></li></ul></body></html>"; try { PreMailer.MoveCssInline(input); } catch (Exception ex) { Assert.Fail(ex.Message); } }
public void ContainsLinkCssElement_DownloadsCss_InlinesContent() { var mockDownloader = new Mock <IWebDownloader>(); mockDownloader.Setup(d => d.DownloadString(It.IsAny <Uri>())).Returns(".test { width: 150px; }"); WebDownloader.SharedDownloader = mockDownloader.Object; string input = "<html><head><link href=\"http://a.com/b.css\"></link></head><body><div class=\"test\">test</div></body></html>"; PreMailer sut = new PreMailer(input, new Uri("http://a.com")); var premailedOutput = sut.MoveCssInline(); Assert.IsTrue(premailedOutput.Html.Contains("<div class=\"test\" style=\"width: 150px\">")); }
public void ManualIntegrationTest() { string testProjectDirectoryPath = System.Reflection.Assembly.GetExecutingAssembly().Location; var directory = new DirectoryInfo(testProjectDirectoryPath); while (!directory.Name.Equals("PreMailer.Net.Tests")) { directory = directory.Parent; } testProjectDirectoryPath = directory.FullName; string htmlSource = File.ReadAllText(String.Join("\\", testProjectDirectoryPath, "testmail.html")); string premailedOutput = PreMailer.MoveCssInline(htmlSource, false); }
public void MoveCSSInline_AcceptsStream() { string input = "<html><head><style type=\"text/css\" media=\"screen\">div { width: 100% }</style></head><body><div>Target</div></body></html>"; using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream)) { writer.Write(input); writer.Flush(); stream.Position = 0; var premailedOutput = PreMailer.MoveCssInline(stream); Assert.IsTrue(premailedOutput.Html.Contains("<div style=\"width: 100%\">Target</div>")); } } }
public void ContainsKeyframeCSS_InlinesCSSWithOutError() { string keyframeAnimation = @" @keyframes mymove { 0% {top: 0px;} 25% {top: 200px;} 75% {top: 50px} 100% {top: 100px;} } " ; string input = "<html><head><style type=\"text/css\">.test { background-color:#f1f1f1; } " + keyframeAnimation + "</style></head><body><div class=\"test\">test</div></body></html>"; var premailedOutput = PreMailer.MoveCssInline(input, false); Assert.IsTrue(premailedOutput.Html.Contains("<div class=\"test\" style=\"background-color: #f1f1f1\"")); }
public void ContainsLinkCssElement_NotCssFile_DoNotDownload() { var mockDownloader = new Mock <IWebDownloader>(); mockDownloader.Setup(d => d.DownloadString(It.IsAny <Uri>())).Returns(".a { display: block; }"); WebDownloader.SharedDownloader = mockDownloader.Object; Uri baseUri = new Uri("http://a.com"); Uri fullUrl = new Uri(baseUri, "b.bs"); string input = $"<html><head><link href=\"{fullUrl}\"></link></head><body><div id=\"high-imp\" class=\"test\">test</div></body></html>"; PreMailer sut = new PreMailer(input, baseUri); sut.MoveCssInline(); mockDownloader.Verify(d => d.DownloadString(It.IsAny <Uri>()), Times.Never()); }
public void ContainsLinkCssElement_Bundle_DownloadsCss() { var mockDownloader = new Mock <IWebDownloader>(); mockDownloader.Setup(d => d.DownloadString(It.IsAny <Uri>())).Returns(".a { display: block; }"); WebDownloader.SharedDownloader = mockDownloader.Object; Uri baseUri = new Uri("http://a.com"); Uri fullUrl = new Uri(baseUri, "/Content/css?v=7V7TZzP9Wo7LiH9_q-r5mRBdC_N0lA_YJpRL_1V424E1"); string input = $"<html><head><link href=\"{fullUrl}\" rel=\"stylesheet\"></head><body><div id=\"high-imp\" class=\"test\">test</div></body></html>"; PreMailer sut = new PreMailer(input, baseUri); sut.MoveCssInline(); mockDownloader.Verify(d => d.DownloadString(fullUrl)); }
public void TestMethod1() { string testProjectDirectoryPath = System.Reflection.Assembly.GetExecutingAssembly().Location; var directory = new DirectoryInfo(testProjectDirectoryPath); while (!directory.Name.Equals("PreMailer.Net.Tests")) { directory = directory.Parent; } testProjectDirectoryPath = directory.FullName; string htmlSource = File.ReadAllText(String.Join("\\", testProjectDirectoryPath, "testmail.html")); PreMailer pm = new PreMailer(); string premailedOutput = pm.MoveCssInline(htmlSource, false); }
public void MoveCSSInline_MergingTwoValidCssRules() { string input = @"<html> <head> <style><!-- /* Font Definitions */ p.MsoNormal {margin:0cm;} p {mso-style-priority:99;} --></style> </head> <body> <div> <p class=""MsoNormal""><span style=""font-family:Source Sans Pro,serif"">Line1</span></p> </div> </body> </html>"; var premailedOutput = PreMailer.MoveCssInline(input, true, null, null); Assert.IsTrue(premailedOutput.Html.Contains("style=\"mso-style-priority: 99;margin: 0cm\"")); }
public void AddAnalyticsTags_AddsTagsAndExcludesDomain() { const string input = @"<div><a href=""http://www.blah.com/someurl"">Some URL</a><a>No href</a></div><div><a href=""https://www.nomatch.com/someurl?extra=1"">Extra Stuff</a></div>"; const string expected = @"<html><head></head><body><div><a href=""http://www.blah.com/someurl?utm_source=source&utm_medium=medium&utm_campaign=campaign&utm_content=content"">Some URL</a><a>No href</a></div><div><a href=""https://www.nomatch.com/someurl?extra=1"">Extra Stuff</a></div></body></html>"; var premailedOutput = new PreMailer(input,HtmlParsingMode.Auto) .AddAnalyticsTags("source", "medium", "campaign", "content", "www.Blah.com") .MoveCssInline(); Assert.IsTrue(expected == premailedOutput.Html); }
public void TestInitialize() { this.sut = new PreMailer(); }
public void ContainsLinkCssElement_NotCssFile_DoNotDownload() { var mockDownloader = new Mock<IWebDownloader>(); mockDownloader.Setup(d => d.DownloadString(It.IsAny<Uri>())).Returns(".a { display: block; }"); WebDownloader.SharedDownloader = mockDownloader.Object; Uri baseUri = new Uri("http://a.com"); Uri fullUrl = new Uri(baseUri, "b.bs"); string input = String.Format("<html><head><link href=\"{0}\"></link></head><body><div id=\"high-imp\" class=\"test\">test</div></body></html>", fullUrl); PreMailer sut = new PreMailer(input, baseUri); sut.MoveCssInline(); mockDownloader.Verify(d => d.DownloadString(It.IsAny<Uri>()), Times.Never()); }
public void ContainsLinkCssElement_DownloadsCss_InlinesContent() { var mockDownloader = new Mock<IWebDownloader>(); mockDownloader.Setup(d => d.DownloadString(It.IsAny<Uri>())).Returns(".test { width: 150px; }"); WebDownloader.SharedDownloader = mockDownloader.Object; string input = "<html><head><link href=\"http://a.com/b.css\"></link></head><body><div class=\"test\">test</div></body></html>"; PreMailer sut = new PreMailer(input, new Uri("http://a.com")); var premailedOutput = sut.MoveCssInline(); Assert.IsTrue(premailedOutput.Html.Contains("<div class=\"test\" style=\"width: 150px\">")); }
public void AddAnalyticsTags_AddsTags() { const string input = @"<div><a href=""blah.com/someurl"">Some URL</a><a>No href</a></div><div><a href=""blah.com/someurl?extra=1"">Extra Stuff</a></div>"; const string expected = @"<html><head></head><body><div><a href=""blah.com/someurl?utm_source=source&utm_medium=medium&utm_campaign=campaign&utm_content=content"">Some URL</a><a>No href</a></div><div><a href=""blah.com/someurl?extra=1&utm_source=source&utm_medium=medium&utm_campaign=campaign&utm_content=content"">Extra Stuff</a></div></body></html>"; var premailedOutput = new PreMailer(input) .AddAnalyticsTags("source", "medium", "campaign", "content") .MoveCssInline(); Assert.IsTrue(expected == premailedOutput.Html); }