Class ComponentParameterCollectionBuilder<TComponent>
- Namespace
- Bunit
- Assembly
- Bunit.Core.dll
A ComponentParameterCollection builder for a specific TComponent component under test.
public sealed class ComponentParameterCollectionBuilder<TComponent> where TComponent : IComponent
Type Parameters
TComponentThe type of component under test to add the parameters.
- Inheritance
-
ComponentParameterCollectionBuilder<TComponent>
- Inherited Members
- Extension Methods
Constructors
ComponentParameterCollectionBuilder()
Initializes a new instance of the ComponentParameterCollectionBuilder<TComponent> class.
public ComponentParameterCollectionBuilder()
ComponentParameterCollectionBuilder(Action<ComponentParameterCollectionBuilder<TComponent>>?)
Initializes a new instance of the ComponentParameterCollectionBuilder<TComponent> class
and invokes the parameterAdder with it as the argument.
public ComponentParameterCollectionBuilder(Action<ComponentParameterCollectionBuilder<TComponent>>? parameterAdder)
Parameters
parameterAdderAction<ComponentParameterCollectionBuilder<TComponent>>
Methods
Add(Expression<Func<TComponent, EventCallback>>, Action)
Adds a component parameter for an EventCallback parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add(Expression<Func<TComponent, EventCallback>> parameterSelector, Action callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback>>A lambda function that selects the parameter.
callbackActionThe callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Add(Expression<Func<TComponent, EventCallback>>, Action<object>)
Adds a component parameter for an EventCallback parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add(Expression<Func<TComponent, EventCallback>> parameterSelector, Action<object> callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback>>A lambda function that selects the parameter.
callbackAction<object>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Add(Expression<Func<TComponent, EventCallback>>, Func<Task>)
Adds a component parameter for an EventCallback parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add(Expression<Func<TComponent, EventCallback>> parameterSelector, Func<Task> callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback>>A lambda function that selects the parameter.
callbackFunc<Task>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Add(Expression<Func<TComponent, RenderFragment?>>, string)
Adds a component parameter for a RenderFragment parameter selected with parameterSelector,
where the RenderFragment value is the markup passed in through the markup argument.
public ComponentParameterCollectionBuilder<TComponent> Add(Expression<Func<TComponent, RenderFragment?>> parameterSelector, string markup)
Parameters
parameterSelectorExpression<Func<TComponent, RenderFragment>>A lambda function that selects the parameter.
markupstringThe markup string to pass to the RenderFragment.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Add(Expression<Func<TComponent, EventCallback?>>, Action)
Adds a component parameter for a nullable EventCallback parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add(Expression<Func<TComponent, EventCallback?>> parameterSelector, Action callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback?>>A lambda function that selects the parameter.
callbackActionThe callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Add(Expression<Func<TComponent, EventCallback?>>, Action<object>)
Adds a component parameter for a nullable EventCallback parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add(Expression<Func<TComponent, EventCallback?>> parameterSelector, Action<object> callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback?>>A lambda function that selects the parameter.
callbackAction<object>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Add(Expression<Func<TComponent, EventCallback?>>, Func<Task>)
Adds a component parameter for a nullable EventCallback parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add(Expression<Func<TComponent, EventCallback?>> parameterSelector, Func<Task> callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback?>>A lambda function that selects the parameter.
callbackFunc<Task>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
AddCascadingValue<TValue>(string, TValue)
Adds an NAMED cascading value around the TComponent when it is rendered. Used to
pass cascading values to child components of TComponent.
public ComponentParameterCollectionBuilder<TComponent> AddCascadingValue<TValue>(string name, TValue cascadingValue) where TValue : notnull
Parameters
namestringThe name of the cascading value.
cascadingValueTValueThe cascading value.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueThe type of cascading value.
AddCascadingValue<TValue>(TValue)
Adds an UNNAMED cascading value around the TComponent when it is rendered. Used to
pass cascading values to child components of TComponent.
public ComponentParameterCollectionBuilder<TComponent> AddCascadingValue<TValue>(TValue cascadingValue) where TValue : notnull
Parameters
cascadingValueTValueThe cascading value.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueThe type of cascading value.
AddChildContent(RenderFragment)
Adds a ChildContent RenderFragment type parameter with the childContent as value.
Note, this is equivalent to Add(p => p.ChildContent, childContent).
public ComponentParameterCollectionBuilder<TComponent> AddChildContent(RenderFragment childContent)
Parameters
childContentRenderFragmentThe RenderFragment to pass the ChildContent parameter.
Returns
- ComponentParameterCollectionBuilder<TComponent>
AddChildContent(string)
Adds a ChildContent RenderFragment type parameter with the markup as value
wrapped in a RenderFragment.
Note, this is equivalent to Add(p => p.ChildContent, "...").
public ComponentParameterCollectionBuilder<TComponent> AddChildContent(string markup)
Parameters
markupstringThe markup string to pass the ChildContent parameter wrapped in a RenderFragment.
Returns
- ComponentParameterCollectionBuilder<TComponent>
AddChildContent<TChildComponent>(Action<ComponentParameterCollectionBuilder<TChildComponent>>?)
Adds a ChildContent RenderFragment type parameter, that is passed a RenderFragment,
which will render the TChildComponent with the parameters passed to childParameterBuilder.
public ComponentParameterCollectionBuilder<TComponent> AddChildContent<TChildComponent>(Action<ComponentParameterCollectionBuilder<TChildComponent>>? childParameterBuilder = null) where TChildComponent : IComponent
Parameters
childParameterBuilderAction<ComponentParameterCollectionBuilder<TChildComponent>>A parameter builder for the
TChildComponent.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TChildComponentType of child component to pass to the ChildContent parameter.
AddUnmatched(string, object?)
Adds an unmatched attribute value to TComponent.
public ComponentParameterCollectionBuilder<TComponent> AddUnmatched(string name, object? value = null)
Parameters
Returns
- ComponentParameterCollectionBuilder<TComponent>
Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>>>, Action)
Adds a component parameter for an EventCallback<TValue> parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>>> parameterSelector, Action callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback<TValue>>>A lambda function that selects the parameter.
callbackActionThe callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueThe value returned in the EventCallback<TValue>.
Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>>>, Action<TValue>)
Adds a component parameter for an EventCallback<TValue> parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>>> parameterSelector, Action<TValue> callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback<TValue>>>A lambda function that selects the parameter.
callbackAction<TValue>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueThe value returned in the EventCallback<TValue>.
Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>>>, Func<Task>)
Adds a component parameter for an EventCallback<TValue> parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>>> parameterSelector, Func<Task> callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback<TValue>>>A lambda function that selects the parameter.
callbackFunc<Task>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueThe value returned in the EventCallback<TValue>.
Add<TValue>(Expression<Func<TComponent, RenderFragment<TValue>?>>, Func<TValue, string>)
Adds a component parameter for a RenderFragment<TValue> template parameter selected with parameterSelector,
where the RenderFragment<TValue> template is based on the markupFactory argument.
public ComponentParameterCollectionBuilder<TComponent> Add<TValue>(Expression<Func<TComponent, RenderFragment<TValue>?>> parameterSelector, Func<TValue, string> markupFactory)
Parameters
parameterSelectorExpression<Func<TComponent, RenderFragment<TValue>>>A lambda function that selects the parameter.
markupFactoryFunc<TValue, string>A markup factory used to create the RenderFragment<TValue> template with.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueThe context type of the RenderFragment<TValue>.
Add<TChildComponent>(Expression<Func<TComponent, RenderFragment?>>, Action<ComponentParameterCollectionBuilder<TChildComponent>>?)
Adds a component parameter for a RenderFragment parameter selected with parameterSelector,
where the RenderFragment value is created through the childParameterBuilder argument.
public ComponentParameterCollectionBuilder<TComponent> Add<TChildComponent>(Expression<Func<TComponent, RenderFragment?>> parameterSelector, Action<ComponentParameterCollectionBuilder<TChildComponent>>? childParameterBuilder = null) where TChildComponent : IComponent
Parameters
parameterSelectorExpression<Func<TComponent, RenderFragment>>A lambda function that selects the parameter.
childParameterBuilderAction<ComponentParameterCollectionBuilder<TChildComponent>>A parameter builder for the
TChildComponent.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TChildComponentThe type of component to create a RenderFragment for.
Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>?>>, Action)
Adds a component parameter for a nullable EventCallback<TValue> parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>?>> parameterSelector, Action callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback<TValue>?>>A lambda function that selects the parameter.
callbackActionThe callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueThe value returned in the EventCallback<TValue>.
Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>?>>, Action<TValue>)
Adds a component parameter for a nullable EventCallback<TValue> parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>?>> parameterSelector, Action<TValue> callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback<TValue>?>>A lambda function that selects the parameter.
callbackAction<TValue>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueThe value returned in the EventCallback<TValue>.
Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>?>>, Func<Task>)
Adds a component parameter for a nullable EventCallback<TValue> parameter selected with parameterSelector,
where the callback is used as value.
public ComponentParameterCollectionBuilder<TComponent> Add<TValue>(Expression<Func<TComponent, EventCallback<TValue>?>> parameterSelector, Func<Task> callback)
Parameters
parameterSelectorExpression<Func<TComponent, EventCallback<TValue>?>>A lambda function that selects the parameter.
callbackFunc<Task>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueThe value returned in the EventCallback<TValue>.
Add<TValue>(Expression<Func<TComponent, TValue>>, TValue)
Adds a component parameter for the parameter selected with parameterSelector
with the value value.
public ComponentParameterCollectionBuilder<TComponent> Add<TValue>(Expression<Func<TComponent, TValue>> parameterSelector, TValue value)
Parameters
parameterSelectorExpression<Func<TComponent, TValue>>A lambda function that selects the parameter.
valueTValueThe value to pass to
TComponent.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValueType of
value.
Add<TChildComponent, TValue>(Expression<Func<TComponent, RenderFragment<TValue>?>>, Func<TValue, Action<ComponentParameterCollectionBuilder<TChildComponent>>>)
Adds a component parameter for a RenderFragment<TValue> template parameter selected with parameterSelector,
where the RenderFragment<TValue> template is based on the templateFactory, which is used
to create a RenderFragment<TValue> that renders a TChildComponent inside the template.
public ComponentParameterCollectionBuilder<TComponent> Add<TChildComponent, TValue>(Expression<Func<TComponent, RenderFragment<TValue>?>> parameterSelector, Func<TValue, Action<ComponentParameterCollectionBuilder<TChildComponent>>> templateFactory) where TChildComponent : IComponent
Parameters
parameterSelectorExpression<Func<TComponent, RenderFragment<TValue>>>A lambda function that selects the parameter.
templateFactoryFunc<TValue, Action<ComponentParameterCollectionBuilder<TChildComponent>>>A template factory used to create the parameters being passed to the
TChildComponent.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TChildComponentThe type of component to create a RenderFragment<TValue> for.
TValueThe context type of the RenderFragment<TValue>.
Bind<TValue>(Expression<Func<TComponent, TValue>>, TValue, Action<TValue>, Expression<Func<TValue>>?)
Adds two-way binding, simulating the @bind-Parameter directive, to a given pair of parameters.
public ComponentParameterCollectionBuilder<TComponent> Bind<TValue>(Expression<Func<TComponent, TValue>> parameterSelector, TValue initialValue, Action<TValue> changedAction, Expression<Func<TValue>>? valueExpression = null)
Parameters
parameterSelectorExpression<Func<TComponent, TValue>>Parameter-selector for the two-way binding.
initialValueTValueThe initial value to pass to
TComponent.changedActionAction<TValue>Action which gets invoked when the value has changed.
valueExpressionExpression<Func<TValue>>Optional value expression.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
Remarks
This function is a short-hand form for the following expression:
RenderComponent<TComponent>(ps => ps
.Add(c => c.Value, value)
.Add(c => c.ValueChanged, newValue => value = newValue)
.Add(c => c.ValueExpression, () => value));
With Bind, it can be written like this:
RenderComponent<TComponent>(ps => ps
.Bind(c => c.Value, value, newValue => value = newValue, () => value));
Build()
Builds the ComponentParameterCollection.
public ComponentParameterCollection Build()
Returns
- ComponentParameterCollection
The created ComponentParameterCollection.
SetAssignedRenderMode(IComponentRenderMode?)
Sets (or unsets) the IComponentRenderMode for the component and child components.
public ComponentParameterCollectionBuilder<TComponent> SetAssignedRenderMode(IComponentRenderMode? renderMode)
Parameters
renderModeIComponentRenderModeThe render mode to assign to the component, e.g.
RenderMode.InteractiveServer, or null, to not assign a specific render mode.
Returns
- ComponentParameterCollectionBuilder<TComponent>
TryAdd<TValue>(string, TValue)
Try to add a value for a parameter with the name, if
TComponent has a property with that name, AND that property has a ParameterAttribute
or a CascadingParameterAttribute.
public bool TryAdd<TValue>(string name, TValue value)
Parameters
namestringName of the property for the parameter.
valueTValueValue to assign to the parameter.
Returns
- bool
True if parameter with the name exists and value was set, false otherwise.
Type Parameters
TValueValue type.
Remarks
This is an untyped version of this method named AddUnmatched(string, object?). Always
prefer the strongly typed Add methods whenever possible.