public void GetRulesWithDependenciesShouldThrowIfTheMatchingValueDoesNotHaveTheSpecifiedRule([Frozen] IGetsAllExecutableRules executableRulesProvider,
                                                                                                     [ManifestModel] ManifestValue manifestValue,
                                                                                                     object objectToBeValidated,
                                                                                                     IValidationLogic logic,
                                                                                                     ManifestRule manifestRule,
                                                                                                     ManifestRule manifestDependency,
                                                                                                     [ExecutableModel] ValidatedValue validatedValue,
                                                                                                     [ExecutableModel] ValidatedValue parentValue,
                                                                                                     ExecutableRulesAndDependenciesProvider sut,
                                                                                                     ResolvedValidationOptions validationOptions)
        {
            var rule = new ExecutableRule {
                ValidatedValue = validatedValue, ManifestRule = manifestRule, RuleLogic = logic
            };

            validatedValue.ParentValue = parentValue;
            var dependency = new ExecutableRule {
                ValidatedValue = parentValue, ManifestRule = manifestDependency, RuleLogic = logic
            };

            parentValue.ManifestValue = manifestDependency.Identifier.ManifestValue;
            Mock.Get(executableRulesProvider)
            .Setup(x => x.GetExecutableRules(manifestValue, objectToBeValidated, validationOptions))
            .Returns(new [] { rule, dependency });
            rule.ManifestRule.DependencyRules.Clear();
            rule.ManifestRule.DependencyRules.Add(manifestDependency.Identifier);

            Assert.That(() => sut.GetRulesWithDependencies(manifestValue, objectToBeValidated, validationOptions), Throws.InstanceOf <ValidationException>());
        }
        public void GetRulesWithDependenciesShouldReturnAnObjectWithDependencyExecutableRulesWhereItHasADependencyUponAParentValue([Frozen] IGetsAllExecutableRules executableRulesProvider,
                                                                                                                                   [ManifestModel] ManifestValue manifestValue,
                                                                                                                                   object objectToBeValidated,
                                                                                                                                   IValidationLogic logic,
                                                                                                                                   ManifestRule manifestRule,
                                                                                                                                   ManifestRule manifestDependency,
                                                                                                                                   [ExecutableModel] ValidatedValue validatedValue,
                                                                                                                                   [ExecutableModel] ValidatedValue parentValue,
                                                                                                                                   ExecutableRulesAndDependenciesProvider sut,
                                                                                                                                   ResolvedValidationOptions validationOptions)
        {
            var rule = new ExecutableRule {
                ValidatedValue = validatedValue, ManifestRule = manifestRule, RuleLogic = logic
            };

            validatedValue.ParentValue = parentValue;
            var dependency = new ExecutableRule {
                ValidatedValue = parentValue, ManifestRule = manifestDependency, RuleLogic = logic
            };

            parentValue.ManifestValue = manifestDependency.Identifier.ManifestValue;
            parentValue.Rules.Add(dependency);
            Mock.Get(executableRulesProvider)
            .Setup(x => x.GetExecutableRules(manifestValue, objectToBeValidated, validationOptions))
            .Returns(new [] { rule, dependency });
            rule.ManifestRule.DependencyRules.Clear();
            rule.ManifestRule.DependencyRules.Add(manifestDependency.Identifier);

            var result = sut.GetRulesWithDependencies(manifestValue, objectToBeValidated, validationOptions);

            Assert.That(result.First(x => x.ExecutableRule == rule).Dependencies, Is.EqualTo(new[] { dependency }));
        }
        public void GetRulesWithDependenciesShouldNotReturnAnyDependenciesForARuleWhichHasNone([Frozen] IGetsAllExecutableRules executableRulesProvider,
                                                                                               [ManifestModel] ManifestValue manifestValue,
                                                                                               object objectToBeValidated,
                                                                                               [ExecutableModel] ExecutableRule rule,
                                                                                               ExecutableRulesAndDependenciesProvider sut,
                                                                                               ResolvedValidationOptions validationOptions)
        {
            Mock.Get(executableRulesProvider)
            .Setup(x => x.GetExecutableRules(manifestValue, objectToBeValidated, validationOptions))
            .Returns(new [] { rule });

            var result = sut.GetRulesWithDependencies(manifestValue, objectToBeValidated, validationOptions);

            Assert.That(result.Single().Dependencies, Is.Empty);
        }