Skip to content

Commit

Permalink
chore (Tests): consolidate test logic into parent class
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiepollock committed Feb 7, 2024
1 parent ad778d1 commit 6c19101
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
namespace Rhythm.Drop.Web.Tests.TagHelperRenderers.Components;

using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Moq;
using Rhythm.Drop.Web.Factories.MetaData;
using Rhythm.Drop.Web.Infrastructure.Factories.MetaData;
using Rhythm.Drop.Web.Infrastructure.Helpers.Rendering;
using Rhythm.Drop.Web.Infrastructure.MetaData;
using Rhythm.Drop.Web.Infrastructure.TagHelperRenderers.Components;
using Rhythm.Drop.Web.TagHelperRenderers.Components;
using System.Threading.Tasks;

public abstract class DefaultDropComponentTagHelperRendererTestsBase : TagHelperRendererTestsBase
{
protected const string DefaultTheme = "Default";



protected static IRenderingHelper CreateRenderingHelper()
{
return CreateRenderingHelper(new HtmlString("<div>Test</div>"));
}

protected static IRenderingHelper CreateRenderingHelper(IHtmlContent htmlContent)
{
var mock = new Mock<IRenderingHelper>();
mock.Setup(x => x.RenderAsync(It.IsAny<ComponentMetaData>())).Returns(Task.FromResult(htmlContent));

return mock.Object;
}

protected static IComponentMetaDataFactory CreateComponentMetaDataFactory()
{
return new DefaultComponentMetaDataFactory();
Expand All @@ -41,9 +18,4 @@ protected static IDropComponentsTagHelperRenderer CreateDefaultDropComponentsTag
var renderingHelper = CreateRenderingHelper();
return new DefaultDropComponentsTagHelperRenderer(componentMetaDataFactory, renderingHelper);
}

protected static ViewContext CreateViewContext()
{
return Mock.Of<ViewContext>();
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
namespace Rhythm.Drop.Web.Tests.TagHelperRenderers.Elements;

using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Moq;
using Rhythm.Drop.Web.Factories.MetaData;
using Rhythm.Drop.Web.Infrastructure.Factories.MetaData;
using Rhythm.Drop.Web.Infrastructure.Helpers.Rendering;
using Rhythm.Drop.Web.Infrastructure.MetaData;
using Rhythm.Drop.Web.Infrastructure.TagHelperRenderers.Elements;
using Rhythm.Drop.Web.TagHelperRenderers.Elements;
using System.Threading.Tasks;

public abstract class DefaultDropElementTagHelperRendererTestsBase : TagHelperRendererTestsBase
{
protected const string DefaultTheme = "Default";



protected static IRenderingHelper CreateRenderingHelper()
{
return CreateRenderingHelper(new HtmlString("<div>Test</div>"));
}

protected static IRenderingHelper CreateRenderingHelper(IHtmlContent htmlContent)
{
var mock = new Mock<IRenderingHelper>();
mock.Setup(x => x.RenderAsync(It.IsAny<ElementMetaData>())).Returns(Task.FromResult(htmlContent));

return mock.Object;
}

protected static IElementMetaDataFactory CreateElementMetaDataFactory()
{
return new DefaultElementMetaDataFactory();
Expand All @@ -41,9 +18,4 @@ protected static IDropElementsTagHelperRenderer CreateDefaultDropElementsTagHelp
var renderingHelper = CreateRenderingHelper();
return new DefaultDropElementsTagHelperRenderer(elementMetaDataFactory, renderingHelper);
}

protected static ViewContext CreateViewContext()
{
return Mock.Of<ViewContext>();
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
namespace Rhythm.Drop.Web.Tests.TagHelperRenderers.Modals;

using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Moq;
using Rhythm.Drop.Web.Factories.MetaData;
using Rhythm.Drop.Web.Infrastructure.Factories.MetaData;
using Rhythm.Drop.Web.Infrastructure.Helpers.Rendering;
using Rhythm.Drop.Web.Infrastructure.MetaData;
using Rhythm.Drop.Web.Infrastructure.TagHelperRenderers.Modals;
using Rhythm.Drop.Web.TagHelperRenderers.Modals;
using System.Threading.Tasks;

public abstract class DefaultDropModalTagHelperRendererTestsBase : TagHelperRendererTestsBase
{
protected const string DefaultTheme = "Default";



protected static IRenderingHelper CreateRenderingHelper()
{
return CreateRenderingHelper(new HtmlString("<div>Test</div>"));
}

protected static IRenderingHelper CreateRenderingHelper(IHtmlContent htmlContent)
{
var mock = new Mock<IRenderingHelper>();
mock.Setup(x => x.RenderAsync(It.IsAny<ModalMetaData>())).Returns(Task.FromResult(htmlContent));

return mock.Object;
}

protected static IModalMetaDataFactory CreateModalMetaDataFactory()
{
return new DefaultModalMetaDataFactory();
Expand All @@ -41,9 +18,4 @@ protected static IDropModalsTagHelperRenderer CreateDefaultDropModalsTagHelperRe
var renderingHelper = CreateRenderingHelper();
return new DefaultDropModalsTagHelperRenderer(modalMetaDataFactory, renderingHelper);
}

protected static ViewContext CreateViewContext()
{
return Mock.Of<ViewContext>();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
namespace Rhythm.Drop.Web.Tests.TagHelperRenderers;

using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Razor.TagHelpers;
using Moq;
using Rhythm.Drop.Web.Infrastructure.MetaData;
using Rhythm.Drop.Web.Infrastructure.Helpers.Rendering;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
Expand All @@ -11,6 +15,8 @@
/// </summary>
public abstract class TagHelperRendererTestsBase
{
protected const string DefaultTheme = "Default";

protected const string DefaultTagName = "div";

/// <summary>
Expand Down Expand Up @@ -88,4 +94,26 @@ protected static TagHelperOutput CreateTagHelperOutput(string tagName)
{
return CreateTagHelperOutput(tagName, [], default);
}

/// <summary>
/// Create a <see cref="ViewContext"/>.
/// </summary>
/// <returns>A <see cref="ViewContext"/>.</returns>
protected static ViewContext CreateViewContext()
{
return Mock.Of<ViewContext>();
}

protected static IRenderingHelper CreateRenderingHelper()
{
return CreateRenderingHelper(new HtmlString("<div>Test</div>"));
}

protected static IRenderingHelper CreateRenderingHelper(IHtmlContent htmlContent)
{
var mock = new Mock<IRenderingHelper>();
mock.Setup(x => x.RenderAsync(It.IsAny<MetaData>())).Returns(Task.FromResult(htmlContent));

return mock.Object;
}
}

0 comments on commit 6c19101

Please sign in to comment.