- Print
- Comment
- DarkLight
- PDF
When testing your Logic App when it is deployed to Azure you would use the nuget package IPB.LogicApp.Standard.Testing
This package is designed to allow you to provide information to connect to the Azure Management API and then it will provide a wrapper on the calls to the Logic App API to trigger logic apps and access the run history to make assertions.
To connect to Azure you will need a service principal with permission to access your logic app.
You need to use the class for the LogicAppTestManager to interact with your workflows and you can either create an instance of this yourself or via the LogicAppTestManagerBuilder.
The easiest way to create the LogicAppTestManager is to populate some settings as below in your appsettings.json
{
"logicAppTestManager:LogicAppName":"[The name of the logic app]",
"logicAppTestManager:ResourceGroupName":"[This is the resource group the logic app is deployed to]",
"logicAppTestManager:SubscriptionId":"[Your azure subscription id]",
"logicAppTestManager:TenantId":"[The azure ad tenant id]",
"logicAppTestManager:ClientId":"[Service principal id]",
"logicAppTestManager:ClientSecret":"[Service principal secret]"
}
There are other options than reading the config out from the config file, you can create the test manager yourself with other secret options
You would run a line of code like below to create the test manager
var logicAppTestManager = LogicAppTestManagerBuilder.Build(workflowName);
You can now trigger your workflow with a call like below
var content = new StringContent(inputContent, Encoding.UTF8, "text/xml");
var response = logicAppTestManager.TriggerLogicAppWithPost(content);
You can then check you got a run id for the workflow instance and load the run history
Assert.IsNotNull(testContext.Response.WorkFlowRunId);
Then we will load the workflow run history
logicAppTestManager.LoadWorkflowRunHistory();
You can check the trigger status like this
var triggerStatus = logicAppTestManager.GetTriggerStatus();
Assert.AreEqual(triggerStatus, TriggerStatus.Succeeded);
You can check the result of an action like this
var actionStatus = logicAppTestManager.GetActionStatus("Response");
Assert.AreEqual(actionStatus, ActionStatus.Succeeded);
You can check the result of the workflow like this
var workflowRunStatus = logicAppTestManager.GetWorkflowRunStatus();
Assert.AreEqual(WorkflowRunStatus.Succeeded, workflowRunStatus);