xref: /aosp_15_r20/external/grpc-grpc/test/distrib/csharp/DistribTest/Program.cs (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1 #region Copyright notice and license
2 
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #endregion
18 
19 using System;
20 using System.Linq;
21 using System.Threading.Tasks;
22 using Grpc.Core;
23 using GrpcCsharpDistribtest.Helloworld;
24 
25 namespace TestGrpcPackage
26 {
27     class MainClass
28     {
Main(string[] args)29         public static void Main(string[] args)
30         {
31             CheckGreeterProtobufCodegenWorks();
32             CheckGreeterGrpcProtobufPluginCodegenWorks();
33             CheckDuplicateProtoFilesAreOk();
34         }
35 
CheckGreeterProtobufCodegenWorks()36         private static object CheckGreeterProtobufCodegenWorks()
37         {
38             return new HelloRequest { Name = "ABC" };
39         }
40 
CheckGreeterGrpcProtobufPluginCodegenWorks()41         private static object CheckGreeterGrpcProtobufPluginCodegenWorks()
42         {
43             return typeof(GreeterImpl);
44         }
45 
46         // Test that codegen works well in case the .csproj has .proto files
47         // of the same name, but under different directories (see #17672).
48         // This method doesn't need to be used, it is enough to check that it builds.
CheckDuplicateProtoFilesAreOk()49         private static object CheckDuplicateProtoFilesAreOk()
50         {
51             return new GrpcCsharpDistribtest.DuplicateProto.MessageFromDuplicateProto();
52         }
53     }
54 
55     class GreeterImpl : Greeter.GreeterBase
56     {
57         // Server side handler of the SayHello RPC
SayHello(HelloRequest request, ServerCallContext context)58         public override Task<HelloReply> SayHello(HelloRequest request, ServerCallContext context)
59         {
60             return Task.FromResult(new HelloReply { Message = "Hello " + request.Name });
61         }
62     }
63 }
64