public void Validate_Given_field_value_matches_the_aggregate_ValidResult_should_be_valid() { var config = new FieldRuleConfiguration { Aggregates = new Aggregate[] { new Aggregate { Name = "aggregate-1", Value = 10 }, new Aggregate { Name = "aggregate-2", Value = 20 } } }; var target = CreateRule("rule-name", "rule-description", "aggregate-2", ValidationResultType.Warning); target.Initialize(config); var field = new Field { Value = 20, ValidationResult = ValidationResultType.Valid }; target.Validate(field); Assert.AreEqual(ValidationResultType.Valid, field.ValidationResult); }
public void Validate_Given_that_property_failValidationResult_is_not_set_Should_throw_an_exception() { var config = new FieldRuleConfiguration { Aggregates = new Aggregate[] { new Aggregate { Name = "aggregate-1", Value = 10 }, new Aggregate { Name = "aggregate-2", Value = 20 } } }; var target = new MatchesAggregateRule { Description = "rule-description", Name = "rule-name" }; try { target.Initialize(config); Assert.Fail("An exception was not thrown"); } catch (InvalidOperationException e) { Assert.AreEqual("Property FailValidationResult must be set", e.Message); } }
private static void InitializeRules(IEnumerable <IFieldRule> rules, IEnumerable <Aggregate> aggregates) { var config = new FieldRuleConfiguration { Aggregates = aggregates }; foreach (var rule in rules) { rule.Initialize(config); } }
public override void Initialize(FieldRuleConfiguration config) { base.Initialize(config); SetArg(); }
public virtual void Initialize(FieldRuleConfiguration config) { DataProcessorGlobal.Debug($"Rule: {Name}. Initializing."); EnsureThatPropertiesAreInitialized(); }