示例#1
0
        public void Process_DoesNotResolveNonTildeSlashValues(object url)
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
            {
                { "href", url }
            });
            var urlHelperMock = new Mock <IUrlHelper>();

            urlHelperMock
            .Setup(urlHelper => urlHelper.Content(It.IsAny <string>()))
            .Returns("approot/home/index.html");
            var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, htmlEncoder: null);

            // Act
            tagHelper.Process(context: null, output: tagHelperOutput);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);

            Assert.Equal("href", attribute.Name, StringComparer.Ordinal);
            Assert.Equal(url, attribute.Value);
            Assert.False(attribute.Minimized);
        }
示例#2
0
        public void Process_ThrowsWhenEncodingNeededAndIUrlHelperActsUnexpectedly()
        {
            // Arrange
            var relativeUrl = "~/home/index.html";
            var expectedExceptionMessage = Resources.FormatCouldNotResolveApplicationRelativeUrl_TagHelper(
                relativeUrl,
                nameof(IUrlHelper),
                nameof(IUrlHelper.Content),
                "removeTagHelper",
                typeof(UrlResolutionTagHelper).FullName,
                typeof(UrlResolutionTagHelper).GetTypeInfo().Assembly.GetName().Name);
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
            {
                { "href", new HtmlString(relativeUrl) }
            });
            var urlHelperMock = new Mock <IUrlHelper>();

            urlHelperMock
            .Setup(urlHelper => urlHelper.Content(It.IsAny <string>()))
            .Returns("UnexpectedResult");
            var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, htmlEncoder: null);

            // Act & Assert
            var exception = Assert.Throws <InvalidOperationException>(
                () => tagHelper.Process(context: null, output: tagHelperOutput));

            Assert.Equal(expectedExceptionMessage, exception.Message, StringComparer.Ordinal);
        }
示例#3
0
        public void Process_ResolvesTildeSlashValues(object url, object expectedHref)
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
            {
                { "href", url }
            });
            var urlHelperMock = new Mock <IUrlHelper>();

            urlHelperMock
            .Setup(urlHelper => urlHelper.Content(It.IsAny <string>()))
            .Returns(new Func <string, string>(value => "/approot" + value.Substring(1)));
            var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, new TestHtmlEncoder());

            // Act
            tagHelper.Process(context: null, output: tagHelperOutput);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);

            Assert.Equal("href", attribute.Name, StringComparer.Ordinal);
            Assert.IsType(expectedHref.GetType(), url);
            Assert.Equal(expectedHref.ToString(), attribute.Value.ToString());
            Assert.False(attribute.Minimized);
        }
示例#4
0
        public void Process_ResolvesTildeSlashValues(object url, object expectedHref)
        {
            // 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(new Func <string, string>(value => "/approot" + value.Substring(1)));
            var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, new TestHtmlEncoder());

            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);
            Assert.IsType(expectedHref.GetType(), url);
            Assert.Equal(expectedHref.ToString(), attribute.Value.ToString());
            Assert.False(attribute.Minimized);
        }
        public void Process_ResolvesTildeSlashValues(object url, object expectedHref)
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
                {
                    { "href", url }
                });
            var urlHelperMock = new Mock<IUrlHelper>();
            urlHelperMock
                .Setup(urlHelper => urlHelper.Content(It.IsAny<string>()))
                .Returns(new Func<string, string>(value => "/approot" + value.Substring(1)));
            var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, new TestHtmlEncoder());

            // Act
            tagHelper.Process(context: null, output: tagHelperOutput);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);
            Assert.Equal("href", attribute.Name, StringComparer.Ordinal);
            Assert.IsType(expectedHref.GetType(), url);
            Assert.Equal(expectedHref.ToString(), attribute.Value.ToString());
            Assert.False(attribute.Minimized);
        }
示例#6
0
        public void Process_DoesNotResolveNonTildeSlashValues(object 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 tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, htmlEncoder: null);

            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);
            Assert.Equal(url, attribute.Value);
            Assert.False(attribute.Minimized);
        }
示例#7
0
        public void Process_IgnoresNonHtmlStringOrStringValues()
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
            {
                { "href", true }
            },
                getChildContentAsync: _ => Task.FromResult <TagHelperContent>(null));
            var tagHelper = new UrlResolutionTagHelper(urlHelper: null, htmlEncoder: null);

            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);
            Assert.Equal(true, attribute.Value);
            Assert.False(attribute.Minimized);
        }
        public void Process_ResolvesTildeSlashValues(object url, object expectedHref)
        {
            // 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(new Func<string, string>(value => "/approot" + value.Substring(1)));
            var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, new TestHtmlEncoder());

            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);
            Assert.IsType(expectedHref.GetType(), url);
            Assert.Equal(expectedHref.ToString(), attribute.Value.ToString());
            Assert.False(attribute.Minimized);
        }
        public void Process_ThrowsWhenEncodingNeededAndIUrlHelperActsUnexpectedly()
        {
            // Arrange
            var relativeUrl = "~/home/index.html";
            var expectedExceptionMessage = Resources.FormatCouldNotResolveApplicationRelativeUrl_TagHelper(
                relativeUrl,
                nameof(IUrlHelper),
                nameof(IUrlHelper.Content),
                "removeTagHelper",
                typeof(UrlResolutionTagHelper).FullName,
                typeof(UrlResolutionTagHelper).GetTypeInfo().Assembly.GetName().Name);
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
            {
                { "href", new HtmlString(relativeUrl) }
            },
                getChildContentAsync: _ => Task.FromResult <TagHelperContent>(null));
            var urlHelperMock = new Mock <IUrlHelper>();

            urlHelperMock
            .Setup(urlHelper => urlHelper.Content(It.IsAny <string>()))
            .Returns("UnexpectedResult");
            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 & Assert
            var exception = Assert.Throws <InvalidOperationException>(
                () => tagHelper.Process(context, tagHelperOutput));

            Assert.Equal(expectedExceptionMessage, exception.Message, StringComparer.Ordinal);
        }
示例#10
0
        public void Process_IgnoresNonHtmlStringOrStringValues()
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
            {
                { "href", true }
            });
            var tagHelper = new UrlResolutionTagHelper(urlHelper: null, htmlEncoder: null);

            // Act
            tagHelper.Process(context: null, output: tagHelperOutput);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);

            Assert.Equal("href", attribute.Name, StringComparer.Ordinal);
            Assert.Equal(true, attribute.Value);
            Assert.False(attribute.Minimized);
        }
        public void Process_DoesNotResolveNonTildeSlashValues(object url)
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
                {
                    { "href", url }
                });
            var urlHelperMock = new Mock<IUrlHelper>();
            urlHelperMock
                .Setup(urlHelper => urlHelper.Content(It.IsAny<string>()))
                .Returns("approot/home/index.html");
            var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, htmlEncoder: null);

            // Act
            tagHelper.Process(context: null, output: tagHelperOutput);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);
            Assert.Equal("href", attribute.Name, StringComparer.Ordinal);
            Assert.Equal(url, attribute.Value);
            Assert.False(attribute.Minimized);
        }
        public void Process_ThrowsWhenEncodingNeededAndIUrlHelperActsUnexpectedly()
        {
            // Arrange
            var relativeUrl = "~/home/index.html";
            var expectedExceptionMessage = Resources.FormatCouldNotResolveApplicationRelativeUrl_TagHelper(
                relativeUrl,
                nameof(IUrlHelper),
                nameof(IUrlHelper.Content),
                "removeTagHelper",
                typeof(UrlResolutionTagHelper).FullName,
                typeof(UrlResolutionTagHelper).GetTypeInfo().Assembly.GetName().Name);
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
                {
                    { "href", new HtmlString(relativeUrl) }
                });
            var urlHelperMock = new Mock<IUrlHelper>();
            urlHelperMock
                .Setup(urlHelper => urlHelper.Content(It.IsAny<string>()))
                .Returns("UnexpectedResult");
            var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, htmlEncoder: null);

            // Act & Assert
            var exception = Assert.Throws<InvalidOperationException>(
                () => tagHelper.Process(context: null, output: tagHelperOutput));
            Assert.Equal(expectedExceptionMessage, exception.Message, StringComparer.Ordinal);
        }
        public void Process_IgnoresNonHtmlStringOrStringValues()
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
                {
                    { "href", true }
                });
            var tagHelper = new UrlResolutionTagHelper(urlHelper: null, htmlEncoder: null);

            // Act
            tagHelper.Process(context: null, output: tagHelperOutput);

            // Assert
            var attribute = Assert.Single(tagHelperOutput.Attributes);
            Assert.Equal("href", attribute.Name, StringComparer.Ordinal);
            Assert.Equal(true, attribute.Value);
            Assert.False(attribute.Minimized);
        }
        public void Process_ThrowsWhenEncodingNeededAndIUrlHelperActsUnexpectedly()
        {
            // Arrange
            var relativeUrl = "~/home/index.html";
            var expectedExceptionMessage = Resources.FormatCouldNotResolveApplicationRelativeUrl_TagHelper(
                relativeUrl,
                nameof(IUrlHelper),
                nameof(IUrlHelper.Content),
                "removeTagHelper",
                typeof(UrlResolutionTagHelper).FullName,
                typeof(UrlResolutionTagHelper).GetTypeInfo().Assembly.GetName().Name);
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
                {
                    { "href", new HtmlString(relativeUrl) }
                },
                getChildContentAsync: _ => Task.FromResult<TagHelperContent>(null));
            var urlHelperMock = new Mock<IUrlHelper>();
            urlHelperMock
                .Setup(urlHelper => urlHelper.Content(It.IsAny<string>()))
                .Returns("UnexpectedResult");
            var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, htmlEncoder: null);

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

            // Act & Assert
            var exception = Assert.Throws<InvalidOperationException>(
                () => tagHelper.Process(context, tagHelperOutput));
            Assert.Equal(expectedExceptionMessage, exception.Message, StringComparer.Ordinal);
        }
        public void Process_IgnoresNonHtmlStringOrStringValues()
        {
            // Arrange
            var tagHelperOutput = new TagHelperOutput(
                tagName: "a",
                attributes: new TagHelperAttributeList
                {
                    { "href", true }
                },
                getChildContentAsync: _ => Task.FromResult<TagHelperContent>(null));
            var tagHelper = new UrlResolutionTagHelper(urlHelper: null, htmlEncoder: null);

            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);
            Assert.Equal(true, attribute.Value);
            Assert.False(attribute.Minimized);
        }
        public void Process_DoesNotResolveNonTildeSlashValues(object 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 tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, htmlEncoder: null);

            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);
            Assert.Equal(url, attribute.Value);
            Assert.False(attribute.Minimized);
        }