示例#1
0
        public void Should_validate_against_validator()
        {
            var validator = CreateMock<IValidator<Person, string>>();
            var person = new Person {Name = "Bob"};
            var rule = new ValidatorRule<Person, string>("", "", validator, p => p.Name);

            validator.Expect(v => v.Validate(person, "Bob")).Return(true);

            rule.Validate(person);

            VerifyAll();
        }
示例#2
0
        public void Should_return_valid_result_if_validator_returned_valid()
        {
            var validator = CreateMock<IValidator<Person, string>>();
            var person = new Person { Name = "Bob" };
            var rule = new ValidatorRule<Person, string>("", "", validator, p => p.Name);

            validator.Stub(v => v.Validate(person, "Bob")).Return(true);

            var result = rule.Validate(person);

            Assert.That(result.IsValid, Is.True);
        }
示例#3
0
        public void Should_return_invalid_result_with_broken_rule_if_validator_returned_invalid()
        {
            var validator = CreateMock<IValidator<Person, string>>();
            var person = new Person { Name = "Bob" };
            var rule = new ValidatorRule<Person, string>("", "", validator, p => p.Name) { Message = "Invalid name" };

            validator.Stub(v => v.Validate(person, "Bob")).Return(false);

            var result = rule.Validate(person);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.BrokenRules[0].Message, Is.EqualTo("Invalid name"));
        }
示例#4
0
        public void Should_return_valid_result_if_validator_returned_valid()
        {
            var validator = CreateMock <IValidator <Person, string> >();
            var person    = new Person {
                Name = "Bob"
            };
            var rule = new ValidatorRule <Person, string>("", "", validator, p => p.Name);

            validator.Stub(v => v.Validate(person, "Bob")).Return(true);

            var result = rule.Validate(person);

            Assert.That(result.IsValid, Is.True);
        }
示例#5
0
        public void Should_validate_against_validator()
        {
            var validator = CreateMock <IValidator <Person, string> >();
            var person    = new Person {
                Name = "Bob"
            };
            var rule = new ValidatorRule <Person, string>("", "", validator, p => p.Name);

            validator.Expect(v => v.Validate(person, "Bob")).Return(true);

            rule.Validate(person);

            VerifyAll();
        }
示例#6
0
        public void Should_return_invalid_result_with_broken_rule_if_validator_returned_invalid()
        {
            var validator = CreateMock <IValidator <Person, string> >();
            var person    = new Person {
                Name = "Bob"
            };
            var rule = new ValidatorRule <Person, string>("", "", validator, p => p.Name)
            {
                Message = "Invalid name"
            };

            validator.Stub(v => v.Validate(person, "Bob")).Return(false);

            var result = rule.Validate(person);

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.BrokenRules[0].Message, Is.EqualTo("Invalid name"));
        }