You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In current implementation making API calls is done through methods in ApiExecutor classes, such as SourceFilesApiExecutor, SourceStringsApiExecutor, etc.
Since ICrowdinApiClient defines executor properties as concrete classes and those classes have non-virtual methods, it's not possible to mock a data returned by a client for unit testing purposes.
Moreover, since send request methods of the client are marked as internal, it's also not possible to at least mock the returned JSON, similarly to how it's done in Crowdin client unit tests.
Desired use case example:
using Moq;
using Crowdin.Api;
// ...
private Mock<ICrowdinApiClient> _clientMock;
[SetUp]
public void Setup()
{
_clientMock = new Mock<ICrowdinApiClient>();
}
[Test]
public async Task ShouldPass()
{
var expectedResponse = /* Assign data */
_clientMock.Setup(client => client.SourceStrings.ListStrings(/* setup */).ReturnsAsync(expectedResponse );
^^^^
Moq - Non-overridable members may not be used in setup / verification expressions
One of suggestions is to define interface for every ApiExecturor class or simply mark methods as virtual.
Current workaround is to define a wrapper class and proxy calls to Crowdin Api client.
WDYT?
The text was updated successfully, but these errors were encountered:
Hello 👋
In current implementation making API calls is done through methods in ApiExecutor classes, such as SourceFilesApiExecutor, SourceStringsApiExecutor, etc.
Example:
Since ICrowdinApiClient defines executor properties as concrete classes and those classes have non-virtual methods, it's not possible to mock a data returned by a client for unit testing purposes.
Moreover, since send request methods of the client are marked as internal, it's also not possible to at least mock the returned JSON, similarly to how it's done in Crowdin client unit tests.
Desired use case example:
One of suggestions is to define interface for every ApiExecturor class or simply mark methods as virtual.
Current workaround is to define a wrapper class and proxy calls to Crowdin Api client.
WDYT?
The text was updated successfully, but these errors were encountered: