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
keystringThe key to use to persist the state.
instanceTValueThe instance to persist.
Type Parameters
TValueThe
instancetype.
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
keystringThe key used to persist the instance.
instanceTValueThe persisted instance.
Returns
- bool
trueif the state was found;falseotherwise.
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.