I think you’ll find this implementation of CosmosDB Server for testing your applications locally quite interesting.
We will going through the following steps:
- Download node
- Make an empty package.json file
- Install cosmosdb-server using npm
- Create an app.js file
- Install cosmos dependency using npm
- Start your cosmosdb-server
- Make sure in your TestClass TestInitialize method to ignore SSL verification (self-signed cert)
- Run your unit tests
Download and install node
Navigate to the site I linked to above and install it, the latest LTS Version: 10.16.0 (includes npm 6.9.0) . After you install it you can verify the versions installed on your computer by opening a command prompt and entering the following commands:

Make an empty package.json
This is easy, just fire up your favorite editor and put to curly braces in it to avoid warnings during the install of cosmosdb-server

Install cosmosdb-server using npm
In your command prompt execute the following command, which you can also find in the readme at the GitHub repo.
npm install @zeit/cosmosdb-server

Create an app.js file
A sample of what is required is also in the readme at the GitHub repo. Here is an example of mine. I also created the database and container required for my unit tests

Install Azure Cosmos Client
We need this dependency for the runClient() method in the app.js, at the command prompt enter:
npm install @azure/cosmos

Your package.json should now resemble the following, reflecting the packages for your app.

Start your cosmosdb-server
Again while at your command prompt, you can launch the cosmosdb-server by executing:
node app.js

Get ready to execute your Unit Tests
This implementation uses a self-signed certificate so we need to make sure our Unit Test class doesn’t validate the certificate
I added a ServicePointManager callback to ignore the self-signed certificate in the TestInitialize method of my CosmosDB test class.

Here is my app.config for my Test project which has the settings for this cosmosdb server

Let’s execute some of the unit tests in my test project, the only one that fails is where we are attempting a SQL query with a where exists clause.

Next steps are to get this working during an Azure DevOps build, so until next time if you have any questions or comments feel free to leave them below,
No comments yet... Be the first to leave a reply!