Table of Contents

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 Action

The callback to pass to the EventCallback.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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>

This 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>

This 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 string

The markup string to pass to the RenderFragment.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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 Action

The callback to pass to the EventCallback.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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>

This 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>

This 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 string

The name of the cascading value.

cascadingValue TValue

The cascading value.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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 TValue

The cascading value.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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 RenderFragment

The RenderFragment to pass the ChildContent parameter.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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 string

The markup string to pass the ChildContent parameter wrapped in a RenderFragment.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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>

This 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

name string

The name of the unmatched attribute.

value object

The value of the unmatched attribute.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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 Action

The callback to pass to the EventCallback.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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>

This 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>

This 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>

This 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>

This 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 Action

The callback to pass to the EventCallback.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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>

This 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>

This 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 TValue

The value to pass to TComponent.

Returns

ComponentParameterCollectionBuilder<TComponent>

This 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>

This 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 TValue

The 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>

This 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()

public ComponentParameterCollection Build()

Returns

ComponentParameterCollection

The created ComponentParameterCollection.

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 string

Name of the property for the parameter.

value TValue

Value 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 the Add<TValue>(Expression<Func<TComponent, TValue>>, TValue) method. Always prefer the strongly typed Add methods whenever possible.

Progress Telerik

Premium sponsor: Progress Telerik.

Packt

Editorial support provided by Packt.

.NET Foundation

Supported by the .NET Foundation.