Exemplo n.º 1
0
        public void SingleValidationSuccessTest()
        {
            var validator = ChainingValidator.CreateSimple <int>(source => source < 10);

            // valid source
            validator.Validate(1).IsTrue();
        }
Exemplo n.º 2
0
        public void SingleValidationFailedTest()
        {
            var validator = ChainingValidator.CreateSimple <int>(source => source < 10);

            // invalid source
            validator.Validate(10).IsFalse();
        }
Exemplo n.º 3
0
        public void MultiValidationTooSmallTest()
        {
            var validator = ChainingValidator
                            .CreateSimple <int>(source => source < 10)
                            .Add(source => source >= 0);

            validator.Validate(-1).IsFalse();
        }
Exemplo n.º 4
0
        public void MultiValidationSuccessTest()
        {
            var validator = ChainingValidator
                            .CreateSimple <int>(source => source < 10)
                            .Add(source => source >= 0);

            validator.Validate(5).IsTrue();
        }
Exemplo n.º 5
0
        public void SimpleEqualsTest()
        {
            var expectedPerson = new Person(20, "Taro");
            var validator      = ChainingValidator.CreateSimple <Person>()
                                 .AddEquals(expectedPerson);

            validator.Validate(new Person(20, "Taro")).IsTrue();
            validator.Validate(new Person(19, "Taro")).IsFalse();
            validator.Validate(new Person(20, "Taroo")).IsFalse();
        }
Exemplo n.º 6
0
        public void SingleValidationSuccessTest()
        {
            var validator = ChainingValidator
                            .Create <int, NumberDetail?>(source => source < 10, NumberDetail.TooBig);

            // valid source
            var result = validator.Validate(1);

            result.Detail.IsNull();
            result.IsValid.IsTrue();
            result.Source.Is(1);
        }
Exemplo n.º 7
0
        public void MultiValidationTooSmallTest()
        {
            var validator = ChainingValidator
                            .Create <int, NumberDetail?>((int source) => source < 10, (NumberDetail?)NumberDetail.TooBig)
                            .Add((source) => source >= 0, NumberDetail.TooSmall);

            var result = validator.Validate(-1);

            result.Detail.Is(NumberDetail.TooSmall);
            result.IsValid.IsFalse();
            result.Source.Is(-1);
        }
Exemplo n.º 8
0
        public void SingleValidationFailedTest()
        {
            var validator = ChainingValidator
                            .Create <int, NumberDetail?>(source => source < 10, NumberDetail.TooBig);

            // invalid source
            var result = validator.Validate(10);

            result.Detail.Is(NumberDetail.TooBig);
            result.IsValid.IsFalse();
            result.Source.Is(10);
        }