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

Unified Diff: pkg/appengine/test/utils/mock_rpc.dart

Issue 804973002: Add appengine/gcloud/mustache dependencies. (Closed) Base URL: git@github.com:dart-lang/pub-dartlang-dart.git@master
Patch Set: Added AUTHORS/LICENSE/PATENTS files Created 6 years 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 side-by-side diff with in-line comments
Download patch
Index: pkg/appengine/test/utils/mock_rpc.dart
diff --git a/pkg/appengine/test/utils/mock_rpc.dart b/pkg/appengine/test/utils/mock_rpc.dart
new file mode 100644
index 0000000000000000000000000000000000000000..4b75be71dc05623e7e0fccb0bb70b8c8bb1fe82e
--- /dev/null
+++ b/pkg/appengine/test/utils/mock_rpc.dart
@@ -0,0 +1,41 @@
+// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:mirrors';
+
+import 'package:appengine/src/protobuf_api/rpc/rpc_service.dart';
+
+class MockRPCService extends RPCService {
+ String _service;
+ Map<String, Function> _handlers = {};
+
+ MockRPCService(this._service);
+
+ register(String method, Type requestType, Function handler) {
+ if (handler == null) {
+ _handlers.remove(method);
+ } else {
+ _handlers[method] = (List<int> bytes) {
+ var decodedRequest =
+ reflectClass(requestType).newInstance(#fromBuffer, [bytes]);
+ return handler(decodedRequest.reflectee);
+ };
+ }
+ }
+
+ Future<List<int>> call(String apiPackage,
+ String method,
+ List<int> requestProtocolBuffer,
+ {String ticket}) {
+ if (_service != apiPackage) {
+ throw "This Mock only works for the $_service service.";
+ }
+
+ if (_handlers.containsKey(method)) {
+ return _handlers[method](requestProtocolBuffer);
+ }
+ throw "Not mock handler for $apiPackage.$method found";
+ }
+}
« no previous file with comments | « pkg/appengine/test/utils/error_matchers.dart ('k') | pkg/appengine/test/utils/raw_datastore_test_utils.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698