Пример #1
0
        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);
        }
Пример #2
0
        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);
            }
        }
Пример #4
0
 public override void Initialize(FieldRuleConfiguration config)
 {
     base.Initialize(config);
     SetArg();
 }
Пример #5
0
 public virtual void Initialize(FieldRuleConfiguration config)
 {
     DataProcessorGlobal.Debug($"Rule: {Name}. Initializing.");
     EnsureThatPropertiesAreInitialized();
 }