blob: 8c76781bbe34ac44589f49144b359f028891ddb9 [file] [log] [blame]
Jan Tattermusch2b2723b2017-01-30 17:30:22 +01001#region Copyright notice and license
2
Jan Tattermusch7897ae92017-06-07 22:57:36 +02003// Copyright 2015 gRPC authors.
Jan Tattermusch2b2723b2017-01-30 17:30:22 +01004//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02005// 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
Jan Tattermusch2b2723b2017-01-30 17:30:22 +01008//
Jan Tattermusch7897ae92017-06-07 22:57:36 +02009// http://www.apache.org/licenses/LICENSE-2.0
Jan Tattermusch2b2723b2017-01-30 17:30:22 +010010//
Jan Tattermusch7897ae92017-06-07 22:57:36 +020011// 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.
Jan Tattermusch2b2723b2017-01-30 17:30:22 +010016
17#endregion
18
19using System;
20using System.Threading.Tasks;
21using Grpc.Core;
22
23namespace 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>
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>
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>
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>
Jan Tattermusch1d107022018-06-08 11:07:19 +020068 public static AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TRequest, TResponse>(
Jan Tattermusch2b2723b2017-01-30 17:30:22 +010069 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}