| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 #!/usr/bin/env dart | 
|  | 2 // Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file | 
|  | 3 // for details. All rights reserved. Use of this source code is governed by a | 
|  | 4 // BSD-style license that can be found in the LICENSE file. | 
|  | 5 | 
|  | 6 library client_generator_test; | 
|  | 7 | 
|  | 8 import 'package:protoc_plugin/src/descriptor.pb.dart'; | 
|  | 9 import 'package:protoc_plugin/src/plugin.pb.dart'; | 
|  | 10 import 'package:protoc_plugin/protoc.dart'; | 
|  | 11 import 'package:unittest/unittest.dart'; | 
|  | 12 | 
|  | 13 ServiceDescriptorProto buildServiceDescriptor() { | 
|  | 14   ServiceDescriptorProto sd = new ServiceDescriptorProto() | 
|  | 15     ..name = 'Test' | 
|  | 16     ..method.addAll([ | 
|  | 17       new MethodDescriptorProto() | 
|  | 18         ..name = 'AMethod' | 
|  | 19         ..inputType = 'SomeRequest' | 
|  | 20         ..outputType = 'SomeReply', | 
|  | 21       new MethodDescriptorProto() | 
|  | 22         ..name = 'AnotherMethod' | 
|  | 23         ..inputType = '.foo.bar.EmptyMessage' | 
|  | 24         ..outputType = '.foo.bar.AnotherReply', | 
|  | 25     ]); | 
|  | 26   return sd; | 
|  | 27 } | 
|  | 28 | 
|  | 29 void main() { | 
|  | 30   test('testClientGenerator', () { | 
|  | 31     // NOTE: Below > 80 cols because it is matching generated code > 80 cols. | 
|  | 32     String expected = r''' | 
|  | 33 class TestApi { | 
|  | 34   RpcClient _client; | 
|  | 35   TestApi(this._client); | 
|  | 36 | 
|  | 37   Future<SomeReply> aMethod(ClientContext ctx, SomeRequest request) async { | 
|  | 38     var emptyResponse = new SomeReply(); | 
|  | 39     var result = await _client.invoke(ctx, 'Test', 'AMethod', request, emptyResp
    onse); | 
|  | 40     return result; | 
|  | 41   } | 
|  | 42   Future<AnotherReply> anotherMethod(ClientContext ctx, EmptyMessage request) as
    ync { | 
|  | 43     var emptyResponse = new AnotherReply(); | 
|  | 44     var result = await _client.invoke(ctx, 'Test', 'AnotherMethod', request, emp
    tyResponse); | 
|  | 45     return result; | 
|  | 46   } | 
|  | 47 } | 
|  | 48 | 
|  | 49 '''; | 
|  | 50     var options = parseGenerationOptions( | 
|  | 51         new CodeGeneratorRequest(), new CodeGeneratorResponse()); | 
|  | 52     var context = | 
|  | 53         new GenerationContext(options, new DefaultOutputConfiguration()); | 
|  | 54     var fd = new FileDescriptorProto(); | 
|  | 55     var fg = new FileGenerator(fd, null, context); | 
|  | 56     ServiceDescriptorProto sd = buildServiceDescriptor(); | 
|  | 57     MemoryWriter buffer = new MemoryWriter(); | 
|  | 58     IndentingWriter writer = new IndentingWriter('  ', buffer); | 
|  | 59     ClientApiGenerator cag = new ClientApiGenerator(sd, fg, context); | 
|  | 60     cag.generate(writer); | 
|  | 61     expect(buffer.toString(), expected); | 
|  | 62   }); | 
|  | 63 } | 
| OLD | NEW | 
|---|