From 6a7786387c27619047504a4e57fd75f65c98540f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Sat, 28 Mar 2020 12:07:29 +0000 Subject: [PATCH 1/9] [FEAT] Added single rule validation logic. --- src/Rules.Framework/Builder/RuleBuilder.cs | 13 +++- .../ComposedConditionNodeValidator.cs | 63 +++++++++++++++++ .../Builder/Validation/RuleValidator.cs | 69 +++++++++++++++++++ .../Validation/ValidationExtensions.cs | 19 +++++ .../Validation/ValueConditionNodeValidator.cs | 25 +++++++ src/Rules.Framework/Rules.Framework.csproj | 1 + 6 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 src/Rules.Framework/Builder/Validation/ComposedConditionNodeValidator.cs create mode 100644 src/Rules.Framework/Builder/Validation/RuleValidator.cs create mode 100644 src/Rules.Framework/Builder/Validation/ValidationExtensions.cs create mode 100644 src/Rules.Framework/Builder/Validation/ValueConditionNodeValidator.cs diff --git a/src/Rules.Framework/Builder/RuleBuilder.cs b/src/Rules.Framework/Builder/RuleBuilder.cs index 031835f4..d4b30d71 100644 --- a/src/Rules.Framework/Builder/RuleBuilder.cs +++ b/src/Rules.Framework/Builder/RuleBuilder.cs @@ -1,6 +1,9 @@ namespace Rules.Framework.Builder { using System; + using System.Linq; + using FluentValidation.Results; + using Rules.Framework.Builder.Validation; using Rules.Framework.Core; internal class RuleBuilder : IRuleBuilder @@ -24,7 +27,15 @@ public RuleBuilderResult Build() RootCondition = this.rootCondition }; - return RuleBuilderResult.Success(rule); + RuleValidator ruleValidator = new RuleValidator(); + ValidationResult validationResult = ruleValidator.Validate(rule); + + if (validationResult.IsValid) + { + return RuleBuilderResult.Success(rule); + } + + return RuleBuilderResult.Failure(validationResult.Errors.Select(ve => ve.ErrorMessage).ToList()); } public IRuleBuilder WithCondition(IConditionNode condition) diff --git a/src/Rules.Framework/Builder/Validation/ComposedConditionNodeValidator.cs b/src/Rules.Framework/Builder/Validation/ComposedConditionNodeValidator.cs new file mode 100644 index 00000000..939d0cd1 --- /dev/null +++ b/src/Rules.Framework/Builder/Validation/ComposedConditionNodeValidator.cs @@ -0,0 +1,63 @@ +namespace Rules.Framework.Builder.Validation +{ + using FluentValidation; + using FluentValidation.Results; + using Rules.Framework.Core; + using Rules.Framework.Core.ConditionNodes; + + internal class ComposedConditionNodeValidator : AbstractValidator> + { + private readonly ValueConditionNodeValidator booleanConditionNodeValidator; + private readonly ValueConditionNodeValidator decimalConditionNodeValidator; + private readonly ValueConditionNodeValidator integerConditionNodeValidator; + private readonly ValueConditionNodeValidator stringConditionNodeValidator; + + public ComposedConditionNodeValidator() + { + this.integerConditionNodeValidator = new ValueConditionNodeValidator(); + this.decimalConditionNodeValidator = new ValueConditionNodeValidator(); + this.stringConditionNodeValidator = new ValueConditionNodeValidator(); + this.booleanConditionNodeValidator = new ValueConditionNodeValidator(); + + this.RuleFor(c => c.LogicalOperator).IsContainedOn(LogicalOperators.And, LogicalOperators.Or); + this.RuleForEach(c => c.ChildConditionNodes).Custom((cn, cc) => + { + ValidationResult validationResult = null; + + switch (cn) + { + case ComposedConditionNode composedConditionNode: + validationResult = this.Validate(composedConditionNode); + break; + + case IntegerConditionNode integerConditionNode: + validationResult = this.integerConditionNodeValidator.Validate(integerConditionNode); + break; + + case DecimalConditionNode decimalConditionNode: + validationResult = this.decimalConditionNodeValidator.Validate(decimalConditionNode); + break; + + case StringConditionNode stringConditionNode: + validationResult = this.stringConditionNodeValidator.Validate(stringConditionNode); + break; + + case BooleanConditionNode booleanConditionNode: + validationResult = this.booleanConditionNodeValidator.Validate(booleanConditionNode); + break; + + default: + return; + } + + if (!validationResult.IsValid) + { + foreach (ValidationFailure validationFailure in validationResult.Errors) + { + cc.AddFailure(validationFailure); + } + } + }); + } + } +} \ No newline at end of file diff --git a/src/Rules.Framework/Builder/Validation/RuleValidator.cs b/src/Rules.Framework/Builder/Validation/RuleValidator.cs new file mode 100644 index 00000000..a9e5900c --- /dev/null +++ b/src/Rules.Framework/Builder/Validation/RuleValidator.cs @@ -0,0 +1,69 @@ +namespace Rules.Framework.Builder.Validation +{ + using FluentValidation; + using FluentValidation.Results; + using Rules.Framework.Core; + using Rules.Framework.Core.ConditionNodes; + + internal class RuleValidator : AbstractValidator> + { + private readonly ValueConditionNodeValidator booleanConditionNodeValidator; + private readonly ComposedConditionNodeValidator composedConditionNodeValidator; + private readonly ValueConditionNodeValidator decimalConditionNodeValidator; + private readonly ValueConditionNodeValidator integerConditionNodeValidator; + private readonly ValueConditionNodeValidator stringConditionNodeValidator; + + public RuleValidator() + { + this.composedConditionNodeValidator = new ComposedConditionNodeValidator(); + this.integerConditionNodeValidator = new ValueConditionNodeValidator(); + this.decimalConditionNodeValidator = new ValueConditionNodeValidator(); + this.stringConditionNodeValidator = new ValueConditionNodeValidator(); + this.booleanConditionNodeValidator = new ValueConditionNodeValidator(); + + this.RuleFor(r => r.ContentContainer).NotNull(); + this.RuleFor(r => r.DateBegin).NotEmpty(); + this.RuleFor(r => r.DateEnd).GreaterThanOrEqualTo(r => r.DateBegin).When(r => r.DateEnd != null); + this.RuleFor(r => r.Name).NotNull().NotEmpty(); + this.RuleFor(r => r.Priority).GreaterThan(0); + this.RuleFor(r => r.RootCondition).Custom((cn, cc) => + { + ValidationResult validationResult = null; + + switch (cn) + { + case ComposedConditionNode composedConditionNode: + validationResult = this.composedConditionNodeValidator.Validate(composedConditionNode); + break; + + case IntegerConditionNode integerConditionNode: + validationResult = this.integerConditionNodeValidator.Validate(integerConditionNode); + break; + + case DecimalConditionNode decimalConditionNode: + validationResult = this.decimalConditionNodeValidator.Validate(decimalConditionNode); + break; + + case StringConditionNode stringConditionNode: + validationResult = this.stringConditionNodeValidator.Validate(stringConditionNode); + break; + + case BooleanConditionNode booleanConditionNode: + validationResult = this.booleanConditionNodeValidator.Validate(booleanConditionNode); + break; + + default: + return; + } + + if (!validationResult.IsValid) + { + foreach (ValidationFailure validationFailure in validationResult.Errors) + { + cc.AddFailure(validationFailure); + } + } + }); + } + } +} \ No newline at end of file diff --git a/src/Rules.Framework/Builder/Validation/ValidationExtensions.cs b/src/Rules.Framework/Builder/Validation/ValidationExtensions.cs new file mode 100644 index 00000000..997e481e --- /dev/null +++ b/src/Rules.Framework/Builder/Validation/ValidationExtensions.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Linq; +using FluentValidation; + +namespace Rules.Framework.Builder.Validation +{ + internal static class ValidationExtensions + { + public static IRuleBuilderOptions IsContainedOn(this IRuleBuilderInitial ruleBuilderInitial, IEnumerable values) + { + return ruleBuilderInitial.Must((p) => values.Contains(p)); + } + + public static IRuleBuilderOptions IsContainedOn(this IRuleBuilderInitial ruleBuilderInitial, params TProperty[] values) + { + return ruleBuilderInitial.IsContainedOn((IEnumerable)values); + } + } +} \ No newline at end of file diff --git a/src/Rules.Framework/Builder/Validation/ValueConditionNodeValidator.cs b/src/Rules.Framework/Builder/Validation/ValueConditionNodeValidator.cs new file mode 100644 index 00000000..de4fe855 --- /dev/null +++ b/src/Rules.Framework/Builder/Validation/ValueConditionNodeValidator.cs @@ -0,0 +1,25 @@ +namespace Rules.Framework.Builder.Validation +{ + using System; + using FluentValidation; + using Rules.Framework.Core; + using Rules.Framework.Core.ConditionNodes; + + internal class ValueConditionNodeValidator : AbstractValidator> + where T : IComparable + { + public ValueConditionNodeValidator() + { + this.RuleFor(c => c.ConditionType).NotEmpty(); + this.RuleFor(c => c.ConditionType).IsInEnum().When(c => c.ConditionType is { } && c.ConditionType.GetType().IsEnum); + this.RuleFor(c => c.DataType).IsInEnum(); + this.RuleFor(c => c.DataType).Equal(DataTypes.Integer).When(c => c.Operand is int); + this.RuleFor(c => c.DataType).Equal(DataTypes.String).When(c => c.Operand is string); + this.RuleFor(c => c.DataType).Equal(DataTypes.Decimal).When(c => c.Operand is decimal); + this.RuleFor(c => c.DataType).Equal(DataTypes.Boolean).When(c => c.Operand is bool); + this.RuleFor(c => c.Operator).IsInEnum(); + this.RuleFor(c => c.Operator).IsContainedOn(Operators.Equal, Operators.NotEqual).When(c => c.DataType == DataTypes.String); + this.RuleFor(c => c.Operator).IsContainedOn(Operators.Equal, Operators.NotEqual).When(c => c.DataType == DataTypes.Boolean); + } + } +} \ No newline at end of file diff --git a/src/Rules.Framework/Rules.Framework.csproj b/src/Rules.Framework/Rules.Framework.csproj index 18384102..bd9f398a 100644 --- a/src/Rules.Framework/Rules.Framework.csproj +++ b/src/Rules.Framework/Rules.Framework.csproj @@ -32,6 +32,7 @@ + all runtime; build; native; contentfiles; analyzers; buildtransitive From 7534423f06bd7d879c2f6138f171afc53b4c848e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Sat, 11 Apr 2020 02:18:44 +0100 Subject: [PATCH 2/9] [FEAT] Converted all tests to xunit. Added coverage tooling script. Improved coverage metrics for Sonar on pipeline. --- .gitignore | 3 + appveyor.yml | 8 +- run-tests.ps1 | 17 ++ .../AssemblyMetadata.cs | 5 + .../Rules.Framework.IntegrationTests.csproj | 19 ++- .../Tests/Scenario1/BodyMassIndexTests.cs | 5 +- .../Scenario2/CarInsuranceAdvisorTests.cs | 5 +- .../BuildingSecuritySystemControlTests.cs | 23 ++- .../AssemblyMetadata.cs | 5 + ....Providers.MongoDb.IntegrationTests.csproj | 17 +- .../AssemblyMetadata.cs | 4 +- ...s.Framework.Providers.MongoDb.Tests.csproj | 15 +- .../Rules.Framework.Tests/AssemblyMetadata.cs | 4 +- .../Builder/RuleBuilderResultTests.cs | 73 ++++++++ .../RuleEngineOptionsValidatorTests.cs | 161 ++---------------- .../Builder/SelectorsTests.cs | 13 +- tests/Rules.Framework.Tests/ConditionTests.cs | 16 +- .../BooleanConditionNodeTests.cs | 18 +- .../ComposedConditionNodeTests.cs | 10 +- .../DecimalConditionNodeTests.cs | 18 +- .../IntegerConditionNodeTests.cs | 18 +- .../StringConditionNodeTests.cs | 18 +- .../Core/ContentContainerTests.cs | 27 +-- tests/Rules.Framework.Tests/Core/RuleTests.cs | 46 ++--- .../Evaluation/ConditionsEvalEngineTests.cs | 45 +++-- .../Specification/AndSpecificationTests.cs | 22 +-- .../Specification/FuncSpecificationTests.cs | 28 +-- .../Specification/OrSpecificationTests.cs | 22 +-- .../ValueEvaluation/DeferredEvalTests.cs | 54 +++--- .../EqualOperatorEvalStrategyTests.cs | 16 +- .../GreaterThanOperatorEvalStrategyTests.cs | 22 +-- ...terThanOrEqualOperatorEvalStrategyTests.cs | 22 +-- .../LesserThanOperatorEvalStrategyTests.cs | 22 +-- ...serThanOrEqualOperatorEvalStrategyTests.cs | 22 +-- .../NotEqualOperatorEvalStrategyTests.cs | 16 +- .../OperatorEvalStrategyFactoryTests.cs | 36 ++-- .../Rules.Framework.Tests.csproj | 19 ++- .../Rules.Framework.Tests/RulesEngineTests.cs | 46 ++--- .../SerializedContentContainerTests.cs | 10 +- 39 files changed, 479 insertions(+), 471 deletions(-) create mode 100644 run-tests.ps1 create mode 100644 tests/Rules.Framework.IntegrationTests/AssemblyMetadata.cs create mode 100644 tests/Rules.Framework.Providers.MongoDb.IntegrationTests/AssemblyMetadata.cs create mode 100644 tests/Rules.Framework.Tests/Builder/RuleBuilderResultTests.cs diff --git a/.gitignore b/.gitignore index 923b924b..957dd6b4 100644 --- a/.gitignore +++ b/.gitignore @@ -554,3 +554,6 @@ typings/ # End of https://www.gitignore.io/api/csharp,aspnetcore,visualstudio + +# Specific ones added +coverage-outputs/** \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index db9111d1..f467c7d7 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,10 +20,10 @@ build_script: - sh: dotnet pack src/Rules.Framework/Rules.Framework.csproj --no-build --include-symbols - sh: dotnet pack src/Rules.Framework.Providers.MongoDb/Rules.Framework.Providers.MongoDb.csproj --no-build --include-symbols test_script: - - sh: dotnet test tests/Rules.Framework.Tests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:CoverletOutput=../../rules-framework-tests-coverage - - sh: dotnet test tests/Rules.Framework.Providers.MongoDb.Tests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:CoverletOutput=../../rules-framework-providers-mongodb-tests-coverage - - sh: dotnet test tests/Rules.Framework.IntegrationTests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:CoverletOutput=../../rules-framework-integration-tests-coverage - - sh: dotnet test tests/Rules.Framework.Providers.MongoDb.IntegrationTests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:CoverletOutput=../../rules-framework-providers-mongodb-integration-tests-coverage + - sh: dotnet test tests/Rules.Framework.Tests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json" /p:CoverletOutput=../../coverage-outputs + - sh: dotnet test tests/Rules.Framework.Providers.MongoDb.Tests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json + - sh: dotnet test tests/Rules.Framework.IntegrationTests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json + - sh: dotnet test tests/Rules.Framework.Providers.MongoDb.IntegrationTests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json after_test: - sh: dotnet sonarscanner end /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 artifacts: diff --git a/run-tests.ps1 b/run-tests.ps1 new file mode 100644 index 00000000..c5e440a8 --- /dev/null +++ b/run-tests.ps1 @@ -0,0 +1,17 @@ +$globalTools = dotnet tool list -g +$reportGeneratorTool = $globalTools | Select-String -Pattern "dotnet-reportgenerator-globaltool" + +If (!$reportGeneratorTool) { + dotnet tool install --global dotnet-reportgenerator-globaltool +} + +$reportTimestamp = [DateTime]::UtcNow.ToString("yyyyMMdd_hhmmss") +$currentDir = (Get-Location).Path +$coverageDir = "$currentDir\\coverage-outputs\\$reportTimestamp\\" + +dotnet test .\rules-framework.sln /p:CollectCoverage=true /p:CoverletOutputFormat="opencover%2cjson" /p:CoverletOutput=$coverageDir /p:MergeWith="$coverageDir/coverage.json" -m:1 + +$coverageFile = "$($coverageDir)coverage.opencover.xml" +$coverageReportFolder = "$($currentDir)\\coverage-outputs\\report\\" +reportgenerator -reports:$coverageFile -targetdir:$coverageReportFolder +# start "$($coverageReportFolder)index.htm" \ No newline at end of file diff --git a/tests/Rules.Framework.IntegrationTests/AssemblyMetadata.cs b/tests/Rules.Framework.IntegrationTests/AssemblyMetadata.cs new file mode 100644 index 00000000..c16917bc --- /dev/null +++ b/tests/Rules.Framework.IntegrationTests/AssemblyMetadata.cs @@ -0,0 +1,5 @@ +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] +[assembly: ExcludeFromCodeCoverage] \ No newline at end of file diff --git a/tests/Rules.Framework.IntegrationTests/Rules.Framework.IntegrationTests.csproj b/tests/Rules.Framework.IntegrationTests/Rules.Framework.IntegrationTests.csproj index 5da81365..e643071c 100644 --- a/tests/Rules.Framework.IntegrationTests/Rules.Framework.IntegrationTests.csproj +++ b/tests/Rules.Framework.IntegrationTests/Rules.Framework.IntegrationTests.csproj @@ -1,24 +1,31 @@ - netcoreapp2.1 + netcoreapp3.1 8.0 false - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/Rules.Framework.IntegrationTests/Tests/Scenario1/BodyMassIndexTests.cs b/tests/Rules.Framework.IntegrationTests/Tests/Scenario1/BodyMassIndexTests.cs index 0bf786c6..24baec1b 100644 --- a/tests/Rules.Framework.IntegrationTests/Tests/Scenario1/BodyMassIndexTests.cs +++ b/tests/Rules.Framework.IntegrationTests/Tests/Scenario1/BodyMassIndexTests.cs @@ -3,13 +3,12 @@ namespace Rules.Framework.IntegrationTests.Tests.Scenario1 using System; using System.Threading.Tasks; using FluentAssertions; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Rules.Framework.Core; + using Xunit; - [TestClass] public class BodyMassIndexTests { - [TestMethod] + [Fact] public async Task BodyMassIndex_NoConditions_ReturnsDefaultFormula() { // Arrange diff --git a/tests/Rules.Framework.IntegrationTests/Tests/Scenario2/CarInsuranceAdvisorTests.cs b/tests/Rules.Framework.IntegrationTests/Tests/Scenario2/CarInsuranceAdvisorTests.cs index 66381a75..5079eceb 100644 --- a/tests/Rules.Framework.IntegrationTests/Tests/Scenario2/CarInsuranceAdvisorTests.cs +++ b/tests/Rules.Framework.IntegrationTests/Tests/Scenario2/CarInsuranceAdvisorTests.cs @@ -3,13 +3,12 @@ namespace Rules.Framework.IntegrationTests.Tests.Scenario2 using System; using System.Threading.Tasks; using FluentAssertions; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Rules.Framework.Core; + using Xunit; - [TestClass] public class CarInsuranceAdvisorTests { - [TestMethod] + [Fact] public async Task BodyMassIndex_NoConditions_ReturnsDefaultFormula() { // Arrange diff --git a/tests/Rules.Framework.IntegrationTests/Tests/Scenario3/BuildingSecuritySystemControlTests.cs b/tests/Rules.Framework.IntegrationTests/Tests/Scenario3/BuildingSecuritySystemControlTests.cs index ca94e536..5939f466 100644 --- a/tests/Rules.Framework.IntegrationTests/Tests/Scenario3/BuildingSecuritySystemControlTests.cs +++ b/tests/Rules.Framework.IntegrationTests/Tests/Scenario3/BuildingSecuritySystemControlTests.cs @@ -5,13 +5,12 @@ namespace Rules.Framework.IntegrationTests.Tests.Scenario3 using System.Linq; using System.Threading.Tasks; using FluentAssertions; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Rules.Framework.Core; + using Xunit; - [TestClass] public class BuildingSecuritySystemControlTests { - [TestMethod] + [Fact] public async Task BuildingSecuritySystem_FireScenario_ReturnsActionsToTrigger() { // Assert @@ -60,8 +59,8 @@ public async Task BuildingSecuritySystem_FireScenario_ReturnsActionsToTrigger() .And.HaveCount(3); } - [TestMethod] - public async Task BuildingSecuritySystem_PowerShutdownScenario_ReturnsActionsToTrigger() + [Fact] + public async Task BuildingSecuritySystem_PowerFailureScenario_ReturnsActionsToTrigger() { // Assert const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.PowerSystem; @@ -82,7 +81,7 @@ public async Task BuildingSecuritySystem_PowerShutdownScenario_ReturnsActionsToT new Condition { Type = SecuritySystemConditions.PowerStatus, - Value = "Shutdown" + Value = "Offline" } }; @@ -104,11 +103,12 @@ public async Task BuildingSecuritySystem_PowerShutdownScenario_ReturnsActionsToT IEnumerable securitySystemActions = actual.Select(r => r.ContentContainer.GetContentAs()).ToList(); securitySystemActions.Should().Contain(ssa => ssa.ActionName == "EnableEmergencyLights") - .And.HaveCount(1); + .And.Contain(ssa => ssa.ActionName == "EnableEmergencyPower") + .And.Contain(ssa => ssa.ActionName == "CallPowerGridPicket"); } - [TestMethod] - public async Task BuildingSecuritySystem_PowerFailureScenario_ReturnsActionsToTrigger() + [Fact] + public async Task BuildingSecuritySystem_PowerShutdownScenario_ReturnsActionsToTrigger() { // Assert const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.PowerSystem; @@ -129,7 +129,7 @@ public async Task BuildingSecuritySystem_PowerFailureScenario_ReturnsActionsToTr new Condition { Type = SecuritySystemConditions.PowerStatus, - Value = "Offline" + Value = "Shutdown" } }; @@ -151,8 +151,7 @@ public async Task BuildingSecuritySystem_PowerFailureScenario_ReturnsActionsToTr IEnumerable securitySystemActions = actual.Select(r => r.ContentContainer.GetContentAs()).ToList(); securitySystemActions.Should().Contain(ssa => ssa.ActionName == "EnableEmergencyLights") - .And.Contain(ssa => ssa.ActionName == "EnableEmergencyPower") - .And.Contain(ssa => ssa.ActionName == "CallPowerGridPicket"); + .And.HaveCount(1); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/AssemblyMetadata.cs b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/AssemblyMetadata.cs new file mode 100644 index 00000000..c16917bc --- /dev/null +++ b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/AssemblyMetadata.cs @@ -0,0 +1,5 @@ +using System.Diagnostics.CodeAnalysis; +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] +[assembly: ExcludeFromCodeCoverage] \ No newline at end of file diff --git a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Rules.Framework.Providers.MongoDb.IntegrationTests.csproj b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Rules.Framework.Providers.MongoDb.IntegrationTests.csproj index c6756a41..1a70f2ed 100644 --- a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Rules.Framework.Providers.MongoDb.IntegrationTests.csproj +++ b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Rules.Framework.Providers.MongoDb.IntegrationTests.csproj @@ -12,16 +12,23 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/Rules.Framework.Providers.MongoDb.Tests/AssemblyMetadata.cs b/tests/Rules.Framework.Providers.MongoDb.Tests/AssemblyMetadata.cs index 62ff2128..c16917bc 100644 --- a/tests/Rules.Framework.Providers.MongoDb.Tests/AssemblyMetadata.cs +++ b/tests/Rules.Framework.Providers.MongoDb.Tests/AssemblyMetadata.cs @@ -1,3 +1,5 @@ +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] +[assembly: ExcludeFromCodeCoverage] \ No newline at end of file diff --git a/tests/Rules.Framework.Providers.MongoDb.Tests/Rules.Framework.Providers.MongoDb.Tests.csproj b/tests/Rules.Framework.Providers.MongoDb.Tests/Rules.Framework.Providers.MongoDb.Tests.csproj index be7582dd..1fba0996 100644 --- a/tests/Rules.Framework.Providers.MongoDb.Tests/Rules.Framework.Providers.MongoDb.Tests.csproj +++ b/tests/Rules.Framework.Providers.MongoDb.Tests/Rules.Framework.Providers.MongoDb.Tests.csproj @@ -9,16 +9,23 @@ - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/Rules.Framework.Tests/AssemblyMetadata.cs b/tests/Rules.Framework.Tests/AssemblyMetadata.cs index 62ff2128..c16917bc 100644 --- a/tests/Rules.Framework.Tests/AssemblyMetadata.cs +++ b/tests/Rules.Framework.Tests/AssemblyMetadata.cs @@ -1,3 +1,5 @@ +using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] \ No newline at end of file +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] +[assembly: ExcludeFromCodeCoverage] \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Builder/RuleBuilderResultTests.cs b/tests/Rules.Framework.Tests/Builder/RuleBuilderResultTests.cs new file mode 100644 index 00000000..b15a1910 --- /dev/null +++ b/tests/Rules.Framework.Tests/Builder/RuleBuilderResultTests.cs @@ -0,0 +1,73 @@ +namespace Rules.Framework.Tests.Builder +{ + using System; + using System.Collections.Generic; + using FluentAssertions; + using Rules.Framework.Builder; + using Rules.Framework.Core; + using Rules.Framework.Tests.TestStubs; + using Xunit; + + public class RuleBuilderResultTests + { + [Fact] + public void Failure_GivenAllValidParameters_ReturnsRuleBuilderResultWithFailure() + { + // Arrange + IEnumerable expectedErrors = new[] { "Error1", "Error2" }; + + // Act + RuleBuilderResult ruleBuilderResult = RuleBuilderResult.Failure(expectedErrors); + + // Assert + ruleBuilderResult.Should().NotBeNull(); + ruleBuilderResult.IsSuccess.Should().BeFalse(); + ruleBuilderResult.Errors.Should().NotBeNull().And.BeEquivalentTo(expectedErrors); + ruleBuilderResult.Rule.Should().BeNull(); + } + + [Fact] + public void Failure_GivenNullErrorsCollection_ThrowsArgumentNullException() + { + // Arrange + IEnumerable expectedErrors = null; + + // Act + ArgumentNullException argumentNullException = Assert.Throws(() => RuleBuilderResult.Failure(expectedErrors)); + + // Arrange + argumentNullException.Should().NotBeNull(); + argumentNullException.ParamName.Should().Be("errors"); + } + + [Fact] + public void Success_GivenAllValidParameters_ReturnsRuleBuilderResultWithSuccessAndNewRule() + { + // Arrange + Rule rule = new Rule(); + + // Act + RuleBuilderResult ruleBuilderResult = RuleBuilderResult.Success(rule); + + // Assert + ruleBuilderResult.Should().NotBeNull(); + ruleBuilderResult.IsSuccess.Should().BeTrue(); + ruleBuilderResult.Errors.Should().NotBeNull().And.BeEmpty(); + ruleBuilderResult.Rule.Should().NotBeNull().And.Be(rule); + } + + [Fact] + public void Success_GivenNullErrorsCollection_ThrowsArgumentNullException() + { + // Arrange + Rule rule = null; + + // Act + ArgumentNullException argumentNullException = Assert.Throws(() => RuleBuilderResult.Success(rule)); + + // Arrange + argumentNullException.Should().NotBeNull(); + argumentNullException.ParamName.Should().Be("rule"); + } + } +} \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Builder/RuleEngineOptionsValidatorTests.cs b/tests/Rules.Framework.Tests/Builder/RuleEngineOptionsValidatorTests.cs index 92655e4f..d5b8b64d 100644 --- a/tests/Rules.Framework.Tests/Builder/RuleEngineOptionsValidatorTests.cs +++ b/tests/Rules.Framework.Tests/Builder/RuleEngineOptionsValidatorTests.cs @@ -1,22 +1,21 @@ namespace Rules.Framework.Tests.Builder { using FluentAssertions; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Rules.Framework.Builder; using Rules.Framework.Core; + using Xunit; - [TestClass] public class RuleEngineOptionsValidatorTests { - [TestMethod] - public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsNullReference_ThrowsInvalidRulesEngineOptionsExceptionClaimingNullOptions() + [Fact] + public void EnsureValid_GivenOptionsNullReference_ThrowsInvalidRulesEngineOptionsExceptionClaimingNullOptions() { // Arrange RulesEngineOptions rulesEngineOptions = null; RulesEngineOptionsValidator sut = new RulesEngineOptionsValidator(); - InvalidRulesEngineOptionsException actual = Assert.ThrowsException(() => + InvalidRulesEngineOptionsException actual = Assert.Throws(() => { // Act sut.EnsureValid(rulesEngineOptions); @@ -25,154 +24,30 @@ public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsNullReference_Thr actual.Message.Should().Be("Specified null rulesEngineOptions."); } - - [TestMethod] - public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsWithInvalidDefaultForBooleanDataType_ThrowsInvalidRulesEngineOptionsExceptionClaimingInvalidDefault() - { - // Arrange - RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); - rulesEngineOptions.DataTypeDefaults[DataTypes.Boolean] = "abc"; - - RulesEngineOptionsValidator sut = new RulesEngineOptionsValidator(); - - InvalidRulesEngineOptionsException actual = Assert.ThrowsException(() => - { - // Act - sut.EnsureValid(rulesEngineOptions); - }); - - actual.Message.Should().Be("Specified invalid default value for data type Boolean: abc."); - } - - - [TestMethod] - public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsWithNullDefaultForBooleanDataType_ThrowsInvalidRulesEngineOptionsExceptionClaimingInvalidDefault() - { - // Arrange - RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); - rulesEngineOptions.DataTypeDefaults[DataTypes.Boolean] = null; - - RulesEngineOptionsValidator sut = new RulesEngineOptionsValidator(); - - InvalidRulesEngineOptionsException actual = Assert.ThrowsException(() => - { - // Act - sut.EnsureValid(rulesEngineOptions); - }); - - actual.Message.Should().Be("Specified invalid default value for data type Boolean: null."); - } - - - [TestMethod] - public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsWithInvalidDefaultForDecimalDataType_ThrowsInvalidRulesEngineOptionsExceptionClaimingInvalidDefault() - { - // Arrange - RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); - rulesEngineOptions.DataTypeDefaults[DataTypes.Decimal] = "abc"; - - RulesEngineOptionsValidator sut = new RulesEngineOptionsValidator(); - - InvalidRulesEngineOptionsException actual = Assert.ThrowsException(() => - { - // Act - sut.EnsureValid(rulesEngineOptions); - }); - - actual.Message.Should().Be("Specified invalid default value for data type Decimal: abc."); - } - - - [TestMethod] - public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsWithNullDefaultForDecimalDataType_ThrowsInvalidRulesEngineOptionsExceptionClaimingInvalidDefault() - { - // Arrange - RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); - rulesEngineOptions.DataTypeDefaults[DataTypes.Decimal] = null; - - RulesEngineOptionsValidator sut = new RulesEngineOptionsValidator(); - - InvalidRulesEngineOptionsException actual = Assert.ThrowsException(() => - { - // Act - sut.EnsureValid(rulesEngineOptions); - }); - - actual.Message.Should().Be("Specified invalid default value for data type Decimal: null."); - } - - - [TestMethod] - public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsWithInvalidDefaultForIntegerDataType_ThrowsInvalidRulesEngineOptionsExceptionClaimingInvalidDefault() - { - // Arrange - RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); - rulesEngineOptions.DataTypeDefaults[DataTypes.Integer] = "abc"; - - RulesEngineOptionsValidator sut = new RulesEngineOptionsValidator(); - - InvalidRulesEngineOptionsException actual = Assert.ThrowsException(() => - { - // Act - sut.EnsureValid(rulesEngineOptions); - }); - - actual.Message.Should().Be("Specified invalid default value for data type Integer: abc."); - } - - - [TestMethod] - public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsWithNullDefaultForIntegerDataType_ThrowsInvalidRulesEngineOptionsExceptionClaimingInvalidDefault() - { - // Arrange - RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); - rulesEngineOptions.DataTypeDefaults[DataTypes.Integer] = null; - - RulesEngineOptionsValidator sut = new RulesEngineOptionsValidator(); - - InvalidRulesEngineOptionsException actual = Assert.ThrowsException(() => - { - // Act - sut.EnsureValid(rulesEngineOptions); - }); - - actual.Message.Should().Be("Specified invalid default value for data type Integer: null."); - } - - [TestMethod] - public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsWithInvalidDefaultForStringDataType_ThrowsInvalidRulesEngineOptionsExceptionClaimingInvalidDefault() - { - // Arrange - RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); - rulesEngineOptions.DataTypeDefaults[DataTypes.String] = 0; - - RulesEngineOptionsValidator sut = new RulesEngineOptionsValidator(); - - InvalidRulesEngineOptionsException actual = Assert.ThrowsException(() => - { - // Act - sut.EnsureValid(rulesEngineOptions); - }); - - actual.Message.Should().Be("Specified invalid default value for data type String: 0."); - } - - [TestMethod] - public void RuleEngineOptionsValidator_EnsureValid_GivenOptionsWithNullDefaultForStringDataType_ThrowsInvalidRulesEngineOptionsExceptionClaimingInvalidDefault() + [Theory] + [InlineData(DataTypes.Boolean, "abc")] + [InlineData(DataTypes.Boolean, null)] + [InlineData(DataTypes.Decimal, "abc")] + [InlineData(DataTypes.Decimal, null)] + [InlineData(DataTypes.Integer, "abc")] + [InlineData(DataTypes.Integer, null)] + [InlineData(DataTypes.String, 0)] + [InlineData(DataTypes.String, null)] + public void EnsureValid_GivenOptionsWithInvalidDefaultForDataType_ThrowsInvalidRulesEngineOptionsExceptionClaimingInvalidDefault(DataTypes dataType, object defaultValue) { // Arrange RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); - rulesEngineOptions.DataTypeDefaults[DataTypes.String] = null; + rulesEngineOptions.DataTypeDefaults[dataType] = defaultValue; RulesEngineOptionsValidator sut = new RulesEngineOptionsValidator(); - InvalidRulesEngineOptionsException actual = Assert.ThrowsException(() => + InvalidRulesEngineOptionsException actual = Assert.Throws(() => { // Act sut.EnsureValid(rulesEngineOptions); }); - actual.Message.Should().Be("Specified invalid default value for data type String: null."); + actual.Message.Should().Be($"Specified invalid default value for data type {dataType}: {defaultValue ?? "null"}."); } } -} +} \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Builder/SelectorsTests.cs b/tests/Rules.Framework.Tests/Builder/SelectorsTests.cs index c7833c4d..f795b95b 100644 --- a/tests/Rules.Framework.Tests/Builder/SelectorsTests.cs +++ b/tests/Rules.Framework.Tests/Builder/SelectorsTests.cs @@ -2,16 +2,15 @@ namespace Rules.Framework.Tests.Builder { using System; using FluentAssertions; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Rules.Framework.Builder; using Rules.Framework.Tests.TestStubs; + using Xunit; using static Rules.Framework.Builder.RulesEngineSelectors; - [TestClass] public class SelectorsTests { - [TestMethod] + [Fact] public void ConditionTypeSelector_WithConditionType_GivenTypeOfCondition_ReturnsNewRulesDataSourceSelector() { // Arrange @@ -24,7 +23,7 @@ public void ConditionTypeSelector_WithConditionType_GivenTypeOfCondition_Returns actual.Should().BeOfType>(); } - [TestMethod] + [Fact] public void ContentTypeSelector_WithContentType_GivenTypeOfContent_ReturnsNewConditionTypeSelector() { // Arrange @@ -37,21 +36,21 @@ public void ContentTypeSelector_WithContentType_GivenTypeOfContent_ReturnsNewCon actual.Should().BeOfType>(); } - [TestMethod] + [Fact] public void RulesDataSourceSelector_SetDataSource_GivenNullRulesDataSource_ThrowsArgumentNullException() { // Arrange RulesDataSourceSelector sut = new RulesDataSourceSelector(); // Assert - Assert.ThrowsException(() => + Assert.Throws(() => { // Act sut.SetDataSource(null); }); } - [TestMethod] + [Fact] public void RulesDataSourceSelector_SetDataSource_GivenRulesDataSourceInstance_ReturnsRulesEngine() { // Arrange diff --git a/tests/Rules.Framework.Tests/ConditionTests.cs b/tests/Rules.Framework.Tests/ConditionTests.cs index 314747f0..ee37894c 100644 --- a/tests/Rules.Framework.Tests/ConditionTests.cs +++ b/tests/Rules.Framework.Tests/ConditionTests.cs @@ -1,13 +1,13 @@ namespace Rules.Framework.Tests { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class ConditionTests { - [TestMethod] - public void Condition_Type_HavingSettedType_ReturnsSettedValue() + [Fact] + public void Type_HavingSettedType_ReturnsSettedValue() { // Arrange ConditionType expected = ConditionType.IsoCountryCode; @@ -21,11 +21,11 @@ public void Condition_Type_HavingSettedType_ReturnsSettedValue() ConditionType actual = sut.Type; // Assert - Assert.AreEqual(expected, actual); + actual.Should().Be(expected); } - [TestMethod] - public void Condition_Value_HavingSettedValue_ReturnsSettedValue() + [Fact] + public void Value_HavingSettedValue_ReturnsSettedValue() { // Arrange object expected = "abc"; @@ -39,7 +39,7 @@ public void Condition_Value_HavingSettedValue_ReturnsSettedValue() object actual = sut.Value; // Assert - Assert.AreSame(expected, actual); + actual.Should().Be(expected); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Core/ConditionNodes/BooleanConditionNodeTests.cs b/tests/Rules.Framework.Tests/Core/ConditionNodes/BooleanConditionNodeTests.cs index 5abc4459..4226e8df 100644 --- a/tests/Rules.Framework.Tests/Core/ConditionNodes/BooleanConditionNodeTests.cs +++ b/tests/Rules.Framework.Tests/Core/ConditionNodes/BooleanConditionNodeTests.cs @@ -1,15 +1,15 @@ namespace Rules.Framework.Tests.Core.ConditionNodes { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Core; using Rules.Framework.Core.ConditionNodes; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class BooleanConditionNodeTests { - [TestMethod] - public void BooleanConditionNode_Init_GivenSetupWithBooleanValue_ReturnsSettedValues() + [Fact] + public void Init_GivenSetupWithBooleanValue_ReturnsSettedValues() { // Arrange ConditionType expectedConditionType = ConditionType.IsoCountryCode; @@ -28,11 +28,11 @@ public void BooleanConditionNode_Init_GivenSetupWithBooleanValue_ReturnsSettedVa bool actualOperand = sut.Operand; // Assert - Assert.AreEqual(expectedConditionType, actualConditionType); - Assert.AreEqual(expectedOperator, actualOperator); - Assert.AreEqual(expectedOperand, actualOperand); - Assert.AreEqual(expectedLogicalOperator, actualLogicalOperator); - Assert.AreEqual(expectedDataType, actualDataType); + actualConditionType.Should().Be(expectedConditionType); + actualOperator.Should().Be(expectedOperator); + actualOperand.Should().Be(expectedOperand); + actualLogicalOperator.Should().Be(expectedLogicalOperator); + actualDataType.Should().Be(expectedDataType); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Core/ConditionNodes/ComposedConditionNodeTests.cs b/tests/Rules.Framework.Tests/Core/ConditionNodes/ComposedConditionNodeTests.cs index e1b15294..0a8a0a14 100644 --- a/tests/Rules.Framework.Tests/Core/ConditionNodes/ComposedConditionNodeTests.cs +++ b/tests/Rules.Framework.Tests/Core/ConditionNodes/ComposedConditionNodeTests.cs @@ -1,16 +1,16 @@ namespace Rules.Framework.Tests.Core.ConditionNodes { using System.Collections.Generic; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Moq; using Rules.Framework.Core; using Rules.Framework.Core.ConditionNodes; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class ComposedConditionNodeTests { - [TestMethod] + [Fact] public void ComposedConditionNode_Init_GivenSetupWithChildConditionsAndLogicalOperator_ReturnsSettedValues() { // Arrange @@ -28,8 +28,8 @@ public void ComposedConditionNode_Init_GivenSetupWithChildConditionsAndLogicalOp IEnumerable> actualChildConditionNodes = sut.ChildConditionNodes; // Assert - Assert.AreEqual(expectedLogicalOperator, actualLogicalOperator); - Assert.AreSame(expectedChildConditionNodes, actualChildConditionNodes); + actualLogicalOperator.Should().Be(expectedLogicalOperator); + actualChildConditionNodes.Should().NotBeNull().And.BeSameAs(expectedChildConditionNodes); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Core/ConditionNodes/DecimalConditionNodeTests.cs b/tests/Rules.Framework.Tests/Core/ConditionNodes/DecimalConditionNodeTests.cs index 85bf6f89..9711560f 100644 --- a/tests/Rules.Framework.Tests/Core/ConditionNodes/DecimalConditionNodeTests.cs +++ b/tests/Rules.Framework.Tests/Core/ConditionNodes/DecimalConditionNodeTests.cs @@ -1,15 +1,15 @@ namespace Rules.Framework.Tests.Core.ConditionNodes { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Core; using Rules.Framework.Core.ConditionNodes; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class DecimalConditionNodeTests { - [TestMethod] - public void DecimalConditionNode_Init_GivenSetupWithDecimalValue_ReturnsSettedValues() + [Fact] + public void Init_GivenSetupWithDecimalValue_ReturnsSettedValues() { // Arrange ConditionType expectedConditionType = ConditionType.PluviosityRate; @@ -28,11 +28,11 @@ public void DecimalConditionNode_Init_GivenSetupWithDecimalValue_ReturnsSettedVa decimal actualOperand = sut.Operand; // Assert - Assert.AreEqual(expectedConditionType, actualConditionType); - Assert.AreEqual(expectedOperator, actualOperator); - Assert.AreEqual(expectedOperand, actualOperand); - Assert.AreEqual(expectedLogicalOperator, actualLogicalOperator); - Assert.AreEqual(expectedDataType, actualDataType); + actualConditionType.Should().Be(expectedConditionType); + actualOperator.Should().Be(expectedOperator); + actualOperand.Should().Be(expectedOperand); + actualLogicalOperator.Should().Be(expectedLogicalOperator); + actualDataType.Should().Be(expectedDataType); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Core/ConditionNodes/IntegerConditionNodeTests.cs b/tests/Rules.Framework.Tests/Core/ConditionNodes/IntegerConditionNodeTests.cs index 66038bf0..e9006b37 100644 --- a/tests/Rules.Framework.Tests/Core/ConditionNodes/IntegerConditionNodeTests.cs +++ b/tests/Rules.Framework.Tests/Core/ConditionNodes/IntegerConditionNodeTests.cs @@ -1,15 +1,15 @@ namespace Rules.Framework.Tests.Core.ConditionNodes { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Core; using Rules.Framework.Core.ConditionNodes; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class IntegerConditionNodeTests { - [TestMethod] - public void IntegerConditionNode_Init_GivenSetupWithIntegerValue_ReturnsSettedValues() + [Fact] + public void Init_GivenSetupWithIntegerValue_ReturnsSettedValues() { // Arrange ConditionType expectedConditionType = ConditionType.IsoCountryCode; @@ -28,11 +28,11 @@ public void IntegerConditionNode_Init_GivenSetupWithIntegerValue_ReturnsSettedVa int actualOperand = sut.Operand; // Assert - Assert.AreEqual(expectedConditionType, actualConditionType); - Assert.AreEqual(expectedOperator, actualOperator); - Assert.AreEqual(expectedOperand, actualOperand); - Assert.AreEqual(expectedLogicalOperator, actualLogicalOperator); - Assert.AreEqual(expectedDataType, actualDataType); + actualConditionType.Should().Be(expectedConditionType); + actualOperator.Should().Be(expectedOperator); + actualOperand.Should().Be(expectedOperand); + actualLogicalOperator.Should().Be(expectedLogicalOperator); + actualDataType.Should().Be(expectedDataType); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Core/ConditionNodes/StringConditionNodeTests.cs b/tests/Rules.Framework.Tests/Core/ConditionNodes/StringConditionNodeTests.cs index 25749059..9546631a 100644 --- a/tests/Rules.Framework.Tests/Core/ConditionNodes/StringConditionNodeTests.cs +++ b/tests/Rules.Framework.Tests/Core/ConditionNodes/StringConditionNodeTests.cs @@ -1,15 +1,15 @@ namespace Rules.Framework.Tests.Core.ConditionNodes { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Core; using Rules.Framework.Core.ConditionNodes; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class StringConditionNodeTests { - [TestMethod] - public void StringConditionNode_Init_GivenSetupWithStringValue_ReturnsSettedValues() + [Fact] + public void Init_GivenSetupWithStringValue_ReturnsSettedValues() { // Arrange ConditionType expectedConditionType = ConditionType.IsoCountryCode; @@ -28,11 +28,11 @@ public void StringConditionNode_Init_GivenSetupWithStringValue_ReturnsSettedValu string actualOperand = sut.Operand; // Assert - Assert.AreEqual(expectedConditionType, actualConditionType); - Assert.AreEqual(expectedOperator, actualOperator); - Assert.AreEqual(expectedOperand, actualOperand); - Assert.AreEqual(expectedLogicalOperator, actualLogicalOperator); - Assert.AreEqual(expectedDataType, actualDataType); + actualConditionType.Should().Be(expectedConditionType); + actualOperator.Should().Be(expectedOperator); + actualOperand.Should().Be(expectedOperand); + actualLogicalOperator.Should().Be(expectedLogicalOperator); + actualDataType.Should().Be(expectedDataType); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Core/ContentContainerTests.cs b/tests/Rules.Framework.Tests/Core/ContentContainerTests.cs index 79edd73b..9a98bc72 100644 --- a/tests/Rules.Framework.Tests/Core/ContentContainerTests.cs +++ b/tests/Rules.Framework.Tests/Core/ContentContainerTests.cs @@ -1,13 +1,14 @@ namespace Rules.Framework.Tests.Core { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using System; + using FluentAssertions; using Rules.Framework.Core; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class ContentContainerTests { - [TestMethod] + [Fact] public void ContentContainer_ContentType_HavingProvidedContentTypeByCtor_ReturnsProvidedValue() { // Arrange @@ -19,10 +20,10 @@ public void ContentContainer_ContentType_HavingProvidedContentTypeByCtor_Returns ContentType actual = sut.ContentType; // Assert - Assert.AreEqual(expected, actual); + actual.Should().Be(expected); } - [TestMethod] + [Fact] public void ContentContainer_GetContentAs_HavingProvidedContentByCtorAndGivenCorrectRuntimeType_ReturnsProvidedValue() { // Arrange @@ -34,10 +35,10 @@ public void ContentContainer_GetContentAs_HavingProvidedContentByCtorAndGivenCor object actual = sut.GetContentAs(); // Assert - Assert.AreSame(expected, actual); + actual.Should().BeSameAs(expected); } - [TestMethod] + [Fact] public void ContentContainer_GetContentAs_HavingProvidedContentByCtorAndGivenWrongRuntimeType_ThrowsArgumentException() { // Arrange @@ -45,12 +46,14 @@ public void ContentContainer_GetContentAs_HavingProvidedContentByCtorAndGivenWro ContentContainer sut = new ContentContainer(ContentType.Type1, (t) => expected); + // Act + ContentTypeException contentTypeException = Assert.Throws(() => sut.GetContentAs()); + // Assert - Assert.ThrowsException(() => - { - // Act - sut.GetContentAs(); - }); + contentTypeException.Should().NotBeNull(); + contentTypeException.Message.Should().Be("Cannot cast content to provided type as TContent: System.Int32"); + contentTypeException.InnerException.Should().NotBeNull() + .And.BeOfType($"{nameof(ContentTypeException)} should happen when an invalid cast is attempted."); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Core/RuleTests.cs b/tests/Rules.Framework.Tests/Core/RuleTests.cs index e637ebb7..d85ebebf 100644 --- a/tests/Rules.Framework.Tests/Core/RuleTests.cs +++ b/tests/Rules.Framework.Tests/Core/RuleTests.cs @@ -1,16 +1,16 @@ namespace Rules.Framework.Tests.Core { using System; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Moq; using Rules.Framework.Core; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class RuleTests { - [TestMethod] - public void Rule_ContentContainer_ContentContainer_HavingSettedInstance_ReturnsProvidedInstance() + [Fact] + public void ContentContainer_ContentContainer_HavingSettedInstance_ReturnsProvidedInstance() { // Arrange ContentContainer expected = new ContentContainer(ContentType.Type1, (t) => null); @@ -24,11 +24,11 @@ public void Rule_ContentContainer_ContentContainer_HavingSettedInstance_ReturnsP ContentContainer actual = sut.ContentContainer; // Assert - Assert.AreSame(expected, actual); + actual.Should().BeSameAs(expected); } - [TestMethod] - public void Rule_DateBegin_HavingSettedValue_ReturnsProvidedValue() + [Fact] + public void DateBegin_HavingSettedValue_ReturnsProvidedValue() { // Arrange DateTime expected = new DateTime(2018, 07, 19); @@ -42,11 +42,11 @@ public void Rule_DateBegin_HavingSettedValue_ReturnsProvidedValue() DateTime actual = sut.DateBegin; // Assert - Assert.AreEqual(expected, actual); + actual.Should().Be(expected); } - [TestMethod] - public void Rule_DateEnd_HavingSettedValue_ReturnsProvidedValue() + [Fact] + public void DateEnd_HavingSettedValue_ReturnsProvidedValue() { // Arrange DateTime expected = new DateTime(2018, 07, 19); @@ -60,11 +60,11 @@ public void Rule_DateEnd_HavingSettedValue_ReturnsProvidedValue() DateTime? actual = sut.DateEnd; // Assert - Assert.AreEqual(expected, actual); + actual.Should().Be(expected); } - [TestMethod] - public void Rule_DateEnd_NotHavingSettedValue_ReturnsNull() + [Fact] + public void DateEnd_NotHavingSettedValue_ReturnsNull() { // Arrange Rule sut = new Rule(); @@ -73,11 +73,11 @@ public void Rule_DateEnd_NotHavingSettedValue_ReturnsNull() DateTime? actual = sut.DateEnd; // Assert - Assert.IsNull(actual); + actual.Should().BeNull(); } - [TestMethod] - public void Rule_Name_HavingSettedValue_ReturnsProvidedValue() + [Fact] + public void Name_HavingSettedValue_ReturnsProvidedValue() { // Arrange string expected = "My awesome name"; @@ -91,11 +91,11 @@ public void Rule_Name_HavingSettedValue_ReturnsProvidedValue() string actual = sut.Name; // Assert - Assert.AreEqual(expected, actual); + actual.Should().Be(expected); } - [TestMethod] - public void Rule_Priority_HavingSettedValue_ReturnsProvidedValue() + [Fact] + public void Priority_HavingSettedValue_ReturnsProvidedValue() { // Arrange int expected = 123; @@ -109,11 +109,11 @@ public void Rule_Priority_HavingSettedValue_ReturnsProvidedValue() int actual = sut.Priority; // Arrange - Assert.AreEqual(expected, actual); + actual.Should().Be(expected); } - [TestMethod] - public void Rule_RootCondition_HavingSettedInstance_ReturnsProvidedInstance() + [Fact] + public void RootCondition_HavingSettedInstance_ReturnsProvidedInstance() { // Arrange Mock> mockConditionNode = new Mock>(); @@ -128,7 +128,7 @@ public void Rule_RootCondition_HavingSettedInstance_ReturnsProvidedInstance() IConditionNode actual = sut.RootCondition; // Assert - Assert.AreSame(expected, actual); + actual.Should().BeSameAs(expected); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Evaluation/ConditionsEvalEngineTests.cs b/tests/Rules.Framework.Tests/Evaluation/ConditionsEvalEngineTests.cs index cd8d790b..d87ad8fe 100644 --- a/tests/Rules.Framework.Tests/Evaluation/ConditionsEvalEngineTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/ConditionsEvalEngineTests.cs @@ -2,19 +2,19 @@ namespace Rules.Framework.Tests.Evaluation { using System; using System.Collections.Generic; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Moq; using Rules.Framework.Core; using Rules.Framework.Core.ConditionNodes; using Rules.Framework.Evaluation; using Rules.Framework.Evaluation.ValueEvaluation; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class ConditionsEvalEngineTests { - [TestMethod] - public void ConditionsEvalEngine_Eval_GivenComposedConditionNodeWithAndOperator_EvalsAndReturnsResult() + [Fact] + public void Eval_GivenComposedConditionNodeWithAndOperator_EvalsAndReturnsResult() { // Arrange BooleanConditionNode condition1 = new BooleanConditionNode(ConditionType.IsVip, Operators.Equal, true); @@ -56,13 +56,13 @@ public void ConditionsEvalEngine_Eval_GivenComposedConditionNodeWithAndOperator_ bool actual = sut.Eval(composedConditionNode, conditions); // Assert - Assert.IsTrue(actual); + actual.Should().BeTrue(); mockDeferredEval.Verify(x => x.GetDeferredEvalFor(It.IsAny>()), Times.Exactly(2)); } - [TestMethod] - public void ConditionsEvalEngine_Eval_GivenComposedConditionNodeWithEvalOperator_ThrowsNotSupportedException() + [Fact] + public void Eval_GivenComposedConditionNodeWithEvalOperator_ThrowsNotSupportedException() { // Arrange BooleanConditionNode condition1 = new BooleanConditionNode(ConditionType.IsVip, Operators.Equal, true); @@ -90,18 +90,17 @@ public void ConditionsEvalEngine_Eval_GivenComposedConditionNodeWithEvalOperator ConditionsEvalEngine sut = new ConditionsEvalEngine(mockDeferredEval.Object); - // Assert - Assert.ThrowsException(() => - { - // Act - sut.Eval(composedConditionNode, conditions); - }); + // Act + NotSupportedException notSupportedException = Assert.Throws(() => sut.Eval(composedConditionNode, conditions)); + // Assert + notSupportedException.Should().NotBeNull(); + notSupportedException.Message.Should().Be("Unsupported logical operator: 'Eval'."); mockDeferredEval.Verify(x => x.GetDeferredEvalFor(It.IsAny>()), Times.Never()); } - [TestMethod] - public void ConditionsEvalEngine_Eval_GivenComposedConditionNodeWithOrOperator_EvalsAndReturnsResult() + [Fact] + public void Eval_GivenComposedConditionNodeWithOrOperator_EvalsAndReturnsResult() { // Arrange BooleanConditionNode condition1 = new BooleanConditionNode(ConditionType.IsVip, Operators.Equal, true); @@ -143,13 +142,13 @@ public void ConditionsEvalEngine_Eval_GivenComposedConditionNodeWithOrOperator_E bool actual = sut.Eval(composedConditionNode, conditions); // Assert - Assert.IsTrue(actual); + actual.Should().BeTrue(); mockDeferredEval.Verify(x => x.GetDeferredEvalFor(It.IsAny>()), Times.Exactly(2)); } - [TestMethod] - public void ConditionsEvalEngine_Eval_GivenComposedConditionNodeWithUnknownConditionNode_ThrowsNotSupportedException() + [Fact] + public void Eval_GivenComposedConditionNodeWithUnknownConditionNode_ThrowsNotSupportedException() { // Arrange Mock> mockConditionNode = new Mock>(); @@ -172,12 +171,12 @@ public void ConditionsEvalEngine_Eval_GivenComposedConditionNodeWithUnknownCondi ConditionsEvalEngine sut = new ConditionsEvalEngine(mockDeferredEval.Object); + // Act + NotSupportedException notSupportedException = Assert.Throws(() => sut.Eval(mockConditionNode.Object, conditions)); + // Assert - Assert.ThrowsException(() => - { - // Act - sut.Eval(mockConditionNode.Object, conditions); - }); + notSupportedException.Should().NotBeNull(); + notSupportedException.Message.Should().Be($"Unsupported condition node: '{mockConditionNode.Object.GetType().Name}'."); mockDeferredEval.Verify(x => x.GetDeferredEvalFor(It.IsAny>()), Times.Never()); } diff --git a/tests/Rules.Framework.Tests/Evaluation/Specification/AndSpecificationTests.cs b/tests/Rules.Framework.Tests/Evaluation/Specification/AndSpecificationTests.cs index d626bf87..4f5f643b 100644 --- a/tests/Rules.Framework.Tests/Evaluation/Specification/AndSpecificationTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/Specification/AndSpecificationTests.cs @@ -1,14 +1,14 @@ namespace Rules.Framework.Tests.Evaluation.Specification { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Moq; using Rules.Framework.Evaluation.Specification; + using Xunit; - [TestClass] public class AndSpecificationTests { - [TestMethod] - public void AndSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsFalse_ShortCircuitsDoesNotEvalRightSpecificationAndReturnsFalse() + [Fact] + public void IsSatisfiedBy_GivenLeftSpecificationEvalAsFalse_ShortCircuitsDoesNotEvalRightSpecificationAndReturnsFalse() { // Arrange object expectedInput = new object(); @@ -29,14 +29,14 @@ public void AndSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsFalse_Sho bool actual = sut.IsSatisfiedBy(expectedInput); // Assert - Assert.IsFalse(actual); + actual.Should().BeFalse(); mockLeftSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); mockRightSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Never()); } - [TestMethod] - public void AndSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsTrueAndRightSpecificationEvalAsFalse_EvalsBothSpecificationsAndReturnsFalse() + [Fact] + public void IsSatisfiedBy_GivenLeftSpecificationEvalAsTrueAndRightSpecificationEvalAsFalse_EvalsBothSpecificationsAndReturnsFalse() { // Arrange object expectedInput = new object(); @@ -57,14 +57,14 @@ public void AndSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsTrueAndRi bool actual = sut.IsSatisfiedBy(expectedInput); // Assert - Assert.IsFalse(actual); + actual.Should().BeFalse(); mockLeftSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); mockRightSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); } - [TestMethod] - public void AndSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsTrueAndRightSpecificationEvalAsTrue_EvalsBothSpecificationsAndReturnsTrue() + [Fact] + public void IsSatisfiedBy_GivenLeftSpecificationEvalAsTrueAndRightSpecificationEvalAsTrue_EvalsBothSpecificationsAndReturnsTrue() { // Arrange object expectedInput = new object(); @@ -85,7 +85,7 @@ public void AndSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsTrueAndRi bool actual = sut.IsSatisfiedBy(expectedInput); // Assert - Assert.IsTrue(actual); + actual.Should().BeTrue(); mockLeftSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); mockRightSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); diff --git a/tests/Rules.Framework.Tests/Evaluation/Specification/FuncSpecificationTests.cs b/tests/Rules.Framework.Tests/Evaluation/Specification/FuncSpecificationTests.cs index 4510d585..dedd7fca 100644 --- a/tests/Rules.Framework.Tests/Evaluation/Specification/FuncSpecificationTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/Specification/FuncSpecificationTests.cs @@ -1,15 +1,15 @@ namespace Rules.Framework.Tests.Evaluation.Specification { using System; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Moq; using Rules.Framework.Evaluation.Specification; + using Xunit; - [TestClass] public class FuncSpecificationTests { - [TestMethod] - public void FuncSpecification_And_GivenOtherSpecification_ReturnsAndSpecification() + [Fact] + public void And_GivenOtherSpecification_ReturnsAndSpecification() { // Arrange Mock> mockOtherSpecification = new Mock>(); @@ -22,11 +22,11 @@ public void FuncSpecification_And_GivenOtherSpecification_ReturnsAndSpecificatio ISpecification actual = sut.And(expectedOtherSpecification); // Assert - Assert.IsInstanceOfType(actual, typeof(AndSpecification)); + actual.Should().BeOfType>(); } - [TestMethod] - public void FuncSpecification_IsSatisfiedBy_GivenFuncEvalsAsFalse_ReturnsFalse() + [Fact] + public void IsSatisfiedBy_GivenFuncEvalsAsFalse_ReturnsFalse() { // Arrange object expectedInput = new object(); @@ -38,11 +38,11 @@ public void FuncSpecification_IsSatisfiedBy_GivenFuncEvalsAsFalse_ReturnsFalse() bool actual = sut.IsSatisfiedBy(expectedInput); // Assert - Assert.IsFalse(actual); + actual.Should().BeFalse(); } - [TestMethod] - public void FuncSpecification_IsSatisfiedBy_GivenFuncEvalsAsTrue_ReturnsTrue() + [Fact] + public void IsSatisfiedBy_GivenFuncEvalsAsTrue_ReturnsTrue() { // Arrange object expectedInput = new object(); @@ -54,11 +54,11 @@ public void FuncSpecification_IsSatisfiedBy_GivenFuncEvalsAsTrue_ReturnsTrue() bool actual = sut.IsSatisfiedBy(expectedInput); // Assert - Assert.IsTrue(actual); + actual.Should().BeTrue(); } - [TestMethod] - public void FuncSpecification_Or_GivenOtherSpecification_ReturnsOrSpecification() + [Fact] + public void Or_GivenOtherSpecification_ReturnsOrSpecification() { // Arrange Mock> mockOtherSpecification = new Mock>(); @@ -71,7 +71,7 @@ public void FuncSpecification_Or_GivenOtherSpecification_ReturnsOrSpecification( ISpecification actual = sut.Or(expectedOtherSpecification); // Assert - Assert.IsInstanceOfType(actual, typeof(OrSpecification)); + actual.Should().BeOfType>(); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Evaluation/Specification/OrSpecificationTests.cs b/tests/Rules.Framework.Tests/Evaluation/Specification/OrSpecificationTests.cs index 7829d20d..81216ae6 100644 --- a/tests/Rules.Framework.Tests/Evaluation/Specification/OrSpecificationTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/Specification/OrSpecificationTests.cs @@ -1,14 +1,14 @@ namespace Rules.Framework.Tests.Evaluation.Specification { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Moq; using Rules.Framework.Evaluation.Specification; + using Xunit; - [TestClass] public class OrSpecificationTests { - [TestMethod] - public void OrSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsFalse_EvalsRightSpecificationAndReturnsFalse() + [Fact] + public void IsSatisfiedBy_GivenLeftSpecificationEvalAsFalse_EvalsRightSpecificationAndReturnsFalse() { // Arrange object expectedInput = new object(); @@ -29,14 +29,14 @@ public void OrSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsFalse_Eval bool actual = sut.IsSatisfiedBy(expectedInput); // Assert - Assert.IsFalse(actual); + actual.Should().BeFalse(); mockLeftSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); mockRightSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); } - [TestMethod] - public void OrSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsFalseAndRightSpecificationEvalAsTrue_EvalsBothSpecificationsAndReturnsTrue() + [Fact] + public void IsSatisfiedBy_GivenLeftSpecificationEvalAsFalseAndRightSpecificationEvalAsTrue_EvalsBothSpecificationsAndReturnsTrue() { // Arrange object expectedInput = new object(); @@ -57,14 +57,14 @@ public void OrSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsFalseAndRi bool actual = sut.IsSatisfiedBy(expectedInput); // Assert - Assert.IsTrue(actual); + actual.Should().BeTrue(); mockLeftSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); mockRightSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); } - [TestMethod] - public void OrSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsTrueAndRightSpecificationEvalAsFalse_ShortCircuitsDoesNotEvalRightSpecificationAndReturnsFalse() + [Fact] + public void IsSatisfiedBy_GivenLeftSpecificationEvalAsTrueAndRightSpecificationEvalAsFalse_ShortCircuitsDoesNotEvalRightSpecificationAndReturnsFalse() { // Arrange object expectedInput = new object(); @@ -85,7 +85,7 @@ public void OrSpecification_IsSatisfiedBy_GivenLeftSpecificationEvalAsTrueAndRig bool actual = sut.IsSatisfiedBy(expectedInput); // Assert - Assert.IsTrue(actual); + actual.Should().BeTrue(); mockLeftSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Once()); mockRightSpecification.Verify(x => x.IsSatisfiedBy(It.Is(o => o == expectedInput)), Times.Never()); diff --git a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/DeferredEvalTests.cs b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/DeferredEvalTests.cs index 9f81f4c0..4e96b489 100644 --- a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/DeferredEvalTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/DeferredEvalTests.cs @@ -2,18 +2,18 @@ namespace Rules.Framework.Tests.Evaluation.ValueEvaluation { using System; using System.Collections.Generic; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Moq; using Rules.Framework.Core; using Rules.Framework.Core.ConditionNodes; using Rules.Framework.Evaluation.ValueEvaluation; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class DeferredEvalTests { - [TestMethod] - public void DeferredEval_GetDeferredEvalFor_GivenBooleanConditionNode_ReturnsFuncToEvalConditionsCollection() + [Fact] + public void GetDeferredEvalFor_GivenBooleanConditionNode_ReturnsFuncToEvalConditionsCollection() { // Arrange BooleanConditionNode conditionNode = new BooleanConditionNode(ConditionType.IsVip, Operators.NotEqual, true); @@ -44,14 +44,14 @@ public void DeferredEval_GetDeferredEvalFor_GivenBooleanConditionNode_ReturnsFun bool actualEvalResult = actual.Invoke(conditions); // Assert - Assert.IsTrue(actualEvalResult); + actualEvalResult.Should().BeTrue(); mockOperatorEvalStrategyFactory.Verify(x => x.GetOperatorEvalStrategy(It.IsAny()), Times.Once()); mockOperatorEvalStrategy.Verify(x => x.Eval(It.IsAny(), It.IsAny()), Times.Once()); } - [TestMethod] - public void DeferredEval_GetDeferredEvalFor_GivenDecimalConditionNode_ReturnsFuncToEvalConditionsCollection() + [Fact] + public void GetDeferredEvalFor_GivenDecimalConditionNode_ReturnsFuncToEvalConditionsCollection() { // Arrange DecimalConditionNode conditionNode = new DecimalConditionNode(ConditionType.PluviosityRate, Operators.GreaterThan, 50); @@ -82,14 +82,14 @@ public void DeferredEval_GetDeferredEvalFor_GivenDecimalConditionNode_ReturnsFun bool actualEvalResult = actual.Invoke(conditions); // Assert - Assert.IsTrue(actualEvalResult); + actualEvalResult.Should().BeTrue(); mockOperatorEvalStrategyFactory.Verify(x => x.GetOperatorEvalStrategy(It.IsAny()), Times.Once()); mockOperatorEvalStrategy.Verify(x => x.Eval(It.IsAny(), It.IsAny()), Times.Once()); } - [TestMethod] - public void DeferredEval_GetDeferredEvalFor_GivenIntegerConditionNode_ReturnsFuncToEvalConditionsCollection() + [Fact] + public void GetDeferredEvalFor_GivenIntegerConditionNode_ReturnsFuncToEvalConditionsCollection() { // Arrange IntegerConditionNode conditionNode = new IntegerConditionNode(ConditionType.NumberOfSales, Operators.GreaterThan, 1000); @@ -120,14 +120,14 @@ public void DeferredEval_GetDeferredEvalFor_GivenIntegerConditionNode_ReturnsFun bool actualEvalResult = actual.Invoke(conditions); // Assert - Assert.IsTrue(actualEvalResult); + actualEvalResult.Should().BeTrue(); mockOperatorEvalStrategyFactory.Verify(x => x.GetOperatorEvalStrategy(It.IsAny()), Times.Once()); mockOperatorEvalStrategy.Verify(x => x.Eval(It.IsAny(), It.IsAny()), Times.Once()); } - [TestMethod] - public void DeferredEval_GetDeferredEvalFor_GivenStringConditionNode_ReturnsFuncToEvalConditionsCollection() + [Fact] + public void GetDeferredEvalFor_GivenStringConditionNode_ReturnsFuncToEvalConditionsCollection() { // Arrange StringConditionNode conditionNode = new StringConditionNode(ConditionType.IsoCurrency, Operators.Equal, "EUR"); @@ -158,14 +158,14 @@ public void DeferredEval_GetDeferredEvalFor_GivenStringConditionNode_ReturnsFunc bool actualEvalResult = actual.Invoke(conditions); // Assert - Assert.IsTrue(actualEvalResult); + actualEvalResult.Should().BeTrue(); mockOperatorEvalStrategyFactory.Verify(x => x.GetOperatorEvalStrategy(It.IsAny()), Times.Once()); mockOperatorEvalStrategy.Verify(x => x.Eval(It.IsAny(), It.IsAny()), Times.Once()); } - [TestMethod] - public void DeferredEval_GetDeferredEvalFor_GivenStringConditionNodeWithNoConditionSuppliedAndRulesEngineConfiguredToDiscardWhenMissing_ReturnsFuncThatEvalsFalse() + [Fact] + public void GetDeferredEvalFor_GivenStringConditionNodeWithNoConditionSuppliedAndRulesEngineConfiguredToDiscardWhenMissing_ReturnsFuncThatEvalsFalse() { // Arrange StringConditionNode conditionNode = new StringConditionNode(ConditionType.IsoCurrency, Operators.Equal, "EUR"); @@ -197,14 +197,14 @@ public void DeferredEval_GetDeferredEvalFor_GivenStringConditionNodeWithNoCondit bool actualEvalResult = actual.Invoke(conditions); // Assert - Assert.IsFalse(actualEvalResult); + actualEvalResult.Should().BeFalse(); mockOperatorEvalStrategyFactory.Verify(x => x.GetOperatorEvalStrategy(It.IsAny()), Times.Never()); mockOperatorEvalStrategy.Verify(x => x.Eval(It.IsAny(), It.IsAny()), Times.Never()); } - [TestMethod] - public void DeferredEval_GetDeferredEvalFor_GivenStringConditionNodeWithNoConditionSuppliedAndRulesEngineConfiguredToUseDataTypeDefaultWhenMissing_ReturnsFuncThatEvalsFalse() + [Fact] + public void GetDeferredEvalFor_GivenStringConditionNodeWithNoConditionSuppliedAndRulesEngineConfiguredToUseDataTypeDefaultWhenMissing_ReturnsFuncThatEvalsFalse() { // Arrange StringConditionNode conditionNode = new StringConditionNode(ConditionType.IsoCurrency, Operators.Equal, "EUR"); @@ -236,14 +236,14 @@ public void DeferredEval_GetDeferredEvalFor_GivenStringConditionNodeWithNoCondit bool actualEvalResult = actual.Invoke(conditions); // Assert - Assert.IsFalse(actualEvalResult); + actualEvalResult.Should().BeFalse(); mockOperatorEvalStrategyFactory.Verify(x => x.GetOperatorEvalStrategy(It.IsAny()), Times.Once()); mockOperatorEvalStrategy.Verify(x => x.Eval(It.IsAny(), It.IsAny()), Times.Once()); } - [TestMethod] - public void DeferredEval_GetDeferredEvalFor_GivenUnknownConditionNodeType_ThrowsNotSupportedException() + [Fact] + public void GetDeferredEvalFor_GivenUnknownConditionNodeType_ThrowsNotSupportedException() { // Arrange Mock> mockValueConditionNode = new Mock>(); @@ -254,12 +254,12 @@ public void DeferredEval_GetDeferredEvalFor_GivenUnknownConditionNodeType_Throws DeferredEval sut = new DeferredEval(mockOperatorEvalStrategyFactory.Object, rulesEngineOptions); + // Act + NotSupportedException notSupportedException = Assert.Throws(() => sut.GetDeferredEvalFor(mockValueConditionNode.Object)); + // Assert - Assert.ThrowsException(() => - { - // Act - sut.GetDeferredEvalFor(mockValueConditionNode.Object); - }); + notSupportedException.Should().NotBeNull(); + notSupportedException.Message.Should().Be($"Unsupported value condition node: '{mockValueConditionNode.Object.GetType().Name}'."); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/EqualOperatorEvalStrategyTests.cs b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/EqualOperatorEvalStrategyTests.cs index bbd5a27b..3a406321 100644 --- a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/EqualOperatorEvalStrategyTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/EqualOperatorEvalStrategyTests.cs @@ -1,13 +1,13 @@ namespace Rules.Framework.Tests.Evaluation.ValueEvaluation { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Evaluation.ValueEvaluation; + using Xunit; - [TestClass] public class EqualOperatorEvalStrategyTests { - [TestMethod] - public void EqualOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsTrue() + [Fact] + public void Eval_GivenAsIntegers1And1_ReturnsTrue() { // Arrange int expectedLeftOperand = 1; @@ -19,11 +19,11 @@ public void EqualOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsTrue() bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsTrue(actual); + actual.Should().BeTrue(); } - [TestMethod] - public void EqualOperatorEvalStrategy_Eval_GivenAsIntegers1And2_ReturnsFalse() + [Fact] + public void Eval_GivenAsIntegers1And2_ReturnsFalse() { // Arrange int expectedLeftOperand = 1; @@ -35,7 +35,7 @@ public void EqualOperatorEvalStrategy_Eval_GivenAsIntegers1And2_ReturnsFalse() bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsFalse(actual); + actual.Should().BeFalse(); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/GreaterThanOperatorEvalStrategyTests.cs b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/GreaterThanOperatorEvalStrategyTests.cs index 8db1a841..c9df2c01 100644 --- a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/GreaterThanOperatorEvalStrategyTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/GreaterThanOperatorEvalStrategyTests.cs @@ -1,13 +1,13 @@ namespace Rules.Framework.Tests.Evaluation.ValueEvaluation { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Evaluation.ValueEvaluation; + using Xunit; - [TestClass] public class GreaterThanOperatorEvalStrategyTests { - [TestMethod] - public void GreaterThanOperatorEvalStrategy_Eval_GivenAsIntegers0And1_ReturnsFalse() + [Fact] + public void Eval_GivenAsIntegers0And1_ReturnsFalse() { // Assert int expectedLeftOperand = 0; @@ -19,11 +19,11 @@ public void GreaterThanOperatorEvalStrategy_Eval_GivenAsIntegers0And1_ReturnsFal bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsFalse(actual); + actual.Should().BeFalse(); } - [TestMethod] - public void GreaterThanOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsFalse() + [Fact] + public void Eval_GivenAsIntegers1And1_ReturnsFalse() { // Assert int expectedLeftOperand = 1; @@ -35,11 +35,11 @@ public void GreaterThanOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsFal bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsFalse(actual); + actual.Should().BeFalse(); } - [TestMethod] - public void GreaterThanOperatorEvalStrategy_Eval_GivenAsIntegers2And1_ReturnsTrue() + [Fact] + public void Eval_GivenAsIntegers2And1_ReturnsTrue() { // Assert int expectedLeftOperand = 2; @@ -51,7 +51,7 @@ public void GreaterThanOperatorEvalStrategy_Eval_GivenAsIntegers2And1_ReturnsTru bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsTrue(actual); + actual.Should().BeTrue(); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/GreaterThanOrEqualOperatorEvalStrategyTests.cs b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/GreaterThanOrEqualOperatorEvalStrategyTests.cs index 064af0a1..b56a612c 100644 --- a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/GreaterThanOrEqualOperatorEvalStrategyTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/GreaterThanOrEqualOperatorEvalStrategyTests.cs @@ -1,13 +1,13 @@ namespace Rules.Framework.Tests.Evaluation.ValueEvaluation { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Evaluation.ValueEvaluation; + using Xunit; - [TestClass] public class GreaterThanOrEqualOperatorEvalStrategyTests { - [TestMethod] - public void GreaterThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers0And1_ReturnsFalse() + [Fact] + public void Eval_GivenAsIntegers0And1_ReturnsFalse() { // Assert int expectedLeftOperand = 0; @@ -19,11 +19,11 @@ public void GreaterThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers0And1_Ret bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsFalse(actual); + actual.Should().BeFalse(); } - [TestMethod] - public void GreaterThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsTrue() + [Fact] + public void Eval_GivenAsIntegers1And1_ReturnsTrue() { // Assert int expectedLeftOperand = 1; @@ -35,11 +35,11 @@ public void GreaterThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers1And1_Ret bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsTrue(actual); + actual.Should().BeTrue(); } - [TestMethod] - public void GreaterThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers2And1_ReturnsTrue() + [Fact] + public void Eval_GivenAsIntegers2And1_ReturnsTrue() { // Assert int expectedLeftOperand = 2; @@ -51,7 +51,7 @@ public void GreaterThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers2And1_Ret bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsTrue(actual); + actual.Should().BeTrue(); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/LesserThanOperatorEvalStrategyTests.cs b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/LesserThanOperatorEvalStrategyTests.cs index cbb57a17..7d38cb91 100644 --- a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/LesserThanOperatorEvalStrategyTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/LesserThanOperatorEvalStrategyTests.cs @@ -1,13 +1,13 @@ namespace Rules.Framework.Tests.Evaluation.ValueEvaluation { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Evaluation.ValueEvaluation; + using Xunit; - [TestClass] public class LesserThanOperatorEvalStrategyTests { - [TestMethod] - public void LesserThanOperatorEvalStrategy_Eval_GivenAsIntegers0And1_ReturnsTrue() + [Fact] + public void Eval_GivenAsIntegers0And1_ReturnsTrue() { // Assert int expectedLeftOperand = 0; @@ -19,11 +19,11 @@ public void LesserThanOperatorEvalStrategy_Eval_GivenAsIntegers0And1_ReturnsTrue bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsTrue(actual); + actual.Should().BeTrue(); } - [TestMethod] - public void LesserThanOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsFalse() + [Fact] + public void Eval_GivenAsIntegers1And1_ReturnsFalse() { // Assert int expectedLeftOperand = 1; @@ -35,11 +35,11 @@ public void LesserThanOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsFals bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsFalse(actual); + actual.Should().BeFalse(); } - [TestMethod] - public void LesserThanOperatorEvalStrategy_Eval_GivenAsIntegers2And1_ReturnsFalse() + [Fact] + public void Eval_GivenAsIntegers2And1_ReturnsFalse() { // Assert int expectedLeftOperand = 2; @@ -51,7 +51,7 @@ public void LesserThanOperatorEvalStrategy_Eval_GivenAsIntegers2And1_ReturnsFals bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsFalse(actual); + actual.Should().BeFalse(); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/LesserThanOrEqualOperatorEvalStrategyTests.cs b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/LesserThanOrEqualOperatorEvalStrategyTests.cs index 630acc09..51c0481f 100644 --- a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/LesserThanOrEqualOperatorEvalStrategyTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/LesserThanOrEqualOperatorEvalStrategyTests.cs @@ -1,13 +1,13 @@ namespace Rules.Framework.Tests.Evaluation.ValueEvaluation { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Evaluation.ValueEvaluation; + using Xunit; - [TestClass] public class LesserThanOrEqualOperatorEvalStrategyTests { - [TestMethod] - public void LesserThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers0And1_ReturnsTrue() + [Fact] + public void Eval_GivenAsIntegers0And1_ReturnsTrue() { // Assert int expectedLeftOperand = 0; @@ -19,11 +19,11 @@ public void LesserThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers0And1_Retu bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsTrue(actual); + actual.Should().BeTrue(); } - [TestMethod] - public void LesserThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsTrue() + [Fact] + public void Eval_GivenAsIntegers1And1_ReturnsTrue() { // Assert int expectedLeftOperand = 1; @@ -35,11 +35,11 @@ public void LesserThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers1And1_Retu bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsTrue(actual); + actual.Should().BeTrue(); } - [TestMethod] - public void LesserThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers2And1_ReturnsFalse() + [Fact] + public void Eval_GivenAsIntegers2And1_ReturnsFalse() { // Assert int expectedLeftOperand = 2; @@ -51,7 +51,7 @@ public void LesserThanOrEqualOperatorEvalStrategy_Eval_GivenAsIntegers2And1_Retu bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsFalse(actual); + actual.Should().BeFalse(); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/NotEqualOperatorEvalStrategyTests.cs b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/NotEqualOperatorEvalStrategyTests.cs index 7b19bc9c..34d72a7d 100644 --- a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/NotEqualOperatorEvalStrategyTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/NotEqualOperatorEvalStrategyTests.cs @@ -1,13 +1,13 @@ namespace Rules.Framework.Tests.Evaluation.ValueEvaluation { - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Evaluation.ValueEvaluation; + using Xunit; - [TestClass] public class NotEqualOperatorEvalStrategyTests { - [TestMethod] - public void NotEqualOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsFalse() + [Fact] + public void Eval_GivenAsIntegers1And1_ReturnsFalse() { // Arrange int expectedLeftOperand = 1; @@ -19,11 +19,11 @@ public void NotEqualOperatorEvalStrategy_Eval_GivenAsIntegers1And1_ReturnsFalse( bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsFalse(actual); + actual.Should().BeFalse(); } - [TestMethod] - public void NotEqualOperatorEvalStrategy_Eval_GivenAsIntegers1And2_ReturnsTrue() + [Fact] + public void Eval_GivenAsIntegers1And2_ReturnsTrue() { // Arrange int expectedLeftOperand = 1; @@ -35,7 +35,7 @@ public void NotEqualOperatorEvalStrategy_Eval_GivenAsIntegers1And2_ReturnsTrue() bool actual = sut.Eval(expectedLeftOperand, expectedRightOperand); // Arrange - Assert.IsTrue(actual); + actual.Should().BeTrue(); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/OperatorEvalStrategyFactoryTests.cs b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/OperatorEvalStrategyFactoryTests.cs index 5f17b8ca..c7c25848 100644 --- a/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/OperatorEvalStrategyFactoryTests.cs +++ b/tests/Rules.Framework.Tests/Evaluation/ValueEvaluation/OperatorEvalStrategyFactoryTests.cs @@ -1,21 +1,21 @@ namespace Rules.Framework.Tests.Evaluation.ValueEvaluation { using System; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Rules.Framework.Core; using Rules.Framework.Evaluation.ValueEvaluation; + using Xunit; - [TestClass] public class OperatorEvalStrategyFactoryTests { - [TestMethod] - [DataRow(Operators.Equal, typeof(EqualOperatorEvalStrategy), DisplayName = "EqualOperator")] - [DataRow(Operators.NotEqual, typeof(NotEqualOperatorEvalStrategy), DisplayName = "NotEqualOperator")] - [DataRow(Operators.GreaterThan, typeof(GreaterThanOperatorEvalStrategy), DisplayName = "GreaterThanOperator")] - [DataRow(Operators.GreaterThanOrEqual, typeof(GreaterThanOrEqualOperatorEvalStrategy), DisplayName = "GreaterThanOrEqualOperator")] - [DataRow(Operators.LesserThan, typeof(LesserThanOperatorEvalStrategy), DisplayName = "LesserThanOperator")] - [DataRow(Operators.LesserThanOrEqual, typeof(LesserThanOrEqualOperatorEvalStrategy), DisplayName = "LesserThanOrEqualOperator")] - public void OperatorEvalStrategyFactory_GetOperatorEvalStrategy_GivenOperator_ReturnsOperatorEvalStrategy(Operators @operator, Type type) + [Theory] + [InlineData(Operators.Equal, typeof(EqualOperatorEvalStrategy))] + [InlineData(Operators.NotEqual, typeof(NotEqualOperatorEvalStrategy))] + [InlineData(Operators.GreaterThan, typeof(GreaterThanOperatorEvalStrategy))] + [InlineData(Operators.GreaterThanOrEqual, typeof(GreaterThanOrEqualOperatorEvalStrategy))] + [InlineData(Operators.LesserThan, typeof(LesserThanOperatorEvalStrategy))] + [InlineData(Operators.LesserThanOrEqual, typeof(LesserThanOrEqualOperatorEvalStrategy))] + public void GetOperatorEvalStrategy_GivenOperator_ReturnsOperatorEvalStrategy(Operators @operator, Type type) { // Arrange Operators expectedOperator = @operator; @@ -27,23 +27,23 @@ public void OperatorEvalStrategyFactory_GetOperatorEvalStrategy_GivenOperator_Re IOperatorEvalStrategy actual = sut.GetOperatorEvalStrategy(expectedOperator); // Assert - Assert.IsInstanceOfType(actual, expectedType); + actual.Should().NotBeNull().And.BeOfType(expectedType); } - [TestMethod] - public void OperatorEvalStrategyFactory_GetOperatorEvalStrategy_GivenUnknownOperator_ThrowsNotSupportedException() + [Fact] + public void GetOperatorEvalStrategy_GivenUnknownOperator_ThrowsNotSupportedException() { // Arrange Operators expectedOperator = (Operators)(-1); OperatorEvalStrategyFactory sut = new OperatorEvalStrategyFactory(); + // Act + NotSupportedException notSupportedException = Assert.Throws(() => sut.GetOperatorEvalStrategy(expectedOperator)); + // Assert - Assert.ThrowsException(() => - { - // Act - sut.GetOperatorEvalStrategy(expectedOperator); - }); + notSupportedException.Should().NotBeNull(); + notSupportedException.Message.Should().Be("Operator evaluation is not supported for operator '-1'."); } } } \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/Rules.Framework.Tests.csproj b/tests/Rules.Framework.Tests/Rules.Framework.Tests.csproj index 68523f77..159e4214 100644 --- a/tests/Rules.Framework.Tests/Rules.Framework.Tests.csproj +++ b/tests/Rules.Framework.Tests/Rules.Framework.Tests.csproj @@ -1,26 +1,33 @@ - netcoreapp2.1 + netcoreapp3.1 8.0 Full false - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + - - all runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + diff --git a/tests/Rules.Framework.Tests/RulesEngineTests.cs b/tests/Rules.Framework.Tests/RulesEngineTests.cs index 82a90a9c..d9840f11 100644 --- a/tests/Rules.Framework.Tests/RulesEngineTests.cs +++ b/tests/Rules.Framework.Tests/RulesEngineTests.cs @@ -4,18 +4,17 @@ namespace Rules.Framework.Tests using System.Collections.Generic; using System.Threading.Tasks; using FluentAssertions; - using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Rules.Framework.Core; using Rules.Framework.Core.ConditionNodes; using Rules.Framework.Evaluation; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class RulesEngineTests { - [TestMethod] - public async Task RulesEngine_MatchManyAsync_GivenContentTypeDateAndConditions_FetchesRulesForDayEvalsAndReturnsAllMatches() + [Fact] + public async Task MatchManyAsync_GivenContentTypeDateAndConditions_FetchesRulesForDayEvalsAndReturnsAllMatches() { // Arrange DateTime matchDateTime = new DateTime(2018, 07, 01, 18, 19, 30); @@ -77,6 +76,7 @@ public async Task RulesEngine_MatchManyAsync_GivenContentTypeDateAndConditions_F { case StringConditionNode stringConditionNode: return stringConditionNode.Operand == "USA"; + default: return false; } @@ -96,8 +96,8 @@ public async Task RulesEngine_MatchManyAsync_GivenContentTypeDateAndConditions_F mockConditionsEvalEngine.Verify(x => x.Eval(It.IsAny>(), It.IsAny>>()), Times.AtLeastOnce()); } - [TestMethod] - public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_FetchesRulesForDayEvalsAndReturnsTheTopmostPriorityOne() + [Fact] + public async Task MatchOneAsync_GivenContentTypeDateAndConditions_FetchesRulesForDayEvalsAndReturnsTheBottommostPriorityOne() { // Arrange DateTime matchDateTime = new DateTime(2018, 07, 01, 18, 19, 30); @@ -116,7 +116,7 @@ public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_Fe } }; - Rule expected = new Rule + Rule other = new Rule { ContentContainer = new ContentContainer(contentType, (t) => new object()), DateBegin = new DateTime(2018, 01, 01), @@ -126,7 +126,7 @@ public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_Fe RootCondition = new StringConditionNode(ConditionType.IsoCountryCode, Operators.Equal, "USA") }; - Rule other = new Rule + Rule expected = new Rule { ContentContainer = new ContentContainer(contentType, (t) => new object()), DateBegin = new DateTime(2010, 01, 01), @@ -138,26 +138,28 @@ public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_Fe IEnumerable> rules = new[] { - expected, - other + other, + expected }; Mock> mockRulesDataSource = SetupMockForRulesDataSource(rules); Mock> mockConditionsEvalEngine = SetupMockForConditionsEvalEngine(true); RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); + rulesEngineOptions.PriotityCriteria = PriorityCriterias.BottommostRuleWins; + RulesEngine sut = new RulesEngine(mockConditionsEvalEngine.Object, mockRulesDataSource.Object, rulesEngineOptions); // Act Rule actual = await sut.MatchOneAsync(contentType, matchDateTime, conditions); // Assert - Assert.AreEqual(expected, actual); + actual.Should().BeSameAs(expected); mockRulesDataSource.Verify(x => x.GetRulesAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); mockConditionsEvalEngine.Verify(x => x.Eval(It.IsAny>(), It.IsAny>>()), Times.AtLeastOnce()); } - [TestMethod] - public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_FetchesRulesForDayEvalsAndReturnsTheBottommostPriorityOne() + [Fact] + public async Task MatchOneAsync_GivenContentTypeDateAndConditions_FetchesRulesForDayEvalsAndReturnsTheTopmostPriorityOne() { // Arrange DateTime matchDateTime = new DateTime(2018, 07, 01, 18, 19, 30); @@ -176,7 +178,7 @@ public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_Fe } }; - Rule other = new Rule + Rule expected = new Rule { ContentContainer = new ContentContainer(contentType, (t) => new object()), DateBegin = new DateTime(2018, 01, 01), @@ -186,7 +188,7 @@ public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_Fe RootCondition = new StringConditionNode(ConditionType.IsoCountryCode, Operators.Equal, "USA") }; - Rule expected = new Rule + Rule other = new Rule { ContentContainer = new ContentContainer(contentType, (t) => new object()), DateBegin = new DateTime(2010, 01, 01), @@ -198,28 +200,26 @@ public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_Fe IEnumerable> rules = new[] { - other, - expected + expected, + other }; Mock> mockRulesDataSource = SetupMockForRulesDataSource(rules); Mock> mockConditionsEvalEngine = SetupMockForConditionsEvalEngine(true); RulesEngineOptions rulesEngineOptions = RulesEngineOptions.NewWithDefaults(); - rulesEngineOptions.PriotityCriteria = PriorityCriterias.BottommostRuleWins; - RulesEngine sut = new RulesEngine(mockConditionsEvalEngine.Object, mockRulesDataSource.Object, rulesEngineOptions); // Act Rule actual = await sut.MatchOneAsync(contentType, matchDateTime, conditions); // Assert - Assert.AreEqual(expected, actual); + actual.Should().BeSameAs(expected); mockRulesDataSource.Verify(x => x.GetRulesAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); mockConditionsEvalEngine.Verify(x => x.Eval(It.IsAny>(), It.IsAny>>()), Times.AtLeastOnce()); } - [TestMethod] - public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_FetchesRulesForDayFailsEvalsAndReturnsNull() + [Fact] + public async Task MatchOneAsync_GivenContentTypeDateAndConditions_FetchesRulesForDayFailsEvalsAndReturnsNull() { // Arrange DateTime matchDateTime = new DateTime(2018, 07, 01, 18, 19, 30); @@ -269,7 +269,7 @@ public async Task RulesEngine_MatchOneAsync_GivenContentTypeDateAndConditions_Fe Rule actual = await sut.MatchOneAsync(contentType, matchDateTime, conditions); // Assert - Assert.IsNull(actual); + actual.Should().BeNull(); mockRulesDataSource.Verify(x => x.GetRulesAsync(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once()); mockConditionsEvalEngine.Verify(x => x.Eval(It.IsAny>(), It.IsAny>>()), Times.AtLeastOnce()); } diff --git a/tests/Rules.Framework.Tests/Serialization/SerializedContentContainerTests.cs b/tests/Rules.Framework.Tests/Serialization/SerializedContentContainerTests.cs index 0135970c..ce311e93 100644 --- a/tests/Rules.Framework.Tests/Serialization/SerializedContentContainerTests.cs +++ b/tests/Rules.Framework.Tests/Serialization/SerializedContentContainerTests.cs @@ -1,16 +1,16 @@ namespace Rules.Framework.Tests.Serialization { using System; - using Microsoft.VisualStudio.TestTools.UnitTesting; + using FluentAssertions; using Moq; using Rules.Framework.Serialization; using Rules.Framework.Tests.TestStubs; + using Xunit; - [TestClass] public class SerializedContentContainerTests { - [TestMethod] - public void SerializedContentContainer_Init_GivenSerializedContent_DeserializesAndReturnsWhenFetchingContent() + [Fact] + public void Init_GivenSerializedContent_DeserializesAndReturnsWhenFetchingContent() { // Arrange ContentType expectedContentType = ContentType.Type1; @@ -31,7 +31,7 @@ public void SerializedContentContainer_Init_GivenSerializedContent_DeserializesA decimal actual = sut.GetContentAs(); // Assert - Assert.AreEqual(expected, actual); + actual.Should().Be(expected.As()); } } } \ No newline at end of file From 7a3f0dd2cafeca9c9842fc581bc35f4ae350d626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Sat, 11 Apr 2020 02:56:41 +0100 Subject: [PATCH 3/9] [FIX] FIxing code duplication. --- .../ComposedConditionNodeValidator.cs | 46 ++++-------------- .../Validation/ConditionNodeValidationArgs.cs | 14 ++++++ .../ConditionNodeValidationExtensions.cs | 47 +++++++++++++++++++ .../Builder/Validation/RuleValidator.cs | 47 ++++--------------- 4 files changed, 77 insertions(+), 77 deletions(-) create mode 100644 src/Rules.Framework/Builder/Validation/ConditionNodeValidationArgs.cs create mode 100644 src/Rules.Framework/Builder/Validation/ConditionNodeValidationExtensions.cs diff --git a/src/Rules.Framework/Builder/Validation/ComposedConditionNodeValidator.cs b/src/Rules.Framework/Builder/Validation/ComposedConditionNodeValidator.cs index 939d0cd1..7f343fa6 100644 --- a/src/Rules.Framework/Builder/Validation/ComposedConditionNodeValidator.cs +++ b/src/Rules.Framework/Builder/Validation/ComposedConditionNodeValidator.cs @@ -1,7 +1,6 @@ namespace Rules.Framework.Builder.Validation { using FluentValidation; - using FluentValidation.Results; using Rules.Framework.Core; using Rules.Framework.Core.ConditionNodes; @@ -20,44 +19,15 @@ public ComposedConditionNodeValidator() this.booleanConditionNodeValidator = new ValueConditionNodeValidator(); this.RuleFor(c => c.LogicalOperator).IsContainedOn(LogicalOperators.And, LogicalOperators.Or); - this.RuleForEach(c => c.ChildConditionNodes).Custom((cn, cc) => + this.RuleForEach(c => c.ChildConditionNodes).Custom((cn, cc) => cn.PerformValidation(new ConditionNodeValidationArgs { - ValidationResult validationResult = null; - - switch (cn) - { - case ComposedConditionNode composedConditionNode: - validationResult = this.Validate(composedConditionNode); - break; - - case IntegerConditionNode integerConditionNode: - validationResult = this.integerConditionNodeValidator.Validate(integerConditionNode); - break; - - case DecimalConditionNode decimalConditionNode: - validationResult = this.decimalConditionNodeValidator.Validate(decimalConditionNode); - break; - - case StringConditionNode stringConditionNode: - validationResult = this.stringConditionNodeValidator.Validate(stringConditionNode); - break; - - case BooleanConditionNode booleanConditionNode: - validationResult = this.booleanConditionNodeValidator.Validate(booleanConditionNode); - break; - - default: - return; - } - - if (!validationResult.IsValid) - { - foreach (ValidationFailure validationFailure in validationResult.Errors) - { - cc.AddFailure(validationFailure); - } - } - }); + BooleanConditionNodeValidator = this.booleanConditionNodeValidator, + ComposedConditionNodeValidator = this, + CustomContext = cc, + DecimalConditionNodeValidator = this.decimalConditionNodeValidator, + IntegerConditionNodeValidator = this.integerConditionNodeValidator, + StringConditionNodeValidator = this.stringConditionNodeValidator + })); } } } \ No newline at end of file diff --git a/src/Rules.Framework/Builder/Validation/ConditionNodeValidationArgs.cs b/src/Rules.Framework/Builder/Validation/ConditionNodeValidationArgs.cs new file mode 100644 index 00000000..869c57d1 --- /dev/null +++ b/src/Rules.Framework/Builder/Validation/ConditionNodeValidationArgs.cs @@ -0,0 +1,14 @@ +namespace Rules.Framework.Builder.Validation +{ + using FluentValidation.Validators; + + internal class ConditionNodeValidationArgs + { + public ValueConditionNodeValidator BooleanConditionNodeValidator { get; set; } + public ComposedConditionNodeValidator ComposedConditionNodeValidator { get; set; } + public CustomContext CustomContext { get; set; } + public ValueConditionNodeValidator DecimalConditionNodeValidator { get; set; } + public ValueConditionNodeValidator IntegerConditionNodeValidator { get; set; } + public ValueConditionNodeValidator StringConditionNodeValidator { get; set; } + } +} \ No newline at end of file diff --git a/src/Rules.Framework/Builder/Validation/ConditionNodeValidationExtensions.cs b/src/Rules.Framework/Builder/Validation/ConditionNodeValidationExtensions.cs new file mode 100644 index 00000000..7bffb0f6 --- /dev/null +++ b/src/Rules.Framework/Builder/Validation/ConditionNodeValidationExtensions.cs @@ -0,0 +1,47 @@ +namespace Rules.Framework.Builder.Validation +{ + using FluentValidation.Results; + using Rules.Framework.Core; + using Rules.Framework.Core.ConditionNodes; + + internal static class ConditionNodeValidationExtensions + { + public static void PerformValidation(this IConditionNode conditionNode, ConditionNodeValidationArgs conditionNodeValidationArgs) + { + ValidationResult validationResult; + switch (conditionNode) + { + case ComposedConditionNode composedConditionNode: + validationResult = conditionNodeValidationArgs.ComposedConditionNodeValidator.Validate(composedConditionNode); + break; + + case IntegerConditionNode integerConditionNode: + validationResult = conditionNodeValidationArgs.IntegerConditionNodeValidator.Validate(integerConditionNode); + break; + + case DecimalConditionNode decimalConditionNode: + validationResult = conditionNodeValidationArgs.DecimalConditionNodeValidator.Validate(decimalConditionNode); + break; + + case StringConditionNode stringConditionNode: + validationResult = conditionNodeValidationArgs.StringConditionNodeValidator.Validate(stringConditionNode); + break; + + case BooleanConditionNode booleanConditionNode: + validationResult = conditionNodeValidationArgs.BooleanConditionNodeValidator.Validate(booleanConditionNode); + break; + + default: + return; + } + + if (!validationResult.IsValid) + { + foreach (ValidationFailure validationFailure in validationResult.Errors) + { + conditionNodeValidationArgs.CustomContext.AddFailure(validationFailure); + } + } + } + } +} \ No newline at end of file diff --git a/src/Rules.Framework/Builder/Validation/RuleValidator.cs b/src/Rules.Framework/Builder/Validation/RuleValidator.cs index a9e5900c..bbd565bb 100644 --- a/src/Rules.Framework/Builder/Validation/RuleValidator.cs +++ b/src/Rules.Framework/Builder/Validation/RuleValidator.cs @@ -1,9 +1,7 @@ namespace Rules.Framework.Builder.Validation { using FluentValidation; - using FluentValidation.Results; using Rules.Framework.Core; - using Rules.Framework.Core.ConditionNodes; internal class RuleValidator : AbstractValidator> { @@ -26,44 +24,15 @@ public RuleValidator() this.RuleFor(r => r.DateEnd).GreaterThanOrEqualTo(r => r.DateBegin).When(r => r.DateEnd != null); this.RuleFor(r => r.Name).NotNull().NotEmpty(); this.RuleFor(r => r.Priority).GreaterThan(0); - this.RuleFor(r => r.RootCondition).Custom((cn, cc) => + this.RuleFor(r => r.RootCondition).Custom((cn, cc) => cn.PerformValidation(new ConditionNodeValidationArgs { - ValidationResult validationResult = null; - - switch (cn) - { - case ComposedConditionNode composedConditionNode: - validationResult = this.composedConditionNodeValidator.Validate(composedConditionNode); - break; - - case IntegerConditionNode integerConditionNode: - validationResult = this.integerConditionNodeValidator.Validate(integerConditionNode); - break; - - case DecimalConditionNode decimalConditionNode: - validationResult = this.decimalConditionNodeValidator.Validate(decimalConditionNode); - break; - - case StringConditionNode stringConditionNode: - validationResult = this.stringConditionNodeValidator.Validate(stringConditionNode); - break; - - case BooleanConditionNode booleanConditionNode: - validationResult = this.booleanConditionNodeValidator.Validate(booleanConditionNode); - break; - - default: - return; - } - - if (!validationResult.IsValid) - { - foreach (ValidationFailure validationFailure in validationResult.Errors) - { - cc.AddFailure(validationFailure); - } - } - }); + BooleanConditionNodeValidator = this.booleanConditionNodeValidator, + ComposedConditionNodeValidator = this.composedConditionNodeValidator, + CustomContext = cc, + DecimalConditionNodeValidator = this.decimalConditionNodeValidator, + IntegerConditionNodeValidator = this.integerConditionNodeValidator, + StringConditionNodeValidator = this.stringConditionNodeValidator + })); } } } \ No newline at end of file From f69e70634726e174527f7b7736bd82030a78aadd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Sat, 11 Apr 2020 02:57:07 +0100 Subject: [PATCH 4/9] [FEAT] Simplifying tests execution and coverage. --- appveyor.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index f467c7d7..ba4fbb90 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,10 +20,8 @@ build_script: - sh: dotnet pack src/Rules.Framework/Rules.Framework.csproj --no-build --include-symbols - sh: dotnet pack src/Rules.Framework.Providers.MongoDb/Rules.Framework.Providers.MongoDb.csproj --no-build --include-symbols test_script: - - sh: dotnet test tests/Rules.Framework.Tests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json" /p:CoverletOutput=../../coverage-outputs - - sh: dotnet test tests/Rules.Framework.Providers.MongoDb.Tests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json - - sh: dotnet test tests/Rules.Framework.IntegrationTests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json - - sh: dotnet test tests/Rules.Framework.Providers.MongoDb.IntegrationTests --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="opencover" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json + - sh: dotnet test rules-framework.sln --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json,opencover" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json -m:1 + - sh: rm coverage-outputs/coverage.json after_test: - sh: dotnet sonarscanner end /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 artifacts: From 94303a604da1589ede728f722ba4801d732490d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Sat, 11 Apr 2020 02:59:05 +0100 Subject: [PATCH 5/9] [FIX] Fix coverage output formats issue. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index ba4fbb90..4f00463b 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,7 +20,7 @@ build_script: - sh: dotnet pack src/Rules.Framework/Rules.Framework.csproj --no-build --include-symbols - sh: dotnet pack src/Rules.Framework.Providers.MongoDb/Rules.Framework.Providers.MongoDb.csproj --no-build --include-symbols test_script: - - sh: dotnet test rules-framework.sln --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json,opencover" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json -m:1 + - sh: dotnet test rules-framework.sln --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json%2copencover" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json -m:1 - sh: rm coverage-outputs/coverage.json after_test: - sh: dotnet sonarscanner end /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 From 47d0a9d474f3f67ace70451505db8920affd6546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Sat, 11 Apr 2020 03:05:27 +0100 Subject: [PATCH 6/9] [FIX] Fix coverage output directory. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 4f00463b..a7c8e920 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -20,7 +20,7 @@ build_script: - sh: dotnet pack src/Rules.Framework/Rules.Framework.csproj --no-build --include-symbols - sh: dotnet pack src/Rules.Framework.Providers.MongoDb/Rules.Framework.Providers.MongoDb.csproj --no-build --include-symbols test_script: - - sh: dotnet test rules-framework.sln --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json%2copencover" /p:CoverletOutput=../../coverage-outputs /p:MergeWith=../../coverage-outputs/coverage.json -m:1 + - sh: dotnet test rules-framework.sln --no-build /p:CollectCoverage=true /p:CoverletOutputFormat="json%2copencover" /p:CoverletOutput=../../coverage-outputs/ /p:MergeWith=../../coverage-outputs/coverage.json -m:1 - sh: rm coverage-outputs/coverage.json after_test: - sh: dotnet sonarscanner end /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 From b1124b0112f80e50beed2ad892ff75b304f8536d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Sat, 11 Apr 2020 03:24:39 +0100 Subject: [PATCH 7/9] [FEAT] Setting branch name for Sonar analysis. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index a7c8e920..a018b2a4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,7 @@ services: mongodb install: - sh: dotnet tool install --global dotnet-sonarscanner before_build: - - sh: dotnet sonarscanner begin /k:pikenikes_rules-framework /v:$APPVEYOR_BUILD_VERSION /o:pikenikes-github /d:sonar.host.url=https://sonarcloud.io /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 /d:sonar.coverage.exclusions="tests/*Tests/**" /d:sonar.cs.opencover.reportsPaths="*.opencover.xml" + - sh: dotnet sonarscanner begin /k:pikenikes_rules-framework /v:$APPVEYOR_BUILD_VERSION /o:pikenikes-github /d:sonar.host.url=https://sonarcloud.io /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 /d:sonar.coverage.exclusions="tests/*Tests/**" /d:sonar.cs.opencover.reportsPaths="*.opencover.xml" /d:sonar.branch.name:$APPVEYOR_REPO_BRANCH build_script: - sh: dotnet restore rules-framework.sln --no-cache - sh: dotnet build rules-framework.sln --no-restore From c1b5602215e11930fb42782958829c4b1d2cd333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Sat, 11 Apr 2020 03:25:58 +0100 Subject: [PATCH 8/9] [FIX] Setting branch name for Sonar analysis. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index a018b2a4..886558db 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,7 @@ services: mongodb install: - sh: dotnet tool install --global dotnet-sonarscanner before_build: - - sh: dotnet sonarscanner begin /k:pikenikes_rules-framework /v:$APPVEYOR_BUILD_VERSION /o:pikenikes-github /d:sonar.host.url=https://sonarcloud.io /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 /d:sonar.coverage.exclusions="tests/*Tests/**" /d:sonar.cs.opencover.reportsPaths="*.opencover.xml" /d:sonar.branch.name:$APPVEYOR_REPO_BRANCH + - sh: dotnet sonarscanner begin /k:pikenikes_rules-framework /v:$APPVEYOR_BUILD_VERSION /o:pikenikes-github /d:sonar.host.url=https://sonarcloud.io /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 /d:sonar.coverage.exclusions="tests/*Tests/**" /d:sonar.cs.opencover.reportsPaths="*.opencover.xml" /d:sonar.branch.name=$APPVEYOR_REPO_BRANCH build_script: - sh: dotnet restore rules-framework.sln --no-cache - sh: dotnet build rules-framework.sln --no-restore From 3e628a564cb9d15e14c63ca77aa4aac71c2c6272 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Sat, 11 Apr 2020 03:30:36 +0100 Subject: [PATCH 9/9] [FIX] Fixing coverage location for SonarQube. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 886558db..bed65e4c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,7 +13,7 @@ services: mongodb install: - sh: dotnet tool install --global dotnet-sonarscanner before_build: - - sh: dotnet sonarscanner begin /k:pikenikes_rules-framework /v:$APPVEYOR_BUILD_VERSION /o:pikenikes-github /d:sonar.host.url=https://sonarcloud.io /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 /d:sonar.coverage.exclusions="tests/*Tests/**" /d:sonar.cs.opencover.reportsPaths="*.opencover.xml" /d:sonar.branch.name=$APPVEYOR_REPO_BRANCH + - sh: dotnet sonarscanner begin /k:pikenikes_rules-framework /v:$APPVEYOR_BUILD_VERSION /o:pikenikes-github /d:sonar.host.url=https://sonarcloud.io /d:sonar.login=8f9e9412fb5ebcf5ea6f9a6b285b288e4645f866 /d:sonar.coverage.exclusions="tests/*Tests/**" /d:sonar.cs.opencover.reportsPaths="coverage-outputs/coverage.opencover.xml" /d:sonar.branch.name=$APPVEYOR_REPO_BRANCH build_script: - sh: dotnet restore rules-framework.sln --no-cache - sh: dotnet build rules-framework.sln --no-restore