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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 import 'dart:async';
6 import 'dart:mirrors';
7
8 import 'package:appengine/src/protobuf_api/rpc/rpc_service.dart';
9
10 class MockRPCService extends RPCService {
11 String _service;
12 Map<String, Function> _handlers = {};
13
14 MockRPCService(this._service);
15
16 register(String method, Type requestType, Function handler) {
17 if (handler == null) {
18 _handlers.remove(method);
19 } else {
20 _handlers[method] = (List<int> bytes) {
21 var decodedRequest =
22 reflectClass(requestType).newInstance(#fromBuffer, [bytes]);
23 return handler(decodedRequest.reflectee);
24 };
25 }
26 }
27
28 Future<List<int>> call(String apiPackage,
29 String method,
30 List<int> requestProtocolBuffer,
31 {String ticket}) {
32 if (_service != apiPackage) {
33 throw "This Mock only works for the $_service service.";
34 }
35
36 if (_handlers.containsKey(method)) {
37 return _handlers[method](requestProtocolBuffer);
38 }
39 throw "Not mock handler for $apiPackage.$method found";
40 }
41 }
OLDNEW
« 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