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

Side by Side Diff: pkg/http/test/mock_client_test.dart

Issue 11975017: Stop treating StreamController as a Stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/http/lib/src/utils.dart ('k') | pkg/http/test/multipart_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
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library mock_client_test; 5 library mock_client_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'dart:json' as json; 9 import 'dart:json' as json;
10 import 'dart:uri'; 10 import 'dart:uri';
(...skipping 17 matching lines...) Expand all
28 'field2': 'value2' 28 'field2': 'value2'
29 }).then((response) => response.body), completion(parse(equals({ 29 }).then((response) => response.body), completion(parse(equals({
30 'field1': 'value1', 30 'field1': 'value1',
31 'field2': 'value2' 31 'field2': 'value2'
32 })))); 32 }))));
33 }); 33 });
34 34
35 test('handles a streamed request', () { 35 test('handles a streamed request', () {
36 var client = new MockClient.streaming((request, bodyStream) { 36 var client = new MockClient.streaming((request, bodyStream) {
37 return bodyStream.bytesToString().then((bodyString) { 37 return bodyStream.bytesToString().then((bodyString) {
38 var stream = new StreamController<List<int>>(); 38 var controller = new StreamController<List<int>>();
39 async.then((_) { 39 async.then((_) {
40 stream.add('Request body was "$bodyString"'.charCodes); 40 controller.add('Request body was "$bodyString"'.charCodes);
41 stream.close(); 41 controller.close();
42 }); 42 });
43 43
44 return new http.StreamedResponse(stream, 200, -1); 44 return new http.StreamedResponse(controller.stream, 200, -1);
45 }); 45 });
46 }); 46 });
47 47
48 var uri = new Uri.fromString("http://example.com/foo"); 48 var uri = new Uri.fromString("http://example.com/foo");
49 var request = new http.Request("POST", uri); 49 var request = new http.Request("POST", uri);
50 request.body = "hello, world"; 50 request.body = "hello, world";
51 var future = client.send(request) 51 var future = client.send(request)
52 .then(http.Response.fromStream) 52 .then(http.Response.fromStream)
53 .then((response) => response.body); 53 .then((response) => response.body);
54 expect(future, completion(equals('Request body was "hello, world"'))); 54 expect(future, completion(equals('Request body was "hello, world"')));
55 }); 55 });
56 56
57 test('handles a request with no body', () { 57 test('handles a request with no body', () {
58 var client = new MockClient((request) { 58 var client = new MockClient((request) {
59 return new Future.immediate(new http.Response('you did it', 200)); 59 return new Future.immediate(new http.Response('you did it', 200));
60 }); 60 });
61 61
62 expect(client.read("http://example.com/foo"), 62 expect(client.read("http://example.com/foo"),
63 completion(equals('you did it'))); 63 completion(equals('you did it')));
64 }); 64 });
65 } 65 }
OLDNEW
« no previous file with comments | « pkg/http/lib/src/utils.dart ('k') | pkg/http/test/multipart_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698