Ejemplo n.º 1
0
        public void errors_are_returned_when_the_object_is_invalid()
        {
            var invalidModel = new ClassToValidate();

            Validator
                .Validate(invalidModel)
                .IsValid
                .ShouldBeFalse();
        }
Ejemplo n.º 2
0
        public void no_errors_are_returned_if_the_object_is_valid()
        {
            var validModel = new ClassToValidate
                            {
                                SimpleRequiredField = "Valid value"
                            };

            Validator
                .Validate(validModel)
                .IsValid
                .ShouldBeTrue();
        }
        public void When_the_options_are_valid()
        {
            var options = new ClassToValidate {
                Name = "Not empty"
            };

            var implementation   = new FluentOptionsValidatorImplementation();
            var validationResult = implementation.Validate("a name", options);

            using (new AssertionScope())
            {
                validationResult.Failed.Should().BeFalse();
                validationResult.Failures.Should().BeNull();
            }
        }
        public void When_the_options_are_invalid()
        {
            var options = new ClassToValidate {
                Name = string.Empty
            };

            var implementation   = new FluentOptionsValidatorImplementation();
            var validationResult = implementation.Validate("a name", options);

            using (new AssertionScope())
            {
                validationResult.Failed.Should().BeTrue();
                validationResult.Failures.Count().Should().Be(1);
                validationResult.Failures.First().Should().Be("'Name' must not be empty.");
            }
        }