public async Task AltTextShouldNotBeOverWrittenIfSet()
        {
            //Arrange
            var clientMock = new Mock <IContentfulClient>();
            var tagHelper  = new ContentfulImageTagHelper(clientMock.Object);

            tagHelper.Asset = new Core.Models.Asset()
            {
                Description = "Banana",
                File        = new Core.Models.File()
                {
                    Url = "https://robertlinde.se"
                }
            };

            var context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), "test");
            var output  = new TagHelperOutput("img", new TagHelperAttributeList()
            {
                new TagHelperAttribute("alt", "alt text")
            }, (b, c) => {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent(string.Empty);
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            //Act
            await tagHelper.ProcessAsync(context, output);

            //Assert
            Assert.Equal("https://robertlinde.se", tagHelper.Url);
            Assert.Equal("alt text", output.Attributes["alt"].Value);
        }
        public async Task SrcSetShouldBePresentIfThereAreSources()
        {
            //Arrange
            var clientMock = new Mock <IContentfulClient>();
            var tagHelper  = new ContentfulImageTagHelper(clientMock.Object);

            tagHelper.Asset = new Core.Models.Asset()
            {
                File = new Core.Models.File()
                {
                    Url = "https://robertlinde.se"
                }
            };

            var context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), "test");
            var output  = new TagHelperOutput("img", new TagHelperAttributeList(), async(b, c) => {
                var childSource   = new ContentfulSource(clientMock.Object);
                childSource.Width = 500;
                await childSource.ProcessAsync(context, new TagHelperOutput("div", new TagHelperAttributeList(), (x, y) => { return(null); }));
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent(string.Empty);
                return(tagHelperContent);
            });

            //Act
            await tagHelper.ProcessAsync(context, output);

            //Assert
            Assert.Equal("https://robertlinde.se", tagHelper.Url);
            Assert.Equal("https://robertlinde.se?w=500 500w", output.Attributes["srcset"].Value);
        }
        public async Task JpgSpecificValuesShouldBeSetForJpgAssetWithFormat()
        {
            //Arrange
            var clientMock = new Mock <IContentfulClient>();
            var tagHelper  = new ContentfulImageTagHelper(clientMock.Object);

            tagHelper.Asset = new Core.Models.Asset()
            {
                Description = "Banana",
                File        = new Core.Models.File()
                {
                    Url         = "https://robertlinde.se",
                    ContentType = "image/png"
                }
            };

            tagHelper.JpgQuality     = 45;
            tagHelper.ProgressiveJpg = true;
            tagHelper.Format         = Core.Images.ImageFormat.Jpg;
            tagHelper.Width          = 50;

            var context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), "test");
            var output  = new TagHelperOutput("img", new TagHelperAttributeList(), (b, c) => {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent(string.Empty);
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            });

            //Act
            await tagHelper.ProcessAsync(context, output);

            //Assert
            Assert.Equal("https://robertlinde.se", tagHelper.Url);
            Assert.Equal("https://robertlinde.se?w=50&q=45&fm=jpg&fl=progressive", output.Attributes["src"].Value);
        }