RpcCallSpy class
An IRpcInterceptor that records every RPC call for later inspection.
Attach to RpcTestApp or RpcApp to capture calls during tests, then assert on entries, callsTo, callCount, etc.
final spy = RpcCallSpy();
final app = await RpcTestApp.start(
modules: [EchoModule()],
interceptors: [spy],
);
final client = EchoCallerContract(app.caller);
await client.ping(PingRequest('hello'));
await client.ping(PingRequest('world'));
expect(spy.callCount, 2);
expect(spy.callsTo('EchoService', 'ping'), hasLength(2));
expect(spy.entries.first.success, isTrue);
expect(spy.wasCalled('EchoService', 'ping'), isTrue);
Constructors
Properties
- callCount → int
-
Total number of recorded calls.
no setter
-
entries
→ List<
RpcSpyEntry> -
All recorded entries in call order.
no setter
- errorCount → int
-
Number of calls that threw an error.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- successCount → int
-
Number of calls that completed successfully.
no setter
Methods
-
callsTo(
String service, String method) → List< RpcSpyEntry> -
All entries for the given
serviceandmethod. -
interceptBidirectionalStream<
TRequest, TResponse> (RpcMiddlewareContext call, Stream< TRequest> requests, RpcBidirectionalStreamNext<TRequest, TResponse> next) → FutureOr<Stream< TResponse> > - Bidirectional-stream call interceptor.
-
interceptClientStream<
TRequest, TResponse> (RpcMiddlewareContext call, Stream< TRequest> requests, RpcClientStreamNext<TRequest, TResponse> next) → Future<TResponse> - Client-stream call interceptor.
-
interceptServerStream<
TRequest, TResponse> (RpcMiddlewareContext call, TRequest request, RpcServerStreamNext< TRequest, TResponse> next) → FutureOr<Stream< TResponse> > - Server-stream call interceptor.
-
interceptUnary<
TRequest, TResponse> (RpcMiddlewareContext call, TRequest request, RpcUnaryNext< TRequest, TResponse> next) → Future<TResponse> - Unary call interceptor.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reset(
) → void - Removes all recorded entries.
-
toString(
) → String -
A string representation of this object.
inherited
-
wasCalled(
String service, String method) → bool -
Whether
service.methodwas called at least once.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited