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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http/lib/testing.dart ('k') | pkg/http/test/request_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 library mock_client_test;
6
7 import 'dart:io';
8 import 'dart:json';
9 import 'dart:uri';
10
11 // TODO(nweiz): make these "package:" imports.
12 import '../../unittest/lib/unittest.dart';
13 import '../lib/http.dart' as http;
14 import '../lib/testing.dart';
15 import '../lib/src/utils.dart';
16 import 'utils.dart';
17
18 void main() {
19 test('handles a request', () {
20 var client = new MockClient((request) {
21 return new Future.immediate(new http.Response(
22 JSON.stringify(request.bodyFields), 200,
23 headers: {'content-type': 'application/json'}));
24 });
25
26 expect(client.post("http://example.com/foo", fields: {
27 'field1': 'value1',
28 'field2': 'value2'
29 }).transform((response) => response.body), completion(parse(equals({
30 'field1': 'value1',
31 'field2': 'value2'
32 }))));
33 });
34
35 test('handles a streamed request', () {
36 var client = new MockClient.streaming((request, bodyStream) {
37 return consumeInputStream(bodyStream).transform((body) {
38 var stream = new ListInputStream();
39 async.then((_) {
40 var bodyString = new String.fromCharCodes(body);
41 stream.write('Request body was "$bodyString"'.charCodes);
42 stream.markEndOfStream();
43 });
44
45 return new http.StreamedResponse(stream, 200, -1);
46 });
47 });
48
49 var uri = new Uri.fromString("http://example.com/foo");
50 var request = new http.Request("POST", uri);
51 request.body = "hello, world";
52 var future = client.send(request)
53 .chain(http.Response.fromStream)
54 .transform((response) => response.body);
55 expect(future, completion(equals('Request body was "hello, world"')));
56 });
57 }
OLDNEW
« 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