Starts in:
2 DAYS
3 HRS
46 MIN
53 SEC
Starts in:
2 D
3 H
46 M
53 S
Open Closed

Mock grpc server #4493


User avatar
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)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    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.

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06