public void RegistrarContinueOrDefaultTest()
        {
            var registrar1   = ValidationRegistrar.ContinueOrDefault("UT_RegistrarContinueOrDefaultTest1");
            var registrarRef = ValidationRegistrar.Continue(); //Default/Main registrar

            registrar1.ShouldNotBeNull();
            registrarRef.ShouldNotBeNull();

            var instance1   = registrar1 as InternalValidationRegistrar;
            var instanceRef = registrarRef as InternalValidationRegistrar;

            instance1.ShouldNotBeNull();
            instanceRef.ShouldNotBeNull();

            instance1.Name.ShouldBe(instanceRef.Name);

            var provider = new ValidationProvider(new FakeProjectManager(), new DefaultVerifiableObjectResolver(), new ValidationOptions());

            var registrar2 = ValidationRegistrar.ForProvider(provider, "UT_RegistrarContinueOrDefaultTest2");
            var registrar3 = ValidationRegistrar.ContinueOrDefault("UT_RegistrarContinueOrDefaultTest2");

            registrar2.ShouldNotBeNull();
            registrar3.ShouldNotBeNull();

            var instance2 = registrar2 as InternalValidationRegistrar;
            var instance3 = registrar3 as InternalValidationRegistrar;

            instance2.ShouldNotBeNull();
            instance3.ShouldNotBeNull();

            instance2.Name.ShouldBe("UT_RegistrarContinueOrDefaultTest2");
            instance3.Name.ShouldBe("UT_RegistrarContinueOrDefaultTest2");
        }
        public void StrategyLevelTakeEffectTest()
        {
            var registrar = ValidationRegistrar.Continue();

            registrar.ShouldNotBeNull();

            var exposedPoint1          = (registrar as InternalValidationRegistrar)?.GetCorrectValueRulesForUnitTests();
            var _typedRulesDictionary1 = exposedPoint1.Value.Item1;
            var _namedRulesDictionary1 = exposedPoint1.Value.Item2;

            _typedRulesDictionary1.ShouldNotBeNull();
            _namedRulesDictionary1.ShouldNotBeNull();

            _typedRulesDictionary1.Keys.Should().HaveCount(0);
            _namedRulesDictionary1.Keys.Should().HaveCount(0);

            registrar.ForStrategy <NormalNiceBoatStrategy>().TakeEffect();
            var exposedPoint2 = (registrar as InternalValidationRegistrar)?.GetCorrectValueRulesForUnitTests();

            exposedPoint2.ShouldNotBeNull();
            var _typedRulesDictionary2 = exposedPoint2.Value.Item1;
            var _namedRulesDictionary2 = exposedPoint2.Value.Item2;

            _typedRulesDictionary2.ShouldNotBeNull();
            _namedRulesDictionary2.ShouldNotBeNull();

            _typedRulesDictionary2.Keys.Should().HaveCount(1);
            _namedRulesDictionary2.Keys.Should().HaveCount(0);

            var rules = _typedRulesDictionary2[typeof(NiceBoat)];

            rules.Should().HaveCount(3);
            rules[0].Should().NotBeNull()
            .And.Match <CorrectValueRule>(x => x.MemberName == "Name")
            .And.Match <CorrectValueRule>(x => x.Mode == CorrectValueRuleMode.Append)
            .And.Match <CorrectValueRule>(x => x.Tokens.Count == 1)
            .And.Match <CorrectValueRule>(x => x.Tokens[0].TokenName == "ValueNotEmptyToken");


            rules[1].Should().NotBeNull()
            .And.Match <CorrectValueRule>(x => x.MemberName == "Length")
            .And.Match <CorrectValueRule>(x => x.Mode == CorrectValueRuleMode.Append)
            .And.Match <CorrectValueRule>(x => x.Tokens.Count == 1)
            .And.Match <CorrectValueRule>(x => x.Tokens[0].TokenName == "ValueGreaterThanOrEqualToken");

            rules[2].Should().NotBeNull()
            .And.Match <CorrectValueRule>(x => x.MemberName == "Width")
            .And.Match <CorrectValueRule>(x => x.Mode == CorrectValueRuleMode.Append)
            .And.Match <CorrectValueRule>(x => x.Tokens.Count == 1)
            .And.Match <CorrectValueRule>(x => x.Tokens[0].TokenName == "ValueGreaterThanOrEqualToken");
        }
        public void MainRegistrarAccessingTest()
        {
            var provider = new ValidationProvider(new FakeProjectManager(), new DefaultVerifiableObjectResolver(), new ValidationOptions());

            var registrar1 = ValidationRegistrar.ForProvider(provider);
            var registrar2 = ValidationRegistrar.Continue();

            registrar1.ShouldNotBeNull();
            registrar2.ShouldNotBeNull();

            var instance1 = registrar1 as InternalValidationRegistrar;
            var instance2 = registrar2 as InternalValidationRegistrar;

            instance1.ShouldNotBeNull();
            instance2.ShouldNotBeNull();

            instance1.Name.ShouldBe(instance2.Name);
        }
Example #4
0
 public IValidationRegistrar ResolveRegistrar() => ValidationRegistrar.Continue();
Example #5
0
 public IValidationRegistrar RequiredResolveRegistrar(string providerName) => ValidationProvider.IsDefault(providerName) ? ValidationRegistrar.DefaultRegistrar : ValidationRegistrar.Continue(providerName);
        public ValidationHandler Build(ValidationOptions options)
        {
            var registrar = ValidationRegistrar.Continue(CorrectnessVerifiableWall.GLOBAL_CORRECT_PROVIDER_KEY);

            return((RegisterHandler?.Invoke(registrar) ?? registrar).TempBuild(options));
        }