From cf3b3c49191055dbbcf1d3e1b41f23a3235642ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Garc=C3=AAs?= Date: Tue, 8 Oct 2024 21:34:48 +0100 Subject: [PATCH] refactor!: replace conditions collection with dictionary (#172) --- .../Engine/RulesService.cs | 7 +-- src/Rules.Framework/Condition.cs | 34 -------------- src/Rules.Framework/Generic/IRulesEngine.cs | 4 +- src/Rules.Framework/Generic/RulesEngine.cs | 16 +++---- src/Rules.Framework/IRulesEngine.cs | 4 +- src/Rules.Framework/RulesEngine.cs | 23 +++++----- src/Rules.Framework/SearchArgs.cs | 7 ++- .../Validation/SearchArgsValidator.cs | 8 ++-- .../Scenarios/IScenarioData.cs | 3 +- .../Scenarios/Scenario6/Scenario6Data.cs | 4 +- .../Scenarios/Scenario7/Scenario7Data.cs | 8 ++-- .../Scenarios/Scenario8/Scenario8Data.cs | 23 +++++----- .../Scenarios/Scenario1/BodyMassIndexTests.cs | 3 +- .../Scenario2/CarInsuranceAdvisorTests.cs | 35 ++++++++------- .../BuildingSecuritySystemControlTests.cs | 25 ++++++----- .../Scenario4/DiscountCampaignTests.cs | 28 ++++++------ .../Scenarios/Scenario5/BestServerTests.cs | 21 ++++----- ...TexasHoldEmPokerSingleCombinationsTests.cs | 23 +++++----- .../RulesEngine/RulesEngineTestsBase.cs | 2 +- .../OperatorContainsManyToOneTests.cs | 8 ++-- .../RulesDeactivateAndActivateTests.cs | 6 +-- .../RulesMatching/RulesInSequenceTests.cs | 8 ++-- .../RulesMatching/RulesUpdateDateEndTests.cs | 6 +-- .../Scenario2/CarInsuranceAdvisorTests.cs | 19 ++++---- .../BuildingSecuritySystemControlTests.cs | 24 +++++----- .../Scenarios/Scenario5/BestServerTests.cs | 30 ++++++------- .../RulesEngine/RulesEngineTestsBase.cs | 2 +- .../RulesDeactivateAndActivateTests.cs | 6 +-- .../RulesMatching/RulesInSequenceTests.cs | 4 +- .../RulesMatching/RulesUpdateDateEndTests.cs | 2 +- .../Scenario2/CarInsuranceAdvisorTests.cs | 12 ++--- .../BuildingSecuritySystemControlTests.cs | 24 +++++----- .../Scenarios/Scenario5/BestServerTests.cs | 22 +++++----- tests/Rules.Framework.Tests/ConditionTests.cs | 24 ---------- .../Rules.Framework.Tests/RulesEngineTests.cs | 28 ++++++------ .../Validation/SearchArgsValidatorTests.cs | 44 +++++-------------- 36 files changed, 230 insertions(+), 317 deletions(-) delete mode 100644 src/Rules.Framework/Condition.cs delete mode 100644 tests/Rules.Framework.Tests/ConditionTests.cs diff --git a/samples/Rules.Framework.InMemory.Sample/Engine/RulesService.cs b/samples/Rules.Framework.InMemory.Sample/Engine/RulesService.cs index ce9d58f2..c37d6553 100644 --- a/samples/Rules.Framework.InMemory.Sample/Engine/RulesService.cs +++ b/samples/Rules.Framework.InMemory.Sample/Engine/RulesService.cs @@ -2,7 +2,6 @@ namespace Rules.Framework.InMemory.Sample.Engine { using System; using System.Collections.Generic; - using System.Linq; using System.Threading.Tasks; using global::Rules.Framework.InMemory.Sample.Enums; using global::Rules.Framework.InMemory.Sample.Exceptions; @@ -21,10 +20,6 @@ public async Task MatchOneAsync( DateTime dateTime, IDictionary conditions) { - var rulesConditions = (conditions is null) ? new Condition[] { } : - conditions.Select(x => new Condition(x.Key, x.Value)) - .ToArray(); - var rulesEngine = await rulesEngineProvider .GetRulesEngineAsync() @@ -32,7 +27,7 @@ public async Task MatchOneAsync( var match = await rulesEngine .MakeGeneric() - .MatchOneAsync(ruleset, dateTime, rulesConditions) + .MatchOneAsync(ruleset, dateTime, conditions) .ConfigureAwait(false); if (match is null) diff --git a/src/Rules.Framework/Condition.cs b/src/Rules.Framework/Condition.cs deleted file mode 100644 index 6931f564..00000000 --- a/src/Rules.Framework/Condition.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace Rules.Framework -{ - using System; - - /// - /// Defines a condition to filter rules. - /// - /// - /// The condition type that allows to filter rules based on a set of conditions. - /// - public class Condition - { - /// - /// Creates a Condition. - /// - /// The type of the condition. - /// The value of the condition. - public Condition(TConditionType type, object value) - { - this.Type = type; - this.Value = value; - } - - /// - /// Gets or sets the condition type. - /// - public TConditionType Type { get; set; } - - /// - /// Gets or sets the condition value. - /// - public object Value { get; set; } - } -} \ No newline at end of file diff --git a/src/Rules.Framework/Generic/IRulesEngine.cs b/src/Rules.Framework/Generic/IRulesEngine.cs index ac002252..34f0bfbb 100644 --- a/src/Rules.Framework/Generic/IRulesEngine.cs +++ b/src/Rules.Framework/Generic/IRulesEngine.cs @@ -101,7 +101,7 @@ public interface IRulesEngine /// All rules matching supplied conditions are returned. /// /// the matched rule; otherwise, null. - Task>> MatchManyAsync(TRuleset ruleset, DateTime matchDateTime, IEnumerable> conditions); + Task>> MatchManyAsync(TRuleset ruleset, DateTime matchDateTime, IDictionary conditions); /// /// Provides a rule match (if any) to the given at the specified @@ -121,7 +121,7 @@ public interface IRulesEngine /// /// /// the matched rule; otherwise, null. - Task> MatchOneAsync(TRuleset ruleset, DateTime matchDateTime, IEnumerable> conditions); + Task> MatchOneAsync(TRuleset ruleset, DateTime matchDateTime, IDictionary conditions); /// /// Searches for rules that match on supplied . diff --git a/src/Rules.Framework/Generic/RulesEngine.cs b/src/Rules.Framework/Generic/RulesEngine.cs index 03745ecc..5e130a65 100644 --- a/src/Rules.Framework/Generic/RulesEngine.cs +++ b/src/Rules.Framework/Generic/RulesEngine.cs @@ -87,15 +87,14 @@ public async Task> GetUniqueConditionsAsync(TRuleset rul public async Task>> MatchManyAsync( TRuleset ruleset, DateTime matchDateTime, - IEnumerable> conditions) + IDictionary conditions) { var rulesetAsString = GenericConversions.Convert(ruleset); + var conditionsConverted = conditions.ToDictionary(c => GenericConversions.Convert(c.Key), c => c.Value, StringComparer.Ordinal); var rules = await this.wrappedRulesEngine.MatchManyAsync( rulesetAsString, matchDateTime, - conditions - .Select(c => new Condition(GenericConversions.Convert(c.Type), c.Value)) - .ToArray()).ConfigureAwait(false); + conditionsConverted).ConfigureAwait(false); return rules.Select(r => r.ToGenericRule()).ToArray(); } @@ -104,15 +103,14 @@ public async Task>> MatchManyAsync( public async Task> MatchOneAsync( TRuleset ruleset, DateTime matchDateTime, - IEnumerable> conditions) + IDictionary conditions) { var rulesetAsString = GenericConversions.Convert(ruleset); + var conditionsConverted = conditions.ToDictionary(c => GenericConversions.Convert(c.Key), c => c.Value, StringComparer.Ordinal); var rule = await this.wrappedRulesEngine.MatchOneAsync( rulesetAsString, matchDateTime, - conditions - .Select(c => new Condition(GenericConversions.Convert(c.Type), c.Value)) - .ToArray()).ConfigureAwait(false); + conditionsConverted).ConfigureAwait(false); return rule?.ToGenericRule()!; } @@ -128,7 +126,7 @@ public async Task>> SearchAsync(SearchArg var rulesetAsString = GenericConversions.Convert(searchArgs.Ruleset); var searchArgsNew = new SearchArgs(rulesetAsString, searchArgs.DateBegin, searchArgs.DateEnd) { - Conditions = searchArgs.Conditions.Select(c => new Condition(GenericConversions.Convert(c.Type), c.Value)).ToArray(), + Conditions = searchArgs.Conditions.ToDictionary(c => GenericConversions.Convert(c.Key), c => c.Value, StringComparer.Ordinal), ExcludeRulesWithoutSearchConditions = searchArgs.ExcludeRulesWithoutSearchConditions, }; diff --git a/src/Rules.Framework/IRulesEngine.cs b/src/Rules.Framework/IRulesEngine.cs index 55fd4bc9..516faf93 100644 --- a/src/Rules.Framework/IRulesEngine.cs +++ b/src/Rules.Framework/IRulesEngine.cs @@ -96,7 +96,7 @@ public interface IRulesEngine /// All rules matching supplied conditions are returned. /// /// the matched rule; otherwise, null. - Task> MatchManyAsync(string ruleset, DateTime matchDateTime, IEnumerable> conditions); + Task> MatchManyAsync(string ruleset, DateTime matchDateTime, IDictionary conditions); /// /// Provides a rule match (if any) to the given at the specified @@ -116,7 +116,7 @@ public interface IRulesEngine /// /// /// the matched rule; otherwise, null. - Task MatchOneAsync(string ruleset, DateTime matchDateTime, IEnumerable> conditions); + Task MatchOneAsync(string ruleset, DateTime matchDateTime, IDictionary conditions); /// /// Searches for rules that match on supplied . diff --git a/src/Rules.Framework/RulesEngine.cs b/src/Rules.Framework/RulesEngine.cs index 90edaf8b..9a686e1a 100644 --- a/src/Rules.Framework/RulesEngine.cs +++ b/src/Rules.Framework/RulesEngine.cs @@ -132,7 +132,7 @@ public async Task> GetUniqueConditionsAsync(string ruleset, public async Task> MatchManyAsync( string ruleset, DateTime matchDateTime, - IEnumerable> conditions) + IDictionary conditions) { if (string.IsNullOrWhiteSpace(ruleset)) { @@ -152,16 +152,15 @@ public async Task> MatchManyAsync( DateEnd = matchDateTime, }; - var conditionsAsDictionary = conditions.ToDictionary(ks => ks.Type, ks => ks.Value, StringComparer.Ordinal); var orderedRules = await this.GetRulesOrderedAscendingAsync(getRulesArgs).ConfigureAwait(false); - return this.EvalAll(orderedRules, evaluationOptions, conditionsAsDictionary, active: true); + return this.EvalAll(orderedRules, evaluationOptions, conditions, active: true); } /// public async Task MatchOneAsync( string ruleset, DateTime matchDateTime, - IEnumerable> conditions) + IDictionary conditions) { if (string.IsNullOrWhiteSpace(ruleset)) { @@ -181,11 +180,10 @@ public async Task MatchOneAsync( DateEnd = matchDateTime, }; - var conditionsAsDictionary = conditions.ToDictionary(ks => ks.Type, ks => ks.Value); var orderedRules = await this.GetRulesOrderedAscendingAsync(getRulesArgs).ConfigureAwait(false); return this.Options.PriorityCriteria == PriorityCriterias.TopmostRuleWins - ? EvalOneTraverse(orderedRules, evaluationOptions, conditionsAsDictionary, active: true) - : EvalOneReverse(orderedRules, evaluationOptions, conditionsAsDictionary, active: true); + ? EvalOneTraverse(orderedRules, evaluationOptions, conditions, active: true) + : EvalOneReverse(orderedRules, evaluationOptions, conditions, active: true); } /// @@ -226,9 +224,8 @@ public async Task> SearchAsync(SearchArgs sear DateEnd = searchArgs.DateEnd, }; - var conditionsAsDictionary = searchArgs.Conditions.ToDictionary(ks => ks.Type, ks => ks.Value); var orderedRules = await this.GetRulesOrderedAscendingAsync(getRulesArgs).ConfigureAwait(false); - return this.EvalAll(orderedRules, evaluationOptions, conditionsAsDictionary, searchArgs.Active); + return this.EvalAll(orderedRules, evaluationOptions, searchArgs.Conditions, searchArgs.Active); } /// @@ -384,7 +381,7 @@ private async Task CreateRulesetInternalAsync(string ruleset) private IEnumerable EvalAll( List orderedRules, EvaluationOptions evaluationOptions, - Dictionary conditionsAsDictionary, + IDictionary conditionsAsDictionary, bool? active) { // Begins evaluation at the first element of the given list as parameter. Returns all @@ -404,7 +401,7 @@ private IEnumerable EvalAll( private Rule EvalOneReverse( List rules, EvaluationOptions evaluationOptions, - Dictionary conditionsAsDictionary, + IDictionary conditionsAsDictionary, bool? active) { // Begins evaluation at the last element of the given list as parameter. Returns the @@ -424,7 +421,7 @@ private Rule EvalOneReverse( private Rule EvalOneTraverse( List rules, EvaluationOptions evaluationOptions, - Dictionary conditionsAsDictionary, + IDictionary conditionsAsDictionary, bool? active) { // Begins evaluation at the first element of the given list as parameter. Returns the @@ -445,7 +442,7 @@ private Rule EvalOneTraverse( private bool EvalRule( Rule rule, EvaluationOptions evaluationOptions, - Dictionary conditionsAsDictionary, + IDictionary conditionsAsDictionary, bool? active) => rule.Active == active.GetValueOrDefault(defaultValue: true) && (rule.RootCondition == null || this.conditionsEvalEngine.Eval(rule.RootCondition, conditionsAsDictionary, evaluationOptions)); diff --git a/src/Rules.Framework/SearchArgs.cs b/src/Rules.Framework/SearchArgs.cs index 9319479f..f8157e2e 100644 --- a/src/Rules.Framework/SearchArgs.cs +++ b/src/Rules.Framework/SearchArgs.cs @@ -2,7 +2,6 @@ namespace Rules.Framework { using System; using System.Collections.Generic; - using System.Linq; /// /// The set of search arguments to find rules. @@ -19,7 +18,7 @@ public class SearchArgs /// The date end. public SearchArgs(TRuleset ruleset, DateTime dateBegin, DateTime dateEnd) { - this.Conditions = Enumerable.Empty>(); + this.Conditions = new Dictionary(); this.Ruleset = ruleset; this.DateBegin = dateBegin; this.DateEnd = dateEnd; @@ -36,7 +35,7 @@ public SearchArgs(TRuleset ruleset, DateTime dateBegin, DateTime dateEnd) /// The active status. public SearchArgs(TRuleset ruleset, DateTime dateBegin, DateTime dateEnd, bool active) { - this.Conditions = Enumerable.Empty>(); + this.Conditions = new Dictionary(); this.Ruleset = ruleset; this.DateBegin = dateBegin; this.DateEnd = dateEnd; @@ -54,7 +53,7 @@ public SearchArgs(TRuleset ruleset, DateTime dateBegin, DateTime dateEnd, bool a /// Gets or sets the search conditions. /// /// The conditions. - public IEnumerable> Conditions { get; set; } + public IDictionary Conditions { get; set; } /// /// Gets or sets the date begin. diff --git a/src/Rules.Framework/Validation/SearchArgsValidator.cs b/src/Rules.Framework/Validation/SearchArgsValidator.cs index aab05d66..0ecad407 100644 --- a/src/Rules.Framework/Validation/SearchArgsValidator.cs +++ b/src/Rules.Framework/Validation/SearchArgsValidator.cs @@ -35,15 +35,15 @@ public SearchArgsValidator() this.RuleForEach(sa => sa.Conditions) .ChildRules(conditionValidator => { - conditionValidator.RuleFor(condition => condition.Type) - .Must(conditionType => + conditionValidator.RuleFor(condition => condition.Key) + .Must(conditionKey => { - if (this.conditionTypeRuntimeType.IsClass && conditionType is null) + if (this.conditionTypeRuntimeType.IsClass && conditionKey is null) { return false; } - if (this.conditionTypeRuntimeType.IsEnum && !Enum.IsDefined(this.conditionTypeRuntimeType, conditionType)) + if (this.conditionTypeRuntimeType.IsEnum && !Enum.IsDefined(this.conditionTypeRuntimeType, conditionKey)) { return false; } diff --git a/tests/Rules.Framework.IntegrationTests.Common/Scenarios/IScenarioData.cs b/tests/Rules.Framework.IntegrationTests.Common/Scenarios/IScenarioData.cs index 7d43d3a3..ef924c41 100644 --- a/tests/Rules.Framework.IntegrationTests.Common/Scenarios/IScenarioData.cs +++ b/tests/Rules.Framework.IntegrationTests.Common/Scenarios/IScenarioData.cs @@ -2,12 +2,11 @@ namespace Rules.Framework.BenchmarkTests.Tests { using System; using System.Collections.Generic; - using Rules.Framework; using Rules.Framework.Generic; public interface IScenarioData { - IEnumerable> Conditions { get; } + IDictionary Conditions { get; } DateTime MatchDate { get; } diff --git a/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario6/Scenario6Data.cs b/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario6/Scenario6Data.cs index 11c2366f..13e0c88d 100644 --- a/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario6/Scenario6Data.cs +++ b/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario6/Scenario6Data.cs @@ -8,9 +8,9 @@ namespace Rules.Framework.BenchmarkTests.Tests.Benchmark1 public class Scenario6Data : IScenarioData { - public IEnumerable> Conditions => new[] + public IDictionary Conditions => new Dictionary { - new Condition(ConditionNames.StringCondition, "Let's benchmark this!") + { ConditionNames.StringCondition, "Let's benchmark this!" }, }; public DateTime MatchDate => DateTime.Parse("2022-10-01"); diff --git a/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario7/Scenario7Data.cs b/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario7/Scenario7Data.cs index f0dfe440..6cfc0a5c 100644 --- a/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario7/Scenario7Data.cs +++ b/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario7/Scenario7Data.cs @@ -7,11 +7,11 @@ namespace Rules.Framework.BenchmarkTests.Tests.Benchmark2 public class Scenario7Data : IScenarioData { - public IEnumerable> Conditions => new[] + public IDictionary Conditions => new Dictionary { - new Condition(ConditionNames.Artist, "Queen"), - new Condition(ConditionNames.Lyrics, "Is this the real life?\nIs this just fantasy?\nCaught in a landside,\nNo escape from reality" ), - new Condition(ConditionNames.ReleaseYear, 1975 ) + { ConditionNames.Artist, "Queen" }, + { ConditionNames.Lyrics, "Is this the real life?\nIs this just fantasy?\nCaught in a landside,\nNo escape from reality" }, + { ConditionNames.ReleaseYear, 1975 }, }; public DateTime MatchDate => DateTime.Parse("2022-11-01"); diff --git a/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario8/Scenario8Data.cs b/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario8/Scenario8Data.cs index d6991d54..354549be 100644 --- a/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario8/Scenario8Data.cs +++ b/tests/Rules.Framework.IntegrationTests.Common/Scenarios/Scenario8/Scenario8Data.cs @@ -3,23 +3,22 @@ namespace Rules.Framework.BenchmarkTests.Tests.Benchmark3 using System; using System.Collections.Generic; using System.Linq; - using Rules.Framework; using Rules.Framework.Generic; public partial class Scenario8Data : IScenarioData { - public IEnumerable> Conditions => new[] + public IDictionary Conditions => new Dictionary { - new Condition(PokerConditions.NumberOfKings, 1), - new Condition(PokerConditions.NumberOfQueens, 1 ), - new Condition(PokerConditions.NumberOfJacks, 1), - new Condition(PokerConditions.NumberOfTens, 1 ), - new Condition(PokerConditions.NumberOfNines, 1 ), - new Condition(PokerConditions.KingOfClubs, true ), - new Condition(PokerConditions.QueenOfDiamonds, true ), - new Condition(PokerConditions.JackOfClubs, true ), - new Condition(PokerConditions.TenOfHearts, true ), - new Condition(PokerConditions.NineOfSpades, true ), + { PokerConditions.NumberOfKings, 1 }, + { PokerConditions.NumberOfQueens, 1 }, + { PokerConditions.NumberOfJacks, 1 }, + { PokerConditions.NumberOfTens, 1 }, + { PokerConditions.NumberOfNines, 1 }, + { PokerConditions.KingOfClubs, true }, + { PokerConditions.QueenOfDiamonds, true }, + { PokerConditions.JackOfClubs, true }, + { PokerConditions.TenOfHearts, true }, + { PokerConditions.NineOfSpades, true }, }; public DateTime MatchDate => DateTime.Parse("2022-12-01"); diff --git a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario1/BodyMassIndexTests.cs b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario1/BodyMassIndexTests.cs index caff919d..4935dde7 100644 --- a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario1/BodyMassIndexTests.cs +++ b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario1/BodyMassIndexTests.cs @@ -1,6 +1,7 @@ namespace Rules.Framework.IntegrationTests.Scenarios.Scenario1 { using System; + using System.Collections.Generic; using System.Threading.Tasks; using FluentAssertions; using Microsoft.Extensions.DependencyInjection; @@ -214,7 +215,7 @@ public async Task BodyMassIndex_NoConditions_ReturnsDefaultFormula(bool enableCo var expectedFormulaValue = "weight / (height ^ 2)"; const Scenario1RulesetNames expectedContent = Scenario1RulesetNames.BodyMassIndexFormula; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = Array.Empty>(); + var expectedConditions = new Dictionary(); var serviceProvider = new ServiceCollection() .AddInMemoryRulesDataSource(ServiceLifetime.Singleton) diff --git a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs index e597e0b2..5b6bf362 100644 --- a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs +++ b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs @@ -1,6 +1,7 @@ namespace Rules.Framework.IntegrationTests.Scenarios.Scenario2 { using System; + using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FluentAssertions; @@ -23,11 +24,11 @@ public async Task GetCarInsuranceAdvice_ClaimDescriptionContionsAlcoholOrDrugs_R var expected = CarInsuranceAdvices.PerformInvestigation; const CarInsuranceRulesetNames expectedRuleset = CarInsuranceRulesetNames.CarInsuranceAdvice; var expectedMatchDate = new DateTime(2020, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts,800.00000m), - new Condition(CarInsuranceConditionNames.RepairCostsCommercialValueRate,23.45602m), - new Condition(CarInsuranceConditionNames.ClaimDescription,"Driver A claims that Driver B appeared to be under the effect of alcohol.") + { CarInsuranceConditionNames.RepairCosts, 800.00000m }, + { CarInsuranceConditionNames.RepairCostsCommercialValueRate, 23.45602m }, + { CarInsuranceConditionNames.ClaimDescription, "Driver A claims that Driver B appeared to be under the effect of alcohol." }, }; var serviceProvider = new ServiceCollection() @@ -79,10 +80,10 @@ public async Task GetCarInsuranceAdvice_RepairCostsNotWorthIt_ReturnsRefusePayme var expected = CarInsuranceAdvices.RefusePaymentPerFranchise; const CarInsuranceRulesetNames expectedContent = CarInsuranceRulesetNames.CarInsuranceAdvice; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts,800.00000m), - new Condition(CarInsuranceConditionNames.RepairCostsCommercialValueRate,23.45602m) + { CarInsuranceConditionNames.RepairCosts,800.00000m }, + { CarInsuranceConditionNames.RepairCostsCommercialValueRate,23.45602m }, }; var serviceProvider = new ServiceCollection() @@ -121,12 +122,12 @@ public async Task GetCarInsuranceAdvice_SearchForRulesExcludingRulesWithoutSearc var expectedMatchDate = new DateTime(2018, 06, 01); var searchArgs = new SearchArgs(expectedContent, expectedMatchDate, expectedMatchDate) { - Conditions = new[] + Conditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts, 800.00000m), - new Condition(CarInsuranceConditionNames.RepairCostsCommercialValueRate, 86.33m) + { CarInsuranceConditionNames.RepairCosts, 800.00000m }, + { CarInsuranceConditionNames.RepairCostsCommercialValueRate, 86.33m }, }, - ExcludeRulesWithoutSearchConditions = true + ExcludeRulesWithoutSearchConditions = true, }; var serviceProvider = new ServiceCollection() @@ -164,11 +165,11 @@ public async Task GetCarInsuranceAdvice_SearchForRulesWithRepairCostsGreaterThan var expectedMatchDate = new DateTime(2018, 06, 01); var searchArgs = new SearchArgs(expectedContent, expectedMatchDate, expectedMatchDate) { - Conditions = new[] + Conditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts, 1200.00000m) + { CarInsuranceConditionNames.RepairCosts, 1200.00000m }, }, - ExcludeRulesWithoutSearchConditions = false + ExcludeRulesWithoutSearchConditions = false, }; var serviceProvider = new ServiceCollection() @@ -206,10 +207,10 @@ public async Task GetCarInsuranceAdvice_UpdatesRuleAndAddsNewOneAndEvaluates_Ret // Arrange const CarInsuranceRulesetNames expectedContent = CarInsuranceRulesetNames.CarInsuranceAdvice; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts,800.00000m), - new Condition(CarInsuranceConditionNames.RepairCostsCommercialValueRate,23.45602m) + { CarInsuranceConditionNames.RepairCosts,800.00000m }, + { CarInsuranceConditionNames.RepairCostsCommercialValueRate,23.45602m }, }; var serviceProvider = new ServiceCollection() diff --git a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs index f4961693..78c92a69 100644 --- a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs +++ b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs @@ -1,6 +1,7 @@ namespace Rules.Framework.IntegrationTests.Scenarios.Scenario3 { using System; + using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FluentAssertions; @@ -19,11 +20,11 @@ public async Task BuildingSecuritySystem_FireScenario_ReturnsActionsToTrigger() const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.FireSystem; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(SecuritySystemConditions.TemperatureCelsius,100.0m), - new Condition(SecuritySystemConditions.SmokeRate,55), - new Condition(SecuritySystemConditions.PowerStatus,"Online") + { SecuritySystemConditions.TemperatureCelsius, 100.0m }, + { SecuritySystemConditions.SmokeRate, 55 }, + { SecuritySystemConditions.PowerStatus, "Online" }, }; var serviceProvider = new ServiceCollection() @@ -58,11 +59,11 @@ public async Task BuildingSecuritySystem_PowerFailureScenario_ReturnsActionsToTr const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.PowerSystem; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(SecuritySystemConditions.TemperatureCelsius,100.0m), - new Condition(SecuritySystemConditions.SmokeRate,55), - new Condition(SecuritySystemConditions.PowerStatus,"Offline") + { SecuritySystemConditions.TemperatureCelsius, 100.0m }, + { SecuritySystemConditions.SmokeRate, 55 }, + { SecuritySystemConditions.PowerStatus, "Offline" }, }; var serviceProvider = new ServiceCollection() @@ -96,11 +97,11 @@ public async Task BuildingSecuritySystem_PowerShutdownScenario_ReturnsActionsToT const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.PowerSystem; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(SecuritySystemConditions.TemperatureCelsius,100.0m), - new Condition(SecuritySystemConditions.SmokeRate,55), - new Condition(SecuritySystemConditions.PowerStatus,"Shutdown") + { SecuritySystemConditions.TemperatureCelsius,100.0m }, + { SecuritySystemConditions.SmokeRate,55 }, + { SecuritySystemConditions.PowerStatus,"Shutdown" }, }; var serviceProvider = new ServiceCollection() diff --git a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario4/DiscountCampaignTests.cs b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario4/DiscountCampaignTests.cs index 5885a80c..c35fe02e 100644 --- a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario4/DiscountCampaignTests.cs +++ b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario4/DiscountCampaignTests.cs @@ -70,10 +70,10 @@ public async Task DiscountsWeekend_Adding15PercentRulePerBrandAndEvaluatingOneOf // Act 3 - Evaluate new rule with "in" operator var matchDateTime = DateTime.Parse("2021-05-29T12:34:52Z"); - var conditions = new[] + var conditions = new Dictionary { - new Condition(DiscountConditions.ProductBrand,"ASUS"), - new Condition(DiscountConditions.ProductRecommendedRetailPrice,1249.90m) + { DiscountConditions.ProductBrand,"ASUS" }, + { DiscountConditions.ProductRecommendedRetailPrice,1249.90m }, }; var actual = await genericRulesEngine.MatchOneAsync(DiscountConfigurations.DiscountCampaigns, matchDateTime, conditions); @@ -134,11 +134,11 @@ public async Task DiscountsWeekend_Adding20PercentRulePerProductTierAndEvaluatin // Act 3 - Evaluate new rule with "in" operator var matchDateTime = DateTime.Parse("2021-05-29T12:34:52Z"); - var conditions = new[] + var conditions = new Dictionary { - new Condition(DiscountConditions.ProductBrand, "ASUS"), - new Condition(DiscountConditions.ProductTier, 1), - new Condition(DiscountConditions.ProductRecommendedRetailPrice, 1249.90m) + { DiscountConditions.ProductBrand, "ASUS" }, + { DiscountConditions.ProductTier, 1 }, + { DiscountConditions.ProductRecommendedRetailPrice, 1249.90m }, }; var actual = await genericRulesEngine.MatchOneAsync(DiscountConfigurations.DiscountCampaigns, matchDateTime, conditions); @@ -193,9 +193,9 @@ public async Task DiscountsWeekend_Adding5PercentRuleWithNotContainsTestConditio // Act 3 - Evaluate new rule with "not contains" operator var matchDateTime = DateTime.Parse("2021-05-29T12:34:52Z"); - var conditions = new[] + var conditions = new Dictionary { - new Condition(DiscountConditions.CustomerEmail, "user12345@somewhere.com") + { DiscountConditions.CustomerEmail, "user12345@somewhere.com" }, }; var actual = await genericRulesEngine.MatchOneAsync(DiscountConfigurations.DiscountCampaigns, matchDateTime, conditions); @@ -250,9 +250,9 @@ public async Task DiscountsWeekend_AddingRuleWithNullTestConditionAndInputWithMa // Act 3 - Evaluate new rule with "in" operator var matchDateTime = DateTime.Parse("2021-05-29T12:34:52Z"); - var conditions = new[] + var conditions = new Dictionary { - new Condition(DiscountConditions.ProductColor, ProductColor.Blue.ToString()) + { DiscountConditions.ProductColor, ProductColor.Blue.ToString() }, }; var actual = await genericRulesEngine.MatchOneAsync(DiscountConfigurations.DiscountCampaigns, matchDateTime, conditions); @@ -307,7 +307,7 @@ public async Task DiscountsWeekend_AddingRuleWithNullTestConditionAndInputWithou // Act 3 - Evaluate new rule with "in" operator var matchDateTime = DateTime.Parse("2021-05-29T12:34:52Z"); - var conditions = new List>(); + var conditions = new Dictionary(); var actual = await genericRulesEngine.MatchOneAsync(DiscountConfigurations.DiscountCampaigns, matchDateTime, conditions); @@ -360,9 +360,9 @@ public async Task DiscountsWeekend_AddingRuleWithNullTestConditionAndInputWithou // Act 3 - Evaluate new rule with "in" operator var matchDateTime = DateTime.Parse("2021-05-29T12:34:52Z"); - var conditions = new[] + var conditions = new Dictionary { - new Condition(DiscountConditions.ProductColor, ProductColor.White.ToString()) + { DiscountConditions.ProductColor, ProductColor.White.ToString() }, }; var actual = await genericRulesEngine.MatchOneAsync(DiscountConfigurations.DiscountCampaigns, matchDateTime, conditions); diff --git a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs index 824e6fe7..cd545839 100644 --- a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs +++ b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs @@ -1,6 +1,7 @@ namespace Rules.Framework.IntegrationTests.Scenarios.Scenario5 { using System; + using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FluentAssertions; @@ -79,12 +80,12 @@ public async Task BestServer_DeactivatingBestServerTop5_ReturnsBestServerDefault // Act 5 - Evaluate new rule with "in" operator var matchDateTime = DateTime.Parse("2021-05-29T12:34:52Z"); - var conditions = new[] + var conditions = new Dictionary { - new Condition(BestServerConditions.Price, 100), - new Condition(BestServerConditions.Memory, 12), - new Condition(BestServerConditions.StoragePartionable, true), - new Condition(BestServerConditions.Brand, "AMD") + { BestServerConditions.Price, 100 }, + { BestServerConditions.Memory, 12 }, + { BestServerConditions.StoragePartionable, true }, + { BestServerConditions.Brand, "AMD" }, }; var actual = await genericRulesEngine.MatchOneAsync(BestServerConfigurations.BestServerEvaluation, matchDateTime, conditions); @@ -178,12 +179,12 @@ public async Task BestServer_UpdatingBestServerTop5_ReturnsBestServerDefault() // Act 5 - Evaluate new rule with "in" operator var matchDateTime = DateTime.Parse("2021-05-29T12:34:52Z"); - var conditions = new[] + var conditions = new Dictionary { - new Condition(BestServerConditions.Price,100), - new Condition(BestServerConditions.Memory,12), - new Condition(BestServerConditions.StoragePartionable,true), - new Condition(BestServerConditions.Brand,"AMD") + { BestServerConditions.Price, 100 }, + { BestServerConditions.Memory, 12 }, + { BestServerConditions.StoragePartionable, true }, + { BestServerConditions.Brand, "AMD" }, }; var actual = await genericRulesEngine.MatchOneAsync(BestServerConfigurations.BestServerEvaluation, matchDateTime, conditions); diff --git a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario8/TexasHoldEmPokerSingleCombinationsTests.cs b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario8/TexasHoldEmPokerSingleCombinationsTests.cs index 400c269c..b2f448d1 100644 --- a/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario8/TexasHoldEmPokerSingleCombinationsTests.cs +++ b/tests/Rules.Framework.IntegrationTests/Scenarios/Scenario8/TexasHoldEmPokerSingleCombinationsTests.cs @@ -1,6 +1,7 @@ namespace Rules.Framework.IntegrationTests.Scenarios.Scenario8 { using System; + using System.Collections.Generic; using System.Threading.Tasks; using FluentAssertions; using Rules.Framework.BenchmarkTests.Tests.Benchmark3; @@ -16,18 +17,18 @@ public async Task PokerCombinations_Given_EvaluatesStraightCombination(bool enab { // Arrange var matchDate = new DateTime(2023, 1, 1); - var conditions = new[] + var conditions = new Dictionary { - new Condition(PokerConditions.NumberOfKings, 1), - new Condition(PokerConditions.NumberOfQueens, 1), - new Condition(PokerConditions.NumberOfJacks, 1 ), - new Condition(PokerConditions.NumberOfTens, 1 ), - new Condition(PokerConditions.NumberOfNines, 1), - new Condition(PokerConditions.KingOfClubs, true), - new Condition(PokerConditions.QueenOfDiamonds, true), - new Condition(PokerConditions.JackOfClubs, true), - new Condition(PokerConditions.TenOfHearts, true), - new Condition(PokerConditions.NineOfSpades, true), + { PokerConditions.NumberOfKings, 1 }, + { PokerConditions.NumberOfQueens, 1 }, + { PokerConditions.NumberOfJacks, 1 }, + { PokerConditions.NumberOfTens, 1 }, + { PokerConditions.NumberOfNines, 1 }, + { PokerConditions.KingOfClubs, true }, + { PokerConditions.QueenOfDiamonds, true }, + { PokerConditions.JackOfClubs, true }, + { PokerConditions.TenOfHearts, true }, + { PokerConditions.NineOfSpades, true }, }; var rulesEngine = RulesEngineBuilder.CreateRulesEngine() diff --git a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesEngineTestsBase.cs b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesEngineTestsBase.cs index d467e676..90e153df 100644 --- a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesEngineTestsBase.cs +++ b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesEngineTestsBase.cs @@ -81,7 +81,7 @@ protected async Task DeactivateRuleAsync(Rule> MatchOneAsync( DateTime matchDate, - Condition[] conditions, + IDictionary conditions, bool compiled) { if (compiled) diff --git a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/OperatorContainsManyToOneTests.cs b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/OperatorContainsManyToOneTests.cs index 8c6c9208..33035b00 100644 --- a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/OperatorContainsManyToOneTests.cs +++ b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/OperatorContainsManyToOneTests.cs @@ -42,9 +42,9 @@ public OperatorContainsManyToOneTests() public async Task RulesEngine_GivenConditionType1WithArrayOfStringsContainingCat_MatchesExpectedRule(bool compiled) { // Arrange - var emptyConditions = new[] + var emptyConditions = new Dictionary { - new Condition(ConditionNames.Condition1, new[]{ "Dog", "Fish", "Cat", "Spider", "Mockingbird", }) + { ConditionNames.Condition1, new[]{ "Dog", "Fish", "Cat", "Spider", "Mockingbird", } }, }; var matchDate = UtcDate("2020-01-02Z"); @@ -61,9 +61,9 @@ public async Task RulesEngine_GivenConditionType1WithArrayOfStringsContainingCat public async Task RulesEngine_GivenConditionType1WithArrayOfStringsNotContainingCat_MatchesOtherRule(bool compiled) { // Arrange - var emptyConditions = new[] + var emptyConditions = new Dictionary { - new Condition(ConditionNames.Condition1, new[]{ "Dog", "Fish", "Bat", "Spider", "Mockingbird", }) + { ConditionNames.Condition1, new[]{ "Dog", "Fish", "Bat", "Spider", "Mockingbird", } }, }; var matchDate = UtcDate("2020-01-02Z"); diff --git a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesDeactivateAndActivateTests.cs b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesDeactivateAndActivateTests.cs index b9546beb..d8851651 100644 --- a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesDeactivateAndActivateTests.cs +++ b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesDeactivateAndActivateTests.cs @@ -45,7 +45,7 @@ public RulesDeactivateAndActivateTests() : base(testRuleset) public async Task RulesEngine_DeactivateThenActivateRule_Validations(bool compiled) { // Arrange - var emptyConditions = Array.Empty>(); + var emptyConditions = new Dictionary(); var matchDate = new DateTime(2020, 01, 02); // Act 1: Deactivate the rule @@ -71,8 +71,8 @@ private IEnumerable CreateTestRules() { var ruleSpecs = new List { - new RuleSpecification(rule1, RuleAddPriorityOption.ByPriorityNumber(1)), - new RuleSpecification(rule2, RuleAddPriorityOption.ByPriorityNumber(2)) + new(rule1, RuleAddPriorityOption.ByPriorityNumber(1)), + new(rule2, RuleAddPriorityOption.ByPriorityNumber(2)) }; return ruleSpecs; diff --git a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesInSequenceTests.cs b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesInSequenceTests.cs index bb177a41..ed66dbc8 100644 --- a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesInSequenceTests.cs +++ b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesInSequenceTests.cs @@ -21,7 +21,7 @@ public class RulesInSequenceTests : RulesEngineTestsBase public RulesInSequenceTests() : base(testRuleset) { - this.AddRules(this.CreateTestRules()); + this.AddRules(CreateTestRules()); } public static IEnumerable FailureCases => @@ -51,7 +51,7 @@ public RulesInSequenceTests() : base(testRuleset) public async Task RulesEngine_MatchOneAsync_OutsideRulesPeriod_Failure(DateTime matchDate, bool compiled) { // Arrange - var emptyConditions = Array.Empty>(); + var emptyConditions = new Dictionary(); // Act var actualMatch = await this.MatchOneAsync(matchDate, emptyConditions, compiled); @@ -65,7 +65,7 @@ public async Task RulesEngine_MatchOneAsync_OutsideRulesPeriod_Failure(DateTime public async Task RulesEngine_MatchOneAsync_WithRulesInSequence_ReturnsCorrectRule(DateTime matchDate, string expectedName, string expectedValue, bool compiled) { // Arrange - var emptyConditions = Array.Empty>(); + var emptyConditions = new Dictionary(); // Act var actualMatch = await this.MatchOneAsync(matchDate, emptyConditions, compiled); @@ -76,7 +76,7 @@ public async Task RulesEngine_MatchOneAsync_WithRulesInSequence_ReturnsCorrectRu Assert.Equal(expectedValue, actualMatch.ContentContainer.GetContentAs()); } - private IEnumerable CreateTestRules() + private static List CreateTestRules() { var ruleSpecs = new List(); diff --git a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesUpdateDateEndTests.cs b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesUpdateDateEndTests.cs index 8e4a2a35..1835d713 100644 --- a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesUpdateDateEndTests.cs +++ b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Features/RulesEngine/RulesMatching/RulesUpdateDateEndTests.cs @@ -54,7 +54,7 @@ public RulesUpdateDateEndTests() : base(testRuleset) public async Task RulesEngine_UpdateRuleDateEnd_Validations(DateTime dateEnd, bool success, bool compiled) { // Arrange - var emptyConditions = Array.Empty>(); + var emptyConditions = new Dictionary(); var matchDate = new DateTime(2020, 01, 02); // Act @@ -75,8 +75,8 @@ private IEnumerable CreateTestRules() { var ruleSpecs = new List { - new RuleSpecification(rule1, RuleAddPriorityOption.ByPriorityNumber(1)), - new RuleSpecification(rule2, RuleAddPriorityOption.ByPriorityNumber(2)) + new(rule1, RuleAddPriorityOption.ByPriorityNumber(1)), + new(rule2, RuleAddPriorityOption.ByPriorityNumber(2)) }; return ruleSpecs; diff --git a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs index aa1caa59..120f1674 100644 --- a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs +++ b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs @@ -1,6 +1,7 @@ namespace Rules.Framework.Providers.InMemory.IntegrationTests.Scenarios.Scenario2 { using System; + using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using FluentAssertions; @@ -32,10 +33,10 @@ public async Task GetCarInsuranceAdvice_RepairCostsNotWorthIt_ReturnsPayOldCar() var expected = CarInsuranceAdvices.PayOldCar; const CarInsuranceRulesetNames expectedRuleset = CarInsuranceRulesetNames.CarInsuranceAdvice; var expectedMatchDate = new DateTime(2016, 06, 01, 20, 23, 23); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts, 0.0m), - new Condition(CarInsuranceConditionNames.RepairCostsCommercialValueRate, 0.0m) + { CarInsuranceConditionNames.RepairCosts, 0.0m }, + { CarInsuranceConditionNames.RepairCostsCommercialValueRate, 0.0m }, }; var serviceDescriptors = new ServiceCollection(); @@ -67,10 +68,10 @@ public async Task GetCarInsuranceAdvice_RepairCostsNotWorthIt_ReturnsRefusePayme var expected = CarInsuranceAdvices.RefusePaymentPerFranchise; const CarInsuranceRulesetNames expectedRuleset = CarInsuranceRulesetNames.CarInsuranceAdvice; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts, 800.00000m), - new Condition(CarInsuranceConditionNames.RepairCostsCommercialValueRate, 23.45602m) + { CarInsuranceConditionNames.RepairCosts, 800.00000m }, + { CarInsuranceConditionNames.RepairCostsCommercialValueRate, 23.45602m }, }; var serviceDescriptors = new ServiceCollection(); @@ -101,10 +102,10 @@ public async Task GetCarInsuranceAdvice_UpdatesRuleAndAddsNewOneAndEvaluates_Ret // Arrange const CarInsuranceRulesetNames expectedRuleset = CarInsuranceRulesetNames.CarInsuranceAdvice; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts, 800.00000m), - new Condition(CarInsuranceConditionNames.RepairCostsCommercialValueRate, 23.45602m) + { CarInsuranceConditionNames.RepairCosts, 800.00000m }, + { CarInsuranceConditionNames.RepairCostsCommercialValueRate, 23.45602m }, }; var serviceDescriptors = new ServiceCollection(); diff --git a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs index e9014fef..b5c52113 100644 --- a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs +++ b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs @@ -36,11 +36,11 @@ public async Task BuildingSecuritySystem_FireScenario_ReturnsActionsToTrigger(bo const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.FireSystem; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(SecuritySystemConditions.TemperatureCelsius, 100.0m), - new Condition(SecuritySystemConditions.SmokeRate, 55.0m), - new Condition(SecuritySystemConditions.PowerStatus, "Online") + { SecuritySystemConditions.TemperatureCelsius, 100.0m }, + { SecuritySystemConditions.SmokeRate, 55.0m }, + { SecuritySystemConditions.PowerStatus, "Online" }, }; IServiceCollection serviceDescriptors = new ServiceCollection(); @@ -79,11 +79,11 @@ public async Task BuildingSecuritySystem_PowerFailureScenario_ReturnsActionsToTr const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.PowerSystem; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(SecuritySystemConditions.TemperatureCelsius, 100.0m), - new Condition(SecuritySystemConditions.SmokeRate, 55.0m), - new Condition(SecuritySystemConditions.PowerStatus, "Offline") + { SecuritySystemConditions.TemperatureCelsius, 100.0m }, + { SecuritySystemConditions.SmokeRate, 55.0m }, + { SecuritySystemConditions.PowerStatus, "Offline" }, }; IServiceCollection serviceDescriptors = new ServiceCollection(); @@ -121,11 +121,11 @@ public async Task BuildingSecuritySystem_PowerShutdownScenario_ReturnsActionsToT const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.PowerSystem; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(SecuritySystemConditions.TemperatureCelsius, 100.0m), - new Condition(SecuritySystemConditions.SmokeRate, 55.0m), - new Condition(SecuritySystemConditions.PowerStatus, "Shutdown") + { SecuritySystemConditions.TemperatureCelsius, 100.0m }, + { SecuritySystemConditions.SmokeRate, 55.0m }, + { SecuritySystemConditions.PowerStatus, "Shutdown" }, }; IServiceCollection serviceDescriptors = new ServiceCollection(); diff --git a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs index 1c927998..738e6b9a 100644 --- a/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs +++ b/tests/Rules.Framework.Providers.InMemory.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs @@ -15,33 +15,33 @@ public class BestServerTests { new object[] { - new[] + new Dictionary { - new Condition(BestServerConditions.Price,100), - new Condition(BestServerConditions.Memory,12), - new Condition(BestServerConditions.StoragePartionable,true), - new Condition(BestServerConditions.Brand,"AMD") + { BestServerConditions.Price,100 }, + { BestServerConditions.Memory,12 }, + { BestServerConditions.StoragePartionable,true }, + { BestServerConditions.Brand,"AMD" }, }, "Best Server Top5" }, new object[] { - new[] + new Dictionary { - new Condition(BestServerConditions.Price,110), - new Condition(BestServerConditions.Memory,12), - new Condition(BestServerConditions.StoragePartionable,true), - new Condition(BestServerConditions.Brand,"AMD") + { BestServerConditions.Price,110 }, + { BestServerConditions.Memory,12 }, + { BestServerConditions.StoragePartionable,true }, + { BestServerConditions.Brand,"AMD" }, }, "Best Server Default" }, new object[] { - new[] + new Dictionary { - new Condition(BestServerConditions.Price,100), - new Condition(BestServerConditions.Memory,12), - new Condition(BestServerConditions.StoragePartionable,true), + { BestServerConditions.Price,100 }, + { BestServerConditions.Memory,12 }, + { BestServerConditions.StoragePartionable,true }, }, "Best Server Default" } @@ -49,7 +49,7 @@ public class BestServerTests [Theory] [MemberData(nameof(DataTest))] - public async Task BestServer_InEvaluation(IEnumerable> conditions, string expectedRuleName) + public async Task BestServer_InEvaluation(Dictionary conditions, string expectedRuleName) { // Arrange var rulesEngine = RulesEngineBuilder.CreateRulesEngine() diff --git a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesEngineTestsBase.cs b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesEngineTestsBase.cs index 3208ea23..68f59a3a 100644 --- a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesEngineTestsBase.cs +++ b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesEngineTestsBase.cs @@ -55,7 +55,7 @@ protected void AddRules(IEnumerable ruleSpecifications) protected async Task> MatchOneAsync( DateTime matchDate, - Condition[] conditions) => await RulesEngine.MatchOneAsync( + Dictionary conditions) => await RulesEngine.MatchOneAsync( TestRuleset, matchDate, conditions); diff --git a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesDeactivateAndActivateTests.cs b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesDeactivateAndActivateTests.cs index 72f02aed..614266ec 100644 --- a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesDeactivateAndActivateTests.cs +++ b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesDeactivateAndActivateTests.cs @@ -43,7 +43,7 @@ public RulesDeactivateAndActivateTests() : base(testRuleset) public async Task RulesEngine_DeactivateThenActivateRule_Validations() { // Arrange - var emptyConditions = Array.Empty>(); + var emptyConditions = new Dictionary(); var matchDate = new DateTime(2020, 01, 02); // Act 1: Deactivate the rule @@ -69,8 +69,8 @@ private IEnumerable CreateTestRules() { var ruleSpecs = new List { - new RuleSpecification(rule1, RuleAddPriorityOption.ByPriorityNumber(1)), - new RuleSpecification(rule2, RuleAddPriorityOption.ByPriorityNumber(2)) + new(rule1, RuleAddPriorityOption.ByPriorityNumber(1)), + new(rule2, RuleAddPriorityOption.ByPriorityNumber(2)) }; return ruleSpecs; diff --git a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesInSequenceTests.cs b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesInSequenceTests.cs index f815b7a9..5c540443 100644 --- a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesInSequenceTests.cs +++ b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesInSequenceTests.cs @@ -44,7 +44,7 @@ public RulesInSequenceTests() : base(testRuleset) public async Task RulesEngine_MatchOneAsync_OutsideRulesPeriod_Failure(DateTime matchDate) { // Arrange - var emptyConditions = Array.Empty>(); + var emptyConditions = new Dictionary(); // Act var actualMatch = await this.MatchOneAsync(matchDate, emptyConditions); @@ -58,7 +58,7 @@ public async Task RulesEngine_MatchOneAsync_OutsideRulesPeriod_Failure(DateTime public async Task RulesEngine_MatchOneAsync_WithRulesInSequence_ReturnsCorrectRule(DateTime matchDate, string expectedName, string expectedValue) { // Arrange - var emptyConditions = Array.Empty>(); + var emptyConditions = new Dictionary(); // Act var actualMatch = await this.MatchOneAsync(matchDate, emptyConditions); diff --git a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesUpdateDateEndTests.cs b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesUpdateDateEndTests.cs index d9e5d57d..cc346c7f 100644 --- a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesUpdateDateEndTests.cs +++ b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Features/RulesEngine/RulesMatching/RulesUpdateDateEndTests.cs @@ -51,7 +51,7 @@ public RulesUpdateDateEndTests() : base(testRuleset) public async Task RulesEngine_UpdateRuleDateEnd_Validations(DateTime dateEnd, bool success) { // Arrange - var emptyConditions = Array.Empty>(); + var emptyConditions = new Dictionary(); var matchDate = new DateTime(2020, 01, 02); // Act diff --git a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs index 00a383a9..51fcdba9 100644 --- a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs +++ b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario2/CarInsuranceAdvisorTests.cs @@ -87,10 +87,10 @@ public async Task GetCarInsuranceAdvice_RepairCostsNotWorthIt_ReturnsRefusePayme var expected = CarInsuranceAdvices.RefusePaymentPerFranchise; const CarInsuranceRulesetNames expectedRuleset = CarInsuranceRulesetNames.CarInsuranceAdvice; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts, 800.00000m), - new Condition(CarInsuranceConditionNames.RepairCostsCommercialValueRate, 23.45602m) + { CarInsuranceConditionNames.RepairCosts, 800.00000m }, + { CarInsuranceConditionNames.RepairCostsCommercialValueRate, 23.45602m }, }; var rulesEngine = RulesEngineBuilder.CreateRulesEngine() @@ -120,10 +120,10 @@ public async Task GetCarInsuranceAdvice_UpdatesRuleAndAddsNewOneAndEvaluates_Ret // Arrange const CarInsuranceRulesetNames expectedContent = CarInsuranceRulesetNames.CarInsuranceAdvice; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(CarInsuranceConditionNames.RepairCosts, 800.00000m), - new Condition(CarInsuranceConditionNames.RepairCostsCommercialValueRate, 23.45602m) + { CarInsuranceConditionNames.RepairCosts, 800.00000m }, + { CarInsuranceConditionNames.RepairCostsCommercialValueRate, 23.45602m }, }; var rulesEngine = RulesEngineBuilder.CreateRulesEngine() diff --git a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs index e03e7200..5fb6d81b 100644 --- a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs +++ b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario3/BuildingSecuritySystemControlTests.cs @@ -81,11 +81,11 @@ public async Task BuildingSecuritySystem_FireScenario_ReturnsActionsToTrigger(bo const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.FireSystem; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(SecuritySystemConditions.TemperatureCelsius, 100.0m), - new Condition(SecuritySystemConditions.SmokeRate, 55.0m), - new Condition(SecuritySystemConditions.PowerStatus, "Online") + { SecuritySystemConditions.TemperatureCelsius, 100.0m }, + { SecuritySystemConditions.SmokeRate, 55.0m }, + { SecuritySystemConditions.PowerStatus, "Online" }, }; var rulesEngine = RulesEngineBuilder.CreateRulesEngine() @@ -135,11 +135,11 @@ public async Task BuildingSecuritySystem_PowerFailureScenario_ReturnsActionsToTr const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.PowerSystem; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(SecuritySystemConditions.TemperatureCelsius, 100.0m), - new Condition(SecuritySystemConditions.SmokeRate, 55.0m), - new Condition(SecuritySystemConditions.PowerStatus, "Offline") + { SecuritySystemConditions.TemperatureCelsius, 100.0m }, + { SecuritySystemConditions.SmokeRate, 55.0m }, + { SecuritySystemConditions.PowerStatus, "Offline" }, }; var rulesEngine = RulesEngineBuilder.CreateRulesEngine() @@ -173,11 +173,11 @@ public async Task BuildingSecuritySystem_PowerShutdownScenario_ReturnsActionsToT const SecuritySystemActionables securitySystemActionable = SecuritySystemActionables.PowerSystem; var expectedMatchDate = new DateTime(2018, 06, 01); - var expectedConditions = new[] + var expectedConditions = new Dictionary { - new Condition(SecuritySystemConditions.TemperatureCelsius, 100.0m), - new Condition(SecuritySystemConditions.SmokeRate, 55.0m), - new Condition(SecuritySystemConditions.PowerStatus, "Shutdown") + { SecuritySystemConditions.TemperatureCelsius, 100.0m }, + { SecuritySystemConditions.SmokeRate, 55.0m }, + { SecuritySystemConditions.PowerStatus, "Shutdown" }, }; var rulesEngine = RulesEngineBuilder.CreateRulesEngine() diff --git a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs index a2e240b5..f1138650 100644 --- a/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs +++ b/tests/Rules.Framework.Providers.MongoDb.IntegrationTests/Scenarios/Scenario5/BestServerTests.cs @@ -17,23 +17,23 @@ public sealed class BestServerTests : IDisposable { new object[] { - new[] + new Dictionary { - new Condition(BestServerConditions.Price, 100), - new Condition(BestServerConditions.Memory, 12), - new Condition(BestServerConditions.StoragePartionable, true), - new Condition(BestServerConditions.Brand, "AMD") + { BestServerConditions.Price, 100 }, + { BestServerConditions.Memory, 12 }, + { BestServerConditions.StoragePartionable, true }, + { BestServerConditions.Brand, "AMD" }, }, "Best Server Top5" }, new object[] { - new[] + new Dictionary { - new Condition(BestServerConditions.Price, 110), - new Condition(BestServerConditions.Memory, 12), - new Condition(BestServerConditions.StoragePartionable, true), - new Condition(BestServerConditions.Brand, "AMD") + { BestServerConditions.Price, 110 }, + { BestServerConditions.Memory, 12 }, + { BestServerConditions.StoragePartionable, true }, + { BestServerConditions.Brand, "AMD" }, }, "Best Server Default" } @@ -50,7 +50,7 @@ public BestServerTests() [Theory] [MemberData(nameof(DataTest))] - public async Task BestServer_InEvaluation(IEnumerable> conditions, string expectedRuleName, bool enableCompilation) + public async Task BestServer_InEvaluation(Dictionary conditions, string expectedRuleName, bool enableCompilation) { // Arrange var rulesEngine = RulesEngineBuilder.CreateRulesEngine() diff --git a/tests/Rules.Framework.Tests/ConditionTests.cs b/tests/Rules.Framework.Tests/ConditionTests.cs deleted file mode 100644 index 3a8d4471..00000000 --- a/tests/Rules.Framework.Tests/ConditionTests.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Rules.Framework.Tests -{ - using FluentAssertions; - using Rules.Framework.Tests.Stubs; - using Xunit; - - public class ConditionTests - { - [Fact] - public void Condition_Ctor_Success() - { - // Arrange - var expectedType = ConditionNames.IsoCountryCode; - var expectedValue = "abc"; - - // Act - var sut = new Condition(expectedType, expectedValue); - - // Assert - sut.Type.Should().Be(expectedType); - sut.Value.Should().Be(expectedValue); - } - } -} \ No newline at end of file diff --git a/tests/Rules.Framework.Tests/RulesEngineTests.cs b/tests/Rules.Framework.Tests/RulesEngineTests.cs index f0679c3a..af9c4500 100644 --- a/tests/Rules.Framework.Tests/RulesEngineTests.cs +++ b/tests/Rules.Framework.Tests/RulesEngineTests.cs @@ -367,10 +367,10 @@ public async Task MatchManyAsync_GivenRulesetDateAndConditions_FetchesRulesForDa // Arrange var matchDateTime = new DateTime(2018, 07, 01, 18, 19, 30); var ruleset = RulesetNames.Type1.ToString(); - var conditions = new[] + var conditions = new Dictionary { - new Condition(ConditionNames.IsoCountryCode.ToString(), "USA"), - new Condition(ConditionNames.IsoCurrency.ToString(), "USD") + { ConditionNames.IsoCountryCode.ToString(), "USA" }, + { ConditionNames.IsoCurrency.ToString(), "USD" }, }; var expected1 = new Rule @@ -447,10 +447,10 @@ public async Task MatchOneAsync_GivenRulesetDateAndConditions_FetchesRulesForDay // Arrange var matchDateTime = new DateTime(2018, 07, 01, 18, 19, 30); var ruleset = RulesetNames.Type1.ToString(); - var conditions = new[] + var conditions = new Dictionary { - new Condition(ConditionNames.IsoCountryCode.ToString(), "USA"), - new Condition(ConditionNames.IsoCurrency.ToString(), "USD") + { ConditionNames.IsoCountryCode.ToString(), "USA" }, + { ConditionNames.IsoCurrency.ToString(), "USD" }, }; var other = new Rule @@ -513,10 +513,10 @@ public async Task MatchOneAsync_GivenRulesetDateAndConditions_FetchesRulesForDay // Arrange var matchDateTime = new DateTime(2018, 07, 01, 18, 19, 30); var ruleset = RulesetNames.Type1.ToString(); - var conditions = new[] + var conditions = new Dictionary { - new Condition(ConditionNames.IsoCountryCode.ToString(), "USA"), - new Condition(ConditionNames.IsoCurrency.ToString(), "USD") + { ConditionNames.IsoCountryCode.ToString(), "USA" }, + { ConditionNames.IsoCurrency.ToString(), "USD" }, }; var expected = new Rule @@ -577,10 +577,10 @@ public async Task MatchOneAsync_GivenRulesetDateAndConditions_FetchesRulesForDay // Arrange var matchDateTime = new DateTime(2018, 07, 01, 18, 19, 30); var ruleset = RulesetNames.Type1.ToString(); - var conditions = new[] + var conditions = new Dictionary { - new Condition(ConditionNames.IsoCountryCode.ToString(), "USA"), - new Condition(ConditionNames.IsoCurrency.ToString(), "USD") + { ConditionNames.IsoCountryCode.ToString(), "USA" }, + { ConditionNames.IsoCurrency.ToString(), "USD" }, }; var rules = new[] @@ -793,11 +793,11 @@ public async Task VerifyParameters_GivenNullParameter_ThrowsArgumentNullExceptio break; case nameof(RulesEngine.MatchManyAsync): - _ = await sut.MatchManyAsync(null, DateTime.UtcNow, Enumerable.Empty>()); + _ = await sut.MatchManyAsync(null, DateTime.UtcNow, new Dictionary()); break; case nameof(RulesEngine.MatchOneAsync): - _ = await sut.MatchOneAsync(null, DateTime.UtcNow, Enumerable.Empty>()); + _ = await sut.MatchOneAsync(null, DateTime.UtcNow, new Dictionary()); break; case nameof(RulesEngine.SearchAsync): diff --git a/tests/Rules.Framework.Tests/Validation/SearchArgsValidatorTests.cs b/tests/Rules.Framework.Tests/Validation/SearchArgsValidatorTests.cs index c6ca9d05..45c1d572 100644 --- a/tests/Rules.Framework.Tests/Validation/SearchArgsValidatorTests.cs +++ b/tests/Rules.Framework.Tests/Validation/SearchArgsValidatorTests.cs @@ -1,6 +1,7 @@ namespace Rules.Framework.Tests.Validation { using System; + using System.Collections.Generic; using System.Linq; using FluentAssertions; using Rules.Framework.Tests.Stubs; @@ -15,10 +16,10 @@ public void Validate_GivenConditionWithTypeAsAsEnumTypeAndUndefinedValue_Returns // Arrange var searchArgs = new SearchArgs(RulesetNames.Type1, DateTime.MinValue, DateTime.MaxValue) { - Conditions = new[] + Conditions = new Dictionary { - new Condition(0, 1) - } + { 0, 1 }, + }, }; var validator = new SearchArgsValidator(); @@ -29,7 +30,7 @@ public void Validate_GivenConditionWithTypeAsAsEnumTypeAndUndefinedValue_Returns // Assert validationResult.IsValid.Should().BeFalse(); validationResult.Errors.Should().HaveCount(1); - validationResult.Errors.Should().Match(c => c.Any(vf => vf.PropertyName == $"{nameof(searchArgs.Conditions)}[0].Type")); + validationResult.Errors.Should().Match(c => c.Any(vf => vf.PropertyName == $"{nameof(searchArgs.Conditions)}[0].Key")); } [Fact] @@ -38,10 +39,10 @@ public void Validate_GivenConditionWithTypeAsClassTypeAndNotNullValue_ReturnsSuc // Arrange var searchArgs = new SearchArgs(RulesetNames.Type1, DateTime.MinValue, DateTime.MaxValue) { - Conditions = new[] + Conditions = new Dictionary { - new Condition(new ConditionClass{Id = 1, Name = "Sample Condition Type" }, 1) - } + { new ConditionClass { Id = 1, Name = "Sample Condition Type" }, 1 }, + }, }; var validator = new SearchArgsValidator(); @@ -54,39 +55,16 @@ public void Validate_GivenConditionWithTypeAsClassTypeAndNotNullValue_ReturnsSuc validationResult.Errors.Should().BeEmpty(); } - [Fact] - public void Validate_GivenConditionWithTypeAsClassTypeAndNullValue_ReturnsFailedValidation() - { - // Arrange - var searchArgs = new SearchArgs(RulesetNames.Type1, DateTime.MinValue, DateTime.MaxValue) - { - Conditions = new[] - { - new Condition(null, 1) - } - }; - - var validator = new SearchArgsValidator(); - - // Act - var validationResult = validator.Validate(searchArgs); - - // Assert - validationResult.IsValid.Should().BeFalse(); - validationResult.Errors.Should().HaveCount(1); - validationResult.Errors.Should().Match(c => c.Any(vf => vf.PropertyName == $"{nameof(searchArgs.Conditions)}[0].Type")); - } - [Fact] public void Validate_GivenConditionWithTypeAsEnumTypeAndDefinedValue_ReturnsSuccessValidation() { // Arrange var searchArgs = new SearchArgs(RulesetNames.Type1, DateTime.MinValue, DateTime.MaxValue) { - Conditions = new[] + Conditions = new Dictionary { - new Condition(ConditionNames.IsoCountryCode,"PT") - } + { ConditionNames.IsoCountryCode, "PT" }, + }, }; var validator = new SearchArgsValidator();