Class FakePersistentComponentState
- Namespace
- Bunit.TestDoubles
- Assembly
- Bunit.Core.dll
Represents a fake PersistentComponentState, that can be used to the real PersistentComponentState in the Blazor runtime.
public sealed class FakePersistentComponentState
- Inheritance
-
FakePersistentComponentState
- Inherited Members
- Extension Methods
Methods
Persist<TValue>(string, TValue)
Persists instance
under the given key
in the store.
public void Persist<TValue>(string key, TValue instance)
Parameters
key
stringThe key to use to persist the state.
instance
TValueThe instance to persist.
Type Parameters
TValue
The
instance
type.
Remarks
Only call this method after all services has been registered with the Services. Calling this method will lookup dependencies of the FakePersistentComponentState from the TestServiceProvider, which means no other services can be registered after this point.
TriggerOnPersisting()
Triggers any listeners registered to the RegisterOnPersisting(Func<Task>) method.
Use this method to emulate the Blazor runtime invoking the OnPersisting
callbacks during
component persistence.
public void TriggerOnPersisting()
Remarks
Only call this method after all services has been registered with the Services. Calling this method will lookup dependencies of the FakePersistentComponentState from the TestServiceProvider, which means no other services can be registered after this point.
TryTake<TValue>(string, out TValue?)
Tries to retrieve the persisted state with the given key
.
When the key is present, the state is successfully returned via instance
.
public bool TryTake<TValue>(string key, out TValue? instance)
Parameters
key
stringThe key used to persist the instance.
instance
TValueThe persisted instance.
Returns
- bool
true
if the state was found;false
otherwise.
Type Parameters
TValue
Remarks
Only call this method after all services has been registered with the Services. Calling this method will lookup dependencies of the FakePersistentComponentState from the TestServiceProvider, which means no other services can be registered after this point.