Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: test/server_test.dart

Issue 14267030: Added support for http methods when mounting routes. (Closed) Base URL: git@github.com:dart-lang/route.git@master
Patch Set: responding to review comments Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/server.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/server_test.dart
diff --git a/test/server_test.dart b/test/server_test.dart
index e4234139105c318c878778ba17d419aeb98b291b..6fb2fbbf614f7059daf13445397fce449f8a2694 100644
--- a/test/server_test.dart
+++ b/test/server_test.dart
@@ -13,8 +13,9 @@ import 'dart:uri';
class HttpRequestMock extends Mock implements HttpRequest {
Uri uri;
+ String method;
HttpResponseMock response = new HttpResponseMock();
- HttpRequestMock(this.uri);
+ HttpRequestMock(this.uri, {this.method});
}
class HttpResponseMock extends Mock implements HttpResponse {
@@ -28,6 +29,34 @@ class HttpResponseMock extends Mock implements HttpResponse {
}
main() {
+ test ('http method can be used to distinguish route', (){
+ var controller = new StreamController<HttpRequest>();
+ var router = new Router(controller.stream);
+ var testReq = new HttpRequestMock(new Uri('/foo'),method:'GET');
+ router.serve('/foo', method:'GET').listen(expectAsync1((req) {
+ expect(req, testReq);
+ }));
+ router.serve('/foo', method:'POST').listen(expectAsync1((_) {}, count:0));
+ controller.add(testReq);
+ });
+
+ test ('if no http method provided, all methods match', (){
+ var controller = new StreamController<HttpRequest>();
+ var router = new Router(controller.stream);
+ var testGetReq = new HttpRequestMock(new Uri('/foo'), method:'GET');
+ var testPostReq = new HttpRequestMock(new Uri('/foo'), method:'POST');
+ var requests = <HttpRequest>[];
+ router.serve('/foo').listen(expectAsync1((request) {
+ requests.add(request);
+ if (requests.length == 2){
+ expect(requests, [testGetReq, testPostReq]);
+ }
+ }, count: 2));
+ controller.add(testGetReq);
+ controller.add(testPostReq);
+
+ });
+
test('serve 1', () {
var controller = new StreamController<HttpRequest>();
var router = new Router(controller.stream);
« no previous file with comments | « lib/server.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698