2017-02-26 21:31:09 +00:00
|
|
|
import 'dart:io';
|
2018-08-20 02:31:08 +00:00
|
|
|
|
2021-05-14 10:34:09 +00:00
|
|
|
import 'package:angel3_container/mirrors.dart';
|
|
|
|
import 'package:angel3_framework/angel3_framework.dart';
|
|
|
|
import 'package:angel3_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';
|
|
|
|
|
2021-05-14 10:34:09 +00:00
|
|
|
void main() {
|
2021-04-03 05:50:52 +00:00
|
|
|
late Angel app;
|
|
|
|
late http.Client client;
|
2021-03-20 08:11:18 +00:00
|
|
|
late HttpServer server;
|
2021-04-03 05:50:52 +00:00
|
|
|
late String url;
|
2017-02-26 21:31:09 +00:00
|
|
|
|
|
|
|
setUp(() async {
|
2019-05-02 22:48:31 +00:00
|
|
|
app = 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'},
|
2019-05-02 22:48:31 +00:00
|
|
|
contentType: MediaType('text', 'html'));
|
2018-08-20 02:31:08 +00:00
|
|
|
});
|
2019-05-02 22:48:31 +00:00
|
|
|
client = http.Client();
|
2017-02-26 21:31:09 +00:00
|
|
|
|
2019-05-02 22:48:31 +00:00
|
|
|
server = await AngelHttp(app).startServer();
|
2021-07-08 02:42:40 +00:00
|
|
|
url = 'http://${server.address.host}:${server.port}';
|
2017-02-26 21:31:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
tearDown(() async {
|
2021-04-03 05:50:52 +00:00
|
|
|
client.close();
|
2017-02-26 21:31:09 +00:00
|
|
|
await server.close(force: true);
|
|
|
|
});
|
|
|
|
|
2021-07-08 02:42:40 +00:00
|
|
|
test('correct content-type', () async {
|
2021-04-03 05:50:52 +00:00
|
|
|
var response = await client.get(Uri.parse('$url/foo'));
|
2017-02-26 21:31:09 +00:00
|
|
|
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
|
|
|
|
2021-04-03 05:50:52 +00:00
|
|
|
response = await client.get(Uri.parse('$url/bar'));
|
2017-02-26 21:31:09 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
}
|