Exemplo n.º 1
0
        public void given_root_has_invalid_property_then_TryValidate_fails()
        {
            var instance = new RootObject
            {
                Int32Property = -1,
            };

            bool successful = ObjectValidator.TryValidate(
                instance,
                out IEnumerable <ObjectValidationError> errors);

            successful.Should().BeFalse();
            errors.Should().ContainSingle();
            ObjectValidationError error = errors.Single();

            error.ObjectPath.Should().BeEmpty();
            error.ValidationAttribute.Should().BeOfType <RangeAttribute>();
            error.ValidationResult.MemberNames.Should().BeEquivalentTo("Int32Property");
            error.Value.Should().Be(instance.Int32Property);
        }
        public void MemberPaths_composes_path_correctly()
        {
            var instance = new Component
            {
                Child = new Component
                {
                    Child = new Component
                    {
                        Value = -1,
                    },
                },
            };

            ObjectValidator.TryValidate(
                instance,
                out IEnumerable <ObjectValidationError> errors);

            ObjectValidationError sut = errors.Single();

            sut.MemberPaths.Should().ContainSingle();
            sut.MemberPaths.Single().Should().Be("Child.Child.Value");
        }
Exemplo n.º 3
0
        public void given_stem_has_invalid_property_then_TryValidate_fails()
        {
            var instance = new RootObject
            {
                StemObjectProperty =
                {
                    StringProperty = "f to the o to the o",
                },
            };

            bool successful = ObjectValidator.TryValidate(
                instance,
                out IEnumerable <ObjectValidationError> errors);

            successful.Should().BeFalse();
            errors.Should().ContainSingle();
            ObjectValidationError error = errors.Single();

            error.ObjectPath.Should().Be("StemObjectProperty");
            error.ValidationAttribute.Should().BeOfType <StringLengthAttribute>();
            error.ValidationResult.MemberNames.Should().BeEquivalentTo("StringProperty");
            error.Value.Should().Be(instance.StemObjectProperty.StringProperty);
        }
Exemplo n.º 4
0
        public void given_null_argument_then_Validate_succeeds()
        {
            Action action = () => ObjectValidator.Validate(instance: null);

            action.Should().NotThrow();
        }