FakeVaultService class
In-memory fake implementation of MagicVaultService for testing.
Replaces FlutterSecureStorage with a simple Map so tests run without platform channels.
Usage
final fake = Vault.fake({'token': 'abc123'});
await Vault.put('key', 'value');
fake.assertWritten('key');
fake.assertContains('key');
Vault.unfake();
- Inheritance
-
- Object
- MagicVaultService
- FakeVaultService
Constructors
-
FakeVaultService([Map<
String, String> initialValues = const {}]) -
Creates a FakeVaultService with optional
initialValues.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- macOsUsesDataProtectionKeychain → bool?
-
The macOS keychain this instance was told to use, or
nullto let it choose on first use (see the constructor).finalinherited -
recorded
→ List<
VaultOperation> -
All recorded operations in the order they were performed.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- usesDataProtectionKeychain → bool?
-
The macOS keychain in use: the constructor's value when one was given,
otherwise what the probe found.
no setterinherited
Methods
-
assertContains(
String key) → void -
Assert that
keycurrently exists in the store. -
assertDeleted(
String key) → void -
Assert that
keywas deleted (via remove) at least once. -
assertMissing(
String key) → void -
Assert that
keydoes not currently exist in the store. -
assertWritten(
String key) → void -
Assert that
keywas written (via put) at least once. -
flush(
) → Future< void> -
Flush all values from the vault.
override
-
get(
String key) → Future< String?> -
Retrieve a value from the vault.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
put(
String key, String value) → Future< void> -
Store a value in the vault.
override
-
remove(
String key) → Future< void> -
Remove a value from the vault.
override
-
reset(
) → void - Clear the in-memory store, the recorded operations list, and every configured throw.
-
throwOnFlush(
[Object? error]) → void -
Makes flush throw
errorinstead of clearing the store, until reset clears it. Defaults to a MagicVaultException, for the same reason as throwOnGet. -
throwOnGet(
[Object? error]) → void -
Makes get throw
errorinstead of returning a value, until reset clears it. Defaults to a MagicVaultException, the type MagicVaultService.get itself throws when the platform channel fails (magic_vault_service.dart:48-54), so a consumer'scatchclause sees the shape it would see from a real keychain read failure. -
throwOnPut(
[Object? error]) → void -
Makes put throw
errorinstead of storing the value, until reset clears it. Defaults to a MagicVaultException, for the same reason as throwOnGet. -
throwOnRemove(
[Object? error]) → void -
Makes remove throw
errorinstead of deleting the value, until reset clears it. Defaults to a MagicVaultException, for the same reason as throwOnGet. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited