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.Threading.Tasks;
21 using Grpc.Core;
22 
23 namespace Grpc.Core.Testing
24 {
25     /// <summary>
26     /// Test doubles for client-side call objects.
27     /// </summary>
28     public static class TestCalls
29     {
30         /// <summary>
31         /// Creates a test double for <c>AsyncUnaryCall</c>. Only for testing.
32         /// Note: experimental API that can change or be removed without any prior notice.
33         /// </summary>
AsyncUnaryCall( Task<TResponse> responseAsync, Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc, Func<Metadata> getTrailersFunc, Action disposeAction)34         public static AsyncUnaryCall<TResponse> AsyncUnaryCall<TResponse> (
35             Task<TResponse> responseAsync, Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc,
36             Func<Metadata> getTrailersFunc, Action disposeAction)
37         {
38             return new AsyncUnaryCall<TResponse>(responseAsync, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction);
39         }
40 
41         /// <summary>
42         /// Creates a test double for <c>AsyncClientStreamingCall</c>. Only for testing.
43         /// Note: experimental API that can change or be removed without any prior notice.
44         /// </summary>
AsyncClientStreamingCall( IClientStreamWriter<TRequest> requestStream, Task<TResponse> responseAsync, Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc, Func<Metadata> getTrailersFunc, Action disposeAction)45         public static AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>(
46             IClientStreamWriter<TRequest> requestStream, Task<TResponse> responseAsync,
47             Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc,
48             Func<Metadata> getTrailersFunc, Action disposeAction)
49         {
50             return new AsyncClientStreamingCall<TRequest, TResponse>(requestStream, responseAsync, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction);
51         }
52 
53         /// <summary>
54         /// Creates a test double for <c>AsyncServerStreamingCall</c>. Only for testing.
55         /// Note: experimental API that can change or be removed without any prior notice.
56         /// </summary>
AsyncServerStreamingCall( IAsyncStreamReader<TResponse> responseStream, Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc, Func<Metadata> getTrailersFunc, Action disposeAction)57         public static AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TResponse>(
58             IAsyncStreamReader<TResponse> responseStream, Task<Metadata> responseHeadersAsync,
59             Func<Status> getStatusFunc, Func<Metadata> getTrailersFunc, Action disposeAction)
60         {
61             return new AsyncServerStreamingCall<TResponse>(responseStream, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction);
62         }
63 
64         /// <summary>
65         /// Creates a test double for <c>AsyncDuplexStreamingCall</c>. Only for testing.
66         /// Note: experimental API that can change or be removed without any prior notice.
67         /// </summary>
AsyncDuplexStreamingCall( IClientStreamWriter<TRequest> requestStream, IAsyncStreamReader<TResponse> responseStream, Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc, Func<Metadata> getTrailersFunc, Action disposeAction)68         public static AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(
69             IClientStreamWriter<TRequest> requestStream, IAsyncStreamReader<TResponse> responseStream,
70             Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc,
71             Func<Metadata> getTrailersFunc, Action disposeAction)
72         {
73             return new AsyncDuplexStreamingCall<TRequest, TResponse>(requestStream, responseStream, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction);
74         }
75     }
76 }
77