| OLD | NEW |
| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 | 7 |
| 8 import 'package:http/http.dart' as http; | 8 import 'package:http/http.dart' as http; |
| 9 import 'package:http/src/utils.dart'; | 9 import 'package:http/src/utils.dart'; |
| 10 import 'package:http/testing.dart'; | 10 import 'package:http/testing.dart'; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 }).then((response) => response.body), completion(parse(equals({ | 26 }).then((response) => response.body), completion(parse(equals({ |
| 27 'field1': 'value1', | 27 'field1': 'value1', |
| 28 'field2': 'value2' | 28 'field2': 'value2' |
| 29 })))); | 29 })))); |
| 30 }); | 30 }); |
| 31 | 31 |
| 32 test('handles a streamed request', () { | 32 test('handles a streamed request', () { |
| 33 var client = new MockClient.streaming((request, bodyStream) { | 33 var client = new MockClient.streaming((request, bodyStream) { |
| 34 return bodyStream.bytesToString().then((bodyString) { | 34 return bodyStream.bytesToString().then((bodyString) { |
| 35 var controller = new StreamController<List<int>>(sync: true); | 35 var controller = new StreamController<List<int>>(sync: true); |
| 36 async.then((_) { | 36 new Future.sync(() { |
| 37 controller.add('Request body was "$bodyString"'.codeUnits); | 37 controller.add('Request body was "$bodyString"'.codeUnits); |
| 38 controller.close(); | 38 controller.close(); |
| 39 }); | 39 }); |
| 40 | 40 |
| 41 return new http.StreamedResponse(controller.stream, 200); | 41 return new http.StreamedResponse(controller.stream, 200); |
| 42 }); | 42 }); |
| 43 }); | 43 }); |
| 44 | 44 |
| 45 var uri = Uri.parse("http://example.com/foo"); | 45 var uri = Uri.parse("http://example.com/foo"); |
| 46 var request = new http.Request("POST", uri); | 46 var request = new http.Request("POST", uri); |
| 47 request.body = "hello, world"; | 47 request.body = "hello, world"; |
| 48 var future = client.send(request) | 48 var future = client.send(request) |
| 49 .then(http.Response.fromStream) | 49 .then(http.Response.fromStream) |
| 50 .then((response) => response.body); | 50 .then((response) => response.body); |
| 51 expect(future, completion(equals('Request body was "hello, world"'))); | 51 expect(future, completion(equals('Request body was "hello, world"'))); |
| 52 }); | 52 }); |
| 53 | 53 |
| 54 test('handles a request with no body', () { | 54 test('handles a request with no body', () { |
| 55 var client = new MockClient((request) { | 55 var client = new MockClient((request) { |
| 56 return new Future.value(new http.Response('you did it', 200)); | 56 return new Future.value(new http.Response('you did it', 200)); |
| 57 }); | 57 }); |
| 58 | 58 |
| 59 expect(client.read("http://example.com/foo"), | 59 expect(client.read("http://example.com/foo"), |
| 60 completion(equals('you did it'))); | 60 completion(equals('you did it'))); |
| 61 }); | 61 }); |
| 62 } | 62 } |
| OLD | NEW |