Esempio n. 1
0
        public void GetStringContent_WithInlineEditingAttribute_TextElelementProperlyCreated()
        {
            //Arrange
            var htmlProcessor = new HtmlProcessor();
            var dummyWidgetModel = new DummyWidgetModel { EditableContent = this.dummyContent, NonEditableContent = this.dummyContent };

            string fieldName = "DummyWidget";
            string type = "LongText";

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

            //Assert
            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(this.htmlWrapperTag, StringComparison.InvariantCultureIgnoreCase), "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<string>(fieldName, chunk.GetParamValue(this.fieldAttribute), "The value of the field attribute is not correct.");
                Assert.AreEqual<string>(type, chunk.GetParamValue(this.fieldTypeAttribute), "The value of the fieldType attribute is not correct.");

                this.AssertContentAndCloseTag(parser);
            }
        }
Esempio n. 2
0
        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);
            }
        }
 /// <summary>
 /// HTML helper which adds an InlineEditing region. This should be added once at the top of the page, and the whole region will support InlineEditing.
 /// </summary>
 /// <param name="htmlHelper">The HTML helper.</param>
 /// <param name="providerName">Name of the provider.</param>
 /// <param name="type">The type.</param>
 /// <param name="id">The identifier.</param>
 /// <returns></returns>
 public static HtmlRegion InlineEditingRegion(this HtmlHelper htmlHelper,
                            string providerName,
                            string type, Guid id)
 {
     var htmlProcessor = new HtmlProcessor();
     return htmlProcessor.CreateInlineEditingRegion(htmlHelper.ViewContext.Writer,
         providerName, type, id);
 }
Esempio n. 4
0
        public void CreateInlineEditingRegion_DummyContent_IsWrappedIntoInlineEditingRegion()
        {
            // Arrange: create dummy data which will be set to the related attributes inside the region div tag
            TextWriter writer = new StringWriter(System.Globalization.CultureInfo.InvariantCulture);
            var providerName = "dummyProvider";
            var type = "dummyType";
            Guid id = Guid.NewGuid();

            // Act: create the CreateInlineEditingRegion
            var htmlProcessor = new HtmlProcessor(isInlineEditing: true);

            using (htmlProcessor.CreateInlineEditingRegion(writer, providerName, type, id))
            {
                writer.WriteLine(this.dummyContent);
            }

            string 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 (var parser = new HtmlParser(outPut))
            {
                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));
                Assert.IsTrue(chunk.HasAttribute(this.idAttribute), "The id of the item is not appended as attribute correctly.");
                Assert.IsTrue(chunk.HasAttribute(this.providerAttribute), "The provider is not appended as attribute correctly.");
                Assert.IsTrue(chunk.HasAttribute(this.typeAttribute), "The id type the item is not appended as attribute correctly.");

                // checks if the required attributes has proper values assigned to them
                Assert.AreEqual(providerName, chunk.GetParamValue(this.providerAttribute), "The value of the provider attribute is not correct.");
                Assert.AreEqual(type, chunk.GetParamValue(this.typeAttribute), "The value of the provider attribute is not correct.");
                Assert.AreEqual(id.ToString(), chunk.GetParamValue(this.idAttribute), "The value of the id 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);
 }
Esempio n. 6
0
        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.");
        }
Esempio n. 7
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);
            }
        }