コード例 #1
0
        public void Validate_WhenRuleIsHonored_ThenValidatableObjectShouldBeValid()
        {
            _validatableObject.AddValidationRule(_mockValidationRule);
            _mockValidationRule.SetCheckReturnValueTo(true);

            _validatableObject.Validate();

            Assert.True(_validatableObject.IsValid);
        }
コード例 #2
0
        public void Validate_WhenRuleIsHonored_ThenValidatableObjectShouldBeValid()
        {
            _validatableObject.AddValidationRule(_mockValidationRule.Object);
            _mockValidationRule
            .Setup(v => v.Check(It.IsAny <string>()))
            .Returns(true);

            _validatableObject.Validate();

            _validatableObject.IsValid.Should().BeTrue();
        }
コード例 #3
0
        public void TestFirstValidationRule_secondError()
        {
            //arrange
            var name = new ValidatableObject <string>();

            name.AddValidationRule(new IsNotNullOrEmptyRule <string>("Must have value"));
            name.AddValidationRule(new IsValidEmailValidationRule("Invalid Email"));
            //act
            name.Value = "John";
            name.Validate();
            //assert

            var actual = _converter.Convert(name.Errors, null, null, CultureInfo.CurrentCulture);

            Assert.AreEqual("Invalid Email", actual);
        }
コード例 #4
0
        private void AddValidationRulesToValidatable()
        {
            var isBiggerThanZero = new IsBiggerThanZero <float>
            {
                ErrorMessage = UiText.DOG_NEED_A_GOOD_PRICE
            };
            var haveAName = new HaveAName <string>
            {
                ErrorMessage = UiText.DOG_NEED_A_NAME
            };

            _name.AddValidationRule(haveAName);
            _price.AddValidationRule(isBiggerThanZero);
        }