2024-09-23 01:44:59 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:platform_container/mirrors.dart';
|
2024-09-25 04:04:57 +00:00
|
|
|
import 'package:platform_core/core.dart';
|
|
|
|
import 'package:platform_core/http.dart';
|
2024-11-11 19:49:32 +00:00
|
|
|
import 'package:platform_testing/http.dart';
|
2024-09-23 01:44:59 +00:00
|
|
|
|
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
void main() {
|
2024-11-22 03:03:45 +00:00
|
|
|
test('preinjects functions when executed', () async {
|
|
|
|
// Create app with mirrors reflector
|
2024-09-28 23:14:48 +00:00
|
|
|
var app = Application(reflector: MirrorsReflector())
|
2024-09-23 01:44:59 +00:00
|
|
|
..configuration['foo'] = 'bar'
|
|
|
|
..get('/foo', ioc(echoAppFoo));
|
|
|
|
|
2024-11-22 03:03:45 +00:00
|
|
|
// Create request and response contexts
|
2024-09-23 01:44:59 +00:00
|
|
|
var rq = MockHttpRequest('GET', Uri(path: '/foo'));
|
2024-11-22 03:03:45 +00:00
|
|
|
var reqContext = await HttpRequestContext.from(rq, app, '/foo');
|
|
|
|
var resContext = HttpResponseContext(rq.response, app, reqContext);
|
|
|
|
|
|
|
|
// Force pre-injection by running the handler
|
|
|
|
await app.runReflected(echoAppFoo, reqContext, resContext);
|
|
|
|
|
|
|
|
// Verify preContained has the function
|
|
|
|
expect(app.preContained.keys, contains(echoAppFoo));
|
|
|
|
|
|
|
|
// Clean up
|
|
|
|
await reqContext.close();
|
|
|
|
});
|
2024-09-23 01:44:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
String echoAppFoo(String foo) => foo;
|