|
| 1 | +--- |
| 2 | +title: DataMapTestExecutor class |
| 3 | +description: Learn about the DataMapTestExecutor class in the Azure Logic Apps Unit Testing SDK. |
| 4 | +services: logic-apps |
| 5 | +ms.suite: integration |
| 6 | +author: wsilveiranz |
| 7 | +ms.reviewers: estfan, azla |
| 8 | +ms.topic: reference |
| 9 | +ms.date: 12/03/2025 |
| 10 | +--- |
| 11 | + |
| 12 | +# DataMapTestExecutor class |
| 13 | + |
| 14 | +This class provides functionality that compiles, generates XSLT, and executes data map tests for Standard logic app workflows in single-tenant Azure Logic Apps. The class serves as the main entry point for testing data transformations with data maps. |
| 15 | + |
| 16 | +## Namespace |
| 17 | + |
| 18 | +**`Microsoft.Azure.Workflows.UnitTesting`** |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +You can use the **`DataMapTestExecutor`** class to generate XSLT from data map definitions and execute data transformations: |
| 23 | + |
| 24 | +```csharp |
| 25 | +using Microsoft.Azure.Workflows.Data.Entities; |
| 26 | + |
| 27 | +// Initialize with app directory path |
| 28 | +var executor = new DataMapTestExecutor("path/to/logic-app-project"); |
| 29 | + |
| 30 | +// Generate XSLT from map name |
| 31 | +var xslt = await executor.GenerateXslt("MyDataMap"); |
| 32 | + |
| 33 | +// Generate XSLT from map content |
| 34 | +var generateXsltInput = new GenerateXsltInput { MapContent = mapContent }; |
| 35 | +var xsltContent = await executor.GenerateXslt(generateXsltInput); |
| 36 | + |
| 37 | +// Execute data map transformation by map name |
| 38 | +var inputData = System.Text.Encoding.UTF8.GetBytes(xmlInput); |
| 39 | +var result = await executor.RunMapAsync("MyDataMap", inputData); |
| 40 | + |
| 41 | +// Execute data map transformation with XSLT content |
| 42 | +var result = await executor.RunMapAsync(xsltContent, inputData); |
| 43 | +``` |
| 44 | + |
| 45 | +## Constructors |
| 46 | + |
| 47 | +### DataMapTestExecutor(string) |
| 48 | + |
| 49 | +Initializes a new instance of the **`DataMapTestExecutor`** class by using the logic app project root path. |
| 50 | + |
| 51 | +#### Parameters |
| 52 | + |
| 53 | +| Name | Type | Description | Required | |
| 54 | +|------|------|-------------|----------| |
| 55 | +| appDirectoryPath | string | The logic app project root path | Yes | |
| 56 | + |
| 57 | +#### Example |
| 58 | + |
| 59 | +```csharp |
| 60 | +var executor = new DataMapTestExecutor("C:\\MyLogicApp"); |
| 61 | +``` |
| 62 | + |
| 63 | +## Properties |
| 64 | + |
| 65 | +### AppDirectoryPath |
| 66 | + |
| 67 | +The logic app project root directory path. |
| 68 | + |
| 69 | +| Property | Type | Description | Required | |
| 70 | +|----------|------|-------------|----------| |
| 71 | +| AppDirectoryPath | string | The root path of the logic app project | Yes | |
| 72 | + |
| 73 | +## Methods |
| 74 | + |
| 75 | +### GenerateXslt(string) |
| 76 | + |
| 77 | +Compiles a data map and generates XSLT. The operation uses the map name to find the data map. |
| 78 | + |
| 79 | +#### Parameters |
| 80 | + |
| 81 | +| Name | Type | Description | Required | |
| 82 | +|------|------|-------------|----------| |
| 83 | +| mapName | string | The data map file name without the LML extension | Yes | |
| 84 | + |
| 85 | +#### Returns |
| 86 | + |
| 87 | +**`Task<byte[]>`**: A task representing the asynchronous operation that returns the generated XSLT content as a byte array. |
| 88 | + |
| 89 | +#### Exceptions |
| 90 | + |
| 91 | +- **`ArgumentException`**: Thrown when the data map file doesn't exist in the expected path. |
| 92 | + |
| 93 | +#### Example |
| 94 | + |
| 95 | +```csharp |
| 96 | +var executor = new DataMapTestExecutor("C:\\MyLogicApp"); |
| 97 | +var xslt = await executor.GenerateXslt("OrderToInvoice"); |
| 98 | +``` |
| 99 | + |
| 100 | +> [!NOTE] |
| 101 | +> |
| 102 | +> This method looks for the data map file in the path: `{appDirectoryPath}\Artifacts\MapDefinitions\{mapName}.lml` |
| 103 | +
|
| 104 | +### GenerateXslt(GenerateXsltInput) |
| 105 | + |
| 106 | +Compiles a data map and generates XSLT from the provided map content. |
| 107 | + |
| 108 | +#### Parameters |
| 109 | + |
| 110 | +| Name | Type | Description | Required | |
| 111 | +|------|------|-------------|----------| |
| 112 | +| generateXsltInput | GenerateXsltInput | The input containing data map content | Yes | |
| 113 | + |
| 114 | +#### Returns |
| 115 | + |
| 116 | +**`Task<byte[]>`**: A task representing the asynchronous operation that returns the generated XSLT content as a byte array. |
| 117 | + |
| 118 | +#### Example |
| 119 | + |
| 120 | +```csharp |
| 121 | +var mapContent = await File.ReadAllTextAsync("CustomMap.lml"); |
| 122 | +var generateXsltInput = new GenerateXsltInput { MapContent = mapContent }; |
| 123 | +var xslt = await executor.GenerateXslt(generateXsltInput); |
| 124 | +``` |
| 125 | + |
| 126 | +### RunMapAsync(string, byte[]) |
| 127 | + |
| 128 | +Executes a data map by applying the given XSLT to sample input data. The operation uses the map name to find the XSLT. |
| 129 | + |
| 130 | +#### Parameters |
| 131 | + |
| 132 | +| Name | Type | Description | Required | |
| 133 | +|------|------|-------------|----------| |
| 134 | +| mapName | string | The data map XSLT file name without the extension | Yes | |
| 135 | +| inputContent | byte[] | The content to transform | Yes | |
| 136 | + |
| 137 | +#### Returns |
| 138 | + |
| 139 | +**`Task<JToken>`**: A task representing the asynchronous operation that returns the transformed output as a JSON token. |
| 140 | + |
| 141 | +#### Example |
| 142 | + |
| 143 | +```csharp |
| 144 | +var xmlInput = "<Order><Item>Widget</Item></Order>"; |
| 145 | +var inputData = System.Text.Encoding.UTF8.GetBytes(xmlInput); |
| 146 | +var result = await executor.RunMapAsync("OrderToInvoice", inputData); |
| 147 | +Console.WriteLine(result.ToString()); |
| 148 | +``` |
| 149 | + |
| 150 | +> [!NOTE] |
| 151 | +> |
| 152 | +> This method looks for the XSLT file in the path: `{appDirectoryPath}\Artifacts\Maps\{mapName}.xslt` |
| 153 | +
|
| 154 | +### RunMapAsync(byte[], byte[]) |
| 155 | + |
| 156 | +Executes a data map by applying the given XSLT content to sample input data. |
| 157 | + |
| 158 | +#### Parameters |
| 159 | + |
| 160 | +| Name | Type | Description | Required | |
| 161 | +|------|------|-------------|----------| |
| 162 | +| xsltContent | byte[] | The data map XSLT content | Yes | |
| 163 | +| inputContent | byte[] | The input content to be transformed | Yes | |
| 164 | + |
| 165 | +#### Returns |
| 166 | + |
| 167 | +**`Task<JToken>`**: A task representing the asynchronous operation that returns the transformed output as a JSON token. |
| 168 | + |
| 169 | +#### Example |
| 170 | + |
| 171 | +```csharp |
| 172 | +// First generate XSLT |
| 173 | +var xslt = await executor.GenerateXslt("OrderToInvoice"); |
| 174 | + |
| 175 | +// Then execute transformation |
| 176 | +var xmlInput = "<Order><Item>Widget</Item></Order>"; |
| 177 | +var inputData = System.Text.Encoding.UTF8.GetBytes(xmlInput |
| 178 | +var result = await executor.RunMapAsync(xslt, inputData); |
| 179 | +Console.WriteLine(result.ToString()); |
| 180 | +``` |
| 181 | + |
| 182 | +## Related content |
| 183 | + |
| 184 | +- [UnitTestExecutor Class Definition](unit-test-executor-class-definition.md) |
| 185 | +- [ActionMock Class Definition](action-mock-class-definition.md) |
| 186 | +- [TriggerMock Class Definition](trigger-mock-class-definition.md) |
| 187 | +- [TestWorkflowRun Class Definition](test-workflow-run-class-definition.md) |
0 commit comments