0
AbpRaven created
How can I mock grpc server for tests? I have 2 microservices and from one of them i send request through gprc to second one. I have overwrited AfterAddApplication. This works but the request is sent to real service and of couse i got exception.
protected override void AfterAddApplication(IServiceCollection services)
{
_client = Substitute.For<MyClass>();
var responce = AsyncUnaryCall<SomeClass>(); //responce with real value
_client.GetAllAsync(Arg.Any<Request>()).Returns(responce);
services.AddSingleton(_client);
}
1 Answer(s)
-
0
Hi, can you check Microsoft's Mock gRPC client in tests documentation, it describes how you can mock your gRPC client with Moq. ABP Framework uses NSubstitude for the mocking library, so you should update the mocking statement according to the NSubstitute library.
Btw, this question is not related to ABP Framework and ABP Framework doesn't provide any helper class/method to mock gRPC clients. You should be able to mock the gRPC client like you would do any .NET Core application.