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

Unified Diff: pkg/http/test/mock_client_test.dart

Issue 11364134: Merge libv1. (Closed) Base URL: https://dart.googlecode.com/svn/experimental/lib_v2/dart
Patch Set: Reupload due to error Created 8 years, 1 month 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 | « pkg/http/lib/testing.dart ('k') | pkg/http/test/request_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/http/test/mock_client_test.dart
diff --git a/pkg/http/test/mock_client_test.dart b/pkg/http/test/mock_client_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..2425467c98a34a51507969209a9eb07bc1c88cee
--- /dev/null
+++ b/pkg/http/test/mock_client_test.dart
@@ -0,0 +1,57 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+library mock_client_test;
+
+import 'dart:io';
+import 'dart:json';
+import 'dart:uri';
+
+// TODO(nweiz): make these "package:" imports.
+import '../../unittest/lib/unittest.dart';
+import '../lib/http.dart' as http;
+import '../lib/testing.dart';
+import '../lib/src/utils.dart';
+import 'utils.dart';
+
+void main() {
+ test('handles a request', () {
+ var client = new MockClient((request) {
+ return new Future.immediate(new http.Response(
+ JSON.stringify(request.bodyFields), 200,
+ headers: {'content-type': 'application/json'}));
+ });
+
+ expect(client.post("http://example.com/foo", fields: {
+ 'field1': 'value1',
+ 'field2': 'value2'
+ }).transform((response) => response.body), completion(parse(equals({
+ 'field1': 'value1',
+ 'field2': 'value2'
+ }))));
+ });
+
+ test('handles a streamed request', () {
+ var client = new MockClient.streaming((request, bodyStream) {
+ return consumeInputStream(bodyStream).transform((body) {
+ var stream = new ListInputStream();
+ async.then((_) {
+ var bodyString = new String.fromCharCodes(body);
+ stream.write('Request body was "$bodyString"'.charCodes);
+ stream.markEndOfStream();
+ });
+
+ return new http.StreamedResponse(stream, 200, -1);
+ });
+ });
+
+ var uri = new Uri.fromString("http://example.com/foo");
+ var request = new http.Request("POST", uri);
+ request.body = "hello, world";
+ var future = client.send(request)
+ .chain(http.Response.fromStream)
+ .transform((response) => response.body);
+ expect(future, completion(equals('Request body was "hello, world"')));
+ });
+}
« no previous file with comments | « pkg/http/lib/testing.dart ('k') | pkg/http/test/request_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698