Пример #1
0
        /// <summary>
        /// Добавить правило логического сложения для текущей коллекции.
        /// </summary>
        public void Or(Action <CollectionValidationBuilder> buildAction)
        {
            var validationOperator = new OrValidator {
                Property = Property
            };

            buildAction(new CollectionValidationBuilder(validationOperator));

            Operator = validationOperator;
        }
        public void Should_Call_IsValid_On_Both_Validators() {
            // Arrange
            var lhs = new Mock<IValidator<string>>();
            lhs.Setup(x => x.IsValid(It.IsAny<string>())).Returns(ValidationResult.Success);
            var rhs = new Mock<IValidator<string>>();
            rhs.Setup(x => x.IsValid(It.IsAny<string>())).Returns(ValidationResult.Success);
            var validator = new OrValidator<string>(lhs.Object, rhs.Object);

            // Act
            validator.IsValid(Thumbprint);

            // Assert
            rhs.Verify(x => x.IsValid(It.IsAny<string>()));
            lhs.Verify(x => x.IsValid(It.IsAny<string>()));
        }
Пример #3
0
        public void Validate_OneValidatorValidation_Fails()
        {
            //Arrange
            const int        actualResponseCode   = 200;
            int              expectedResponseCode = 400;
            IValidator       validator            = new ResponseCodeValidator(expectedResponseCode);
            IValidator       orValidator          = new OrValidator(new IValidator[] { validator });
            ResponseDataMock responseData         = new ResponseDataMock {
                StatusCode = actualResponseCode
            };

            //Test
            ValidationResult result = orValidator.Validate(responseData, null, null);

            // Assert
            Assert.IsTrue(result.HasFailures);
        }
Пример #4
0
        public void Validate_MultipleValidatorsAllInvalid_Fails()
        {
            //Arrange
            const int actualResponseCode = 200;

            IValidator[] validators = new ResponseCodeValidator[] {
                new ResponseCodeValidator(400),
                new ResponseCodeValidator(401)
            };
            IValidator       orValidator  = new OrValidator(validators);
            ResponseDataMock responseData = new ResponseDataMock {
                StatusCode = actualResponseCode
            };

            //Test
            ValidationResult result = orValidator.Validate(responseData, null, null);

            // Assert
            Assert.IsTrue(result.HasFailures);
        }