2017-02-26 21:31:09 +00:00
|
|
|
import 'dart:io';
|
2018-08-20 02:31:08 +00:00
|
|
|
|
2018-08-19 15:33:25 +00:00
|
|
|
import 'package:angel_container/mirrors.dart';
|
2017-02-26 21:31:09 +00:00
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
2018-10-22 15:54:41 +00:00
|
|
|
import 'package:angel_framework/http.dart';
|
2017-02-26 21:31:09 +00:00
|
|
|
import 'package:http/http.dart' as http;
|
2018-08-20 02:31:08 +00:00
|
|
|
import 'package:http_parser/http_parser.dart';
|
2017-02-26 21:31:09 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
|
|
|
main() {
|
|
|
|
Angel app;
|
|
|
|
http.Client client;
|
|
|
|
HttpServer server;
|
|
|
|
String url;
|
|
|
|
|
|
|
|
setUp(() async {
|
2018-08-20 02:40:11 +00:00
|
|
|
app = new Angel(reflector: MirrorsReflector())
|
2018-08-20 20:43:38 +00:00
|
|
|
..get('/foo', ioc(() => {'hello': 'world'}))
|
|
|
|
..get('/bar', (req, res) async {
|
2018-08-21 18:50:43 +00:00
|
|
|
await res.serialize({'hello': 'world'},
|
|
|
|
contentType: new MediaType('text', 'html'));
|
2018-08-20 02:31:08 +00:00
|
|
|
});
|
2017-02-26 21:31:09 +00:00
|
|
|
client = new http.Client();
|
|
|
|
|
2018-02-07 05:36:24 +00:00
|
|
|
server = await new AngelHttp(app).startServer();
|
2017-02-26 21:31:09 +00:00
|
|
|
url = "http://${server.address.host}:${server.port}";
|
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
|
|
|
app = null;
|
|
|
|
url = null;
|
|
|
|
client.close();
|
|
|
|
client = null;
|
|
|
|
await server.close(force: true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("correct content-type", () async {
|
|
|
|
var response = await client.get('$url/foo');
|
|
|
|
print('Response: ${response.body}');
|
2018-06-23 03:29:38 +00:00
|
|
|
expect(response.headers['content-type'], contains('application/json'));
|
2017-02-26 21:31:09 +00:00
|
|
|
|
|
|
|
response = await client.get('$url/bar');
|
|
|
|
print('Response: ${response.body}');
|
2018-06-23 03:29:38 +00:00
|
|
|
expect(response.headers['content-type'], contains('text/html'));
|
2017-02-26 21:31:09 +00:00
|
|
|
});
|
|
|
|
}
|