public void GetAttributes_returns_attributes_from_buddy_class()
        {
            var attributes = new AttributeProvider()
                .GetAttributes(typeof(AttributeProviderTestClass).GetProperty("BuddyProp"));

            Assert.Equal(1, attributes.OfType<KeyAttribute>().Count());
        }
        public void GetAttributes_returns_correct_set_of_non_public_type_attributes()
        {
            var attributes = new AttributeProvider().GetAttributes(typeof(NonPublicAttributeProviderTestClass));

            Assert.Equal(1, attributes.OfType<DataContractAttribute>().Count());
            Assert.Equal(1, attributes.OfType<TableAttribute>().Count());
        }
        public void AttributeCollectionFactory_returns_correct_set_of_empty_property_attributes()
        {
            var attributes = new AttributeProvider()
                .GetAttributes(typeof(AttributeProviderTestEmptyClass).GetProperty("MyProp"));

            Assert.Equal(0, attributes.Count());
        }
        public void AttributeCollectionFactory_returns_only_property_attributes_for_complex_type()
        {
            var attributes = new AttributeProvider()
                .GetAttributes(typeof(AttributeProviderEntityWithComplexProperty).GetProperty("CT"));

            Assert.Equal(1, attributes.Count());
            Assert.Equal(typeof(AttributeProviderEntityWithComplexProperty), ((CustomValidationAttribute)attributes.First()).ValidatorType);
            Assert.Equal("ValidateProperty", ((CustomValidationAttribute)attributes.First()).Method);
        }
        public void GetAttributes_returns_correct_set_of_property_attributes()
        {
            var attributes = new AttributeProvider()
                .GetAttributes(typeof(AttributeProviderTestClass).GetProperty("MyProp"));

            Assert.Equal(1, attributes.OfType<KeyAttribute>().Count());
            Assert.Equal(1, attributes.OfType<RequiredAttribute>().Count());
            Assert.Equal(1, attributes.OfType<DataMemberAttribute>().Count());
            Assert.Equal(1, attributes.OfType<MaxLengthAttribute>().Count());
        }
        public MappingContext(
            ModelConfiguration modelConfiguration,
            ConventionsConfiguration conventionsConfiguration,
            EdmModel model)
        {
            //Contract.Requires(modelConfiguration != null);
            //Contract.Requires(conventionsConfiguration != null);
            //Contract.Requires(model != null);

            _modelConfiguration = modelConfiguration;
            _conventionsConfiguration = conventionsConfiguration;
            _model = model;
            _attributeProvider = new AttributeProvider();
        }
        public MappingContext(
            ModelConfiguration modelConfiguration,
            ConventionsConfiguration conventionsConfiguration,
            EdmModel model,
            DbModelBuilderVersion modelBuilderVersion = DbModelBuilderVersion.Latest,
            AttributeProvider attributeProvider = null)
        {
            DebugCheck.NotNull(modelConfiguration);
            DebugCheck.NotNull(conventionsConfiguration);
            DebugCheck.NotNull(model);

            _modelConfiguration = modelConfiguration;
            _conventionsConfiguration = conventionsConfiguration;
            _model = model;
            _modelBuilderVersion = modelBuilderVersion;
            _attributeProvider = attributeProvider ?? new AttributeProvider();
        }
        public void GetAttributes_returns_correct_set_of_empty_type_attributes()
        {
            var attributes = new AttributeProvider().GetAttributes(typeof(AttributeProviderTestEmptyClass));

            Assert.Equal(0, attributes.Count());
        }
        public AttributeMapper(AttributeProvider attributeProvider)
        {
            DebugCheck.NotNull(attributeProvider);

            _attributeProvider = attributeProvider;
        }
 public EntityValidatorBuilderForMock(AttributeProvider attributeProvider)
     : base(attributeProvider)
 {
 }
        /// <summary>
        ///     Constructs a <see cref="LazyInternalContext" /> for the given <see cref="DbContext" /> owner that will be initialized
        ///     on first use.
        /// </summary>
        /// <param name="owner">
        ///     The owner <see cref="DbContext" /> .
        /// </param>
        /// <param name="internalConnection"> Responsible for creating a connection lazily when the context is used for the first time. </param>
        /// <param name="model"> The model, or null if it will be created by convention </param>
        public LazyInternalContext(
            DbContext owner,
            IInternalConnection internalConnection,
            DbCompiledModel model,
            Func<DbContext, IDbModelCacheKey> cacheKeyFactory = null,
            AttributeProvider attributeProvider = null,
            Lazy<Dispatchers> dispatchers = null)
            : base(owner, dispatchers)
        {
            DebugCheck.NotNull(internalConnection);

            _internalConnection = internalConnection;
            _model = model;
            _cacheKeyFactory = cacheKeyFactory ?? new DefaultModelCacheKeyFactory().Create;
            _attributeProvider = attributeProvider ?? new AttributeProvider();

            _createdWithExistingModel = model != null;
        }
        public void GetAttributes_returns_correct_set_of_empty_type_attributes()
        {
            var attributes = new AttributeProvider().GetAttributes(typeof(AttributeProviderTestEmptyClass));

            Assert.Equal(0, attributes.Count());
        }
        public void GetAttributes_returns_empty_enumerable_when_no_property_descriptor()
        {
            var attributes = new AttributeProvider().GetAttributes(new MockPropertyInfo());

            Assert.Equal(0, attributes.Count());
        }
        /// <summary>
        ///     Creates and configures the <see cref = "DbModelBuilder" /> instance that will be used to build the
        ///     <see cref = "DbCompiledModel" />.
        /// </summary>
        /// <returns>The builder.</returns>
        public DbModelBuilder CreateModelBuilder()
        {
            var versionAttribute = new AttributeProvider().GetAttributes(Owner.GetType())
                .OfType<DbModelBuilderVersionAttribute>()
                .FirstOrDefault();
            var version = versionAttribute != null ? versionAttribute.Version : DbModelBuilderVersion.Latest;

            var modelBuilder = new DbModelBuilder(version);

            var modelNamespace = EdmUtil.StripInvalidCharacters(Owner.GetType().Namespace);
            if (!String.IsNullOrWhiteSpace(modelNamespace))
            {
                modelBuilder.Conventions.Add(new ModelNamespaceConvention(modelNamespace));
            }

            var modelContainer = EdmUtil.StripInvalidCharacters(Owner.GetType().Name);
            if (!String.IsNullOrWhiteSpace(modelContainer))
            {
                modelBuilder.Conventions.Add(new ModelContainerConvention(modelContainer));
            }

            new DbSetDiscoveryService(Owner).RegisterSets(modelBuilder);

            Owner.CallOnModelCreating(modelBuilder);

            if (OnModelCreating != null)
            {
                OnModelCreating(modelBuilder);
            }

            return modelBuilder;
        }
        public void GetAttributes_does_not_return_attributes_from_non_public_buddy_class()
        {
            var attributes = new AttributeProvider()
                .GetAttributes(typeof(NonPublicAttributeProviderTestClass)
                .GetProperty("BuddyProp", BindingFlags.NonPublic | BindingFlags.Instance));

            Assert.Equal(0, attributes.OfType<KeyAttribute>().Count());
        }
        public void GetAttributes_returns_correct_set_of_non_public_property_attributes()
        {
            var attributes = new AttributeProvider()
                .GetAttributes(typeof(NonPublicAttributeProviderTestClass)
                    .GetProperty("MyProp", BindingFlags.NonPublic | BindingFlags.Instance));

            Assert.Equal(1, attributes.OfType<KeyAttribute>().Count());
            Assert.Equal(1, attributes.OfType<RequiredAttribute>().Count());
            Assert.Equal(1, attributes.OfType<DataMemberAttribute>().Count());
            Assert.Equal(1, attributes.OfType<MaxLengthAttribute>().Count());
        }
        public void GetAttributes_returns_empty_enumerable_when_no_property_descriptor()
        {
            var attributes = new AttributeProvider().GetAttributes(new MockPropertyInfo());

            Assert.Equal(0, attributes.Count());
        }
        public AttributeMapper(AttributeProvider attributeProvider)
        {
            //Contract.Requires(attributeProvider != null);

            _attributeProvider = attributeProvider;
        }
 /// <summary>
 ///     Initializes a new instance of <see cref="ValidationProvider" /> class.
 /// </summary>
 public ValidationProvider(EntityValidatorBuilder builder = null, AttributeProvider attributeProvider = null)
 {
     _entityValidators = new Dictionary<Type, EntityValidator>();
     _entityValidatorBuilder = builder ?? new EntityValidatorBuilder(attributeProvider ?? new AttributeProvider());
 }