Skip to content

Commit

Permalink
downgrading and then running seemed to fix whatever its issue was, th…
Browse files Browse the repository at this point in the history
…en upgrading seems to work
  • Loading branch information
Aaron Sulwer committed Jun 21, 2024
1 parent 04c51f5 commit 2c69ea8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 29 deletions.
1 change: 0 additions & 1 deletion RulesEngine.sln
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Global
{57BB8C07-799A-4F87-A7CC-D3D3F694DD02}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57BB8C07-799A-4F87-A7CC-D3D3F694DD02}.Release|Any CPU.Build.0 = Release|Any CPU
{C058809F-C720-4EFC-925D-A486627B238B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C058809F-C720-4EFC-925D-A486627B238B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C058809F-C720-4EFC-925D-A486627B238B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C058809F-C720-4EFC-925D-A486627B238B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
44 changes: 20 additions & 24 deletions test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public async Task RulesEngine_InjectedRules_ContainsInjectedRules(string ruleFil
dynamic input2 = GetInput2();
dynamic input3 = GetInput3();

List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflowReference", [input1, input2, input3]);
List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflowReference", new[] { input1, input2, input3 });
Assert.NotNull(result);
Assert.True(result.Any());
}
Expand All @@ -58,7 +58,7 @@ public async Task ExecuteRule_ReturnsListOfRuleResultTree(string ruleFileName)
dynamic input2 = GetInput2();
dynamic input3 = GetInput3();

List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result);
Assert.IsType<List<RuleResultTree>>(result);
Assert.Contains(result, c => c.IsSuccess);
Expand All @@ -75,7 +75,7 @@ public async Task ExecuteRule_AddWorkflowWithSameName_ThrowsValidationException(
dynamic input3 = GetInput3();

// Run previous rules.
List<RuleResultTree> result1 = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
List<RuleResultTree> result1 = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result1);
Assert.IsType<List<RuleResultTree>>(result1);
Assert.Contains(result1, c => c.IsSuccess);
Expand All @@ -97,7 +97,7 @@ public async Task ExecuteRule_AddOrUpdateWorkflow_ExecutesUpdatedRules(string pr
dynamic input3 = GetInput3();

// Run previous rules.
List<RuleResultTree> result1 = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
List<RuleResultTree> result1 = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result1);
Assert.IsType<List<RuleResultTree>>(result1);
Assert.Contains(result1, c => c.IsSuccess);
Expand All @@ -107,7 +107,7 @@ public async Task ExecuteRule_AddOrUpdateWorkflow_ExecutesUpdatedRules(string pr
re.AddOrUpdateWorkflow(newWorkflow);

// Run new rules.
List<RuleResultTree> result2 = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
List<RuleResultTree> result2 = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result2);
Assert.IsType<List<RuleResultTree>>(result2);
Assert.DoesNotContain(result2, c => c.IsSuccess);
Expand Down Expand Up @@ -171,10 +171,7 @@ public async Task ExecuteRule_ManyInputs_ReturnsListOfRuleResultTree(string rule
dynamic input17 = GetInput2();
dynamic input18 = GetInput3();

List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow",
[input1, input2, input3, input4, input5, input6, input7, input8, input9, input10, input11, input12, input13, input14, input15, input16, input17, input18]);
//, input9, input10, input11, input12, input13, input14, input15, input16, input17, input18);
Assert.NotNull(result);
List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3, input4, input5, input6, input7, input8, input9, input10, input11, input12, input13, input14, input15, input16, input17, input18 });
Assert.IsType<List<RuleResultTree>>(result);
Assert.Contains(result, c => c.IsSuccess);
}
Expand All @@ -190,12 +187,12 @@ public async Task ExecuteRule_CalledMultipleTimes_ReturnsSameResult(string ruleF
dynamic input2 = GetInput2();
dynamic input3 = GetInput3();

List<RuleResultTree> result1 = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
List<RuleResultTree> result1 = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result1);
Assert.IsType<List<RuleResultTree>>(result1);
Assert.Contains(result1, c => c.IsSuccess);

List<RuleResultTree> result2 = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
List<RuleResultTree> result2 = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result2);
Assert.IsType<List<RuleResultTree>>(result2);
Assert.Contains(result2, c => c.IsSuccess);
Expand All @@ -217,7 +214,7 @@ public async Task ExecuteRule_SingleObject_ReturnsListOfRuleResultTree(string ru
dynamic input2 = GetInput2();
dynamic input3 = GetInput3();

List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", input1);
List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1 });
Assert.NotNull(result);
Assert.IsType<List<RuleResultTree>>(result);
Assert.DoesNotContain(result, c => c.IsSuccess);
Expand All @@ -233,7 +230,7 @@ public async Task ExecuteRule_ExceptionScenario_RulesInvalid(string ruleFileName
dynamic input2 = GetInput2();
dynamic input3 = GetInput3();

List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result);
Assert.False(string.IsNullOrEmpty(result[0].ExceptionMessage) || string.IsNullOrWhiteSpace(result[0].ExceptionMessage));
}
Expand Down Expand Up @@ -278,7 +275,7 @@ public async Task ExecuteRule_InvalidWorkFlow_ThrowsException(string ruleFileNam
var re = GetRulesEngine(ruleFileName);
dynamic input = GetInput1();

await Assert.ThrowsAsync<ArgumentException>(async () => { await re.ExecuteAllRulesAsync("inputWorkflow1", input); });
await Assert.ThrowsAsync<ArgumentException>(async () => { await re.ExecuteAllRulesAsync("inputWorkflow1", new[] { input }); });
}

[Theory]
Expand All @@ -290,11 +287,11 @@ public async Task RemoveWorkflow_RemovesWorkflow(string ruleFileName)
dynamic input2 = GetInput2();
dynamic input3 = GetInput3();

var result = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
var result = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result);
re.RemoveWorkflow("inputWorkflow");

await Assert.ThrowsAsync<ArgumentException>(async () => await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]));
await Assert.ThrowsAsync<ArgumentException>(async () => await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 }));
}


Expand All @@ -309,8 +306,8 @@ public async Task ClearWorkflow_RemovesAllWorkflow(string ruleFileName)
dynamic input2 = GetInput2();
dynamic input3 = GetInput3();

await Assert.ThrowsAsync<ArgumentException>(async () => await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]));
await Assert.ThrowsAsync<ArgumentException>(async () => await re.ExecuteAllRulesAsync("inputWorkflowReference", [input1, input2, input3]));
await Assert.ThrowsAsync<ArgumentException>(async () => await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 }));
await Assert.ThrowsAsync<ArgumentException>(async () => await re.ExecuteAllRulesAsync("inputWorkflowReference", new[] { input1, input2, input3 }));
}

[Theory]
Expand All @@ -324,14 +321,14 @@ public async Task ExecuteRule_InputWithVariableProps_ReturnsResult(string ruleFi
dynamic input2 = GetInput2();
dynamic input3 = GetInput3();

List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
List<RuleResultTree> result = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result);
Assert.IsType<List<RuleResultTree>>(result);
Assert.Contains(result, c => c.IsSuccess);

input3.hello = "world";

result = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
result = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result);
Assert.IsType<List<RuleResultTree>>(result);
Assert.Contains(result, c => c.IsSuccess);
Expand Down Expand Up @@ -378,7 +375,7 @@ public async Task ExecuteRule_ReturnsProperErrorOnMissingRuleParameter(string ru
var input2 = new RuleParameter("input2", GetInput2());
var input3 = new RuleParameter("input3", GetInput3());

var result = await re.ExecuteAllRulesAsync("inputWorkflow", [input1, input2, input3]);
var result = await re.ExecuteAllRulesAsync("inputWorkflow", new[] { input1, input2, input3 });
Assert.NotNull(result);
Assert.IsType<List<RuleResultTree>>(result);
Assert.Contains(result.First().ChildResults, c => c.ExceptionMessage.Contains("Unknown identifier 'input1'"));
Expand Down Expand Up @@ -980,15 +977,14 @@ public async Task ExecuteRule_WithNullInput_ShouldNotThrowException()
var result1 = await re.ExecuteAllRulesAsync("Test", [new RuleParameter("input1", value: null)]);
Assert.True(result1.All(c => c.IsSuccess));


var result2 = await re.ExecuteAllRulesAsync("Test", new object[] { null });
Assert.True(result2.All(c => c.IsSuccess));

dynamic input1 = new ExpandoObject();
input1.hello = new ExpandoObject();
input1.hello.world = "wow";

List<RuleResultTree> result3 = await re.ExecuteAllRulesAsync("Test", input1);
List<RuleResultTree> result3 = await re.ExecuteAllRulesAsync("Test", new[] { input1 });
Assert.True(result3.All(c => c.IsSuccess));

}
Expand Down Expand Up @@ -1016,7 +1012,7 @@ public async Task ExecuteRule_SpecialCharInWorkflowName_RunsSuccessfully()
input1.hello = new ExpandoObject();
input1.hello.world = "wow";

List<RuleResultTree> result3 = await re.ExecuteAllRulesAsync("Exámple", input1);
List<RuleResultTree> result3 = await re.ExecuteAllRulesAsync("Exámple", new[] { input1 });
Assert.True(result3.All(c => c.IsSuccess));

}
Expand Down
6 changes: 3 additions & 3 deletions test/RulesEngine.UnitTest/NestedRulesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task NestedRulesShouldFollowExecutionMode(NestedRuleExecutionMode m
dynamic input1 = new ExpandoObject();
input1.trueValue = true;

List<RuleResultTree> result = await rulesEngine.ExecuteAllRulesAsync("NestedRulesTest", input1);
List<RuleResultTree> result = await rulesEngine.ExecuteAllRulesAsync("NestedRulesTest", new[] { input1 });
var andResults = result.Where(c => c.Rule.Operator == "And").ToList();
var orResults = result.Where(c => c.Rule.Operator == "Or").ToList();
Assert.All(andResults,
Expand Down Expand Up @@ -74,7 +74,7 @@ private async Task NestedRulesWithNestedActions_ReturnsCorrectResults()
dynamic input1 = new ExpandoObject();
input1.trueValue = true;

List<RuleResultTree> result = await rulesEngine.ExecuteAllRulesAsync("NestedRulesActionsTest", input1);
List<RuleResultTree> result = await rulesEngine.ExecuteAllRulesAsync("NestedRulesActionsTest", new[] { input1 });

Assert.False(result[0].IsSuccess);
Assert.Equal(input1.trueValue, result[0].ActionResult.Output);
Expand All @@ -97,7 +97,7 @@ private async Task NestedRulesWithNestedActions_WorkflowParsedWithSystemTextJson
dynamic input1 = new ExpandoObject();
input1.trueValue = true;

List<RuleResultTree> result = await rulesEngine.ExecuteAllRulesAsync("NestedRulesActionsTest", input1);
List<RuleResultTree> result = await rulesEngine.ExecuteAllRulesAsync("NestedRulesActionsTest", new[] { input1 });

Assert.False(result[0].IsSuccess);
Assert.Equal(input1.trueValue, result[0].ActionResult.Output);
Expand Down
4 changes: 3 additions & 1 deletion test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<SignAssembly>True</SignAssembly>
Expand All @@ -9,7 +9,9 @@
<PackageReference Include="AutoFixture" Version="4.18.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit 2c69ea8

Please sign in to comment.