Net.Testing.Moq.Grpc
1.3.0
dotnet add package Net.Testing.Moq.Grpc --version 1.3.0
NuGet\Install-Package Net.Testing.Moq.Grpc -Version 1.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Net.Testing.Moq.Grpc" Version="1.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Net.Testing.Moq.Grpc --version 1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Net.Testing.Moq.Grpc, 1.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Net.Testing.Moq.Grpc as a Cake Addin #addin nuget:?package=Net.Testing.Moq.Grpc&version=1.3.0 // Install Net.Testing.Moq.Grpc as a Cake Tool #tool nuget:?package=Net.Testing.Moq.Grpc&version=1.3.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
grpc.net.testing.moq
Library to mocking gRPC client. Instead of Grpc.Core.Testing
using extensions for Moq
Based on libraries:
Install
Nuget:
Install-Package Net.Testing.Moq.Grpc
Using example
There is naming policy aka
.Setup(...).Returns(...)
, but it cannot use with Delegates (only for values computed outside)
Simple sync calling:
1. Call with exists response
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
// Setup and set return
grpcMock
.Setup(c => c.Simple(It.IsAny<TestRequest>(), null, null, default))
.ReturnsAsync(new TestResponse());
var client = grpcMock.Object;
// Call
var response = client.Simple(new TestRequest());
Simple async calling:
1. Call with exists response
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
var testResponse = new TestResponse();
// Setup and set return
grpcMock
.Setup(c => c.SimpleAsync(It.IsAny<TestRequest>(), null, null, default))
.ReturnsAsync(testResponse);
var client = grpcMock.Object;
// Call
var response = await client.SimpleAsync(new TestRequest());
2. Call with response creating on call
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
// Setup and set return by lambda
grpcMock
.Setup(c => c.SimpleAsync(It.IsAny<TestRequest>(), null, null, default))
.ReturnsAsync(() => new TestResponse());
var client = grpcMock.Object;
// Call
var response = client.SimpleAsync(new TestRequest());
3. Call with response creating on call and based on request
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
// Setup and set return by lambda with request param
grpcMock
.Setup(c => c.SimpleAsync(It.IsAny<TestRequest>(), null, null, default))
.ReturnsAsync<TestService.TestServiceClient, TestRequest, TestResponse>(r => new TestResponse{ Val = r.Val });
var client = grpcMock.Object;
// Call
var response = client.SimpleAsync(new TestRequest());
Simple client stream calling:
1. Call with exists response
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
var testResponse = new TestResponse();
// Setup and set response
grpcMock
.Setup(c => c.SimpleClientStream(null, null, default))
.ReturnsAsync(testResponse);
var client = grpcMock.Object;
// Call
var stream = client.SimpleClientStream();
await stream.RequestStream.WriteAllAsync(new[] {new TestRequest()}, true);
var response = await stream;
2. Call with response creating on call
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
var testResponse = new TestResponse();
// Setup and set response by lambda
grpcMock
.Setup(c => c.SimpleClientStream(null, null, default))
.ReturnsAsync(() => testResponse);
var client = grpcMock.Object;
// Call
var stream = client.SimpleClientStream();
await stream.RequestStream.WriteAllAsync(new[] {new TestRequest()}, true);
var response = await stream;
3. Call with response creating on call and based on request
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
// Setup and set response by lambda and requests like param
grpcMock
.Setup(c => c.SimpleClientStream(null, null, default))
.ReturnsAsync(rs => new TestResponse{ Val = rs.Sum(r => r.Val) });
var client = grpcMock.Object;
// Call
var stream = client.SimpleClientStream();
await stream.RequestStream.WriteAllAsync(new[] {new TestRequest()}, true);
var response = await stream;
Simple server stream calling:
1. Call with exists response
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
var testResponse = new[]{ new TestResponse() };
// Setup and set responses like argument (params TResponse[] responses)
grpcMock
.Setup(c => c.SimpleServerStream(It.IsAny<TestRequest>(), null, null, default))
.ReturnsAsync(testResponse);
var client = grpcMock.Object;
// Call
var stream = client.SimpleServerStream(new TestRequest());
var responses = stream.ResponseStream.ReadAllAsync();
2. Call with response creating on call
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
var testResponse = new[]{ new TestResponse() };
// Setup and set responses by lambda (factory)
grpcMock
.Setup(c => c.SimpleServerStream(It.IsAny<TestRequest>(), null, null, default))
.ReturnsAsync(() => testResponse);
var client = grpcMock.Object;
// Call
var stream = client.SimpleServerStream(new TestRequest());
var responses = stream.ResponseStream.ReadAllAsync();
3. Call with response creating on call and based on request
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
// Setup and set responses by lambda and request like argument
grpcMock
.Setup(c => c.SimpleServerStream(It.IsAny<TestRequest>(), null, null, default))
.ReturnsAsync<TestService.TestServiceClient, TestRequest, TestResponse>(r => new[]{ new TestResponse{ Val = r.Val } });
var client = grpcMock.Object;
// Call
var stream = client.SimpleServerStream(new TestRequest());
var responses = stream.ResponseStream.ReadAllAsync();
Simple client server streams calling:
1. Call with exists response
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
var testResponse = new[]{ new TestResponse() };
// Setup and set responses like argument (params TResponse[] responses)
grpcMock
.Setup(c => c.SimpleClientServerStream(null, null, default))
.ReturnsAsync(testResponse);
var client = grpcMock.Object;
// Call
var stream = client.SimpleClientServerStream();
await stream.RequestStream.WriteAsync(new TestRequest(), true);
var responses = stream.ResponseStream.ReadAllAsync();
2. Call with response creating on call
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
var testResponse = new[]{ new TestResponse() };
// Setup and set responses by lambda
grpcMock
.Setup(c => c.SimpleClientServerStream(null, null, default))
.ReturnsAsync(() => testResponse);
var client = grpcMock.Object;
// Call
var stream = client.SimpleClientServerStream();
await stream.RequestStream.WriteAsync(new TestRequest(), true);
var responses = stream.ResponseStream.ReadAllAsync();
3. Call with response creating on call and based on request
// Creation moq
var grpcMock = new Mock<TestService.TestServiceClient>();
var testResponse = new[]{ new TestResponse() };
// Setup and set responses by lambda and requests like args
grpcMock
.Setup(c => c.SimpleClientServerStream(null, null, default))
.ReturnsAsync(rs => rs.Select(r => new TestResponse{ Val = r.Val }));
var client = grpcMock.Object;
// Call
var stream = client.SimpleClientServerStream();
await stream.RequestStream.WriteAsync(new TestRequest(), true);
var responses = stream.ResponseStream.ReadAllAsync();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.