Jan Tattermusch | 2b2723b | 2017-01-30 17:30:22 +0100 | [diff] [blame] | 1 | #region Copyright notice and license |
| 2 | |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 3 | // Copyright 2015 gRPC authors. |
Jan Tattermusch | 2b2723b | 2017-01-30 17:30:22 +0100 | [diff] [blame] | 4 | // |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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 |
Jan Tattermusch | 2b2723b | 2017-01-30 17:30:22 +0100 | [diff] [blame] | 8 | // |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
Jan Tattermusch | 2b2723b | 2017-01-30 17:30:22 +0100 | [diff] [blame] | 10 | // |
Jan Tattermusch | 7897ae9 | 2017-06-07 22:57:36 +0200 | [diff] [blame] | 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. |
Jan Tattermusch | 2b2723b | 2017-01-30 17:30:22 +0100 | [diff] [blame] | 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> |
| 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> |
| 68 | public static AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TResponse, TRequest>( |
| 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 | } |