public void HtmlProcessor_CreateInlineEditingRegion_IsDummyContentwrappedIntoInlineEditingRegion() { //Arrange: create dummy data which will be set to the related attributes inside the region div tag TextWriter writer = new StringWriter(); string providerName = "dummyProvider"; string type = "dummyType"; var id = Guid.NewGuid(); string dummyContent = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit"; var providerAttribute = "data-sf-provider"; var typeAttribute = "data-sf-type"; var idAttribute = "data-sf-id"; //Act: create the HTML region var htmlProcessor = new HtmlProcessor(); using (htmlProcessor.CreateInlineEditingRegion(writer, providerName, type, id)) { writer.WriteLine(dummyContent); } var outPut = writer.ToString(); //Assert: Parses the generated by the htmlTransformationProxy HTML checks if the HTML content is properly wrapped into a div tag //which has the required by the InlineEditing attributes //and these attributes has a proper data assigned using (HtmlParser parser = new HtmlParser(outPut)) { var chunk = parser.ParseNext(); Assert.IsNotNull(chunk); //checks if the HTML tag is of type div and if it has the required attributes Assert.IsTrue(chunk.TagName.Equals("div", StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(chunk.HasAttribute(idAttribute)); Assert.IsTrue(chunk.HasAttribute(providerAttribute)); Assert.IsTrue(chunk.HasAttribute(typeAttribute)); //checks if the required attributes has proper values assigned to them Assert.AreEqual <string>(providerName, chunk.GetParamValue(providerAttribute)); Assert.AreEqual <string>(type, chunk.GetParamValue(typeAttribute)); Assert.AreEqual <string>(id.ToString(), chunk.GetParamValue(idAttribute)); string content = null; HtmlChunk nextChunk = null; while ((nextChunk = parser.ParseNext()) != null) { chunk = nextChunk; if (nextChunk.Type == HtmlChunkType.Text) { content = nextChunk.GenerateHtml(); } } //checks if the region inner content is what it should be Assert.IsTrue(content.StartsWith(dummyContent, StringComparison.InvariantCultureIgnoreCase)); //checks if the region is properly closed Assert.IsTrue(chunk.TagName.Equals("div", StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(chunk.Type == HtmlChunkType.CloseTag); } }
public void HtmlProcessor_GetText_TextElelementProperlyCreatedForInlineEditng() { string dummyContent = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit"; var htmlProcessor = new HtmlProcessor(); var dummyWidgetModel = new DummyWidgetModel { EditableContent = dummyContent, NonEditableContent = dummyContent }; string fieldName = "DummyWidget"; string type = "LongText"; var fieldAttribute = "data-sf-field"; var typeAttribute = "data-sf-ftype"; var inlineeditingAwareContent = htmlProcessor.GetStringContent(dummyWidgetModel, "EditableContent"); var nonInlineeditingAwareContent = htmlProcessor.GetStringContent(dummyWidgetModel, "NonEditableContent"); Assert.AreEqual <string>(dummyContent, nonInlineeditingAwareContent); using (HtmlParser parser = new HtmlParser(inlineeditingAwareContent)) { var chunk = parser.ParseNext(); Assert.IsNotNull(chunk); //checks if the HTML tag is of type div and if it has the required attributes Assert.IsTrue(chunk.TagName.Equals("div", StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(chunk.HasAttribute(fieldAttribute)); Assert.IsTrue(chunk.HasAttribute(typeAttribute)); //checks if the required attributes has proper values assigned to them Assert.AreEqual <string>(fieldName, chunk.GetParamValue(fieldAttribute)); Assert.AreEqual <string>(type, chunk.GetParamValue(typeAttribute)); string content = null; HtmlChunk nextChunk = null; while ((nextChunk = parser.ParseNext()) != null) { chunk = nextChunk; if (nextChunk.Type == HtmlChunkType.Text) { content = nextChunk.GenerateHtml(); } } //checks if the region inner content is what it should be Assert.IsTrue(content.StartsWith(dummyContent, StringComparison.InvariantCultureIgnoreCase)); //checks if the region is properly closed Assert.IsTrue(chunk.TagName.Equals("div", StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(chunk.Type == HtmlChunkType.CloseTag); } }
public void HtmlRegion_CreateFakeHtmlContentInRegion_IsRegionproperlyClosed() { //Arrange: create text writer and dummy content TextWriter writer = new StringWriter(); string dummyContent = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit"; //the HTML tag which must be used as a region wrapper must be of type - div string htmlWrapperTag = "div"; string dummyHtmlContent = string.Format("<{0}>{1}", htmlWrapperTag, dummyContent); //Act: create the HTML region using (new HtmlRegion(writer, htmlWrapperTag)) { writer.WriteLine(dummyHtmlContent); } var outPut = writer.ToString(); //Assert: Parses the generated by the HtmlRegion HTML checks if the HTML content is properly wrapped into a region and if this region is properly closed using (HtmlParser parser = new HtmlParser(outPut)) { var chunk = parser.ParseNext(); Assert.IsNotNull(chunk); //checks if the HTML tag is of type div Assert.IsTrue(chunk.TagName.Equals(htmlWrapperTag, StringComparison.InvariantCultureIgnoreCase)); string content = null; HtmlChunk nextChunk = null; while ((nextChunk = parser.ParseNext()) != null) { chunk = nextChunk; if (nextChunk.Type == HtmlChunkType.Text) { content = nextChunk.GenerateHtml(); } } //checks if the region inner content is what it should be Assert.IsTrue(content.Contains(dummyContent)); //checks if the region is properly closed Assert.IsTrue(chunk.TagName.Equals(htmlWrapperTag, StringComparison.InvariantCultureIgnoreCase)); Assert.IsTrue(chunk.Type == HtmlChunkType.CloseTag); } }
/// <summary> /// Asserts if the content is preserved and whether expected close tag is available. /// </summary> /// <param name="parser"> /// The parser. /// </param> private void AssertContentAndCloseTag(HtmlParser parser) { string content = null; HtmlChunk chunk = null; HtmlChunk nextChunk = null; while ((nextChunk = parser.ParseNext()) != null) { chunk = nextChunk; if (nextChunk.Type == HtmlChunkType.Text) { content = nextChunk.GenerateHtml(); } } Assert.IsTrue(content.StartsWith(this.dummyContent, StringComparison.Ordinal), "The inner content is not preserved correctly."); Assert.IsTrue(chunk.TagName.Equals(this.htmlWrapperTag, StringComparison.Ordinal), "The last tag is not div."); Assert.IsTrue(chunk.Type == HtmlChunkType.CloseTag, "The last tag is not closing tag."); }
/// <summary> /// Asserts if the content is preserved and whether expected close tag is available. /// </summary> /// <param name="parser">The parser.</param> private void AssertContentAndCloseTag(HtmlParser parser) { string content = null; HtmlChunk chunk = null; HtmlChunk nextChunk = null; while ((nextChunk = parser.ParseNext()) != null) { chunk = nextChunk; if (nextChunk.Type == HtmlChunkType.Text) { content = nextChunk.GenerateHtml(); } } Assert.IsTrue(content.StartsWith(dummyContent, StringComparison.InvariantCultureIgnoreCase), "The inner content is not preserved correctly."); //checks if the region is properly closed Assert.IsTrue(chunk.TagName.Equals(this.htmlWrapperTag, StringComparison.InvariantCultureIgnoreCase), "The last tag is not div."); Assert.IsTrue(chunk.Type == HtmlChunkType.CloseTag, "The last tag is not closing tag."); }
/// <summary> /// Processes the layout string adding the required attributes to the head tag /// and also adding the required form tag. /// </summary> /// <param name="template">The template.</param> /// <returns></returns> public virtual string ProcessLayoutString(string template) { var includeFormTag = this.IsFormTagRequired(); StringBuilder outPut = new StringBuilder(); HtmlChunk chunk = null; using (HtmlParser parser = new HtmlParser(template)) { parser.SetChunkHashMode(false); parser.AutoExtractBetweenTagsOnly = false; parser.CompressWhiteSpaceBeforeTag = false; parser.KeepRawHTML = true; bool setTitle = true; bool modified; bool isOpenBodyTag; bool isCloseBodyTag; bool isClosedHeadTag; while ((chunk = parser.ParseNext()) != null) { modified = false; isOpenBodyTag = false; isCloseBodyTag = false; isClosedHeadTag = false; if (chunk.Type == HtmlChunkType.OpenTag) { if (chunk.TagName.Equals("head", StringComparison.OrdinalIgnoreCase)) { if (!chunk.HasAttribute("runat")) { chunk.SetAttribute("runat", "server"); modified = true; } } else if (chunk.TagName.Equals("body", StringComparison.OrdinalIgnoreCase)) { isOpenBodyTag = true; } else if (chunk.TagName.Equals("title", StringComparison.OrdinalIgnoreCase)) { setTitle = false; } } else if (chunk.Type == HtmlChunkType.CloseTag) { if (chunk.TagName.Equals("body", StringComparison.OrdinalIgnoreCase)) { isCloseBodyTag = true; } if (chunk.TagName.Equals("head", StringComparison.OrdinalIgnoreCase)) { isClosedHeadTag = true; } } if (includeFormTag && isCloseBodyTag) { outPut.Append("</form>"); } else if (!includeFormTag && isClosedHeadTag) { this.AppendRequiredHeaderContent(outPut, setTitle); } if (modified) { outPut.Append(chunk.GenerateHtml()); } else { outPut.Append(chunk.Html); } if (includeFormTag && isOpenBodyTag) { outPut.Append("<form runat='server'>"); } } } return(outPut.ToString()); }