-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: increase test coverage and fix some discovered issues (#12)
- Loading branch information
Showing
22 changed files
with
590 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...zureDataFactory.TestingFramework.Tests/Models/Activities/Base/ActivitiesEvaluatorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
using Azure.Core.Expressions.DataFactory; | ||
using AzureDataFactory.TestingFramework.Exceptions; | ||
using AzureDataFactory.TestingFramework.Functions; | ||
using AzureDataFactory.TestingFramework.Models; | ||
using AzureDataFactory.TestingFramework.Models.Activities.Base; | ||
using AzureDataFactory.TestingFramework.Models.Pipelines; | ||
|
||
namespace AzureDataFactory.TestingFramework.Tests.Models.Activities.Base; | ||
|
||
public class ActivitiesEvaluatorTests | ||
{ | ||
private readonly List<PipelineActivity> _activities; | ||
private readonly WebActivity _webActivity; | ||
private readonly SetVariableActivity _setVariableActivity; | ||
|
||
public ActivitiesEvaluatorTests() | ||
{ | ||
_activities = new List<PipelineActivity>(); | ||
_webActivity = new WebActivity("webActivity", WebActivityMethod.Get, "https://www.example.com") | ||
{ | ||
DependsOn = | ||
{ | ||
new PipelineActivityDependency("setVariableActivity", new[] { DependencyCondition.Succeeded }) | ||
} | ||
}; | ||
_setVariableActivity = new SetVariableActivity("setVariableActivity") | ||
{ | ||
VariableName = "variable1", | ||
Value = "value1" | ||
}; | ||
_activities.Add(_webActivity); | ||
_activities.Add(_setVariableActivity); | ||
} | ||
|
||
[Fact] | ||
public void EvaluateWithoutIterationActivities_ShouldEvaluateAccordingToDependencies() | ||
{ | ||
// Act | ||
var state = new PipelineRunState(); | ||
state.Variables.Add(new PipelineRunVariable<string>("variable1", string.Empty)); | ||
var evaluatedActivities = ActivitiesEvaluator.Evaluate(_activities, state).ToList(); | ||
|
||
// Assert | ||
Assert.NotNull(evaluatedActivities); | ||
Assert.Equal(2, evaluatedActivities.Count()); | ||
Assert.Equal("setVariableActivity", evaluatedActivities.First().Name); | ||
Assert.Equal("webActivity", evaluatedActivities.Last().Name); | ||
} | ||
|
||
[Fact] | ||
public void EvaluateWithCircularDependencies_ShouldThrowActivitiesEvaluatorInvalidDependencyException() | ||
{ | ||
// Arrange | ||
_setVariableActivity.DependsOn.Add(new PipelineActivityDependency("webActivity", new[] { DependencyCondition.Succeeded })); | ||
|
||
// Assert | ||
Assert.Throws<ActivitiesEvaluatorInvalidDependencyException>(() => ActivitiesEvaluator.Evaluate(_activities, new PipelineRunState()).ToList()); | ||
} | ||
|
||
[Fact] | ||
public void EvaluateWithForeachActivities_ShouldEvaluateAccordingToDependencies() | ||
{ | ||
// Arrange | ||
var state = new PipelineRunState(); | ||
state.Variables.Add(new PipelineRunVariable<string>("variable1", string.Empty)); | ||
state.Variables.Add(new PipelineRunVariable<string>("iterationItems", "item1,item2,item3")); | ||
var foreachActivity = new ForEachActivity("foreachActivity", | ||
new DataFactoryExpression(DataFactoryExpressionType.Expression, "@split(variables('iterationItems'), ',')"), | ||
_activities); | ||
_webActivity.Uri = new DataFactoryElement<string>("@concat('https://www.example.com/', item())", DataFactoryElementKind.Expression); | ||
|
||
// Act | ||
var evaluatedActivities = ActivitiesEvaluator.Evaluate(new List<PipelineActivity> { foreachActivity }, state); | ||
|
||
// Assert | ||
using var enumerator = evaluatedActivities.GetEnumerator(); | ||
Assert.True(enumerator.MoveNext()); | ||
Assert.Equal("setVariableActivity", enumerator.Current.Name); | ||
Assert.True(enumerator.MoveNext()); | ||
Assert.Equal("webActivity", enumerator.Current.Name); | ||
Assert.Equal("https://www.example.com/item1", ((WebActivity)enumerator.Current).Uri); | ||
Assert.True(enumerator.MoveNext()); | ||
Assert.Equal("setVariableActivity", enumerator.Current.Name); | ||
Assert.True(enumerator.MoveNext()); | ||
Assert.Equal("webActivity", enumerator.Current.Name); | ||
Assert.Equal("https://www.example.com/item2", ((WebActivity)enumerator.Current).Uri); | ||
Assert.True(enumerator.MoveNext()); | ||
Assert.Equal("setVariableActivity", enumerator.Current.Name); | ||
Assert.True(enumerator.MoveNext()); | ||
Assert.Equal("webActivity", enumerator.Current.Name); | ||
Assert.Equal("https://www.example.com/item3", ((WebActivity)enumerator.Current).Uri); | ||
Assert.False(enumerator.MoveNext()); | ||
} | ||
|
||
[Fact] | ||
public void EvaluateWithUntilActivities_ShouldEvaluateAccordingToDependencies() | ||
{ | ||
// Arrange | ||
var state = new PipelineRunState(); | ||
state.Variables.Add(new PipelineRunVariable<string>("variable1", string.Empty)); | ||
var untilActivity = new UntilActivity("untilActivity", | ||
new DataFactoryExpression(DataFactoryExpressionType.Expression, "@equals(variables('variable1'), 'value1')"), | ||
_activities); | ||
|
||
// Act | ||
var evaluatedActivities = ActivitiesEvaluator.Evaluate(new List<PipelineActivity> { untilActivity }, state); | ||
|
||
// Assert | ||
using var enumerator = evaluatedActivities.GetEnumerator(); | ||
Assert.True(enumerator.MoveNext()); | ||
Assert.Equal("setVariableActivity", enumerator.Current.Name); | ||
Assert.True(enumerator.MoveNext()); | ||
Assert.Equal("webActivity", enumerator.Current.Name); | ||
Assert.False(enumerator.MoveNext()); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/AzureDataFactory.TestingFramework.Tests/Models/Activities/Base/PipelineActivityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using AzureDataFactory.TestingFramework.Models; | ||
using AzureDataFactory.TestingFramework.Models.Pipelines; | ||
|
||
namespace AzureDataFactory.TestingFramework.Tests.Models.Activities.Base; | ||
|
||
public class PipelineActivityTests | ||
{ | ||
[Theory] | ||
[InlineData("Succeeded", "Succeeded", true)] | ||
[InlineData("Failed", "Succeeded", false)] | ||
[InlineData("Skipped", "Succeeded", false)] | ||
[InlineData("Completed", "Succeeded", false)] | ||
[InlineData("Failed", "Failed", true)] | ||
[InlineData("Skipped", "Failed", false)] | ||
[InlineData("Completed", "Failed", false)] | ||
[InlineData("Skipped", "Skipped", true)] | ||
[InlineData("Completed", "Skipped", false)] | ||
[InlineData("Completed", "Completed", true)] | ||
public void DependencyConditions_WhenCalled_ReturnsExpected(string requiredCondition, string actualCondition, bool expected) | ||
{ | ||
// Arrange | ||
var pipelineActivity = new PipelineActivity("activity") | ||
{ | ||
DependsOn = { new PipelineActivityDependency("otherActivity", new[] { new DependencyCondition(requiredCondition) }) } | ||
}; | ||
var state = new PipelineRunState(); | ||
state.AddActivityResult(new TestActivityResult("otherActivity", new DependencyCondition(actualCondition))); | ||
|
||
// Assert | ||
Assert.Equal(expected, pipelineActivity.AreDependencyConditionMet(state)); | ||
} | ||
|
||
[Fact] | ||
public void EvaluateWhenNoStatusIsSet_ShouldSetStatusToSucceeded() | ||
{ | ||
// Arrange | ||
var pipelineActivity = new PipelineActivity("activity"); | ||
var state = new PipelineRunState(); | ||
|
||
// Act | ||
pipelineActivity.Evaluate(state); | ||
|
||
// Assert | ||
Assert.Equal(DependencyCondition.Succeeded, pipelineActivity.Status); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...actory.TestingFramework.Tests/Models/Activities/ControlActivities/ForEachActivityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using Azure.Core.Expressions.DataFactory; | ||
using AzureDataFactory.TestingFramework.Models; | ||
using AzureDataFactory.TestingFramework.Models.Pipelines; | ||
|
||
namespace AzureDataFactory.TestingFramework.Tests.Models.Activities.ControlActivities; | ||
|
||
public class ForEachActivityTests | ||
{ | ||
[Fact] | ||
public void WhenEvaluateChildActivities_ThenShouldReturnTheActivityWithItemExpressionEvaluated() | ||
{ | ||
// Arrange | ||
var forEachActivity = new ForEachActivity("ForEachActivity", | ||
new DataFactoryExpression(DataFactoryExpressionType.Expression, "@split('a,b,c', ',')"), | ||
new List<PipelineActivity>() | ||
{ | ||
new SetVariableActivity("setVariable") | ||
{ | ||
VariableName = "variable", | ||
Value = new DataFactoryElement<string>("item()", DataFactoryElementKind.Expression) | ||
} | ||
}); | ||
var state = new PipelineRunState(); | ||
state.Variables.Add(new PipelineRunVariable<string>("variable", string.Empty)); | ||
|
||
// Act | ||
forEachActivity.Evaluate(state); | ||
var childActivities = forEachActivity.EvaluateChildActivities(state); | ||
|
||
// Assert | ||
using var enumarator = childActivities.GetEnumerator(); | ||
Assert.True(enumarator.MoveNext()); | ||
var setVariableActivity = enumarator.Current as SetVariableActivity; | ||
Assert.NotNull(setVariableActivity); | ||
Assert.Equal("a", setVariableActivity.Value); | ||
Assert.True(enumarator.MoveNext()); | ||
setVariableActivity = enumarator.Current as SetVariableActivity; | ||
Assert.NotNull(setVariableActivity); | ||
Assert.Equal("b", setVariableActivity.Value); | ||
Assert.True(enumarator.MoveNext()); | ||
setVariableActivity = enumarator.Current as SetVariableActivity; | ||
Assert.NotNull(setVariableActivity); | ||
Assert.Equal("c", setVariableActivity.Value); | ||
Assert.False(enumarator.MoveNext()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...ry.TestingFramework.Tests/Models/Activities/ControlActivities/IfConditionActivityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using Azure.Core.Expressions.DataFactory; | ||
using AzureDataFactory.TestingFramework.Models; | ||
using AzureDataFactory.TestingFramework.Models.Pipelines; | ||
|
||
namespace AzureDataFactory.TestingFramework.Tests.Models.Activities.ControlActivities; | ||
|
||
public class IfConditionActivityTests | ||
{ | ||
[Fact] | ||
public void WhenEvaluated_ShouldEvaluateExpression() | ||
{ | ||
// Arrange | ||
var activity = new IfConditionActivity("IfConditionActivity", | ||
new DataFactoryExpression(DataFactoryExpressionType.Expression, "@equals(1, 1)")); | ||
|
||
// Act | ||
activity.Evaluate(new PipelineRunState()); | ||
|
||
// Assert | ||
Assert.True(activity.EvaluatedExpression); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, "setVariableActivity1")] | ||
[InlineData(false, "setVariableActivity2")] | ||
public void WhenEvaluated_ShouldEvaluateCorrectChildActivities(bool expressionOutcome, string expectedActivityName) | ||
{ | ||
// Arrange | ||
var expression = expressionOutcome ? "@equals(1, 1)" : "@equals(1, 2)"; | ||
var activity = new IfConditionActivity("IfConditionActivity", | ||
new DataFactoryExpression(DataFactoryExpressionType.Expression, expression)) | ||
{ | ||
IfTrueActivities = { new SetVariableActivity("setVariableActivity1") { VariableName = "variable", Value = "dummy" } }, | ||
IfFalseActivities = { new SetVariableActivity("setVariableActivity2") { VariableName = "variable", Value = "dummy" } } | ||
}; | ||
var state = new PipelineRunState(); | ||
state.Variables.Add(new PipelineRunVariable<string>("variable", string.Empty)); | ||
activity.Evaluate(state); | ||
|
||
// Act | ||
var childActivities = activity.EvaluateChildActivities(state).ToList(); | ||
|
||
// Assert | ||
Assert.Single(childActivities); | ||
Assert.Equal(expectedActivityName, childActivities.First().Name); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/AzureDataFactory.TestingFramework.Tests/Models/Activities/SetVariableTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using AzureDataFactory.TestingFramework.Models; | ||
using AzureDataFactory.TestingFramework.Models.Pipelines; | ||
|
||
namespace AzureDataFactory.TestingFramework.Tests.Models.Activities; | ||
|
||
public class SetVariableTests | ||
{ | ||
[Fact] | ||
public void WhenStringVariableEvaluated_ThenStateVariableShouldBeSet() | ||
{ | ||
// Arrange | ||
var variableName = "TestVariable"; | ||
var variable = new PipelineRunVariable<string>(variableName, string.Empty); | ||
var setVariable = new SetVariableActivity("TestSetVariable") | ||
{ | ||
VariableName = variableName, | ||
Value = "value1" | ||
}; | ||
var state = new PipelineRunState(); | ||
state.Variables.Add(variable); | ||
|
||
// Act | ||
setVariable.Evaluate(state); | ||
|
||
// Assert | ||
Assert.Equal("value1", variable.Value); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/AzureDataFactory.TestingFramework.Tests/Models/DataFactoryEntityTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using AzureDataFactory.TestingFramework.Models; | ||
using Azure.Core.Expressions.DataFactory; | ||
using AzureDataFactory.TestingFramework.Models.Pipelines; | ||
|
||
namespace AzureDataFactory.TestingFramework.Tests.Models; | ||
|
||
public class DataFactoryEntityTests | ||
{ | ||
[Fact] | ||
public void WhenEvaluatingEntity_ShouldEvaluateAllProperties() | ||
{ | ||
// Arrange | ||
var entity = new WebActivity("TestActivity", WebActivityMethod.Get, new DataFactoryElement<string>("@concat('https://example.com', '/123')", DataFactoryElementKind.Expression)); | ||
|
||
// Act | ||
entity.Evaluate(new PipelineRunState()); | ||
|
||
// Assert | ||
Assert.NotNull(entity); | ||
Assert.Equal("https://example.com/123", entity.Uri); | ||
} | ||
|
||
[Fact] | ||
public void WhenNotEvaluatingEntity_ShouldNotEvaluateAllProperties() | ||
{ | ||
// Arrange | ||
var entity = new WebActivity("TestActivity", WebActivityMethod.Get, new DataFactoryElement<string>("@concat('https://example.com', '/123')", DataFactoryElementKind.Expression)); | ||
|
||
// Act | ||
|
||
// Assert | ||
Assert.NotNull(entity); | ||
Assert.Throws<ExpressionNotEvaluatedException>(() => entity.Uri.Value); | ||
} | ||
} |
Oops, something went wrong.