platform/test/precontained_test.dart

29 lines
957 B
Dart
Raw Normal View History

import 'dart:convert';
2018-08-19 15:33:25 +00:00
import 'package:angel_container/mirrors.dart';
2017-06-06 12:42:33 +00:00
import 'package:angel_framework/angel_framework.dart';
2018-10-22 15:54:41 +00:00
import 'package:angel_framework/http.dart';
2017-06-06 12:42:33 +00:00
import 'package:mock_request/mock_request.dart';
2019-04-17 19:42:24 +00:00
import 'package:pedantic/pedantic.dart';
2017-06-06 12:42:33 +00:00
import 'package:test/test.dart';
main() {
test('preinjects functions', () async {
2018-08-20 02:40:11 +00:00
var app = new Angel(reflector: MirrorsReflector())
2017-09-24 19:43:14 +00:00
..configuration['foo'] = 'bar'
..get('/foo', ioc(echoAppFoo));
2017-06-06 12:42:33 +00:00
app.optimizeForProduction(force: true);
print(app.preContained);
2018-08-21 18:50:43 +00:00
expect(app.preContained.keys, contains(echoAppFoo));
2017-06-06 12:42:33 +00:00
var rq = new MockHttpRequest('GET', new Uri(path: '/foo'));
2019-04-17 19:42:24 +00:00
unawaited(rq.close());
2018-02-07 05:36:24 +00:00
await new AngelHttp(app).handleRequest(rq);
2017-06-06 12:42:33 +00:00
var rs = rq.response;
2018-06-08 07:06:26 +00:00
var body = await rs.transform(utf8.decoder).join();
expect(body, json.encode('bar'));
2018-08-21 18:50:43 +00:00
}, skip: 'Angel no longer has to preinject functions');
2017-06-06 12:42:33 +00:00
}
echoAppFoo(String foo) => foo;