I usually do something like this
1: I create an interface for the service to test the DI system and or to be able to mock it. I do this as registering the gRPC service with the framework kinde-does-that as well as it's created similar to a controller
Then I write my Test like so:
[TestMethod]
public async Task Call_Grpc_Method_Test()
{
var grpcService = _service.GetRequiredService<IMyService>();
var request = new MyRequest {When=DateTime.Now.AddDays(30)};
var context = TestServerCallContext.Create(
method: nameof(IMyService.WinningLotteryNumbers)
, host: "localhost"
, deadline: DateTime.Now.AddMinutes(30)
, requestHeaders: new Metadata()
, cancellationToken: CancellationToken.None
, peer: "10.0.0.25:5001"
, authContext: null
, contextPropagationToken: null
, writeHeadersFunc: (metadata) => Task.CompletedTask
, writeOptionsGetter: () => new WriteOptions()
, writeOptionsSetter: (writeOptions) => { }
) ;
var answer= await grpcService.WinningLotteryNumbers(request, context);
Assert.IsNotNull(answer);
}
IMyService is the gRPC service I want to test and I just create an IServiceProvider that can build one for me via the actual implementations making it an integration test or via mocked objects making it a unit test.
The TestServerCallContext class is located in the NuGet package Grpc.Core.Testing, you would need to add that to your test project.
as to the constructor, well you can use hard coded sample data as I demonstrated or go fancy and add meta data for headers and authcontex as well as the stuff when you need it...
As you can see, not that hard to do once you get started ;-)