public void GetStringContent_WithInlineEditingAttribute_TextElementProperlyCreated()
        {
            // Arrange
            var htmlProcessor = new HtmlProcessor();
            var dummyWidgetModel = new DummyWidgetModel { EditableContent = this.dummyContent, NonEditableContent = this.dummyContent };

            var fieldName = "DummyWidget";
            var type = "LongText";

            // Act
            string inlineeditingAwareContent = htmlProcessor.GetStringContent(dummyWidgetModel, "EditableContent");

            // Assert
            using (var parser = new HtmlParser(inlineeditingAwareContent))
            {
                HtmlChunk 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(this.htmlWrapperTag, StringComparison.Ordinal), "There is no wrapper div appended to the property representation.");
                Assert.IsTrue(chunk.HasAttribute(this.fieldAttribute), "The field attribute is not appended correctly.");
                Assert.IsTrue(chunk.HasAttribute(this.fieldTypeAttribute), "The field type attribute is not appended correctly.");

                // checks if the required attributes has proper values assigned to them
                Assert.AreEqual(fieldName, chunk.GetParamValue(this.fieldAttribute), "The value of the field attribute is not correct.");
                Assert.AreEqual(type, chunk.GetParamValue(this.fieldTypeAttribute), "The value of the fieldType attribute is not correct.");

                this.AssertContentAndCloseTag(parser);
            }
        }
 /// <summary>
 /// HTML helper which adds the meta data required by InlineEditing.
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="model">The object which contains the property.</param>
 /// <param name="propName">Name of the property.</param>
 /// <returns></returns>
 public static IHtmlString TextField(this HtmlHelper helper, object model, string propName)
 {
     var htmlProcessor = new HtmlProcessor();
     var htmlString = htmlProcessor.GetStringContent(model, propName);
     return new System.Web.Mvc.MvcHtmlString(htmlString);
 }
        public void GetStringContent_WithoutInlineEditingAttribute_PreservesContent()
        {
            // Arrange
            var htmlProcessor = new HtmlProcessor();
            var dummyWidgetModel = new DummyWidgetModel { EditableContent = this.dummyContent, NonEditableContent = this.dummyContent };

            // Act
            var nonInlineeditingAwareContent = htmlProcessor.GetStringContent(dummyWidgetModel, "NonEditableContent");

            // Assert
            Assert.AreEqual(this.dummyContent, nonInlineeditingAwareContent, "The content is not preserved correctly.");
        }
Example #4
0
        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);
            }
        }