public void WhenGravatarNameIsDisplayed()
        {
            //Arrange
            context = new TagHelperContextBuilder()
                      .AddAttribute("data-gravatar-name", "")
                      .Build();
            output            = new TagHelperOutputBuilder("strong").Build();
            gravatarTagHelper = new GravatarTagHelper(Cache, mockGravatar.Object);

            //Act
            gravatarTagHelper.ProcessAsync(context, output).Wait();

            //Assert
            output.Content.GetContent().ShouldBe("name");
        }
        public void WhenGravatarNameHashIsInCache()
        {
            //Arrange
            context = new TagHelperContextBuilder()
                      .AddAttribute("data-gravatar-name", "")
                      .Build();
            output            = new TagHelperOutputBuilder("strong").Build();
            gravatarTagHelper = new GravatarTagHelper(Cache, mockGravatar.Object);

            //Act
            gravatarTagHelper.ProcessAsync(context, output).Wait();
            gravatarTagHelper.ProcessAsync(context, output).Wait();


            //Assert
            mockGravatar.Verify(g => g.GetGravatarName(It.IsAny <string>()), Times.Once);
        }
        public void WhenGravatarImageIsDisplayed()
        {
            //Arrange
            context = new TagHelperContextBuilder()
                      .AddAttribute("data-gravatar-image", "")
                      .Build();
            output            = new TagHelperOutputBuilder("img").Build();
            gravatarTagHelper = new GravatarTagHelper(Cache, mockGravatar.Object);

            //Act
            gravatarTagHelper.ProcessAsync(context, output).Wait();

            //Assert
            var outputSrcValue = output.Attributes[output.Attributes.IndexOfName("src")];

            outputSrcValue.Value.ShouldBe("image");
        }
        public async Task TestTagHelper()
        {
            var config    = new GravatarTagHelperConfiguration();
            var tagHelper = new GravatarTagHelper(config);

            var ctx = new TagHelperContext(
                new TagHelperAttributeList {
                { "size", "80" },
                { "alt", new HtmlString("Testing") }
            },
                new Dictionary <object, object>(),
                Guid.NewGuid().ToString("N")
                );

            var output = new TagHelperOutput(
                "gravatar",
                new TagHelperAttributeList(), (useCachedResult, htmlEncoder) =>
            {
                var tagHelperContent = new DefaultTagHelperContent();
                tagHelperContent.SetContent("*****@*****.**");
                return(Task.FromResult <TagHelperContent>(tagHelperContent));
            }
                );

            tagHelper.Alt  = "hi";
            tagHelper.Size = 80;

            using (var httpTest = new HttpTest())
            {
                var fullJson = File.ReadAllText("proper-gravatar.json");
                httpTest.RespondWith(fullJson, status: 200);
                await tagHelper.ProcessAsync(ctx, output);
            }


            Output.WriteLine($"Tag is {output.TagName}");
            Assert.Equal("img", output.TagName);
            Assert.Contains("s=80", output.Attributes["src"].Value.ToString());
            Assert.Equal("hi", output.Attributes["alt"].Value.ToString());
        }