public void MixedCaseRule_RetainsCasing() { var attribute = CssAttribute.FromRule("Margin-bottom: 10px"); Assert.AreEqual("Margin-bottom", attribute.Style); Assert.AreEqual("10px", attribute.Value); }
public void StandandUnimportantRule_ReturnsAttribute() { var attribute = CssAttribute.FromRule("color: red"); Assert.AreEqual("color", attribute.Style); Assert.AreEqual("red", attribute.Value); }
public void MixedCaseRuleValue_RetainsCasing() { var attribute = CssAttribute.FromRule(" color: rED"); Assert.AreEqual("color", attribute.Style); Assert.AreEqual("rED", attribute.Value); }
public void ImportantRule_ReturnsValidCssWithoutWhitespaces() { var attribute = CssAttribute.FromRule("color:red!important"); Assert.Equal("color", attribute.Style); Assert.Equal("red", attribute.Value); Assert.True(attribute.Important); }
public void ImportantRule_EmitsImportantAttributeOnlyWhenSpecified() { var attribute = CssAttribute.FromRule("color: red !important"); Assert.Equal("color: red", attribute.ToString()); Assert.Equal("color: red", attribute.ToString(emitImportant: false)); Assert.Equal("color: red !important", attribute.ToString(emitImportant: true)); }
public void SingleAttribute_ShouldNotAppendSemiColonToString() { var clazz = new StyleClass(); clazz.Attributes["color"] = CssAttribute.FromRule("color: red"); Assert.AreEqual("color: red", clazz.ToString()); }
public void ImportantRule_ReturnsImportantAttribute() { var attribute = CssAttribute.FromRule("color: red !important"); Assert.AreEqual("color", attribute.Style); Assert.AreEqual("red", attribute.Value); Assert.IsTrue(attribute.Important); }
public void MultipleAttributes_ShouldJoinAttributesWithSemiColonInString() { var clazz = new StyleClass(); clazz.Attributes["color"] = CssAttribute.FromRule("color: red"); clazz.Attributes["height"] = CssAttribute.FromRule("height: 100%"); Assert.AreEqual("color: red;height: 100%", clazz.ToString()); }
public void Merge_ShouldEmitImportantOnlyWhenSpecified() { var clazz = new StyleClass(); clazz.Attributes["color"] = CssAttribute.FromRule("color: red !important"); Assert.Equal("color: red", clazz.ToString()); Assert.Equal("color: red", clazz.ToString(emitImportant: false)); Assert.Equal("color: red !important", clazz.ToString(emitImportant: true)); }
public void FindEquivalentStyles() { var tableDomObject = CQ.CreateFragment("<td id=\"tabletest\" class=\"test\" bgcolor=\"\"></td>"); var nodewithoutselector = tableDomObject.FirstElement(); var clazz = new StyleClass(); clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red"); var result = CssStyleEquivalence.FindEquivalent(nodewithoutselector, clazz); Assert.AreEqual(1, result.Count); }
public void Merge_ShouldAddNonExistingAttributesToClass() { var target = new StyleClass(); var donator = new StyleClass(); target.Attributes["color"] = CssAttribute.FromRule("color: red"); donator.Attributes["height"] = CssAttribute.FromRule("height: 100%"); target.Merge(donator, true); Assert.IsTrue(target.Attributes.ContainsKey("height")); Assert.AreEqual("100%", target.Attributes["height"].Value); }
public void FindEquivalentStyles() { var tableDomObject = new HtmlParser().Parse("<table id=\"tabletest\" class=\"test\" bgcolor=\"\"></table>"); var nodewithoutselector = (IElement)tableDomObject.Body.FirstChild; var clazz = new StyleClass(); clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red"); var result = CssStyleEquivalence.FindEquivalent(nodewithoutselector, clazz); Assert.AreEqual(1, result.Count); }
public void Merge_ShouldNotOverrideExistingEntriesIfNotSpecified() { var target = new StyleClass(); var donator = new StyleClass(); target.Attributes["color"] = CssAttribute.FromRule("color: red"); target.Attributes["height"] = CssAttribute.FromRule("height: 50%"); donator.Attributes["height"] = CssAttribute.FromRule("height: 100%"); target.Merge(donator, false); Assert.IsTrue(target.Attributes.ContainsKey("height")); Assert.AreEqual("50%", target.Attributes["height"].Value); }
public void Merge_ShouldOverrideExistingEntriesIfSpecifiedIgnoringCasing() { var target = new StyleClass(); var donator = new StyleClass(); target.Attributes["color"] = CssAttribute.FromRule("color: red"); target.Attributes["HEight"] = CssAttribute.FromRule("height: 50%"); donator.Attributes["height"] = CssAttribute.FromRule("height: 100%"); target.Merge(donator, true); Assert.True(target.Attributes.ContainsKey("height")); Assert.Equal("100%", target.Attributes["height"].Value); }
public void Merge_ShouldOverrideExistingImportantEntriesIfNewEntryIsImportant() { var target = new StyleClass(); var donator = new StyleClass(); target.Attributes["color"] = CssAttribute.FromRule("color: red"); target.Attributes["height"] = CssAttribute.FromRule("height: 50% !important"); donator.Attributes["height"] = CssAttribute.FromRule("height: 100% !important"); target.Merge(donator, true); Assert.IsTrue(target.Attributes.ContainsKey("height")); Assert.AreEqual("100%", target.Attributes["height"].Value); }
public void GetAllStylesForElement() { var tableDomObject = CQ.CreateFragment("<td id=\"tabletest\" class=\"test\" bgcolor=\"\"></td>"); var nodewithoutselector = tableDomObject.FirstElement(); var clazz = new StyleClass(); clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red"); var result = CssElementStyleResolver.GetAllStyles(nodewithoutselector, clazz); Assert.AreEqual(2, result.Count()); Assert.AreEqual("style", result.ElementAt(0).AttributeName); Assert.AreEqual("bgcolor", result.ElementAt(1).AttributeName); }
public void GetAllStylesForElement() { var tableDomObject = new HtmlParser().ParseDocument("<table id=\"tabletest\" class=\"test\" bgcolor=\"\"></table>"); var nodewithoutselector = (IElement)tableDomObject.Body.FirstChild; var clazz = new StyleClass(); clazz.Attributes["background-color"] = CssAttribute.FromRule("background-color: red"); var result = CssElementStyleResolver.GetAllStyles(nodewithoutselector, clazz); Assert.AreEqual(2, result.Count()); Assert.AreEqual("style", result.ElementAt(0).AttributeName); Assert.AreEqual("bgcolor", result.ElementAt(1).AttributeName); }
public void ApplyInlineStylesWithoutImportant() { var document = new HtmlParser().ParseDocument("<div></div>"); var clazz = new StyleClass(); clazz.Attributes["color"] = CssAttribute.FromRule("color: #000 !important"); var elementDictionary = new Dictionary <IElement, StyleClass> { { document.Body.FirstElementChild, clazz } }; var result = StyleClassApplier.ApplyAllStyles(elementDictionary); Assert.Equal("<div style=\"color: #000\"></div>", result.ElementAt(0).Key.OuterHtml); }
public void ApplyStylesToAllElements() { var elementDictionary = new Dictionary <IElement, StyleClass>(); var tableDomObject1 = new HtmlParser().ParseDocument("<table id=\"tabletest1\" class=\"test1\" bgcolor=\"\"></table>"); var tableDomObject2 = new HtmlParser().ParseDocument("<table id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"\"></table>"); var tableDomObject3 = new HtmlParser().ParseDocument("<table id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"\"></table>"); var tableDomObject4 = new HtmlParser().ParseDocument("<table id=\"tabletest4\" class=\"test4\" bgcolor=\"\" width=\"\"></table>"); var styleClassBgColor = new StyleClass(); styleClassBgColor.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008001"); var styleClassWidth = new StyleClass(); styleClassWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px"); var styleClassHeight = new StyleClass(); styleClassHeight.Attributes["height"] = CssAttribute.FromRule("height: 10px"); var styleClassBgAndWidth = new StyleClass(); styleClassBgAndWidth.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008003"); styleClassBgAndWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px"); elementDictionary.Add(tableDomObject1.Body.FirstElementChild, styleClassBgColor); elementDictionary.Add(tableDomObject2.Body.FirstElementChild, styleClassWidth); elementDictionary.Add(tableDomObject3.Body.FirstElementChild, styleClassHeight); elementDictionary.Add(tableDomObject4.Body.FirstElementChild, styleClassBgAndWidth); var result = StyleClassApplier.ApplyAllStyles(elementDictionary); Assert.Equal("<table id=\"tabletest1\" class=\"test1\" bgcolor=\"#008001\" style=\"background-color: #008001\"></table>", result.ElementAt(0).Key.OuterHtml); Assert.Equal("<table id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"10px\" style=\"width: 10px\"></table>", result.ElementAt(1).Key.OuterHtml); Assert.Equal("<table id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"10px\" style=\"height: 10px\"></table>", result.ElementAt(2).Key.OuterHtml); Assert.Equal("<table id=\"tabletest4\" class=\"test4\" bgcolor=\"#008003\" width=\"10px\" style=\"background-color: #008003;width: 10px\"></table>", result.ElementAt(3).Key.OuterHtml); }
public void ApplyStylesToAllElements() { var elementDictionary = new Dictionary <IDomObject, StyleClass>(); var tableDomObject1 = CQ.CreateFragment("<td id=\"tabletest1\" class=\"test1\" bgcolor=\"\"></td>"); var tableDomObject2 = CQ.CreateFragment("<td id=\"tabletest2\" class=\"test2\" bgcolor=\"\" width=\"\"></td>"); var tableDomObject3 = CQ.CreateFragment("<td id=\"tabletest3\" class=\"test3\" bgcolor=\"\" height=\"\"></td>"); var tableDomObject4 = CQ.CreateFragment("<td id=\"tabletest4\" class=\"test4\" bgcolor=\"\" width=\"\"></td>"); var styleClassBgColor = new StyleClass(); styleClassBgColor.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008001"); var styleClassWidth = new StyleClass(); styleClassWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px"); var styleClassHeight = new StyleClass(); styleClassHeight.Attributes["height"] = CssAttribute.FromRule("height: 10px"); var styleClassBgAndWidth = new StyleClass(); styleClassBgAndWidth.Attributes["background-color"] = CssAttribute.FromRule("background-color: #008003"); styleClassBgAndWidth.Attributes["width"] = CssAttribute.FromRule("width: 10px"); elementDictionary.Add(tableDomObject1.FirstElement(), styleClassBgColor); elementDictionary.Add(tableDomObject2.FirstElement(), styleClassWidth); elementDictionary.Add(tableDomObject3.FirstElement(), styleClassHeight); elementDictionary.Add(tableDomObject4.FirstElement(), styleClassBgAndWidth); var result = StyleClassApplier.ApplyAllStyles(elementDictionary); Assert.AreEqual("<td class=\"test1\" style=\"background-color: #008001\" id=\"tabletest1\" bgcolor=\"#008001\"></td>", result.ElementAt(0).Key.ToString()); Assert.AreEqual("<td class=\"test2\" style=\"width: 10px\" id=\"tabletest2\" bgcolor width=\"10px\"></td>", result.ElementAt(1).Key.ToString()); Assert.AreEqual("<td class=\"test3\" style=\"height: 10px\" id=\"tabletest3\" bgcolor height=\"10px\"></td>", result.ElementAt(2).Key.ToString()); Assert.AreEqual("<td class=\"test4\" style=\"background-color: #008003;width: 10px\" id=\"tabletest4\" bgcolor=\"#008003\" width=\"10px\"></td>", result.ElementAt(3).Key.ToString()); }
public void FromRule_OnlySplitsTheRuleAtTheFirstColonToSupportUrls() { var attribute = CssAttribute.FromRule("background: url('http://my.web.site.com/Content/email/content.png') repeat-y"); Assert.AreEqual("url('http://my.web.site.com/Content/email/content.png') repeat-y", attribute.Value); }
public void NonRule_ReturnsNull() { var attribute = CssAttribute.FromRule(" "); Assert.IsNull(attribute); }