grpc / grpc

The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)
https://grpc.io
Apache License 2.0
41.84k stars 10.54k forks source link

C# How to Mock generated client base? #14522

Closed Disturbing closed 6 years ago

Disturbing commented 6 years ago

Please answer these questions before submitting your issue.

Should this be an issue in the gRPC issue tracker?

Yes, related to Csharp grpc. Googled / searched for this, couldnt find anything meaningful.

What version of gRPC and what language are you using?

gRPC C# 1.8.3

What operating system (Linux, Windows, …) and version?

Windows 10

What runtime / compiler are you using (e.g. python version or version of gcc)

VS 2017 15.3.3

What am I looking to do?

I'm looking to mock any client generated base.

The use case is to create a service which speaks to 3rd party grpc clients. I want to test all the logic within it, including the data sent to the 3rd party grpc client along with a mock response. I'm using NSubstitute for mocking.

The problem is

_client.CreateUserAsync(Arg.Any()).Returns(.... AsyncUnaryCall)....

How Can I go about mocking async unary call for a return with both Metadata and a Response.

Much thanks in advance!

Disturbing commented 6 years ago

Hey Guys - this would really be helpful to understand mocking with this library... It's quite a pain not being able to write effective tests when a dependency requires another dependency. Any help please?

peterdeme commented 6 years ago

Removing the interfaces from the generated code made it pretty much impossible to execute testing with GRPC...

jtattermusch commented 6 years ago

Can you specify what are the exact API elements that are preventing you from testing/mocking?

jtattermusch commented 6 years ago

I added examples how to create test doubles using public gRPC C# API in #15687.