From 79cf8667d9951c116034997f3cdb9d93feb0c0a8 Mon Sep 17 00:00:00 2001 From: Abbas Cyclewala Date: Sun, 25 Sep 2022 12:06:34 +0000 Subject: [PATCH 1/5] * Updated dependecies * fixed build error * removed obsolete code --- .config/dotnet-tools.json | 2 +- .devcontainer/devcontainer.json | 12 +++-- .github/workflows/dotnetcore-build.yml | 49 ++++++------------- .../RulesEngineBenchmark.csproj | 2 +- .../DemoApp.EFDataExample.csproj | 6 +-- .../RulesEngineContext.cs | 1 - global.json | 2 +- scripts/check-coverage.ps1 | 16 ++++++ scripts/generate-coverage-report.ps1 | 2 + src/RulesEngine/HelperFunctions/Helpers.cs | 45 ----------------- src/RulesEngine/Models/ReSettings.cs | 10 ---- src/RulesEngine/Models/Rule.cs | 11 ----- src/RulesEngine/Models/RuleResultTree.cs | 23 --------- src/RulesEngine/RuleCompiler.cs | 8 --- src/RulesEngine/RulesEngine.csproj | 8 +-- .../BusinessRuleEngineTest.cs | 16 ------ .../RulesEngine.UnitTest.csproj | 10 ++-- test/RulesEngine.UnitTest/ScopedParamsTest.cs | 4 -- 18 files changed, 54 insertions(+), 173 deletions(-) create mode 100644 scripts/check-coverage.ps1 create mode 100644 scripts/generate-coverage-report.ps1 diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json index 9ec9a192..084675a6 100644 --- a/.config/dotnet-tools.json +++ b/.config/dotnet-tools.json @@ -3,7 +3,7 @@ "isRoot": true, "tools": { "dotnet-reportgenerator-globaltool": { - "version": "4.7.1", + "version": "5.1.10", "commands": [ "reportgenerator" ] diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index b83a27ac..85df4add 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,8 +1,8 @@ { "name": "RulesEngine Codespace", - "image": "mcr.microsoft.com/vscode/devcontainers/dotnet:0.201.7-3.1", + "image": "mcr.microsoft.com/vscode/devcontainers/dotnet:0-6.0", "settings": { - "terminal.integrated.defaultProfile.linux": "pwsh" + "terminal.integrated.defaultProfile.linux": "bash" }, "extensions": [ "eamodio.gitlens", @@ -12,12 +12,14 @@ "cschleiden.vscode-github-actions", "redhat.vscode-yaml", "bierner.markdown-preview-github-styles", - "ban.spellright", - "jmrog.vscode-nuget-package-manager", "coenraads.bracket-pair-colorizer", "vscode-icons-team.vscode-icons", - "editorconfig.editorconfig" + "editorconfig.editorconfig", + "aliasadidev.nugetpackagemanagergui" ], "postCreateCommand": "dotnet restore RulesEngine.sln && dotnet build RulesEngine.sln --configuration Release --no-restore && dotnet test RulesEngine.sln --configuration Release --no-build --verbosity minimal", + "features": { + "powershell": "7.1" + }, } // Built with ❤ by [Pipeline Foundation](https://pipeline.foundation) diff --git a/.github/workflows/dotnetcore-build.yml b/.github/workflows/dotnetcore-build.yml index b2e13b2d..2a2ba239 100644 --- a/.github/workflows/dotnetcore-build.yml +++ b/.github/workflows/dotnetcore-build.yml @@ -8,35 +8,13 @@ on: jobs: build: - runs-on: ubuntu-latest - steps: - # extract branch name - - name: Extract branch name - if: github.event_name != 'pull_request' - shell: bash - run: echo "BRANCH_NAME=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_ENV - id: extract_branch - - # extract branch name on pull request - - name: Extract branch name on pull request - if: github.event_name == 'pull_request' - run: echo "BRANCH_NAME=$(echo ${GITHUB_HEAD_REF})" >> $GITHUB_ENV - - # print branch name - - name: Get branch name - run: echo "The branch name is ${{ env.BRANCH_NAME }}" - - - uses: actions/checkout@v3 - name: Setup .NET Core uses: actions/setup-dotnet@v2 with: dotnet-version: 6.0.x - - - name: Install minicover - run: dotnet tool install --global minicover --version 3.4.4 - name: Install dependencies run: dotnet restore RulesEngine.sln @@ -44,19 +22,20 @@ jobs: - name: Build run: dotnet build RulesEngine.sln --configuration Release --no-restore - - name: Instrument - run: minicover instrument - - name: Test - run: dotnet test RulesEngine.sln --no-build --configuration Release --verbosity m - - - name: Uninstrument - run: minicover uninstrument - - - name: Report - run: minicover report --threshold 95 - if: ${{ github.event_name == 'pull_request' }} + run: dotnet test RulesEngine.sln --collect:"XPlat Code Coverage" --no-build --configuration Release --verbosity m + + - name: Generate Report + shell: pwsh + run: ./scripts/generate-coverage-report.ps1 + + - name: Check Coverage + shell: pwsh + run: ./scripts/check-coverage.ps1 -reportPath coveragereport/Cobertura.xml -threshold 97 - - name: Report coveralls - run: minicover coverallsreport --repo-token ${{ secrets.COVERALLS_TOKEN }} --branch ${{ env.BRANCH_NAME }} + - name: Coveralls GitHub Action + uses: coverallsapp/github-action@1.1.3 if: ${{ github.event_name == 'push' }} + with: + github-token: ${{ secrets.COVERALLS_TOKEN }} + path-to-lcov: ./coveragereport/lcov.info diff --git a/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj b/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj index e7acc8c2..798d5fc9 100644 --- a/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj +++ b/benchmark/RulesEngineBenchmark/RulesEngineBenchmark.csproj @@ -6,7 +6,7 @@ - + diff --git a/demo/DemoApp.EFDataExample/DemoApp.EFDataExample.csproj b/demo/DemoApp.EFDataExample/DemoApp.EFDataExample.csproj index 19c8bda3..cd75c12b 100644 --- a/demo/DemoApp.EFDataExample/DemoApp.EFDataExample.csproj +++ b/demo/DemoApp.EFDataExample/DemoApp.EFDataExample.csproj @@ -1,4 +1,4 @@ - + net6.0 @@ -7,8 +7,8 @@ - - + + diff --git a/demo/DemoApp.EFDataExample/RulesEngineContext.cs b/demo/DemoApp.EFDataExample/RulesEngineContext.cs index 35bcd275..ff1b616d 100644 --- a/demo/DemoApp.EFDataExample/RulesEngineContext.cs +++ b/demo/DemoApp.EFDataExample/RulesEngineContext.cs @@ -52,7 +52,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) v => JsonSerializer.Deserialize(v, serializationOptions)); entity.Ignore(b => b.WorkflowsToInject); - entity.Ignore(b => b.WorkflowRulesToInject); }); } } diff --git a/global.json b/global.json index 50f074c4..fc4a588e 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,6 @@ { "sdk": { - "version": "6.0", + "version": "6.0.0", "rollForward": "latestFeature", "allowPrerelease": false } diff --git a/scripts/check-coverage.ps1 b/scripts/check-coverage.ps1 new file mode 100644 index 00000000..b4306ac2 --- /dev/null +++ b/scripts/check-coverage.ps1 @@ -0,0 +1,16 @@ +param( + [Parameter(Mandatory=$true)][string] $reportPath, + [Parameter(Mandatory=$true)][decimal] $threshold +) + + +[XML]$report = Get-Content $reportPath; +[decimal]$coverage = [decimal]$report.coverage.'line-rate' * 100; + +if ($coverage -lt $threshold) { + Write-Error "Coverage($coverage) is less than $threshold percent" + exit 1 +} +else{ + Write-Host "Coverage($coverage) is more than $threshold percent" +} diff --git a/scripts/generate-coverage-report.ps1 b/scripts/generate-coverage-report.ps1 new file mode 100644 index 00000000..8a14cad3 --- /dev/null +++ b/scripts/generate-coverage-report.ps1 @@ -0,0 +1,2 @@ +dotnet tool restore +dotnet reportgenerator "-reports:**/coverage.cobertura.xml" "-targetdir:coveragereport" -reporttypes:"Html;lcov;Cobertura" \ No newline at end of file diff --git a/src/RulesEngine/HelperFunctions/Helpers.cs b/src/RulesEngine/HelperFunctions/Helpers.cs index f96ff50a..481ecc2b 100644 --- a/src/RulesEngine/HelperFunctions/Helpers.cs +++ b/src/RulesEngine/HelperFunctions/Helpers.cs @@ -74,50 +74,5 @@ internal static string GetExceptionMessage(string message,ReSettings reSettings) { return reSettings.IgnoreException ? "" : message; } - - /// - /// To the result tree error messages - /// - /// ruleResultTree - /// ruleResultMessage - [Obsolete] - internal static void ToResultTreeMessages(RuleResultTree ruleResultTree, ref RuleResultMessage ruleResultMessage) - { - if (ruleResultTree.ChildResults != null) - { - GetChildRuleMessages(ruleResultTree.ChildResults, ref ruleResultMessage); - } - else - { - if (!ruleResultTree.IsSuccess) - { - string errMsg = ruleResultTree.Rule.ErrorMessage; - errMsg = string.IsNullOrEmpty(errMsg) ? $"Error message is not configured for {ruleResultTree.Rule.RuleName}" : errMsg; - - if (ruleResultTree.Rule.ErrorType == ErrorType.Error && !ruleResultMessage.ErrorMessages.Contains(errMsg)) - { - ruleResultMessage.ErrorMessages.Add(errMsg); - } - else if (ruleResultTree.Rule.ErrorType == ErrorType.Warning && !ruleResultMessage.WarningMessages.Contains(errMsg)) - { - ruleResultMessage.WarningMessages.Add(errMsg); - } - } - } - } - - /// - /// To get the child error message recursively - /// - /// childResultTree - /// ruleResultMessage - [Obsolete] - private static void GetChildRuleMessages(IEnumerable childResultTree, ref RuleResultMessage ruleResultMessage) - { - foreach (var item in childResultTree) - { - ToResultTreeMessages(item, ref ruleResultMessage); - } - } } } diff --git a/src/RulesEngine/Models/ReSettings.cs b/src/RulesEngine/Models/ReSettings.cs index 51aeedbd..7b6d942d 100644 --- a/src/RulesEngine/Models/ReSettings.cs +++ b/src/RulesEngine/Models/ReSettings.cs @@ -49,16 +49,6 @@ public class ReSettings /// Sets the mode for Nested rule execution, Default: All /// public NestedRuleExecutionMode NestedRuleExecutionMode { get; set; } = NestedRuleExecutionMode.All; - - /// - /// Enables Local params for rules - /// - [Obsolete("Use 'EnableScopedParams' instead. This will be removed in next major version")] - public bool EnableLocalParams { - get { return EnableScopedParams; } - set { EnableScopedParams = value; } - } - public MemCacheConfig CacheConfig { get; set; } } diff --git a/src/RulesEngine/Models/Rule.cs b/src/RulesEngine/Models/Rule.cs index cf080527..2ec76416 100644 --- a/src/RulesEngine/Models/Rule.cs +++ b/src/RulesEngine/Models/Rule.cs @@ -34,20 +34,9 @@ public class Rule /// public bool Enabled { get; set; } = true; - [Obsolete("will be removed in next major version")] - [JsonConverter(typeof(StringEnumConverter))] - public ErrorType ErrorType { get; set; } = ErrorType.Warning; - [JsonConverter(typeof(StringEnumConverter))] public RuleExpressionType RuleExpressionType { get; set; } = RuleExpressionType.LambdaExpression; - - [Obsolete("WorkflowRulesToInject is deprecated. Use WorkflowsToInject instead.")] - public IEnumerable WorkflowRulesToInject { - get { return WorkflowsToInject; } - set { WorkflowsToInject = value; } - } public IEnumerable WorkflowsToInject { get; set; } - public IEnumerable Rules { get; set; } public IEnumerable LocalParams { get; set; } public string Expression { get; set; } diff --git a/src/RulesEngine/Models/RuleResultTree.cs b/src/RulesEngine/Models/RuleResultTree.cs index ecaffedf..2089fdbd 100644 --- a/src/RulesEngine/Models/RuleResultTree.cs +++ b/src/RulesEngine/Models/RuleResultTree.cs @@ -50,29 +50,6 @@ public class RuleResultTree /// public string ExceptionMessage { get; set; } - /// - /// Gets or sets the rule evaluated parameters. - /// - /// - /// The rule evaluated parameters. - /// - [Obsolete("Use `Inputs` field to get details of all input, localParams and globalParams")] - public IEnumerable RuleEvaluatedParams { get; set; } - - /// - /// This method will return all the error and warning messages to caller - /// - /// RuleResultMessage - [ExcludeFromCodeCoverage] - [Obsolete("will be removed in next major version")] - public RuleResultMessage GetMessages() - { - var ruleResultMessage = new RuleResultMessage(); - - Helpers.ToResultTreeMessages(this, ref ruleResultMessage); - - return ruleResultMessage; - } } /// diff --git a/src/RulesEngine/RuleCompiler.cs b/src/RulesEngine/RuleCompiler.cs index 41e40e29..2c3f33a6 100644 --- a/src/RulesEngine/RuleCompiler.cs +++ b/src/RulesEngine/RuleCompiler.cs @@ -252,14 +252,6 @@ private RuleFunc GetWrappedRuleFunc(Rule rule, RuleFunc - netstandard2.0 - 4.0.0-preview.1 + net6.0;netstandard2.0 + 4.0.0 Copyright (c) Microsoft Corporation. LICENSE https://github.com/microsoft/RulesEngine @@ -31,8 +31,8 @@ - - + + diff --git a/test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs b/test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs index a4a6afb5..48203dca 100644 --- a/test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs +++ b/test/RulesEngine.UnitTest/BusinessRuleEngineTest.cs @@ -238,22 +238,6 @@ public async Task ExecuteRule_ExceptionScenario_RulesInvalid(string ruleFileName Assert.False(string.IsNullOrEmpty(result[0].ExceptionMessage) || string.IsNullOrWhiteSpace(result[0].ExceptionMessage)); } - [Theory] - [InlineData("rules2.json")] - [Obsolete] - public async Task ExecuteRule_ReturnsListOfRuleResultTree_ResultMessage(string ruleFileName) - { - var re = GetRulesEngine(ruleFileName); - - dynamic input1 = GetInput1(); - dynamic input2 = GetInput2(); - dynamic input3 = GetInput3(); - - List result = await re.ExecuteAllRulesAsync("inputWorkflow", input1, input2, input3); - Assert.NotNull(result); - Assert.NotNull(result.First().GetMessages()); - Assert.NotNull(result.First().GetMessages().WarningMessages); - } [Fact] public void RulesEngine_New_IncorrectJSON_ThrowsException() diff --git a/test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj b/test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj index 22afccbb..0640f590 100644 --- a/test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj +++ b/test/RulesEngine.UnitTest/RulesEngine.UnitTest.csproj @@ -1,4 +1,4 @@ - + net6.0 True @@ -7,10 +7,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/test/RulesEngine.UnitTest/ScopedParamsTest.cs b/test/RulesEngine.UnitTest/ScopedParamsTest.cs index f3900e75..5979f2b2 100644 --- a/test/RulesEngine.UnitTest/ScopedParamsTest.cs +++ b/test/RulesEngine.UnitTest/ScopedParamsTest.cs @@ -162,10 +162,6 @@ private static void CheckInputs(IEnumerable expectedInputs, RuleResultTr var localParamNames = resultTree.Rule.LocalParams?.Select(c => c.Name) ?? new List(); Assert.All(localParamNames, input => Assert.True(resultTree.Inputs.ContainsKey(input))); -#pragma warning disable CS0618 // Type or member is obsolete - Assert.All(localParamNames, lp => Assert.Contains(resultTree.RuleEvaluatedParams, c => c.Name == lp)); -#pragma warning restore CS0618 // Type or member is obsolete - if (resultTree.ChildResults?.Any() == true) { foreach (var childResultTree in resultTree.ChildResults) From d10941e345fb3a299ffae87f5b1ec47b7a0a0303 Mon Sep 17 00:00:00 2001 From: Abbas Cyclewala Date: Sun, 25 Sep 2022 12:08:33 +0000 Subject: [PATCH 2/5] fixed coverage threshold --- .github/workflows/dotnetcore-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnetcore-build.yml b/.github/workflows/dotnetcore-build.yml index 2a2ba239..58359d8f 100644 --- a/.github/workflows/dotnetcore-build.yml +++ b/.github/workflows/dotnetcore-build.yml @@ -31,7 +31,7 @@ jobs: - name: Check Coverage shell: pwsh - run: ./scripts/check-coverage.ps1 -reportPath coveragereport/Cobertura.xml -threshold 97 + run: ./scripts/check-coverage.ps1 -reportPath coveragereport/Cobertura.xml -threshold 96 - name: Coveralls GitHub Action uses: coverallsapp/github-action@1.1.3 From 22d36ad13da0a00e73ff884e69c2f2a48e0d29ea Mon Sep 17 00:00:00 2001 From: Abbas Cyclewala Date: Sun, 25 Sep 2022 12:30:25 +0000 Subject: [PATCH 3/5] updated changelog --- CHANGELOG.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 832163c1..76180ba6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,36 @@ All notable changes to this project will be documented in this file. +## [4.0.0] +- RulesEngine is now available in both dotnet 6 and netstandard 2.0 +- Dependency on ILogger, MemoryCache have been removed +- Obsolete Properties and Methods have been removed +### Breaking Changes +- ILogger has been removed from RulesEngine and all its constructors +```diff +- RulesEngine(string[] jsonConfig, ILogger logger = null, ReSettings reSettings = null) ++ RulesEngine(string[] jsonConfig, ReSettings reSettings = null) + +- RulesEngine(Workflow[] Workflows, ILogger logger = null, ReSettings reSettings = null) ++ RulesEngine(Workflow[] Workflows, ReSettings reSettings = null) + +- RulesEngine(ILogger logger = null, ReSettings reSettings = null) ++ RulesEngine(ReSettings reSettings = null) +``` +- Obsolete methods and properties have been removed, from the follow models:- + - RuleResultTree + - `ToResultTreeMessages()` has been removed from `RuleResultTree` model + - `GetMessages()` has been removed from `RuleResultTree` model + - `RuleEvaluatedParams` has been removed from `RuleResultTree` model, Please use `Inputs` instead + + - Workflow + - `WorkflowRulesToInject` has been removed, Please use `WorkflowsToInject` instead + - `ErrorType` has been removed from `Rule` + + - Resettings + - `EnableLocalParams` has been removed from `ReSettings`, Please use `EnableScopedParams` instead + + ## [3.5.0] - `EvaluateRule` action now support custom inputs and filtered inputs - Added `ContainsWorkflow` method in RulesEngine (by @okolobaxa) From b6ec1359a348f8c1400210c61974c40cd25eb86e Mon Sep 17 00:00:00 2001 From: Abbas Cyclewala Date: Sun, 25 Sep 2022 13:30:03 +0000 Subject: [PATCH 4/5] removed key hashing as it can lead to conflicts --- src/RulesEngine/Models/Rule.cs | 1 - src/RulesEngine/RulesEngine.cs | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/RulesEngine/Models/Rule.cs b/src/RulesEngine/Models/Rule.cs index 2ec76416..13bf225b 100644 --- a/src/RulesEngine/Models/Rule.cs +++ b/src/RulesEngine/Models/Rule.cs @@ -3,7 +3,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Converters; -using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; diff --git a/src/RulesEngine/RulesEngine.cs b/src/RulesEngine/RulesEngine.cs index 6a44b56d..1a7d62e2 100644 --- a/src/RulesEngine/RulesEngine.cs +++ b/src/RulesEngine/RulesEngine.cs @@ -345,8 +345,8 @@ private List ExecuteAllRuleByWorkflow(string workflowName, RuleP private string GetCompiledRulesKey(string workflowName, RuleParameter[] ruleParams) { - var ruleParamsHash = string.Join("-", ruleParams.Select(c => $"{c.Name}_{c.Type.Name}")).GetHashCode(); - var key = $"{workflowName}-" + ruleParamsHash; + var ruleParamsKey = string.Join("-", ruleParams.Select(c => $"{c.Name}_{c.Type.Name}")); + var key = $"{workflowName}-" + ruleParamsKey; return key; } From 4f9b0ffdbdb30fd34ee5e03b13abb02fee1c9e14 Mon Sep 17 00:00:00 2001 From: Abbas Cyclewala Date: Sun, 25 Sep 2022 13:49:55 +0000 Subject: [PATCH 5/5] updated container image --- .devcontainer/devcontainer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 85df4add..5feb34ac 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,7 +15,8 @@ "coenraads.bracket-pair-colorizer", "vscode-icons-team.vscode-icons", "editorconfig.editorconfig", - "aliasadidev.nugetpackagemanagergui" + "aliasadidev.nugetpackagemanagergui", + "formulahendry.dotnet-test-explorer" ], "postCreateCommand": "dotnet restore RulesEngine.sln && dotnet build RulesEngine.sln --configuration Release --no-restore && dotnet test RulesEngine.sln --configuration Release --no-build --verbosity minimal", "features": {