From 9e4384fdea65c1d8ea72026f3ed149ad249de0f6 Mon Sep 17 00:00:00 2001 From: Jamie Pollock Date: Fri, 26 Jan 2024 18:02:53 -0500 Subject: [PATCH] feat (Tests): adds tests for DefaultDropPictureImageTagHelperRenderer --- ...faultPictureImageTagHelperRendererTests.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Rhythm.Drop.Web.Tests/TagHelperRenderers/Images/DefaultPictureImageTagHelperRendererTests.cs diff --git a/tests/Rhythm.Drop.Web.Tests/TagHelperRenderers/Images/DefaultPictureImageTagHelperRendererTests.cs b/tests/Rhythm.Drop.Web.Tests/TagHelperRenderers/Images/DefaultPictureImageTagHelperRendererTests.cs new file mode 100644 index 0000000..19a287a --- /dev/null +++ b/tests/Rhythm.Drop.Web.Tests/TagHelperRenderers/Images/DefaultPictureImageTagHelperRendererTests.cs @@ -0,0 +1,46 @@ +namespace Rhythm.Drop.Web.Tests.TagHelperRenderers.Images; + +using Rhythm.Drop.Models.Images; +using Rhythm.Drop.Web.Infrastructure; +using Rhythm.Drop.Web.Infrastructure.TagHelperRenderers.Images; +using Rhythm.Drop.Web.TagHelperRenderers.Images; +using System.Threading.Tasks; + +[TestFixture] +public class DefaultPictureImageTagHelperRendererTests : TagHelperRendererTestsBase +{ + private const string ImgTagName = "img"; + + [Test] + public async Task RenderAsync_With_Valid_Image_Should_Return_Output_With_Modified_Content() + { + // arrange + var tagHelperRenderer = new DefaultDropPictureTagHelperRenderer(); + var image = new Image("/image.gif", "Test", 200, 200); + var rendererContext = new DropImageTagHelperRendererContext(image, LoadingMode.Default); + var context = CreateTagHelperContext(ImgTagName); + var output = CreateTagHelperOutput(ImgTagName); + + await tagHelperRenderer.RenderAsync(rendererContext, context, output); + + Assert.That(output.IsContentModified, Is.True); + } + + [Test] + public async Task RenderAsync_With_No_Valid_Image_Should_Return_Output_With_Suppressed_Content() + { + // arrange + var tagHelperRenderer = new DefaultDropPictureTagHelperRenderer(); + var rendererContext = new DropImageTagHelperRendererContext(default, LoadingMode.Default); + var context = CreateTagHelperContext(ImgTagName); + var output = CreateTagHelperOutput(ImgTagName); + + await tagHelperRenderer.RenderAsync(rendererContext, context, output); + + Assert.Multiple(() => + { + Assert.That(output.TagName, Is.Default); + Assert.That(output.Content.IsEmptyOrWhiteSpace, Is.True); + }); + } +}