コード例 #1
0
        public void GetValidationLogicShouldConfigureRuleWithConfigurationAction([Frozen] IResolvesRule ruleResolver,
                                                                                 ValidationLogicFactory sut,
                                                                                 string str,
                                                                                 string configValue)
        {
            var value = new ManifestValue {
                ValidatedType = typeof(string)
            };
            var rule = new ManifestRule(value, new ManifestRuleIdentifier(value, typeof(StringRule)));

            rule.RuleConfiguration = obj => ((StringRule)obj).ConfigurableValue = configValue;
            value.Rules.Add(rule);
            var ruleBody = new StringRule();

            Mock.Get(ruleResolver).Setup(x => x.ResolveRule(typeof(StringRule))).Returns(ruleBody);

            var result = sut.GetValidationLogic(rule);

            Assert.That(ruleBody.ConfigurableValue, Is.EqualTo(configValue));
        }
コード例 #2
0
        public async Task GetValidationLogicShouldReturnWorkingLogicForNormalRule([Frozen] IResolvesRule ruleResolver,
                                                                                  ValidationLogicFactory sut,
                                                                                  string str,
                                                                                  [RuleContext] RuleContext context)
        {
            var value = new ManifestValue {
                ValidatedType = typeof(string)
            };
            var rule = new ManifestRule(value, new ManifestRuleIdentifier(value, typeof(StringRule)));

            value.Rules.Add(rule);
            var ruleBody = new StringRule();

            Mock.Get(ruleResolver).Setup(x => x.ResolveRule(typeof(StringRule))).Returns(ruleBody);

            var result = sut.GetValidationLogic(rule);
            await result.GetResultAsync(str, null, context);

            Assert.That(ruleBody.Executed, Is.True);
        }
コード例 #3
0
        public async Task GetValidationLogicShouldReturnRuleThatUsesCorrectInterfaceWhenOriginalLogicWasAmbiguousBetweenRuleAndValueRule([Frozen] IResolvesRule ruleResolver,
                                                                                                                                         ValidationLogicFactory sut,
                                                                                                                                         string str,
                                                                                                                                         [RuleContext] RuleContext context)
        {
            var value = new ManifestValue {
                ValidatedType = typeof(string)
            };
            var rule = new ManifestRule(value, new ManifestRuleIdentifier(value, typeof(StringValueRule)));

            value.Rules.Add(rule);
            var ruleBody = new StringValueRule();

            Mock.Get(ruleResolver).Setup(x => x.ResolveRule(typeof(StringValueRule))).Returns(ruleBody);

            var result = sut.GetValidationLogic(rule);
            await result.GetResultAsync(str, null, context);

            Assert.That(ruleBody.ExecutedAsRule, Is.True);
        }
コード例 #4
0
        public void GetValidationLogicShouldThrowValidatorBuildingExceptionIfRuleWhichOperatesOnCollectionButValueIsNotEnumerable([Frozen] IResolvesRule ruleResolver,
                                                                                                                                  ValidationLogicFactory sut,
                                                                                                                                  string str)
        {
            var value = new ManifestValue
            {
                ValidatedType       = typeof(int),
                CollectionItemValue = new ManifestCollectionItem {
                    ValidatedType = typeof(int)
                }
            };
            var rule = new ManifestRule(value.CollectionItemValue, new ManifestRuleIdentifier(value.CollectionItemValue, typeof(StringRule)));

            value.Rules.Add(rule);
            var ruleBody = new StringRule();

            Mock.Get(ruleResolver).Setup(x => x.ResolveRule(typeof(StringRule))).Returns(ruleBody);

            Assert.That(() => sut.GetValidationLogic(rule), Throws.InstanceOf <ValidatorBuildingException>());
        }
コード例 #5
0
        public void GetValidationLogicShouldThrowValidatorBuildingExceptionIfRuleIsWrongInterfaceForValueRule([Frozen] IResolvesRule ruleResolver,
                                                                                                              ValidationLogicFactory sut,
                                                                                                              string str)
        {
            var value = new ManifestValue
            {
                ValidatedType = typeof(string),
                Parent        = new ManifestValue
                {
                    ValidatedType = typeof(int),
                }
            };
            var rule = new ManifestRule(value, new ManifestRuleIdentifier(value, typeof(object)));

            value.Rules.Add(rule);
            var ruleBody = new object();

            Mock.Get(ruleResolver).Setup(x => x.ResolveRule(typeof(object))).Returns(ruleBody);

            Assert.That(() => sut.GetValidationLogic(rule), Throws.InstanceOf <ValidatorBuildingException>());
        }
コード例 #6
0
        public void GetValidationLogicShouldThrowValidatorBuildingExceptionIfTheRuleConfigurationActionThrowsAnException([Frozen] IResolvesRule ruleResolver,
                                                                                                                         ValidationLogicFactory sut,
                                                                                                                         string str)
        {
            var value = new ManifestValue {
                ValidatedType = typeof(string)
            };
            var rule = new ManifestRule(value, new ManifestRuleIdentifier(value, typeof(StringRule)));

            rule.RuleConfiguration = obj => throw new Exception();
            value.Rules.Add(rule);
            var ruleBody = new StringRule();

            Mock.Get(ruleResolver).Setup(x => x.ResolveRule(typeof(StringRule))).Returns(ruleBody);

            Assert.That(() => sut.GetValidationLogic(rule), Throws.InstanceOf <ValidatorBuildingException>());
        }