diff --git a/lib/src/request/request_manager.dart b/lib/src/request/request_manager.dart index 5a28e5d..839e4fc 100644 --- a/lib/src/request/request_manager.dart +++ b/lib/src/request/request_manager.dart @@ -43,6 +43,13 @@ class RequestManager { _requestHandlerStore.register(handler); } + /// Registers the request [handler] for the given [TRequest]. + void unregister>( + RequestHandler handler, + ) { + _requestHandlerStore.unregister(handler); + } + /// Sends a [request] to a single [RequestHandler]. /// /// Make sure the [RequestHandler] is [register]ed before calling this method. diff --git a/test/integration/request_test.dart b/test/integration/request_test.dart index 363d704..2fa7abb 100644 --- a/test/integration/request_test.dart +++ b/test/integration/request_test.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:dart_mediator/mediator.dart'; import 'package:test/test.dart'; +import '../mocks.dart'; import '../test_data.dart'; class GetDataQueryHandler implements QueryHandler { @@ -22,6 +23,18 @@ void main() { }); group('requests', () { + test('it unregisters the request handler', () async { + final handler = GetDataQueryHandler(); + + mediator.requests.register(handler); + mediator.requests.unregister(handler); + + await expectLater( + mediator.requests.send(const GetDataQuery(123)), + throwsAssertionError, + ); + }); + test('it handles the normal request', () async { mediator.requests.register(GetDataQueryHandler()); diff --git a/test/unit/request/requests_manager_test.dart b/test/unit/request/requests_manager_test.dart index 0e66af8..0e71763 100644 --- a/test/unit/request/requests_manager_test.dart +++ b/test/unit/request/requests_manager_test.dart @@ -82,6 +82,17 @@ void main() { }); }); + group('unregister', () { + test('it unregisters the handler', () { + final mockRequestHandler = + MockRequestHandler>(); + + requestsManager.unregister(mockRequestHandler); + + verify(() => mockRequestHandlerStore.unregister(mockRequestHandler)); + }); + }); + group('send{TResponse, TRequest}', () { const output = '123'; late MockRequest mockRequest;