Пример #1
0
        public void GetManifestRuleShouldReturnAManifestRuleWithCorrectConfigurationAction([Frozen] IGetsManifestRuleIdentifier identifierFactory,
                                                                                           [Frozen, ManifestModel] ValidatorBuilderContext context,
                                                                                           RuleBuilder <SampleRule> sut,
                                                                                           [ManifestModel] ManifestRuleIdentifier identifier,
                                                                                           string stringPropValue)
        {
            Mock.Get(identifierFactory)
            .Setup(x => x.GetManifestRuleIdentifier(typeof(SampleRule), It.IsAny <ValidatorBuilderContext>(), It.IsAny <string>()))
            .Returns(identifier);
            sut.ConfigureRule(r => r.StringProp = stringPropValue);
            sut.Dependencies.Clear();

            var rule = sut.GetManifestValue().Rules.Single();

            var sampleRule = new SampleRule();

            rule.RuleConfiguration(sampleRule);
            Assert.That(sampleRule.StringProp, Is.EqualTo(stringPropValue), "Configuration action applied correctly");
        }
Пример #2
0
        public void GetManifestRuleShouldReturnAManifestRulewithCorrectIdentifierFromService([Frozen, ManifestModel] ValidatorBuilderContext context,
                                                                                             [Frozen] IGetsManifestRuleIdentifier identifierFactory,
                                                                                             RuleBuilder <SampleRule> sut,
                                                                                             [ManifestModel] ManifestRuleIdentifier identifier)
        {
            Mock.Get(identifierFactory)
            .Setup(x => x.GetManifestRuleIdentifier(typeof(SampleRule), It.IsAny <ValidatorBuilderContext>(), It.IsAny <string>()))
            .Returns(identifier);
            Func <object, object> GetFunc(Func <object, object> input) => input;

            context.ManifestValue.IdentityAccessor = GetFunc(x => new object());
            sut.Dependencies.Clear();

            sut.Name = "Rule name";

            var rule = sut.GetManifestValue().Rules.Single();

            Assert.That(rule.Identifier, Is.SameAs(identifier));
        }