1 #region Copyright notice and license
3 // Copyright 2015 gRPC authors.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
20 using System.Threading.Tasks;
23 namespace Grpc.Core.Testing
26 /// Test doubles for client-side call objects.
28 public static class TestCalls
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.
34 public static AsyncUnaryCall<TResponse> AsyncUnaryCall<TResponse> (
35 Task<TResponse> responseAsync, Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc,
36 Func<Metadata> getTrailersFunc, Action disposeAction)
38 return new AsyncUnaryCall<TResponse>(responseAsync, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction);
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.
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)
50 return new AsyncClientStreamingCall<TRequest, TResponse>(requestStream, responseAsync, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction);
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.
57 public static AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TResponse>(
58 IAsyncStreamReader<TResponse> responseStream, Task<Metadata> responseHeadersAsync,
59 Func<Status> getStatusFunc, Func<Metadata> getTrailersFunc, Action disposeAction)
61 return new AsyncServerStreamingCall<TResponse>(responseStream, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction);
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.
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)
73 return new AsyncDuplexStreamingCall<TRequest, TResponse>(requestStream, responseStream, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction);