2017-08-28 15:29:27 +00:00
|
|
|
import 'dart:async';
|
2018-08-20 20:43:38 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
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';
|
|
|
|
import 'package:angel3_mock_request/angel3_mock_request.dart';
|
2017-08-28 15:29:27 +00:00
|
|
|
import 'package:test/test.dart';
|
|
|
|
|
2021-05-14 10:34:09 +00:00
|
|
|
void main() {
|
2017-08-28 15:29:27 +00:00
|
|
|
MockHttpRequest mk(int id) {
|
2019-05-02 22:48:31 +00:00
|
|
|
return MockHttpRequest('GET', Uri.parse('/test/$id'))..close();
|
2017-08-28 15:29:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test('can request the same url twice', () async {
|
2019-05-02 22:48:31 +00:00
|
|
|
var app = Angel(reflector: MirrorsReflector())
|
2018-08-20 20:43:38 +00:00
|
|
|
..get('/test/:id', ioc((id) => 'Hello $id'));
|
2017-08-28 15:29:27 +00:00
|
|
|
var rq1 = mk(1), rq2 = mk(2), rq3 = mk(1);
|
2019-05-02 22:48:31 +00:00
|
|
|
await Future.wait([rq1, rq2, rq3].map(AngelHttp(app).handleRequest));
|
2018-06-08 07:06:26 +00:00
|
|
|
var body1 = await rq1.response.transform(utf8.decoder).join(),
|
|
|
|
body2 = await rq2.response.transform(utf8.decoder).join(),
|
|
|
|
body3 = await rq3.response.transform(utf8.decoder).join();
|
2017-08-28 15:29:27 +00:00
|
|
|
print('Response #1: $body1');
|
|
|
|
print('Response #2: $body2');
|
|
|
|
print('Response #3: $body3');
|
|
|
|
expect(
|
|
|
|
body1,
|
|
|
|
allOf(
|
|
|
|
isNot(body2),
|
|
|
|
equals(body3),
|
|
|
|
));
|
|
|
|
});
|
|
|
|
}
|