Nota
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare ad accedere o modificare le directory.
L'accesso a questa pagina richiede l'autorizzazione. È possibile provare a modificare le directory.
Spazio dei nomi: Microsoft.Azure.Workflows.UnitTesting.Definitions
Questa classe crea un'istanza fittizia per un trigger in un flusso di lavoro dell'app per la logica Standard. La TriggerMock classe offre diversi modi per creare trigger fittizi per testare flussi di lavoro Standard usando output statici, condizioni di errore o comportamento dinamico in base al contesto di esecuzione.
Uso
// 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");
Costruttori
Costruttore con output statici
Crea un'istanza fittizia per TriggerMock con output statici.
public TriggerMock(TestWorkflowStatus status, string name = null, MockOutput outputs = null)
| Nome | Descrizione | TIPO | Obbligatorio |
|---|---|---|---|
| stato | Stato del risultato del trigger fittizio | TestWorkflowStatus | Sì |
| nome | Nome del trigger fittizio | corda | NO |
| Risultati | Output statici fittizi | 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);
Costruttore con informazioni sull'errore
Crea un'istanza fittizia per TriggerMock con informazioni sull'errore statico.
public TriggerMock(TestWorkflowStatus status, string name = null, TestErrorInfo error = null)
| Nome | Descrizione | TIPO | Obbligatorio |
|---|---|---|---|
| stato | Stato del risultato del trigger fittizio | TestWorkflowStatus | Sì |
| nome | Nome del trigger fittizio | corda | NO |
| Errore | Informazioni sull'errore del trigger fittizio | 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);
Costruttore con funzione di callback
Crea un'istanza fittizia per TriggerMock con una funzione di callback per gli output dinamici.
public TriggerMock(Func<TestExecutionContext, TriggerMock> onGetTriggerMock, string name = null)
| Nome | Descrizione | TIPO | Obbligatorio |
|---|---|---|---|
| onGetTriggerMock | Funzione di callback per ottenere il trigger fittizio | Func<TestExecutionContext, TriggerMock> | Sì |
| nome | Nome del trigger fittizio | corda | 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");
Costruttore JSON
Crea un'istanza fittizia per TriggerMock da JSON.
public TriggerMock(TestWorkflowStatus status, string name = null, JToken outputs = null, TestErrorInfo error = null)
| Nome | Descrizione | TIPO | Obbligatorio |
|---|---|---|---|
| stato | Stato del risultato del trigger fittizio | TestWorkflowStatus | Sì |
| nome | Nome del trigger fittizio | corda | NO |
| Risultati | Output fittizi | MockOutput | NO |
| Errore | Errore fittizio | TestErrorInfo | NO |
// Example: Create a mock trigger from JSON
var triggerFromJson = JsonConvert.DeserializeObject<TriggerMock>(File.ReadAllText(mockDataPath));
Proprietà
| Nome | Descrizione | TIPO | Obbligatorio |
|---|---|---|---|
| Nome | Nome dell'operazione fittizia | corda | NO |
| stato | Stato dell'operazione | TestWorkflowStatus | NO |
| Risultati | Output statico in formato JSON | JToken | NO |
| Errore | Errore dell'operazione | TestErrorInfo | NO |
Contenuti correlati
- Definizione della classe ActionMock
- Definizione della classe TestActionExecutionContext
- Definizione della classe TestErrorInfo
- Definizione della classe TestErrorResponseAdditionalInfo
- Definizione della classe TestExecutionContext
- Definizione della classe TestIterationItem
- Definizione della classe TestWorkflowOutputParameter
- Definizione della classe TestWorkflowRun
- Definizione della classe TestWorkflowRunActionRepetitionResult
- Definizione della classe TestWorkflowRunActionResult
- Definizione della classe TestWorkflowRunTriggerResult
- Definizione enumerazione TestWorkflowStatus
- Definizione della classe UnitTestExecutor