Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Namespace: Microsoft.Azure.Workflows.UnitTesting.Definitions
This class creates a mock instance for a trigger in a Standard logic app workflow. The TriggerMock
class provides multiple ways to create mock triggers for testing Standard workflows by using static outputs, error conditions, or dynamic behavior based on execution context.
Usage
// Simple trigger mock with success status
var successTrigger = new TriggerMock(TestWorkflowStatus.Succeeded, "HttpTrigger");
// Trigger mock with specific outputs
var outputTrigger = new TriggerMock(
TestWorkflowStatus.Succeeded,
"EmailTrigger",
new MockOutput {
Body = JToken.Parse(@"{""subject"": ""Test Email"", ""from"": ""test@example.com""}")
});
// Failed trigger with error information
var failedTrigger = new TriggerMock(
TestWorkflowStatus.Failed,
"DatabaseTrigger",
new TestErrorInfo(
ErrorResponseCode.ConnectionError,
"Failed to connect to database"
));
// Dynamic trigger that changes behavior based on execution context
var dynamicTrigger = new TriggerMock(
(context) => {
var actionName = context.ActionContext.ActionName;
if (actionName == "ProcessOrder") {
return new TriggerMock(
TestWorkflowStatus.Succeeded,
"OrderTrigger",
new MockOutput { Body = JToken.Parse(@"{""orderId"": 12345}") }
);
}
return new TriggerMock(TestWorkflowStatus.Failed, "OrderTrigger");
},
"ContextAwareTrigger");
Constructors
Constructor with static outputs
Creates a mock instance for TriggerMock
with static outputs.
public TriggerMock(TestWorkflowStatus status, string name = null, MockOutput outputs = null)
Name | Description | Type | Required |
---|---|---|---|
status | The mock trigger result status | TestWorkflowStatus | Yes |
name | The mock trigger name | string | No |
outputs | The mock static outputs | MockOutput | No |
// Example: Create a mock trigger with successful status and static outputs
var outputs = new MockOutput {
Body = JToken.Parse(@"{""webhookData"": ""sample payload""}")
};
var triggerMock = new TriggerMock(TestWorkflowStatus.Succeeded, "WebhookTrigger", outputs);
Constructor with error information
Creates a mock instance for TriggerMock
with static error information.
public TriggerMock(TestWorkflowStatus status, string name = null, TestErrorInfo error = null)
Name | Description | Type | Required |
---|---|---|---|
status | The mock trigger result status | TestWorkflowStatus | Yes |
name | The mock trigger name | string | No |
error | The mock trigger error info | TestErrorInfo | No |
// Example: Create a mock trigger with failed status and error information
var errorInfo = new TestErrorInfo(
ErrorResponseCode.Unauthorized,
"Authentication failed for trigger"
);
var triggerMock = new TriggerMock(TestWorkflowStatus.Failed, "SecureTrigger", errorInfo);
Constructor with callback function
Creates a mock instance for TriggerMock
with a callback function for dynamic outputs.
public TriggerMock(Func<TestExecutionContext, TriggerMock> onGetTriggerMock, string name = null)
Name | Description | Type | Required |
---|---|---|---|
onGetTriggerMock | The callback function to get the mock trigger | Func<TestExecutionContext, TriggerMock> | Yes |
name | The mock trigger name | string | No |
// Example: Create a mock trigger with dynamic outputs based on execution context
var triggerMock = new TriggerMock(
(context) => {
var inputs = context.ActionContext.ActionInputs;
var eventType = inputs["eventType"]?.Value<string>();
// Return different mock based on event type
if (eventType == "priority") {
return new TriggerMock(
TestWorkflowStatus.Succeeded,
"EventTrigger",
new MockOutput { Body = JToken.Parse(@"{""priority"": true}") }
);
}
return new TriggerMock(TestWorkflowStatus.Succeeded, "EventTrigger");
},
"ConditionalEventTrigger");
JSON constructor
Creates a mock instance for TriggerMock
from JSON.
public TriggerMock(TestWorkflowStatus status, string name = null, JToken outputs = null, TestErrorInfo error = null)
Name | Description | Type | Required |
---|---|---|---|
status | The mock trigger result status | TestWorkflowStatus | Yes |
name | The mock trigger name | string | No |
outputs | The mock outputs | MockOutput | No |
error | The mock error | TestErrorInfo | No |
// Example: Create a mock trigger from JSON
var triggerFromJson = JsonConvert.DeserializeObject<TriggerMock>(File.ReadAllText(mockDataPath));
Properties
Name | Description | Type | Required |
---|---|---|---|
Name | The name of the mock operation | string | No |
Status | The operation status | TestWorkflowStatus | No |
Outputs | The static output in JSON format | JToken | No |
Error | The operation error | TestErrorInfo | No |
Related content
- ActionMock Class Definition
- TestActionExecutionContext Class Definition
- TestErrorInfo Class Definition
- TestErrorResponseAdditionalInfo Class Definition
- TestExecutionContext Class Definition
- TestIterationItem Class Definition
- TestWorkflowOutputParameter Class Definition
- TestWorkflowRun Class Definition
- TestWorkflowRunActionRepetitionResult Class Definition
- TestWorkflowRunActionResult Class Definition
- TestWorkflowRunTriggerResult Class Definition
- TestWorkflowStatus Enum Definition
- UnitTestExecutor Class Definition