Skip to content

Actions that use a Built In Service Provider Connector

MarkAbrams edited this page Feb 6, 2024 · 8 revisions

A workflow action can communicate with an external service using a built-in service provider connector which runs in-process with the workflow. The configuration of the built-in connection is part of the workflow action configuration. There are many different types of built-in service provider connector, for example Service Bus, Event Grid, SQL Server, SMTP and Salesforce.

When unit testing a workflow with actions that use a built-in connector, any dependency on an external service needs to be removed. The testing framework does this by replacing the action with a HTTP action that is configured to call a mock HTTP server that is managed by the testing framework. This allows the action to run independently of any external dependency.

Replacing the connector like this does not affect the functionality of the workflow action or change the behaviour. Every action generates an input JSON message which is then sent to the external service via the connector. The action then generates an output JSON message which is then processed by the rest of the workflow. The structure of the input and output JSON messages differs for each type of action and connector, but as long as the same message structures are used in the request and response for the HTTP connector and mock HTTP server, the rest of the workflow will execute in exactly the same way.

The testing framework will only replace actions using built-in connectors where the action's operationId is listed in the workflow.builtInConnectorsToMock section in the testConfiguration.json file. The example below will enable the update of all actions that use the executeQuery (SQL Server) and sendMessage (Service Bus) operations:

"workflow": {
    "builtInConnectorsToMock": [
      "executeQuery",
      "sendMessage"
    ]
}

As an example, this is an Execute Query action that runs a SQL query against a database and receives a response:

"Execute_Query": {
    "type": "ServiceProvider",
    "inputs": {
        "parameters": {
            "query": "SELECT LanguageName, LanguageCode FROM config.Languages WHERE LanguageCode = @LanguageCode",
            "queryParameters": {
                "LanguageCode": "@body('Parse_Customer')?['languageCode']"
            }
        },
        "serviceProviderConfiguration": {
            "connectionName": "sql",
            "operationId": "executeQuery",
            "serviceProviderId": "/serviceProviders/sql"
        }
    }
}

The testing framework will replace the action with a HTTP action that calls the mock HTTP server using a POST operation:

"Execute_Query": {
    "type": "Http",
    "inputs": {
        "method": "POST",
        "uri": "http://local-server-name:7075/Execute_Query",
        "body": {
            "query": "SELECT LanguageName, LanguageCode FROM config.Languages WHERE LanguageCode = @LanguageCode",
            "queryParameters": {
                "LanguageCode": "@body('Parse_Customer')?['languageCode']"
            }
        },
        "retryPolicy": {
            "type": "none"
        }
    },
    "operationOptions": "DisableAsyncPattern"
}

The contents of the parameters attribute in the original action configuration is included in the JSON request body that is sent to the mock HTTP server. This includes the SQL query and any parameters and their values. The request is sent to the mock HTTP server using a URL that includes the action name. The test case can assert the contents of the request to ensure that the SQL query is correct and any parameter values match expectations. Other built-in service provider connector types work in exactly the same way - the contents of the parameters attribute is always included in the request body for the mock HTTP server.

The test execution log will include logging to show when an action using a built-in connector has been replaced with a HTTP action:

Replacing workflow actions using a built-in connector with a HTTP action for the mock test server:
    Execute_Query:
      Connector Type: /serviceProviders/sql/executeQuery
      Mocked URL: http://local-server-name:7075/Execute_Query
    Send_message_to_Topic:
      Connector Type: /serviceProviders/serviceBus/sendMessage
      Mocked URL: http://local-server-name:7075/Send_message_to_Topic

Example Requests and Responses

You can find examples of the requests that are generated by replacement HTTP actions here. There are also examples of responses that you can create in your test cases to simulate specific test scenarios, for example failure to create a blob in a Storage account, or a failed SQL stored procedure execution.

Clone this wiki locally