POSTMAN for entity testing
At https://github.com/Microsoft/Dynamics-AX-Integration, Microsoft provides sample code for consuming services. However, there are many scenarios where the other endpoint in an integration might not use a Microsoft stack. Even when the other endpoint does use, for example, the Open Data Protocol (OData) client code that Microsoft makes available, you might find it useful to perform the following actions:
- Explore and analyze how an interaction's messages are constructed.
- Test the response of a service to a well-known request.
- Determine how exceptions will appear to the other endpoint.
Many frequently used tools that will help you perform these actions are available. This topic isn't an endorsement of any tool. Although it provides examples that use some frequently used software utilities, the principles should broadly apply to other, similar tools.
Prerequisites
Before you can test a service by using an external application, you must register the application in Microsoft Azure, and in Finance and Operations.
For details, see:
Query OData by using Postman
Postman (https://www.getpostman.com/postman) is a tool that is often used to interact with RESTful services (such as OData) in scenarios that involve the development and testing of application programming interfaces (APIs). This procedure isn't an endorsement of Postman, and other similar tools are available. However, we are using Postman to illustrate the concepts and messages that are involved when you use OAuth to authenticate with Azure AD, and then make OData requests to and receive responses from the application.
Start Postman.
In the upper-right corner, select the gear button, and then select Manage environments to create or update an environment.
Enter a name for the environment, and then select Bulk Edit.
Enter key-value pairs as shown in the following table. Enter one pair per line, and separate the key and value by using a colon (:).
To verify that the key-value pairs can be parsed correctly, select Key-Value Edit, and review the results.
Close the environment page.
In the field to the left of the gear and eye buttons, select the new or updated environment.
To retrieve an Azure AD token, create a POST request that has a URL in the format
https://login.microsoftonline.com/[tenant ID]/oauth2/token
.You can use a URL parameter that refers to the tenant_id environment variable, such as
https://login.microsoftonline.com/:tenant_id/oauth2/token
.On the Body tab, add body elements as request parameters that refer to the environment variables that you created earlier. Select Bulk Edit, enter the keys from the previous table, enter a colon (:), and then enter the key name again but enclose it in double braces ({{}}). Enter one request parameter per line. For example, enter grant_type:{{grant_type}}. Here is an example.
On the Tests tab, create a test that validates that the response is reasonable, and that stores the returned authorization token in an environment variable. Here is an example.
C#var json = JSON.parse(responseBody); tests["Get Azure AD Token"] = !json.error && responseBody !== '' && responseBody !== '{}' && json.access_token !== ''; postman.setEnvironmentVariable("bearerToken", json.access_token);
Select Save, enter a name and collection for the request, and then select Save again.
Select Send to make the authorization request. The Body tab should now contain an Azure AD token together with other response details.
Because of the test code, the token is now in an environment variable. You can see that the token is an environment variable by selecting the Environment quick look button (the eye button).
Create a request to perform create, read, update, or delete (CRUD) operations on the desired data entity via the OData service. Create the URL according to your requirements. For more information, see Open Data Protocol (OData). You might find it useful to parameterize the request by using a variable that is stored in the environment, as shown earlier. The following example of a GET query uses a Customer Account parameter. The query returns name and address details for the customer account that is specified in the environment variable. Note that special characters must be correctly URL-encoded.
Consolehttps://[Finance and Operations instance URL]/data/Customers?$format=json&$filter=CustomerAccount%20eq%20%27{{custAccount}}%27&$select=CustomerAccount,Name,AddressDescription,FullPrimaryAddress
Add an Authorization header that refers to the authorization token that was retrieved earlier and stored in the bearerToken environment variable. The token must be prefixed by Bearer in the header.
Create a test to help validate the response. The following example tests that non-empty, JSON-formatted data is returned in the response body.
C#var json = JSON.parse(responseBody); tests["Get customer info"] = !json.error && responseBody !== '' && responseBody !== '{}';
Save and send the request, and then verify the result. You must ensure that the user account being used is set to a default company that has data. Alternatively, you can also specify cross-company=true as the query parameter in the OData request.
In our example, we have now successfully authenticated and then used the OData service to read a customer record.
Above content is taken from https://docs.microsoft.com/
Thanks,
Vikas Mehta
Thank you for helping people get the information they need.
ReplyDeleteDynamics 365 testing
Dynamics 365 quality assurance
Dynamics 365 automation testing