Skip to content

Commit e21240b

Browse files
authored
ComponentParameterBuilder (#94)
New `ComponentParameterBuilder` with auxiliary changes
1 parent 1033f05 commit e21240b

6 files changed

Lines changed: 821 additions & 1 deletion

File tree

src/Builders/ComponentParameterBuilder.cs

Lines changed: 395 additions & 0 deletions
Large diffs are not rendered by default.

src/Extensions/Internal/ComponentParamenterExtensions.cs renamed to src/Extensions/Internal/ComponentParameterExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Bunit
88
/// <summary>
99
/// Helpful extensions for working with <see cref="ComponentParameter"/> and collections of these.
1010
/// </summary>
11-
internal static class ComponentParamenterExtensions
11+
internal static class ComponentParameterExtensions
1212
{
1313
/// <summary>
1414
/// Creates a <see cref="RenderFragment"/> that will render a component of <typeparamref name="TComponent"/> type,

src/ITestContext.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,13 @@ public interface ITestContext : IDisposable
3535
/// <param name="parameters">Parameters to pass to the component when it is rendered</param>
3636
/// <returns>The rendered <typeparamref name="TComponent"/></returns>
3737
IRenderedComponent<TComponent> RenderComponent<TComponent>(params ComponentParameter[] parameters) where TComponent : class, IComponent;
38+
39+
/// <summary>
40+
/// Instantiates and performs a first render of a component of type <typeparamref name="TComponent"/>.
41+
/// </summary>
42+
/// <typeparam name="TComponent">Type of the component to render</typeparam>
43+
/// <param name="componentParameterBuilderAction">The ComponentParameterBuilder action to add type safe parameters to pass to the component when it is rendered</param>
44+
/// <returns>The rendered <typeparamref name="TComponent"/></returns>
45+
IRenderedComponent<TComponent> RenderComponent<TComponent>(Action<ComponentParameterBuilder<TComponent>> componentParameterBuilderAction) where TComponent : class, IComponent;
3846
}
3947
}

src/TestContext.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.Extensions.Logging.Abstractions;
88
using Microsoft.JSInterop;
99
using System;
10+
using System.Linq;
1011

1112
namespace Bunit
1213
{
@@ -53,6 +54,20 @@ public virtual IRenderedComponent<TComponent> RenderComponent<TComponent>(params
5354
return result;
5455
}
5556

57+
/// <inheritdoc/>
58+
public virtual IRenderedComponent<TComponent> RenderComponent<TComponent>(Action<ComponentParameterBuilder<TComponent>> componentParameterBuilderAction) where TComponent : class, IComponent
59+
{
60+
if (componentParameterBuilderAction is null)
61+
{
62+
throw new ArgumentNullException(nameof(componentParameterBuilderAction));
63+
}
64+
65+
var builder = new ComponentParameterBuilder<TComponent>();
66+
componentParameterBuilderAction(builder);
67+
68+
return RenderComponent<TComponent>(builder.Build().ToArray());
69+
}
70+
5671
#region IDisposable Support
5772
private bool _disposed = false;
5873

0 commit comments

Comments
 (0)