コード例 #1
0
        public void Validate_TypeWithCustomNestedTypeIsNull_Succeeds()
        {
            var instance = new TypeWithCustomNestedType {
                Property1 = "x"
            };
            var result = RecursiveValidator.Validate(instance);

            result.Should().BeOfType <SuccessfulResult>();
        }
コード例 #2
0
        public void Validate_TypeWithCustomNestedTypeInvalid_Fails()
        {
            var instance = new TypeWithCustomNestedType {
                Property2 = new NestedType()
            };
            var result = RecursiveValidator.Validate(instance);

            result.Should().BeOfType <FailedResult>();

            var errorDetails = ((FailedResult)result).Details.ToArray();

            errorDetails[0].Source.Should().Be($"{nameof(TypeWithCustomNestedType)}.{nameof(TypeWithCustomNestedType.Property1)}");
            errorDetails[0].CodeInfo.Code.Should().BeEquivalentTo(AnnotationErrorCodes.Required.Code);
            errorDetails[1].Source.Should().Be($"{nameof(TypeWithCustomNestedType)}.{nameof(TypeWithCustomNestedType.Property2)}.{nameof(NestedType.NestedProperty)}");
            errorDetails[1].CodeInfo.Code.Should().BeEquivalentTo(AnnotationErrorCodes.Required.Code);
        }