mirror of https://github.com/grpc/grpc.git
Merge pull request #9519 from jtattermusch/csharp_test_doubles
Add a way to create testing doubles for C# calls.pull/9558/head
commit
b70c06dd3b
16 changed files with 341 additions and 0 deletions
@ -0,0 +1,2 @@ |
||||
bin |
||||
obj |
@ -0,0 +1,8 @@ |
||||
{ |
||||
"frameworks": { |
||||
"net45": { } |
||||
}, |
||||
"runtimes": { |
||||
"win": { } |
||||
} |
||||
} |
@ -0,0 +1,10 @@ |
||||
<StyleCopSettings Version="105"> |
||||
<SourceFileList> |
||||
<SourceFile>Health.cs</SourceFile> |
||||
<Settings> |
||||
<GlobalSettings> |
||||
<BooleanProperty Name="RulesEnabledByDefault">False</BooleanProperty> |
||||
</GlobalSettings> |
||||
</Settings> |
||||
</SourceFileList> |
||||
</StyleCopSettings> |
@ -0,0 +1,91 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, Google Inc. |
||||
// All rights reserved. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Threading.Tasks; |
||||
using Grpc.Core; |
||||
|
||||
namespace Grpc.Core.Testing |
||||
{ |
||||
/// <summary> |
||||
/// Test doubles for client-side call objects. |
||||
/// </summary> |
||||
public static class TestCalls |
||||
{ |
||||
/// <summary> |
||||
/// Creates a test double for <c>AsyncUnaryCall</c>. Only for testing. |
||||
/// Note: experimental API that can change or be removed without any prior notice. |
||||
/// </summary> |
||||
public static AsyncUnaryCall<TResponse> AsyncUnaryCall<TResponse> ( |
||||
Task<TResponse> responseAsync, Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc, |
||||
Func<Metadata> getTrailersFunc, Action disposeAction) |
||||
{ |
||||
return new AsyncUnaryCall<TResponse>(responseAsync, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a test double for <c>AsyncClientStreamingCall</c>. Only for testing. |
||||
/// Note: experimental API that can change or be removed without any prior notice. |
||||
/// </summary> |
||||
public static AsyncClientStreamingCall<TRequest, TResponse> AsyncClientStreamingCall<TRequest, TResponse>( |
||||
IClientStreamWriter<TRequest> requestStream, Task<TResponse> responseAsync, |
||||
Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc, |
||||
Func<Metadata> getTrailersFunc, Action disposeAction) |
||||
{ |
||||
return new AsyncClientStreamingCall<TRequest, TResponse>(requestStream, responseAsync, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a test double for <c>AsyncServerStreamingCall</c>. Only for testing. |
||||
/// Note: experimental API that can change or be removed without any prior notice. |
||||
/// </summary> |
||||
public static AsyncServerStreamingCall<TResponse> AsyncServerStreamingCall<TResponse>( |
||||
IAsyncStreamReader<TResponse> responseStream, Task<Metadata> responseHeadersAsync, |
||||
Func<Status> getStatusFunc, Func<Metadata> getTrailersFunc, Action disposeAction) |
||||
{ |
||||
return new AsyncServerStreamingCall<TResponse>(responseStream, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction); |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Creates a test double for <c>AsyncDuplexStreamingCall</c>. Only for testing. |
||||
/// Note: experimental API that can change or be removed without any prior notice. |
||||
/// </summary> |
||||
public static AsyncDuplexStreamingCall<TRequest, TResponse> AsyncDuplexStreamingCall<TResponse, TRequest>( |
||||
IClientStreamWriter<TRequest> requestStream, IAsyncStreamReader<TResponse> responseStream, |
||||
Task<Metadata> responseHeadersAsync, Func<Status> getStatusFunc, |
||||
Func<Metadata> getTrailersFunc, Action disposeAction) |
||||
{ |
||||
return new AsyncDuplexStreamingCall<TRequest, TResponse>(requestStream, responseStream, responseHeadersAsync, getStatusFunc, getTrailersFunc, disposeAction); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,39 @@ |
||||
{ |
||||
"version": "1.2.0-dev", |
||||
"title": "gRPC C# Core Testing", |
||||
"authors": [ "Google Inc." ], |
||||
"copyright": "Copyright 2017, Google Inc.", |
||||
"packOptions": { |
||||
"summary": "Testing support for gRPC C#", |
||||
"description": "Useful when testing code that uses gRPC.", |
||||
"owners": [ "grpc-packages" ], |
||||
"licenseUrl": "https://github.com/grpc/grpc/blob/master/LICENSE", |
||||
"projectUrl": "https://github.com/grpc/grpc", |
||||
"requireLicenseAcceptance": false, |
||||
"tags": [ "gRPC test testing" ] |
||||
}, |
||||
"buildOptions": { |
||||
"define": [ "SIGNED" ], |
||||
"keyFile": "../keys/Grpc.snk", |
||||
"xmlDoc": true, |
||||
"compile": { |
||||
"includeFiles": [ "../Grpc.Core/Version.cs" ] |
||||
} |
||||
}, |
||||
"dependencies": { |
||||
"Grpc.Core": "1.2.0-dev" |
||||
}, |
||||
"frameworks": { |
||||
"net45": { |
||||
"frameworkAssemblies": { |
||||
"System.Runtime": "", |
||||
"System.IO": "" |
||||
} |
||||
}, |
||||
"netstandard1.5": { |
||||
"dependencies": { |
||||
"NETStandard.Library": "1.6.0" |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,41 @@ |
||||
%YAML 1.2 |
||||
--- | |
||||
{ |
||||
"version": "${settings.csharp_version}", |
||||
"title": "gRPC C# Core Testing", |
||||
"authors": [ "Google Inc." ], |
||||
"copyright": "Copyright 2017, Google Inc.", |
||||
"packOptions": { |
||||
"summary": "Testing support for gRPC C#", |
||||
"description": "Useful when testing code that uses gRPC.", |
||||
"owners": [ "grpc-packages" ], |
||||
"licenseUrl": "https://github.com/grpc/grpc/blob/master/LICENSE", |
||||
"projectUrl": "https://github.com/grpc/grpc", |
||||
"requireLicenseAcceptance": false, |
||||
"tags": [ "gRPC test testing" ] |
||||
}, |
||||
"buildOptions": { |
||||
"define": [ "SIGNED" ], |
||||
"keyFile": "../keys/Grpc.snk", |
||||
"xmlDoc": true, |
||||
"compile": { |
||||
"includeFiles": [ "../Grpc.Core/Version.cs" ] |
||||
} |
||||
}, |
||||
"dependencies": { |
||||
"Grpc.Core": "${settings.csharp_version}" |
||||
}, |
||||
"frameworks": { |
||||
"net45": { |
||||
"frameworkAssemblies": { |
||||
"System.Runtime": "", |
||||
"System.IO": "" |
||||
} |
||||
}, |
||||
"netstandard1.5": { |
||||
"dependencies": { |
||||
"NETStandard.Library": "1.6.0" |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue