Azure-cosmos-dotnet-v3: CosmosClient Unit Test Constructor marked internal

Created on 27 Feb 2019  路  4Comments  路  Source: Azure/azure-cosmos-dotnet-v3

We are continuously addressing and improving the SDK, if possible, make sure the problem persist in the latest SDK version.

Describe the bug
There is a constructor on CosmosClient that takes a DocumentClient for mocking purposes but it is marked internal. This needs to be public so that it can be used for mocking.

To Reproduce
Open the source code and navigate to Microsoft.Azure.Cosmos/Resource/Database/CosmosDatabase.cs and note that there is a constructor marked internal when it should not be as it is a stated intent to make mocking easy of v3.

Expected behavior
Not have the CosmosClient(config,documentclient) constructor marked as internal

Actual behavior
CosmosClient(config,documentclient) is marked internal and unusable

Environment summary
SDK Version: Microsoft.Azure.Cosmos v3.0.0.1-preview1
OS Version: Windows 10

duplicate

Most helpful comment

Hi, I am trying to mock the CosmosClient and facing the same issue. Any progress on this since then? If yes, please provide an example or means to do it. I am using xUnit and NSubstitute.

All 4 comments

Hi, the constructor is marked as internal because we are planning to remove all documentclient dependencies. We didn't want people taking dependency on something we know will be removed in the future. I'm working on adding a new abstraction layer to allow mocking the object without the need of creating the CosmosClient.

@j82w can you make sure to also provide an example of mocking with this new abstraction layer? I know there are tons of different mock frameworks out there, just pick one (MOQ wink wink) to provide as an example.

The current design is to refactor all the classes from CosmosDatabases down to CosmosItems to abstract base classes. Then the implementation will be made internal. The base abstract class can then be mocked without needing to create the client.

Hi, I am trying to mock the CosmosClient and facing the same issue. Any progress on this since then? If yes, please provide an example or means to do it. I am using xUnit and NSubstitute.

Was this page helpful?
0 / 5 - 0 ratings