MockOnlineSim class final

In-process fake OnlineSim API for tests: no network, no key, no money, no clock.

It is an OnlineSimTransport that answers like the real backend; client returns a normal OnlineSim wired to it. Test helpers add SMS, queue failures and expose the state. Deterministic: ids and numbers come from a counter.

final mock = MockOnlineSim(balance: 10);
final client = mock.client();
final tzid = await client.numbers.get('google', country: 44);
mock.addSmsAfter(tzid, 'Your code: 123-456', 2);
await client.numbers.waitCode(tzid, interval: Duration.zero); // '123456'
Implemented types

Constructors

MockOnlineSim({String apiKey = 'mock-key', double balance = 100, MockPrices prices = defaultMockPrices, Map<int, MockRentTariff> rentTariffs = defaultMockRentTariffs, int guardInterval = 0})
Creates a mock.

Properties

hashCode → int
The hash code for this object.
no setterinherited
requests → List<MockRequest>
Every request received, in order.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addSms(int tzid, String text, {String? service}) → void
An SMS arrives now at number operation or rent tzid. Throws StateError when there is no open operation or rent with that id. The first rent SMS whose service is not notify confirms the rent and charges it; service: 'notify' adds a notice with code 0 that confirms nothing.
addSmsAfter(int tzid, String text, int polls, {String? service}) → void
The SMS arrives after polls state requests for tzid (getState / rent getRentState, listing it alone or with others): with polls = 2 the third poll sees it. Lets waitCode run with a zero interval.
balance() → double
Total balance, USD, including the part frozen by open operations and unconfirmed rents (as user.balance() reports it).
client({String? apiKey, String lang = 'en', String? devId, Duration timeout = defaultTimeout}) → OnlineSim
A normal client wired to the mock. apiKey defaults to the mock's key; pass another one (or '' for none) to test a wrong key.
failNext(String code, {String? endpoint}) → void
The next request (to endpoint only, e.g. getNum.php, when given) answers {"response": code}.
failNextTransport({int status = 502, String? endpoint}) → void
The next request (to endpoint only, when given) fails at transport level: a non-JSON body with HTTP status.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
operations() → List<MockOperation>
Number operations, oldest first (snapshots).
rents() → List<MockRent>
Open rents, oldest first (snapshots).
reset() → void
Back to the constructor's state: balance, no operations, rents, logs, schedules or failures.
send(TransportRequest request) → Future<TransportResponse>
Sends request and returns the answer, whatever its HTTP status.
override
setBalance(double usd) → void
Sets the total balance, USD.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited