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 library mock_client_test; | 5 library mock_client_test; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:json' as json; | 8 import 'dart:convert'; |
9 | 9 |
10 import 'package:http/http.dart' as http; | 10 import 'package:http/http.dart' as http; |
11 import 'package:http/src/utils.dart'; | 11 import 'package:http/src/utils.dart'; |
12 import 'package:http/testing.dart'; | 12 import 'package:http/testing.dart'; |
13 import 'package:unittest/unittest.dart'; | 13 import 'package:unittest/unittest.dart'; |
14 | 14 |
15 import 'utils.dart'; | 15 import 'utils.dart'; |
16 | 16 |
17 void main() { | 17 void main() { |
18 test('handles a request', () { | 18 test('handles a request', () { |
19 var client = new MockClient((request) { | 19 var client = new MockClient((request) { |
20 return new Future.value(new http.Response( | 20 return new Future.value(new http.Response( |
21 json.stringify(request.bodyFields), 200, | 21 JSON.encode(request.bodyFields), 200, |
22 request: request, headers: {'content-type': 'application/json'})); | 22 request: request, headers: {'content-type': 'application/json'})); |
23 }); | 23 }); |
24 | 24 |
25 expect(client.post("http://example.com/foo", fields: { | 25 expect(client.post("http://example.com/foo", fields: { |
26 'field1': 'value1', | 26 'field1': 'value1', |
27 'field2': 'value2' | 27 'field2': 'value2' |
28 }).then((response) => response.body), completion(parse(equals({ | 28 }).then((response) => response.body), completion(parse(equals({ |
29 'field1': 'value1', | 29 'field1': 'value1', |
30 'field2': 'value2' | 30 'field2': 'value2' |
31 })))); | 31 })))); |
(...skipping 23 matching lines...) Expand all Loading... |
55 | 55 |
56 test('handles a request with no body', () { | 56 test('handles a request with no body', () { |
57 var client = new MockClient((request) { | 57 var client = new MockClient((request) { |
58 return new Future.value(new http.Response('you did it', 200)); | 58 return new Future.value(new http.Response('you did it', 200)); |
59 }); | 59 }); |
60 | 60 |
61 expect(client.read("http://example.com/foo"), | 61 expect(client.read("http://example.com/foo"), |
62 completion(equals('you did it'))); | 62 completion(equals('you did it'))); |
63 }); | 63 }); |
64 } | 64 } |
OLD | NEW |