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
TComponent
The 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
parameterAdder
Action<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
parameterSelector
Expression<Func<TComponent, EventCallback>>A lambda function that selects the parameter.
callback
ActionThe 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
parameterSelector
Expression<Func<TComponent, EventCallback>>A lambda function that selects the parameter.
callback
Action<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
parameterSelector
Expression<Func<TComponent, EventCallback>>A lambda function that selects the parameter.
callback
Func<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
parameterSelector
Expression<Func<TComponent, RenderFragment>>A lambda function that selects the parameter.
markup
stringThe 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
parameterSelector
Expression<Func<TComponent, EventCallback?>>A lambda function that selects the parameter.
callback
ActionThe 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
parameterSelector
Expression<Func<TComponent, EventCallback?>>A lambda function that selects the parameter.
callback
Action<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
parameterSelector
Expression<Func<TComponent, EventCallback?>>A lambda function that selects the parameter.
callback
Func<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
name
stringThe name of the cascading value.
cascadingValue
TValueThe cascading value.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
The 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
cascadingValue
TValueThe cascading value.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
The 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
childContent
RenderFragmentThe 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
markup
stringThe 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
childParameterBuilder
Action<ComponentParameterCollectionBuilder<TChildComponent>>A parameter builder for the
TChildComponent
.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TChildComponent
Type 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
parameterSelector
Expression<Func<TComponent, EventCallback<TValue>>>A lambda function that selects the parameter.
callback
ActionThe callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
The 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
parameterSelector
Expression<Func<TComponent, EventCallback<TValue>>>A lambda function that selects the parameter.
callback
Action<TValue>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
The 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
parameterSelector
Expression<Func<TComponent, EventCallback<TValue>>>A lambda function that selects the parameter.
callback
Func<Task>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
The 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
parameterSelector
Expression<Func<TComponent, RenderFragment<TValue>>>A lambda function that selects the parameter.
markupFactory
Func<TValue, string>A markup factory used to create the RenderFragment<TValue> template with.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
The 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
parameterSelector
Expression<Func<TComponent, RenderFragment>>A lambda function that selects the parameter.
childParameterBuilder
Action<ComponentParameterCollectionBuilder<TChildComponent>>A parameter builder for the
TChildComponent
.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TChildComponent
The 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
parameterSelector
Expression<Func<TComponent, EventCallback<TValue>?>>A lambda function that selects the parameter.
callback
ActionThe callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
The 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
parameterSelector
Expression<Func<TComponent, EventCallback<TValue>?>>A lambda function that selects the parameter.
callback
Action<TValue>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
The 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
parameterSelector
Expression<Func<TComponent, EventCallback<TValue>?>>A lambda function that selects the parameter.
callback
Func<Task>The callback to pass to the EventCallback.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
The 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
parameterSelector
Expression<Func<TComponent, TValue>>A lambda function that selects the parameter.
value
TValueThe value to pass to
TComponent
.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TValue
Type 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
parameterSelector
Expression<Func<TComponent, RenderFragment<TValue>>>A lambda function that selects the parameter.
templateFactory
Func<TValue, Action<ComponentParameterCollectionBuilder<TChildComponent>>>A template factory used to create the parameters being passed to the
TChildComponent
.
Returns
- ComponentParameterCollectionBuilder<TComponent>
Type Parameters
TChildComponent
The type of component to create a RenderFragment<TValue> for.
TValue
The 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
parameterSelector
Expression<Func<TComponent, TValue>>Parameter-selector for the two-way binding.
initialValue
TValueThe initial value to pass to
TComponent
.changedAction
Action<TValue>Action which gets invoked when the value has changed.
valueExpression
Expression<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
renderMode
IComponentRenderModeThe 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
name
stringName of the property for the parameter.
value
TValueValue to assign to the parameter.
Returns
- bool
True if parameter with the name exists and value was set, false otherwise.
Type Parameters
TValue
Value type.
Remarks
This is an untyped version of this method named AddUnmatched(string, object?). Always
prefer the strongly typed Add
methods whenever possible.