Skip to content

Commit

Permalink
feat: introduce TestFramework class to evaluate child executePipeline… (
Browse files Browse the repository at this point in the history
#21)

* feat: introduce TestFramework class to evaluate child executePipelineActivities

* refactor: move pipeline evaluation logic to framework (SRP)

* refactor: rename ParameterType.Parameter to ParameterType.Pipeline to better reflect its meaning

* docs: improve getting started docs

* docs: add missing testFramework xml documentation

* docs: add missing testFramework xml documentation
  • Loading branch information
arjendev committed Nov 6, 2023
1 parent b80a686 commit 6048e79
Show file tree
Hide file tree
Showing 31 changed files with 497 additions and 190 deletions.
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If there's a lot of interest in this framework, then I will continue to improve

1. Evaluate the outcome of any data factory resource result given a set of input parameters. The framework will evaluate parameters, globalParameters, variables, activityOutputs and their expressions, so that the final result can be asserted.
2. Simulate a pipeline run and evaluate the execution flow and outcome of each activity.
3. Automatically parse any data factory resource into the correct typed class (1500+ classes available).
3. Automatically parse the entire data factory folder and parse any data factory entity into the correct typed class (1500+ classes available).
4. Evaluate expressions, but not all functions are supported yet. You can always easily register your own custom functions.

## Why
Expand All @@ -27,9 +27,11 @@ Azure Data Factory does not support unit testing out of the box. The only way to
## Getting started

1. Add the following nuget source to `nuget.config`: `https://nuget.pkg.github.com/arjendev/index.json`
2. Install the nuget package: `dotnet add package AzureDataFactory.TestingFramework --prerelease`
3. Start writing tests
1. Create a .NET Unit Test project (xUnit is used in examples)
2. Navigate in terminal to the project folder
3. Add private github package nuget source: `dotnet nuget add source https://nuget.pkg.github.com/arjendev/index.json --name arjendevfeed --username <GITHUB_HANDLE> --password <TOKEN>`
4. Add package to project: `dotnet add package AzureDataFactory.TestingFramework --prerelease`
5. Start writing tests

## Features - Examples

Expand All @@ -43,7 +45,7 @@ The samples seen below is the _only_ code that you need to write! The framework
var activity = pipeline.GetActivityByName("Trigger Azure Batch Job") as WebHookActivity;

_state.Parameters.Add(new RunParameter(ParameterType.Global, "BaseUrl", "https://example.com"));
_state.Parameters.Add(new RunParameter(ParameterType.Parameter, "JobId", "123"));
_state.Parameters.Add(new RunParameter(ParameterType.Pipeline, "JobId", "123"));
_state.Variables.Add(new PipelineRunVariable("JobName", "Job-123"));
_state.AddActivityResult(new TestActivityResult("Get version", new
{
Expand All @@ -63,15 +65,16 @@ The samples seen below is the _only_ code that you need to write! The framework
2. Evaluate Pipelines and test the flow of activities given a specific input

```csharp
var pipeline = PipelineFactory.ParseFromFile(pipelineFileName);
var testFramework = new TestFramework(dataFactoryFolderPath: "BatchJob");
var pipeline = testFramework.Repository.GetPipelineByName("batch_job");
Assert.Equal("example-pipeline", pipeline.Name);
Assert.Equal(6, pipeline.Activities.Count);

// Runs the pipeline with the provided parameters
var activities = pipeline.EvaluateWithActivityEnumerator(new List<RunParameter>
var activities = testFramework.Evaluate(pipeline, new List<RunParameter>
{
new(ParameterType.Parameter, "JobId", "123"),
new(ParameterType.Parameter, "ContainerName", "test-container"),
new(ParameterType.Pipeline, "JobId", "123"),
new(ParameterType.Pipeline, "ContainerName", "test-container"),
new(ParameterType.Global, "BaseUrl", "https://example.com"),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
</ItemGroup>

<ItemGroup>
<None Update="BatchJob\pipeline.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<ProjectReference Include="..\AzureDataFactory.TestingFramework\AzureDataFactory.TestingFramework.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\AzureDataFactory.TestingFramework\AzureDataFactory.TestingFramework.csproj" />
<None Update="BatchJob\pipeline\batch_job.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,36 @@
using AzureDataFactory.TestingFramework.Exceptions;
using AzureDataFactory.TestingFramework.Models;
using AzureDataFactory.TestingFramework.Models.Base;
using AzureDataFactory.TestingFramework.Models.Pipelines;

namespace AzureDataFactory.TestingFramework.Example.BatchJob;

public class BatchJobFunctionalTests
{

[Fact]
public void BatchJobTest()
{
var pipeline = PipelineFactory.ParseFromFile("BatchJob/pipeline.json");
var testFramework = new TestFramework(dataFactoryFolderPath: "BatchJob");
var pipeline = testFramework.Repository.GetPipelineByName("batch_job");
Assert.Equal("batch_job", pipeline.Name);
Assert.Equal(11, pipeline.Activities.Count);

var activities = pipeline.EvaluateWithActivityEnumerator(new List<IRunParameter>
var activities = testFramework.EvaluateWithEnumerator(pipeline, new List<IRunParameter>
{
new RunParameter<string>(ParameterType.Parameter, "BatchPoolId", "batch-pool-id"),
new RunParameter<string>(ParameterType.Parameter, "WorkloadApplicationPackageName", "test-application"),
new RunParameter<string>(ParameterType.Parameter, "WorkloadApplicationPackageVersion", "1.5.0"),
new RunParameter<string>(ParameterType.Parameter, "ManagerApplicationPackageName", "batchmanager"),
new RunParameter<string>(ParameterType.Parameter, "ManagerApplicationPackageVersion", "2.0.0"),
new RunParameter<string>(ParameterType.Parameter, "ManagerTaskParameters", "--parameter1 dummy --parameter2 another-dummy"),
new RunParameter<string>(ParameterType.Parameter, "JobId", "802100a5-ec79-4a52-be62-8d6109f3ff9a"),
new RunParameter<string>(ParameterType.Parameter, "TaskOutputFolderPrefix", "TASKOUTPUT_"),
new RunParameter<string>(ParameterType.Parameter, "WorkloadUserAssignedIdentityName", "test-application-identity-name"),
new RunParameter<string>(ParameterType.Parameter, "WorkloadUserAssignedIdentityClientId", "/subscriptions/SUBSCRIPTION_ID/resourcegroups/RESOURCE_GROUP/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-application-identity-name"),
new RunParameter<string>(ParameterType.Parameter, "JobAdditionalEnvironmentSettings", "[]"),
new RunParameter<string>(ParameterType.Parameter, "OutputStorageAccountName", "test-application-output-storage-account-name"),
new RunParameter<string>(ParameterType.Parameter, "OutputContainerName", "test-application-output-container-name"),
new RunParameter<string>(ParameterType.Parameter, "OutputFolderName", "TEMP"),
new RunParameter<string>(ParameterType.Parameter, "BatchJobTimeout", "PT4H"),
new RunParameter<string>(ParameterType.Pipeline, "BatchPoolId", "batch-pool-id"),
new RunParameter<string>(ParameterType.Pipeline, "WorkloadApplicationPackageName", "test-application"),
new RunParameter<string>(ParameterType.Pipeline, "WorkloadApplicationPackageVersion", "1.5.0"),
new RunParameter<string>(ParameterType.Pipeline, "ManagerApplicationPackageName", "batchmanager"),
new RunParameter<string>(ParameterType.Pipeline, "ManagerApplicationPackageVersion", "2.0.0"),
new RunParameter<string>(ParameterType.Pipeline, "ManagerTaskParameters", "--parameter1 dummy --parameter2 another-dummy"),
new RunParameter<string>(ParameterType.Pipeline, "JobId", "802100a5-ec79-4a52-be62-8d6109f3ff9a"),
new RunParameter<string>(ParameterType.Pipeline, "TaskOutputFolderPrefix", "TASKOUTPUT_"),
new RunParameter<string>(ParameterType.Pipeline, "WorkloadUserAssignedIdentityName", "test-application-identity-name"),
new RunParameter<string>(ParameterType.Pipeline, "WorkloadUserAssignedIdentityClientId", "/subscriptions/SUBSCRIPTION_ID/resourcegroups/RESOURCE_GROUP/providers/Microsoft.ManagedIdentity/userAssignedIdentities/test-application-identity-name"),
new RunParameter<string>(ParameterType.Pipeline, "JobAdditionalEnvironmentSettings", "[]"),
new RunParameter<string>(ParameterType.Pipeline, "OutputStorageAccountName", "test-application-output-storage-account-name"),
new RunParameter<string>(ParameterType.Pipeline, "OutputContainerName", "test-application-output-container-name"),
new RunParameter<string>(ParameterType.Pipeline, "OutputFolderName", "TEMP"),
new RunParameter<string>(ParameterType.Pipeline, "BatchJobTimeout", "PT4H"),
new RunParameter<string>(ParameterType.Global, "BatchStorageAccountName", "batch-account-name"),
new RunParameter<string>(ParameterType.Global, "BatchAccountSubscription", "SUBSCRIPTION_ID"),
new RunParameter<string>(ParameterType.Global, "BatchAccountResourceGroup", "RESOURCE_GROUP"),
Expand Down
Loading

0 comments on commit 6048e79

Please sign in to comment.