Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking grain client and testability #2019

Open
AqlaSolutions opened this issue May 29, 2023 · 2 comments
Open

Mocking grain client and testability #2019

AqlaSolutions opened this issue May 29, 2023 · 2 comments

Comments

@AqlaSolutions
Copy link
Contributor

AqlaSolutions commented May 29, 2023

Currently it's not possible to mock generated grain clients because their generated methods are not virtual. For better testability could you consider making them virtual or better additionally generating interfaces for them? For an example, I want to unit test a class which needs to call some grain. Currently I can't test it in isolation because I need to pass an instance of that grain client and that instance can't be mocked.

class SomeClass
{
    private readonly Func<string, MyGrainClient> _grainFactory;
    public SomeClass(Func<string, MyGrainClient> grainFactory) // But MyGrainClient can't be mocked!
    {
        _grainFactory = grainFactory;
    }

    public void SomeMethod(string arg) // I want to test this method without real MyGrainClient
    {
        _grainFactory(arg).MyMethod();
    }
}

@jkpark
Copy link

jkpark commented Apr 2, 2024

I am facing to mock grain client, Can I ask if you have any solution to mock or fake job?

@rogeralsing
Copy link
Contributor

rogeralsing commented Apr 2, 2024

Currently there are no great ways to do this.
However, the code generation is customizable.

e.g. in your project file where you include the ProtoGrain includes:

 <ProtoGrain Include="MyProtoFile.proto" AdditionalImportDirs="." TemplateFiles="MyCustomTemplate.txt" />

This way, it is at least open for modification, you can generate your own extra types, or modify how the grains are generated completely.

The default template can be found here : https://gist.github.com/rogeralsing/4908f8e0063687acfe12c0616b022844

Make a copy of that file, and reference it in the TemplateFiles= part of the ProtoGrain section.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants