DwFakeServer class final

An in-memory DartWay server for tests of the client and of the screens on top of it: the HTTP contract through httpTransport and the live socket through liveConnector.

Not the real server: handlers are closures registered per DTO type, there is no database and no access rule beyond what a test declares. What it reproduces is the protocol as dartway_core_server speaks it — headers and their checks, honest statuses, 426 for an incompatible build, idempotent commands, the response transport filtered by Dw-Live-Connection, hello and authentication on the socket, a changed account closing subscriptions, key revocation, subscriptions and their accounting — so a client talks to it exactly as to a real one.

final server = DwFakeServer(protocol: appProtocol)
  ..onRequest<ListRooms>((request, call) => DwCallOk(rooms));
final client = server.newClient();
await client.start();

Constructors

DwFakeServer({required DwWireProtocol protocol, String? contractVersion})

Properties

acceptsConnections ↔ bool
While false, live connection attempts fail as against an unreachable server.
getter/setter pair
baseUrl → Uri
The address clients of this server use. Informational: httpTransport and liveConnector are what reach it.
final
calls → List<DwFakeRecordedCall>
Every call answered, in arrival order.
final
connections → List<DwFakeConnection>
Every live connection ever accepted, open or not.
final
contractVersion ↔ String?
The contract this server serves (DwContractVersion): a client of an older breaking line, or one that sends none, is answered 426 with dw.updateRequired, on calls and on the live upgrade. The protocol's own by default; set a newer line to play a server that moved on.
getter/setter pair
errors → List<Object>
Handler exceptions, calls nobody registered a handler for, and messages that do not decode. A test that expects none asserts this is empty: a fake that swallowed them would let a broken test pass.
final
failingChannels → Set<String>
Channels whose subscription check fails, as a throwing rule does on a real server: answered as a failure with subscriptionIncident.
final
hashCode → int
The hash code for this object.
no setterinherited
httpTransport → DwMemoryHttpTransport
Carries calls to this server in memory.
latefinal
interceptPost ↔ FutureOr<DwHttpReply?> Function(DwHttpPost post)?
Answers a call before the server does — a proxy's error page, say. A null answer lets the server handle it.
getter/setter pair
liveConnector → DwMemoryLiveConnector
Connects live sockets to this server in memory.
latefinal
openConnections → Iterable<DwFakeConnection>
no setter
protocol → DwWireProtocol
final
protocolVersion ↔ int
The protocol version this server speaks.
getter/setter pair
reachable ↔ bool
While false, every call fails on the network.
getter/setter pair
received → List<DwClientMessage>
Every live message received from any client, in arrival order.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sent → List<DwServerMessage>
Every live message sent to any client.
final
subscriptionRule ↔ DwCallRefusal? Function(String channel, int? accountId)?
Decides whether an account may read a channel — for a subscription, and for what a successful call's response carries: null allows it, a refusal refuses it. The account is null only for a subscription when subscriptionsRequireAccount is off.
getter/setter pair
subscriptionsRequireAccount ↔ bool
Every subscription needs a signed-in connection, as on a real server (D-020).
getter/setter pair

Methods

callsOf<C extends DwServerCall<Object?>>() → List<DwFakeRecordedCall>
Calls whose DTO is a C, in arrival order.
closeChannel(DwLiveChannel channel, {int? accountId}) → void
Closes channel for every subscribed connection, or only for those of accountId — what revoking access does.
dropConnections({int? code, String? reason}) → Future<void>
Drops every open live connection from the server side.
executions(String idempotencyKey) → int
How many times the handler ran for the command with idempotencyKey.
isTokenValid(String token) → bool
newClient({DwTokenStore? tokenStore, String appVersion = '1.0.0+1', DwClientOptions options = dwFakeClientOptions, void onError(Object error, StackTrace stackTrace)?, DwStorageTransport? storageTransport}) → DwAppClient
A client of this server — not started, with timings short enough for tests unless options says otherwise.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onCommand<C extends DwActionCommand<Object?>>(DwFakeHandler<C> handle) → void
Answers commands of type C. A command runs once per idempotency key; a repeat answers the stored outcome unless it failed.
onRequest<Q extends DwDataRequest<Object?>>(DwFakeHandler<Q> handle) → void
Answers requests of type Q.
publish(DwLiveChannel channel, List<DwWireObject> objects) → void
Publishes objects to every open connection subscribed to channel: an update from someone else, outside any call of the client under test.
receivedOf<M extends DwClientMessage>() → List<M>
Received live messages of type M.
registerToken(String token, int accountId) → void
Makes token valid for accountId.
requestsOf<Q extends DwDataRequest<Object?>>() → List<Q>
Requests of type Q that arrived, in arrival order.
revokeToken(String token) → void
Makes token invalid, as revoking a key does on a real server: every open connection bound to it loses its subscriptions (closed for each) and its session (authed with rejected, unasked).
subscribeCount(DwLiveChannel channel) → int
How many sub messages arrived for channel, from any connection.
subscriberCount(DwLiveChannel channel) → int
How many open connections are subscribed to channel.
toString() → String
A string representation of this object.
inherited
unsubscribeCount(DwLiveChannel channel) → int
How many unsub messages arrived for channel.

Operators

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

Constants

subscriptionIncident → const String