Testing the Code
Quick Start Guide
This is the last of the four Quick Start Guides for the .Net Serverless variant of the Connected Car solution. In this document we'll go through the steps to set up Postman to test one of the APIs for the code that you previously deployed in AWS. If you haven't yet gone through the previous Quick Start Guides, then follow the links at the bottom for the "Getting the Code", "Exploring the Code", and "Deploying the Code" pages.
Setting up Postman
In the previous "Deploying the Code" guide you will have set up your workstation, which will have included the installation of the Postman API testing tool. If you haven't yet installed Postman then jump back to that guide and follow the links to the workstation setup document for your operating system. Assuming you do have Postman installed, start the application and follow these next few steps to create a workspace and import the test collections and global variables.
Sign-in to Postman
You can run a "lightweight" version of Postman standalone on your workstation, but to use the full version and to synchronize your workspace to the cloud you need to create an account or sign-in with one of the supported third-party options.
Create a Workspace
Once signed-in, create a new workspace by selecting the "Workspace" menu at the top, and then clicking the "Create Workspace" button. Click "Next" to get to the screen shown below, where you can enter the name "ConnectedCar". Click the "Create" button to create the workspace.
Import the Test Collections
Once the workspace is created, click on the "Collections" option on the far left and then click the "Import" button at the top, to the right of the "New" button. This should display the import popup dialog shown below:
You can drag and drop the four JSON files that are found in the common repository in the /postman/functional folder. Three of these files define API test collections, and the fourth file defines the global variables referenced in these collections. Once you've drag and dropped these files onto the dialog box, Postman should parse and identify them as shown below:
After you click the "Import" button on the dialog box, you should see three test collections on the left side, as shown below. Open the "Admin_API" collection, then the "Dealers" folder and select the "Create Dealer" test. You should see the test URL and settings as below. This is what an individual API test looks like in Postman. Note the variables within curly braces in the URL used for the test:
Setting Variables
The global variables file that you previously imported defines several variables that the test collections reference when running. Some of these variables are set during runtime by the tests, and others need to have values set before you run the tests. We're only going to run the first test collection here, so you only need to assign values for three of these variables.
Getting values from the AWS console
There are multiple ways to get these values, including using scripts that are included in the common repository. However, the simplest way is to use the AWS console. Two of the values that you need are found in the API Gateway service, so navigate to the landing page for API Gateway. You should see rows for the three APIs that you previously deployed, as shown below:
Have a text editor open, and copy the ID shown above highlighted, to the right of the link for the "ConnectedCar_Admin_API_Dev" API. This is the generated ID value for the Admin API. Paste this ID value into your text editor.
Next, click on the link for this API, then select the "API keys" option on the left-side of the page. You should then see the one row displayed, as shown below, with a row of asterisks for the value of the API key. Above this row of asterisks there's a copy icon, which you can click. Once again, paste this value into your text editor.
Setting the variables in Postman
Now you can return to Postman and click on the small square icon at the top-right that has an eye symbol. This should open the dialog box that shows all the named environment variables, as shown below:
Click the "Edit" button on this dialog box, and you'll see a tab with all the variables ready for editing. Here is where you'll paste the first value that you copied from the AWS console into the "Initial value" and "Current value" columns for the "adminApi" variable, as shown below.
Repeat this step for the API key value that you copied from the console, and paste this into the same two columns for the "apiKey" variable. You must also edit the "region" variable to match the region code that you have configured for your AWS CLI, and to which your code will have been deployed. When finished, click the "Save" button and close this tab.
Running the Tests
With the variables set, you're now ready to run the tests in the Admin_API collection. Select this collection on the left side of Postman, and then click the "Run" button that you'll see in the top right. You should then see the list of tests in this collection, as below:
All the default settings on the right are fine, so when ready, click the orange "Run Admin_API" button on the lower-right. The API tests will now run in sequence, and provided all the variables are set correctly, after a couple of minutes you should see a list of success entries as shown below: