Skip to content

Call Local Function Actions

MarkAbrams edited this page Feb 6, 2024 · 7 revisions

A workflow can call a local function written using the .Net Framework using the Call a Local Function action. The action configuration includes the name of the function to be called, along with any parameters. The function must be written using the .NET Framework 4.8 and must exist in an assembly that has been copied to the lib\custom\net472 folder in the Logic App.

When unit testing a workflow that calls a local function, the dependency needs to be removed. The testing framework does this by replacing the Call a Local Function 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 other functions.

Replacing the action like this does not affect the functionality of the action or change the behaviour. Every Call a Local Function action generates an input request which is then passed to the called function. The called function then generates an output which is then processed by the rest of the workflow. 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.

As an example, this is a Call a Local Function action that calls a WeatherForecast function, passing a ZIP code and a temperature scale as parameters:

"Get_Weather_Forecast": {
    "type": "InvokeFunction",
    "inputs": {
        "functionName": "WeatherForecast",
        "parameters": {
            "zipCode": "@triggerOutputs()['queries']['zipCode']",
            "temperatureScale": "@{triggerOutputs()['queries']['tempScale']}"
        }
    },
}

This is the same example function that Microsoft uses in its documentation.

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

"Get_Weather_Forecast": {
    "type": "Http",
    "inputs": {
        "method": "POST",
        "uri": "http://local-server-name:7075/Get_Weather_Forecast",
        "body": {
            "functionName": "WeatherForecast",
            "parameters": {
                "zipCode": "@triggerOutputs()['queries']['zipCode']",
                "temperatureScale": "@{triggerOutputs()['queries']['tempScale']}"
        }
    },
        "retryPolicy": {
            "type": "none"
    },
    "operationOptions": "DisableAsyncPattern"
}

The contents of the inputs attribute in the original action configuration is included in the JSON request body that is sent to the mock HTTP server. This includes the name of the called function and any parameters. 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 parameters match expectations.

The test execution log will include logging to show when a Call a Local Function action has been replaced with a HTTP action:

Updating Call Local Function actions to replace call with a HTTP action for the mock test server:
    Get_Weather_Forecast:
      Mocked URL: http://local-server-name:7075/Get_Weather_Forecast

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 a successful function call or a thrown exception in a function call.

Clone this wiki locally