OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, 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 usage.usage_impl_io_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 import 'dart:io'; |
| 9 |
| 10 import 'package:unittest/unittest.dart'; |
| 11 import 'package:usage/src/usage_impl_io.dart'; |
| 12 |
| 13 void defineTests() { |
| 14 group('IOPostHandler', () { |
| 15 test('sendPost', () { |
| 16 var httpClient = new MockHttpClient(); |
| 17 IOPostHandler postHandler = new IOPostHandler(mockClient: httpClient); |
| 18 Map args = {'utv': 'varName', 'utt': 123}; |
| 19 return postHandler.sendPost('http://www.google.com', args).then((_) { |
| 20 expect(httpClient.sendCount, 1); |
| 21 }); |
| 22 }); |
| 23 }); |
| 24 |
| 25 group('IOPersistentProperties', () { |
| 26 test('add', () { |
| 27 IOPersistentProperties props = new IOPersistentProperties('foo_props'); |
| 28 props['foo'] = 'bar'; |
| 29 expect(props['foo'], 'bar'); |
| 30 }); |
| 31 |
| 32 test('remove', () { |
| 33 IOPersistentProperties props = new IOPersistentProperties('foo_props'); |
| 34 props['foo'] = 'bar'; |
| 35 expect(props['foo'], 'bar'); |
| 36 props['foo'] = null; |
| 37 expect(props['foo'], null); |
| 38 }); |
| 39 }); |
| 40 } |
| 41 |
| 42 class MockHttpClient implements HttpClient { |
| 43 String userAgent; |
| 44 int sendCount = 0; |
| 45 int writeCount = 0; |
| 46 bool closed = false; |
| 47 Future<HttpClientRequest> postUrl(Uri url) { |
| 48 return new Future.value(new MockHttpClientRequest(this)); |
| 49 } |
| 50 noSuchMethod(Invocation invocation) { } |
| 51 } |
| 52 |
| 53 class MockHttpClientRequest implements HttpClientRequest { |
| 54 final MockHttpClient client; |
| 55 MockHttpClientRequest(this.client); |
| 56 void write(Object obj) { |
| 57 client.writeCount++; |
| 58 } |
| 59 Future<HttpClientResponse> close() { |
| 60 client.closed = true; |
| 61 return new Future.value(new MockHttpClientResponse(client)); |
| 62 } |
| 63 noSuchMethod(Invocation invocation) { } |
| 64 } |
| 65 |
| 66 class MockHttpClientResponse implements HttpClientResponse { |
| 67 final MockHttpClient client; |
| 68 MockHttpClientResponse(this.client); |
| 69 Future drain([var futureValue]) { |
| 70 client.sendCount++; |
| 71 return new Future.value(); |
| 72 } |
| 73 noSuchMethod(Invocation invocation) { } |
| 74 } |
OLD | NEW |