69 lines
1.7 KiB
Dart
69 lines
1.7 KiB
Dart
|
import 'package:angel3_bus/angel3_bus.dart';
|
||
|
import 'package:angel3_container/angel3_container.dart';
|
||
|
import 'package:angel3_reactivex/angel3_reactivex.dart';
|
||
|
import 'package:angel3_event_bus/event_bus.dart';
|
||
|
import 'package:angel3_mq/mq.dart';
|
||
|
import 'package:test/test.dart';
|
||
|
import 'package:mockito/annotations.dart';
|
||
|
import 'package:mockito/mockito.dart';
|
||
|
|
||
|
import 'dispatcher_test.mocks.dart';
|
||
|
|
||
|
@GenerateMocks([Container, EventBus, MQClient])
|
||
|
|
||
|
// class MockContainer extends Mock implements Container {}
|
||
|
|
||
|
class MockEventBus extends Mock implements EventBus {}
|
||
|
|
||
|
class MockMQClient extends Mock implements MQClient {}
|
||
|
|
||
|
class TestCommand implements Command {
|
||
|
final String data;
|
||
|
TestCommand(this.data);
|
||
|
}
|
||
|
|
||
|
class TestHandler implements Handler {
|
||
|
@override
|
||
|
Future<dynamic> handle(Command command) async {
|
||
|
if (command is TestCommand) {
|
||
|
return 'Handled: ${command.data}';
|
||
|
}
|
||
|
throw UnimplementedError();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void main() {
|
||
|
late MockContainer container;
|
||
|
//late MockEventBus eventBus;
|
||
|
//late MockMQClient mqClient;
|
||
|
late Dispatcher dispatcher;
|
||
|
|
||
|
setUpAll(() {
|
||
|
provideDummy<EventBus>(MockEventBus());
|
||
|
provideDummy<MQClient>(MockMQClient());
|
||
|
});
|
||
|
|
||
|
setUp(() {
|
||
|
container = MockContainer();
|
||
|
//eventBus = MockEventBus();
|
||
|
//mqClient = MockMQClient();
|
||
|
|
||
|
dispatcher = Dispatcher(container);
|
||
|
});
|
||
|
|
||
|
group('Dispatcher', () {
|
||
|
test('dispatchNow should handle command and return result', () async {
|
||
|
final command = TestCommand('test data');
|
||
|
final handler = TestHandler();
|
||
|
|
||
|
when(container.make(TestHandler)).thenReturn(handler);
|
||
|
dispatcher.map({TestCommand: TestHandler});
|
||
|
|
||
|
final result = await dispatcher.dispatchNow(command);
|
||
|
|
||
|
expect(result, equals('Handled: test data'));
|
||
|
});
|
||
|
;
|
||
|
});
|
||
|
}
|