/// <summary>
        /// Initialises a new instance of <see cref="ContentWidgetResult"/>.
        /// </summary>
        /// <param name="encodedContent"></param>
        public ContentWidgetResult(HtmlString encodedContent)
        {
            if (encodedContent == null)
            {
                throw new ArgumentNullException(nameof(encodedContent));
            }

            EncodedContent = encodedContent;
            Content = WebUtility.HtmlDecode(encodedContent.ToString());
        }
Ejemplo n.º 2
0
        public void FromEncodedText_DoesNotEncodeOnWrite()
        {
            // Arrange
            var expectedText = "Hello";

            // Act
            var content = new HtmlString(expectedText);

            // Assert
            Assert.Equal(expectedText, content.ToString());
        }
Ejemplo n.º 3
0
        public void FromEncodedText_DoesNotEncodeOnWrite()
        {
            // Arrange
            var expectedText = "Hello";

            // Act
            var content = new HtmlString(expectedText);

            // Assert
            Assert.Equal(expectedText, content.ToString());
        }
Ejemplo n.º 4
0
        public void ToString_ReturnsText()
        {
            // Arrange
            var expectedText = "Hello";
            var content = new HtmlString(expectedText);

            // Act
            var result = content.ToString();

            // Assert
            Assert.Equal(expectedText, result);
        }
Ejemplo n.º 5
0
        public void ToString_ReturnsText()
        {
            // Arrange
            var expectedText = "Hello";
            var content      = new HtmlString(expectedText);

            // Act
            var result = content.ToString();

            // Assert
            Assert.Equal(expectedText, result);
        }
        private void Verify(HtmlString html, string src, string alt)
        {
            var doc = new XmlDocument();
            doc.LoadXml(html.ToString());

            Assert.Equal(1, doc.ChildNodes.Count);

            var node = doc.ChildNodes.Item(0);

            Assert.Equal("img", node.Name);

            var srcNode = node.Attributes.GetNamedItem("src");

            Assert.NotNull(srcNode);
            Assert.Equal("src", srcNode.Name);
            Assert.Equal(src, srcNode.Value);

            var altNode = node.Attributes.GetNamedItem("alt");

            if (!string.IsNullOrWhiteSpace(alt))
            {
                Assert.NotNull(altNode);
                Assert.Equal("alt", altNode.Name);
                Assert.Equal(alt, altNode.Value);
            }
            else
            {
                Assert.Null(altNode);
            }
        }
        private void VerifyContentLinks(HtmlString html, string path, ContentLinkType contentType, ILookup<string, string> lookup)
        {
            var xmlDoc = new XmlDocument();
            var doc = xmlDoc.CreateDocumentFragment();

            doc.InnerXml = html.ToString();

            var childNodes = doc.ChildNodes.Cast<XmlNode>().Where(n => !(n is XmlWhitespace)).ToList();
            var expectedList = lookup[path];

            Assert.Equal(expectedList.Count(), childNodes.Count);

            foreach (var pair in childNodes.Zip(expectedList, Tuple.Create))
            {
                var node = pair.Item1;
                var expected = pair.Item2;

                if (contentType == ContentLinkType.Javascript)
                {
                    Assert.Equal("script", node.Name);
                    Assert.Equal(2, node.Attributes.Count);

                    Assert.Equal("text/javascript", node.Attributes.GetNamedItem("type").Value);
                    Assert.Equal(expected, node.Attributes.GetNamedItem("src").Value);
                }
                else
                {
                    Assert.Equal("link", node.Name);
                    Assert.Equal(2, node.Attributes.Count);

                    Assert.Equal("stylesheet", node.Attributes.GetNamedItem("rel").Value);
                    Assert.Equal(expected, node.Attributes.GetNamedItem("href").Value);
                }
            }
        }
        public void Process_DoesNotResolveNonTildeSlashValues_InHtmlString(HtmlString url)
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
                {
                    { "href", url }
                },
                getChildContentAsync: _ => Task.FromResult<TagHelperContent>(null));
            var urlHelperMock = new Mock<IUrlHelper>();
            urlHelperMock
                .Setup(urlHelper => urlHelper.Content(It.IsAny<string>()))
                .Returns("approot/home/index.html");
            var urlHelperFactory = new Mock<IUrlHelperFactory>();
            urlHelperFactory
                .Setup(f => f.GetUrlHelper(It.IsAny<ActionContext>()))
                .Returns(urlHelperMock.Object);
            var tagHelper = new UrlResolutionTagHelper(urlHelperFactory.Object, new HtmlTestEncoder());

            var context = new TagHelperContext(
                allAttributes: new ReadOnlyTagHelperAttributeList<IReadOnlyTagHelperAttribute>(
                    Enumerable.Empty<IReadOnlyTagHelperAttribute>()),
                items: new Dictionary<object, object>(),
                uniqueId: "test");

            // Act
            tagHelper.Process(context, tagHelperOutput);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);
            Assert.Equal("href", attribute.Name, StringComparer.Ordinal);
            var attributeValue = Assert.IsType<HtmlString>(attribute.Value);
            Assert.Equal(url.ToString(), attributeValue.ToString(), StringComparer.Ordinal);
            Assert.False(attribute.Minimized);
        }