Fixed framework test cases

This commit is contained in:
thomashii@dukefirehawk.com 2021-05-29 07:44:06 +08:00
parent 6890155712
commit 16fc8c3436
5 changed files with 12 additions and 18 deletions

View file

@ -11,7 +11,7 @@
* Migrated angel_container to 3.0.0 (55/55 tests passed) * Migrated angel_container to 3.0.0 (55/55 tests passed)
* Added merge_map and migrated to 2.0.0 (6/6 tests passed) * Added merge_map and migrated to 2.0.0 (6/6 tests passed)
* Added mock_request and migrated to 2.0.0 (0/0 tests) * Added mock_request and migrated to 2.0.0 (0/0 tests)
* Migrated angel_framework to 4.0.0 (146/150 tests passed) * Migrated angel_framework to 4.0.0 (148/150 tests passed)
* Migrated angel_auth to 4.0.0 (23/30 tests passed) * Migrated angel_auth to 4.0.0 (23/30 tests passed)
* Migrated angel_configuration to 4.0.0 (6/8 testspassed) * Migrated angel_configuration to 4.0.0 (6/8 testspassed)
* Migrated angel_validate to 4.0.0 (6/7 tests passed) * Migrated angel_validate to 4.0.0 (6/7 tests passed)

View file

@ -74,7 +74,7 @@ abstract class ResponseContext<RawResponse>
/// ```dart /// ```dart
/// app.injectSerializer(JSON.encode); /// app.injectSerializer(JSON.encode);
/// ``` /// ```
FutureOr<String> Function(dynamic)? serializer = c.json.encode; FutureOr<String> Function(dynamic) serializer = c.json.encode;
/// This response's status code. /// This response's status code.
int get statusCode => _statusCode; int get statusCode => _statusCode;
@ -182,7 +182,7 @@ abstract class ResponseContext<RawResponse>
{String callbackName = "callback", MediaType? contentType}) { {String callbackName = "callback", MediaType? contentType}) {
if (!isOpen) throw closed(); if (!isOpen) throw closed();
this.contentType = contentType ?? MediaType('application', 'javascript'); this.contentType = contentType ?? MediaType('application', 'javascript');
write("$callbackName(${serializer!(value)})"); write("$callbackName(${serializer(value)})");
return close(); return close();
} }
@ -308,7 +308,7 @@ abstract class ResponseContext<RawResponse>
Future<bool> serialize(value, {MediaType? contentType}) async { Future<bool> serialize(value, {MediaType? contentType}) async {
if (!isOpen) throw closed(); if (!isOpen) throw closed();
this.contentType = contentType ?? MediaType('application', 'json'); this.contentType = contentType ?? MediaType('application', 'json');
var text = await serializer!(value); var text = await serializer(value);
if (text.isEmpty) return true; if (text.isEmpty) return true;
write(text); write(text);
await close(); await close();

View file

@ -31,7 +31,7 @@ RequestHandler chain(Iterable<RequestHandler> handlers) {
runPipeline = () => Future.sync(() => handler(req, res)); runPipeline = () => Future.sync(() => handler(req, res));
} else { } else {
var current = runPipeline; var current = runPipeline;
runPipeline = () => current().then((result) => res.isOpen runPipeline = () => current().then((result) => !res.isOpen
? Future.value(result) ? Future.value(result)
: req.app!.executeHandler(handler, req, res)); : req.app!.executeHandler(handler, req, res));
} }

View file

@ -9,8 +9,7 @@ dependencies:
angel3_container: ^3.0.0 angel3_container: ^3.0.0
angel3_http_exception: ^3.0.0 angel3_http_exception: ^3.0.0
angel3_model: ^3.0.0 angel3_model: ^3.0.0
angel3_route: #^5.0.0 angel3_route: ^5.0.0
path: ../route
angel3_combinator: ^2.0.0 angel3_combinator: ^2.0.0
angel3_merge_map: ^2.0.0 angel3_merge_map: ^2.0.0
angel3_mock_request: ^2.0.0 angel3_mock_request: ^2.0.0

View file

@ -63,16 +63,11 @@ void main() {
}); });
test('unparsed primitive throws error', () async { test('unparsed primitive throws error', () async {
try {
var rq = MockHttpRequest('GET', Uri.parse('/num/unparsed/32')); var rq = MockHttpRequest('GET', Uri.parse('/num/unparsed/32'));
await rq.close(); await rq.close();
var req = await http.createRequestContext(rq, rq.response); var req = await http.createRequestContext(rq, rq.response);
var res = await http.createResponseContext(rq, rq.response, req); var res = await http.createResponseContext(rq, rq.response, req);
await app.runContained((num unparsed) => unparsed, req, res); expect(() => app.runContained((num unparsed) => unparsed, req, res),
throw StateError( throwsA(isA<ArgumentError>()));
'ArgumentError should be thrown if a parameter cannot be resolved.');
} on ArgumentError {
// Success
}
}); });
} }