| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 library googleapis.playcustomapp.v1.test; | 
|  | 2 | 
|  | 3 import "dart:core" as core; | 
|  | 4 import "dart:collection" as collection; | 
|  | 5 import "dart:async" as async; | 
|  | 6 import "dart:convert" as convert; | 
|  | 7 | 
|  | 8 import 'package:http/http.dart' as http; | 
|  | 9 import 'package:http/testing.dart' as http_testing; | 
|  | 10 import 'package:test/test.dart' as unittest; | 
|  | 11 | 
|  | 12 import 'package:googleapis/playcustomapp/v1.dart' as api; | 
|  | 13 | 
|  | 14 class HttpServerMock extends http.BaseClient { | 
|  | 15   core.Function _callback; | 
|  | 16   core.bool _expectJson; | 
|  | 17 | 
|  | 18   void register(core.Function callback, core.bool expectJson) { | 
|  | 19     _callback = callback; | 
|  | 20     _expectJson = expectJson; | 
|  | 21   } | 
|  | 22 | 
|  | 23   async.Future<http.StreamedResponse> send(http.BaseRequest request) { | 
|  | 24     if (_expectJson) { | 
|  | 25       return request.finalize() | 
|  | 26           .transform(convert.UTF8.decoder) | 
|  | 27           .join('') | 
|  | 28           .then((core.String jsonString) { | 
|  | 29         if (jsonString.isEmpty) { | 
|  | 30           return _callback(request, null); | 
|  | 31         } else { | 
|  | 32           return _callback(request, convert.JSON.decode(jsonString)); | 
|  | 33         } | 
|  | 34       }); | 
|  | 35     } else { | 
|  | 36       var stream = request.finalize(); | 
|  | 37       if (stream == null) { | 
|  | 38         return _callback(request, []); | 
|  | 39       } else { | 
|  | 40         return stream.toBytes().then((data) { | 
|  | 41           return _callback(request, data); | 
|  | 42         }); | 
|  | 43       } | 
|  | 44     } | 
|  | 45   } | 
|  | 46 } | 
|  | 47 | 
|  | 48 http.StreamedResponse stringResponse( | 
|  | 49     core.int status, core.Map<core.String, core.String> headers, core.String bod
     y) { | 
|  | 50   var stream = new async.Stream.fromIterable([convert.UTF8.encode(body)]); | 
|  | 51   return new http.StreamedResponse(stream, status, headers: headers); | 
|  | 52 } | 
|  | 53 | 
|  | 54 core.int buildCounterCustomApp = 0; | 
|  | 55 buildCustomApp() { | 
|  | 56   var o = new api.CustomApp(); | 
|  | 57   buildCounterCustomApp++; | 
|  | 58   if (buildCounterCustomApp < 3) { | 
|  | 59     o.languageCode = "foo"; | 
|  | 60     o.title = "foo"; | 
|  | 61   } | 
|  | 62   buildCounterCustomApp--; | 
|  | 63   return o; | 
|  | 64 } | 
|  | 65 | 
|  | 66 checkCustomApp(api.CustomApp o) { | 
|  | 67   buildCounterCustomApp++; | 
|  | 68   if (buildCounterCustomApp < 3) { | 
|  | 69     unittest.expect(o.languageCode, unittest.equals('foo')); | 
|  | 70     unittest.expect(o.title, unittest.equals('foo')); | 
|  | 71   } | 
|  | 72   buildCounterCustomApp--; | 
|  | 73 } | 
|  | 74 | 
|  | 75 | 
|  | 76 main() { | 
|  | 77   unittest.group("obj-schema-CustomApp", () { | 
|  | 78     unittest.test("to-json--from-json", () { | 
|  | 79       var o = buildCustomApp(); | 
|  | 80       var od = new api.CustomApp.fromJson(o.toJson()); | 
|  | 81       checkCustomApp(od); | 
|  | 82     }); | 
|  | 83   }); | 
|  | 84 | 
|  | 85 | 
|  | 86   unittest.group("resource-AccountsCustomAppsResourceApi", () { | 
|  | 87     unittest.test("method--create", () { | 
|  | 88       // TODO: Implement tests for media upload; | 
|  | 89       // TODO: Implement tests for media download; | 
|  | 90 | 
|  | 91       var mock = new HttpServerMock(); | 
|  | 92       api.AccountsCustomAppsResourceApi res = new api.PlaycustomappApi(mock).acc
     ounts.customApps; | 
|  | 93       var arg_request = buildCustomApp(); | 
|  | 94       var arg_account = "foo"; | 
|  | 95       mock.register(unittest.expectAsync2((http.BaseRequest req, json) { | 
|  | 96         var obj = new api.CustomApp.fromJson(json); | 
|  | 97         checkCustomApp(obj); | 
|  | 98 | 
|  | 99         var path = (req.url).path; | 
|  | 100         var pathOffset = 0; | 
|  | 101         var index; | 
|  | 102         var subPart; | 
|  | 103         unittest.expect(path.substring(pathOffset, pathOffset + 1), unittest.equ
     als("/")); | 
|  | 104         pathOffset += 1; | 
|  | 105 | 
|  | 106         var query = (req.url).query; | 
|  | 107         var queryOffset = 0; | 
|  | 108         var queryMap = {}; | 
|  | 109         addQueryParam(n, v) => queryMap.putIfAbsent(n, () => []).add(v); | 
|  | 110         parseBool(n) { | 
|  | 111           if (n == "true") return true; | 
|  | 112           if (n == "false") return false; | 
|  | 113           if (n == null) return null; | 
|  | 114           throw new core.ArgumentError("Invalid boolean: $n"); | 
|  | 115         } | 
|  | 116         if (query.length > 0) { | 
|  | 117           for (var part in query.split("&")) { | 
|  | 118             var keyvalue = part.split("="); | 
|  | 119             addQueryParam(core.Uri.decodeQueryComponent(keyvalue[0]), core.Uri.d
     ecodeQueryComponent(keyvalue[1])); | 
|  | 120           } | 
|  | 121         } | 
|  | 122 | 
|  | 123 | 
|  | 124         var h = { | 
|  | 125           "content-type" : "application/json; charset=utf-8", | 
|  | 126         }; | 
|  | 127         var resp = convert.JSON.encode(buildCustomApp()); | 
|  | 128         return new async.Future.value(stringResponse(200, h, resp)); | 
|  | 129       }), true); | 
|  | 130       res.create(arg_request, arg_account).then(unittest.expectAsync1(((api.Cust
     omApp response) { | 
|  | 131         checkCustomApp(response); | 
|  | 132       }))); | 
|  | 133     }); | 
|  | 134 | 
|  | 135   }); | 
|  | 136 | 
|  | 137 | 
|  | 138 } | 
|  | 139 | 
| OLD | NEW | 
|---|