Ejemplo n.º 1
0
        public void BuildEntityValidator_does_not_return_null_for_an_entity_with_property_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
            .Setup <IList <PropertyValidator> >(
                "BuildValidatorsForProperties", ItExpr.IsAny <IEnumerable <PropertyInfo> >(), ItExpr.IsAny <IEnumerable <EdmProperty> >(),
                ItExpr.IsAny <IEnumerable <NavigationProperty> >())
            .Returns <IEnumerable <PropertyInfo>, IEnumerable <EdmProperty>, IEnumerable <NavigationProperty> >(
                (pi, e, n) => new List <PropertyValidator>
            {
                new PropertyValidator("foo", Enumerable.Empty <ValidationAttributeValidator>())
            });

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry);

                Assert.NotNull(validator);
                Assert.Equal(1, validator.PropertyValidators.Count());
                Assert.Equal(0, validator.TypeLevelValidators.Count());
            }
        }
Ejemplo n.º 2
0
        public void BuildComplexTypeValidator_does_not_return_null_for_a_complex_type_with_entity_level_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
            .Setup <IList <IValidator> >("BuildValidationAttributeValidators", ItExpr.IsAny <IEnumerable <Attribute> >())
            .Returns <IEnumerable <Attribute> >(
                a => new List <IValidator>
            {
                new ValidationAttributeValidator(new RequiredAttribute(), null)
            });

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                  .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                var validator = builder.Object.BuildComplexTypeValidatorBase(typeof(ComplexTypeWithNoValidation), complexType);

                Assert.NotNull(validator);
                Assert.Equal(0, validator.PropertyValidators.Count());
                Assert.Equal(1, validator.TypeLevelValidators.Count());
            }
        }
Ejemplo n.º 3
0
        public void BuildValidatorsForProperties_returns_empty_if_no_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validators = builder.Object.BuildValidatorsForPropertiesBase(
                    entity.GetType().GetRuntimeProperties().Where(p => p.IsPublic()),
                    ctx.Entry(entity).InternalEntry.EdmEntityType.Properties,
                    ctx.Entry(entity).InternalEntry.EdmEntityType.NavigationProperties);

                Assert.Equal(0, validators.Count);
            }
        }
Ejemplo n.º 4
0
        public void BuildComplexTypeValidator_does_not_return_null_for_a_complex_type_with_property_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
            .Setup <IList <PropertyValidator> >(
                "BuildValidatorsForProperties", ItExpr.IsAny <IEnumerable <PropertyInfo> >(), ItExpr.IsAny <IEnumerable <EdmProperty> >(),
                ItExpr.IsAny <IEnumerable <NavigationProperty> >())
            .Returns <IEnumerable <PropertyInfo>, IEnumerable <EdmProperty>, IEnumerable <NavigationProperty> >(
                (pi, e, n) => new List <PropertyValidator>
            {
                new PropertyValidator("foo", Enumerable.Empty <IValidator>())
            });

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                  .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                var validator = builder.Object.BuildComplexTypeValidatorBase(typeof(ComplexTypeWithNoValidation), complexType);

                Assert.NotNull(validator);
                Assert.Equal(1, validator.PropertyValidators.Count());
                Assert.Equal(0, validator.TypeLevelValidators.Count());
            }
        }
Ejemplo n.º 5
0
        public void BuildPropertyValidator_with_buildFacetValidators_set_to_false_returns_null_for_a_scalar_property_with_facet_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
            .Setup <IEnumerable <IValidator> >(
                "BuildFacetValidators", ItExpr.IsAny <PropertyInfo>(),
                ItExpr.IsAny <EdmMember>(), ItExpr.IsAny <IEnumerable <Attribute> >())
            .Returns <PropertyInfo, EdmMember, IEnumerable <Attribute> >(
                (pi, e, a) => new[]
            {
                new ValidationAttributeValidator(new RequiredAttribute(), null)
            });

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildPropertyValidatorBase(
                    entity.GetType().GetDeclaredProperty("ID"),
                    ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ID").Single(),
                    false);

                Assert.Null(validator);
            }
        }
Ejemplo n.º 6
0
        public void BuildValidatorsForProperties_calls_BuildPropertyValidator_for_a_scalar_property()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
            .Setup <PropertyValidator>("BuildPropertyValidator", ItExpr.IsAny <PropertyInfo>())
            .Throws <AssertException>();

            builder.Protected()
            .Setup <PropertyValidator>(
                "BuildPropertyValidator", ItExpr.IsAny <PropertyInfo>(), ItExpr.IsAny <EdmProperty>(), ItExpr.IsAny <bool>())
            .Returns <PropertyInfo, EdmProperty, bool>(
                (pi, e, f) => new PropertyValidator(
                    "ID", new[]
            {
                new ValidationAttributeValidator(new RequiredAttribute(), null)
            }));

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validators = builder.Object.BuildValidatorsForPropertiesBase(
                    new[] { entity.GetType().GetDeclaredProperty("ID") },
                    new[] { ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ID").Single() },
                    new NavigationProperty[0]);

                Assert.Equal(1, validators.Count);
            }
        }
Ejemplo n.º 7
0
        public void BuildPropertyValidator_does_not_return_null_for_a_complex_property_with_attribute_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
            .Setup <IList <IValidator> >("BuildValidationAttributeValidators", ItExpr.IsAny <IEnumerable <Attribute> >())
            .Returns <IEnumerable <Attribute> >(
                a => new List <IValidator>
            {
                new ValidationAttributeValidator(new RequiredAttribute(), null)
            });

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildPropertyValidatorBase(
                    entity.GetType().GetDeclaredProperty("ComplexProperty"),
                    ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ComplexProperty").Single(),
                    true);

                Assert.NotNull(validator);
                Assert.IsType <ComplexPropertyValidator>(validator);
                Assert.Equal("ComplexProperty", validator.PropertyName);
                Assert.Equal(1, validator.PropertyAttributeValidators.Count());
                Assert.Null(((ComplexPropertyValidator)validator).ComplexTypeValidator);
            }
        }
Ejemplo n.º 8
0
        public void BuildPropertyValidator_does_not_return_null_for_a_complex_property_with_type_level_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
            .Setup <ComplexTypeValidator>("BuildComplexTypeValidator", ItExpr.IsAny <Type>(), ItExpr.IsAny <ComplexType>())
            .Returns <Type, ComplexType>(
                (t, c) => new ComplexTypeValidator(new PropertyValidator[0], new ValidationAttributeValidator[0]));

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildPropertyValidatorBase(
                    entity.GetType().GetDeclaredProperty("ComplexProperty"),
                    ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ComplexProperty").Single(),
                    false);

                Assert.NotNull(validator);
                Assert.IsType <ComplexPropertyValidator>(validator);
                Assert.Equal("ComplexProperty", validator.PropertyName);
                Assert.Equal(0, validator.PropertyAttributeValidators.Count());
                Assert.NotNull(((ComplexPropertyValidator)validator).ComplexTypeValidator);
            }
        }
Ejemplo n.º 9
0
        public void BuildEntityValidator_returns_null_for_an_entity_with_no_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                Assert.Null(builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry));
            }
        }
Ejemplo n.º 10
0
        public void BuildComplexTypeValidator_returns_null_for_a_complex_type_with_no_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                  .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                Assert.Null(builder.Object.BuildComplexTypeValidatorBase(typeof(ComplexTypeWithNoValidation), complexType));
            }
        }
Ejemplo n.º 11
0
        public void BuildPropertyValidator_returns_null_for_a_complex_property_with_no_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                Assert.Null(
                    builder.Object.BuildPropertyValidatorBase(
                        entity.GetType().GetDeclaredProperty("ComplexProperty"),
                        ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ComplexProperty").Single(),
                        true));
            }
        }
Ejemplo n.º 12
0
        public void BuildEntityValidator_does_not_return_null_for_an_IValidatableObject()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new ValidatableEntity();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry);

                Assert.NotNull(validator);
                Assert.False(validator.PropertyValidators.Any());
                Assert.True(validator.TypeLevelValidators.Any());
            }
        }
Ejemplo n.º 13
0
        public void BuildFacetValidators_returns_empty_for_optional_property()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validators = builder.Object.BuildFacetValidatorsBase(
                    entity.GetType().GetDeclaredProperty("Self"),
                    ctx.Entry(entity).InternalEntry.EdmEntityType.NavigationProperties.Where(p => p.Name == "Self").Single(),
                    new Attribute[0]);

                Assert.False(validators.Any());
            }
        }
Ejemplo n.º 14
0
        public void BuildComplexTypeValidator_does_not_return_null_for_an_IValidatableObject()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new ValidatableEntity();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                  .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                var validator = builder.Object.BuildComplexTypeValidatorBase(typeof(ValidatableComplexType), complexType);

                Assert.NotNull(validator);
                Assert.False(validator.PropertyValidators.Any());
                Assert.True(validator.TypeLevelValidators.Any());
            }
        }
Ejemplo n.º 15
0
        public void BuildEntityValidator_does_not_return_null_for_an_entity_with_entity_level_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
            .Setup <IList <IValidator> >("BuildValidationAttributeValidators", ItExpr.IsAny <IEnumerable <Attribute> >())
            .Returns <IEnumerable <Attribute> >(
                a => new List <IValidator>
            {
                new ValidationAttributeValidator(new RequiredAttribute(), null)
            });

            object entity = new EntityWithComplexType();

            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry);

                Assert.NotNull(validator);
                Assert.Equal(0, validator.PropertyValidators.Count());
                Assert.Equal(1, validator.TypeLevelValidators.Count());
            }
        }
        public void BuildEntityValidator_does_not_return_null_for_an_entity_with_entity_level_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
                .Setup<IList<IValidator>>("BuildValidationAttributeValidators", ItExpr.IsAny<IEnumerable<Attribute>>())
                .Returns<IEnumerable<Attribute>>(
                    a => new List<IValidator>
                             {
                                 new ValidationAttributeValidator(new RequiredAttribute(), null)
                             });

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry);

                Assert.NotNull(validator);
                Assert.Equal(0, validator.PropertyValidators.Count());
                Assert.Equal(1, validator.TypeLevelValidators.Count());
            }
        }
        public void BuildValidatorsForProperties_returns_empty_if_no_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validators = builder.Object.BuildValidatorsForPropertiesBase(
                    entity.GetType().GetProperties(),
                    ctx.Entry(entity).InternalEntry.EdmEntityType.Properties,
                    ctx.Entry(entity).InternalEntry.EdmEntityType.NavigationProperties);

                Assert.Equal(0, validators.Count);
            }
        }
        public void BuildComplexTypeValidator_returns_null_for_a_complex_type_with_no_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                                   .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                Assert.Null(builder.Object.BuildComplexTypeValidatorBase(typeof(ComplexTypeWithNoValidation), complexType));
            }
        }
        public void BuildComplexTypeValidator_does_not_return_null_for_an_IValidatableObject()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new ValidatableEntity();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                                   .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                var validator = builder.Object.BuildComplexTypeValidatorBase(typeof(ValidatableComplexType), complexType);

                Assert.NotNull(validator);
                Assert.False(validator.PropertyValidators.Any());
                Assert.True(validator.TypeLevelValidators.Any());
            }
        }
        public void BuildComplexTypeValidator_does_not_return_null_for_a_complex_type_with_property_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();
            builder.Protected()
                .Setup<IList<PropertyValidator>>(
                    "BuildValidatorsForProperties", ItExpr.IsAny<IEnumerable<PropertyInfo>>(), ItExpr.IsAny<IEnumerable<EdmProperty>>(),
                    ItExpr.IsAny<IEnumerable<NavigationProperty>>())
                .Returns<IEnumerable<PropertyInfo>, IEnumerable<EdmProperty>, IEnumerable<NavigationProperty>>(
                    (pi, e, n) => new List<PropertyValidator>
                                      {
                                          new PropertyValidator("foo", Enumerable.Empty<IValidator>())
                                      });

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                                   .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                var validator = builder.Object.BuildComplexTypeValidatorBase(typeof(ComplexTypeWithNoValidation), complexType);

                Assert.NotNull(validator);
                Assert.Equal(1, validator.PropertyValidators.Count());
                Assert.Equal(0, validator.TypeLevelValidators.Count());
            }
        }
        public void BuildComplexTypeValidator_does_not_return_null_for_a_complex_type_with_entity_level_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
                .Setup<IList<IValidator>>("BuildValidationAttributeValidators", ItExpr.IsAny<IEnumerable<Attribute>>())
                .Returns<IEnumerable<Attribute>>(
                    a => new List<IValidator>
                             {
                                 new ValidationAttributeValidator(new RequiredAttribute(), null)
                             });

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var complexType = (ComplexType)ctx.Entry(entity).InternalEntry.EdmEntityType.Properties
                                                   .Where(p => p.Name == "ComplexProperty").Single().TypeUsage.EdmType;
                var validator = builder.Object.BuildComplexTypeValidatorBase(typeof(ComplexTypeWithNoValidation), complexType);

                Assert.NotNull(validator);
                Assert.Equal(0, validator.PropertyValidators.Count());
                Assert.Equal(1, validator.TypeLevelValidators.Count());
            }
        }
        public void BuildFacetValidators_returns_empty_for_optional_property()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validators = builder.Object.BuildFacetValidatorsBase(
                    entity.GetType().GetProperty("Self"),
                    ctx.Entry(entity).InternalEntry.EdmEntityType.NavigationProperties.Where(p => p.Name == "Self").Single(),
                    new Attribute[0]);

                Assert.False(validators.Any());
            }
        }
        public void BuildValidatorsForProperties_calls_BuildPropertyValidator_for_a_scalar_property()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();
            builder.Protected()
                .Setup<PropertyValidator>("BuildPropertyValidator", ItExpr.IsAny<PropertyInfo>())
                .Throws<AssertException>();

            builder.Protected()
                .Setup<PropertyValidator>(
                    "BuildPropertyValidator", ItExpr.IsAny<PropertyInfo>(), ItExpr.IsAny<EdmProperty>(), ItExpr.IsAny<bool>())
                .Returns<PropertyInfo, EdmProperty, bool>(
                    (pi, e, f) => new PropertyValidator(
                                      "ID", new[]
                                                {
                                                    new ValidationAttributeValidator(new RequiredAttribute(), null)
                                                }));

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validators = builder.Object.BuildValidatorsForPropertiesBase(
                    new[] { entity.GetType().GetProperty("ID") },
                    new[] { ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ID").Single() },
                    new NavigationProperty[0]);

                Assert.Equal(1, validators.Count);
            }
        }
        public void BuildPropertyValidator_returns_null_for_a_complex_property_with_no_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                Assert.Null(
                    builder.Object.BuildPropertyValidatorBase(
                        entity.GetType().GetProperty("ComplexProperty"),
                        ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ComplexProperty").Single(),
                        true));
            }
        }
        public void BuildPropertyValidator_returns_null_for_a_complex_property_with_facet_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();
            builder.Protected()
                .Setup<IEnumerable<IValidator>>(
                    "BuildFacetValidators", ItExpr.IsAny<PropertyInfo>(), ItExpr.IsAny<EdmMember>(), ItExpr.IsAny<IEnumerable<Attribute>>())
                .Returns<PropertyInfo, EdmMember, IEnumerable<Attribute>>(
                    (pi, e, a) => new[]
                                      {
                                          new ValidationAttributeValidator(new RequiredAttribute(), null)
                                      });

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                Assert.Null(
                    builder.Object.BuildPropertyValidatorBase(
                        entity.GetType().GetProperty("ComplexProperty"),
                        ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ComplexProperty").Single(),
                        true));
            }
        }
        public void BuildPropertyValidator_does_not_return_null_for_a_complex_property_with_attribute_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
                .Setup<IList<IValidator>>("BuildValidationAttributeValidators", ItExpr.IsAny<IEnumerable<Attribute>>())
                .Returns<IEnumerable<Attribute>>(
                    a => new List<IValidator>
                             {
                                 new ValidationAttributeValidator(new RequiredAttribute(), null)
                             });

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildPropertyValidatorBase(
                    entity.GetType().GetProperty("ComplexProperty"),
                    ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ComplexProperty").Single(),
                    true);

                Assert.NotNull(validator);
                Assert.IsType<ComplexPropertyValidator>(validator);
                Assert.Equal("ComplexProperty", validator.PropertyName);
                Assert.Equal(1, validator.PropertyAttributeValidators.Count());
                Assert.Null(((ComplexPropertyValidator)validator).ComplexTypeValidator);
            }
        }
        public void BuildEntityValidator_does_not_return_null_for_an_IValidatableObject()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new ValidatableEntity();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry);

                Assert.NotNull(validator);
                Assert.False(validator.PropertyValidators.Any());
                Assert.True(validator.TypeLevelValidators.Any());
            }
        }
        public void BuildEntityValidator_does_not_return_null_for_an_entity_with_property_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();
            builder.Protected()
                .Setup<IList<PropertyValidator>>(
                    "BuildValidatorsForProperties", ItExpr.IsAny<IEnumerable<PropertyInfo>>(), ItExpr.IsAny<IEnumerable<EdmProperty>>(),
                    ItExpr.IsAny<IEnumerable<NavigationProperty>>())
                .Returns<IEnumerable<PropertyInfo>, IEnumerable<EdmProperty>, IEnumerable<NavigationProperty>>(
                    (pi, e, n) => new List<PropertyValidator>
                                      {
                                          new PropertyValidator("foo", Enumerable.Empty<ValidationAttributeValidator>())
                                      });

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry);

                Assert.NotNull(validator);
                Assert.Equal(1, validator.PropertyValidators.Count());
                Assert.Equal(0, validator.TypeLevelValidators.Count());
            }
        }
        public void BuildEntityValidator_returns_null_for_an_entity_with_no_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                Assert.Null(builder.Object.BuildEntityValidatorBase(ctx.Entry(entity).InternalEntry));
            }
        }
        public void BuildPropertyValidator_does_not_return_null_for_a_complex_property_with_type_level_validation()
        {
            var builder = MockHelper.CreateMockEntityValidatorBuilder();

            builder.Protected()
                .Setup<ComplexTypeValidator>("BuildComplexTypeValidator", ItExpr.IsAny<Type>(), ItExpr.IsAny<ComplexType>())
                .Returns<Type, ComplexType>(
                    (t, c) => new ComplexTypeValidator(new PropertyValidator[0], new ValidationAttributeValidator[0]));

            object entity = new EntityWithComplexType();
            using (var ctx = new SelfPopulatingContext(entity))
            {
                var validator = builder.Object.BuildPropertyValidatorBase(
                    entity.GetType().GetProperty("ComplexProperty"),
                    ctx.Entry(entity).InternalEntry.EdmEntityType.Properties.Where(p => p.Name == "ComplexProperty").Single(),
                    false);

                Assert.NotNull(validator);
                Assert.IsType<ComplexPropertyValidator>(validator);
                Assert.Equal("ComplexProperty", validator.PropertyName);
                Assert.Equal(0, validator.PropertyAttributeValidators.Count());
                Assert.NotNull(((ComplexPropertyValidator)validator).ComplexTypeValidator);
            }
        }