-
Notifications
You must be signed in to change notification settings - Fork 14
Call Local Function action
This is an example of JSON request and response message content for a mocked Call a Local Function action.
The name of the function is located in the functionName
field and the input parameters are included in the parameters
field.
{
"functionName": "WeatherForecast",
"parameters": {
"zipCode": "13579",
"temperatureScale": "Fahrenheit"
}
}
The structure of the JSON in the parameters
field will match the request signature of the function that is being called.
The structure of the JSON response must match the response signature of the function that is being called. For example, this JSON response matches a typed response using a class called Weather
:
{
"ZipCode": "13579",
"CurrentWeather": "The current weather is 41 Fahrenheit",
"DayLow": "The low for the day is 31 Fahrenheit",
"DayHigh": "The high for the day is 51 Fahrenheit"
}
where the Weather
class is defined as follows:
public class Weather
{
public int ZipCode { get; set; }
public string CurrentWeather { get; set; }
public string DayLow { get; set; }
public string DayHigh { get; set; }
}
You can easily mock this request and response using the Fluent API:
testRunner
.AddMockResponse(
MockRequestMatcher.Create())
.RespondWith(
MockResponseBuilder.Create()
.WithSuccess()
.WithContentAsJson(new {
ZipCode = "13579",
CurrentWeather = "The current weather is 41 Fahrenheit",
DayLow = "The low for the day is 31 Fahrenheit",
DayHigh = "The high for the day is 51 Fahrenheit"
}));
The Call a Local Function action cannot return a HTTP status code indicating a failure because the action does not use the HTTP protocol to invoke the function. Instead, the called function can throw an exception which is caught by the Logic App runtime and presented to the workflow as a failed action.
You can simulate the throwing of an exception in the called function using the Fluent API:
testRunner
.AddMockResponse(
MockRequestMatcher.Create())
.RespondWith(
MockResponseBuilder.Create()
.ThrowsException(new InvalidOperationException("Something went bang!")));
In this scenario the HTTP action (that is added by the testing framework and replaces the mocked Call a Local Function action) will return a HTTP 500 (Internal Server Error) status code which is presented to the workflow as a failed action, just like the mocked Call a Local Function action would have done.
If you are using a delegate function to create responses, you can simply throw an exception in the delegate function to acheive the same result.
- Home
- Using the Testing Framework
- Test Configuration
- Azurite
- Local Settings File
- Test Execution Logs
- Stateless Workflows
- Handling Workflow Dependencies
- Fluent API
- Automated testing using a DevOps pipeline
- Summary of Test Configuration Options
-
Example Mock Requests and Responses
- Call a Local Function action
- Invoke Workflow action
- Built-In Connectors:
- Service Bus
- SMTP
- Storage Account
- SQL Server