public void GetRuleContextShouldGetCorrectAncestorContexts(RuleContextFactory sut,
                                                                   [ExecutableModel] ExecutableRule rule,
                                                                   ValidatedValue value,
                                                                   ValidatedValue parentValue,
                                                                   ValidatedValue grandparentValue,
                                                                   ValidatedValue greatGrandparentValue)
        {
            rule.ValidatedValue               = value;
            value.ParentValue                 = parentValue;
            parentValue.ParentValue           = grandparentValue;
            grandparentValue.ParentValue      = greatGrandparentValue;
            greatGrandparentValue.ParentValue = null;

            var result = sut.GetRuleContext(rule);

            Assert.Multiple(() =>
            {
                Assert.That(result?.RuleIdentifier,
                            Is.SameAs(rule.RuleIdentifier),
                            nameof(RuleContext.RuleIdentifier));
                Assert.That(result?.AncestorContexts.Select(x => x.ActualValue).ToList(),
                            Is.EqualTo(new [] { parentValue.GetActualValue(), grandparentValue.GetActualValue(), greatGrandparentValue.GetActualValue() }),
                            nameof(RuleContext.AncestorContexts));
            });
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets a rule context for the specified executable rule.
 /// </summary>
 /// <param name="rule">The executable rule.</param>
 /// <returns>A rule context.</returns>
 public RuleContext GetRuleContext(ExecutableRule rule)
 => new RuleContext(rule.ManifestRule,
                    rule.RuleIdentifier,
                    rule.ValidatedValue.GetActualValue(),
                    GetAncestorContexts(rule).ToList(),
                    rule.RuleLogic.RuleInterface,
                    rule.ValidatedValue.CollectionItemOrder);
Ejemplo n.º 3
0
        static IEnumerable <ValueContext> GetAncestorContexts(ExecutableRule rule)
        {
            var value = rule.ValidatedValue;

            while (!(value.ParentValue is null))
            {
                var current = value.ParentValue;
                yield return(new ValueContext(current.ValueIdentity, current.GetActualValue(), current.ManifestValue, current.CollectionItemOrder));

                value = current;
            }
        }
 internal IEnumerable <ExecutableRule> GetDependencies(ExecutableRule rule)
 => allRulesAndDependencies[rule].Dependencies;