예제 #1
0
 private PropertyConventionConfiguration(
     ConventionsConfiguration conventionsConfiguration,
     IEnumerable <Func <PropertyInfo, bool> > predicates)
 {
     this._conventionsConfiguration = conventionsConfiguration;
     this._predicates = predicates;
 }
예제 #2
0
 private TypeConventionConfiguration(
     ConventionsConfiguration conventionsConfiguration,
     IEnumerable <Func <Type, bool> > predicates)
 {
     this._conventionsConfiguration = conventionsConfiguration;
     this._predicates = predicates;
 }
예제 #3
0
 private ConventionsConfiguration(ConventionsConfiguration source)
 {
     this._configurationConventions.AddRange((IEnumerable <IConvention>)source._configurationConventions);
     this._conceptualModelConventions.AddRange((IEnumerable <IConvention>)source._conceptualModelConventions);
     this._conceptualToStoreMappingConventions.AddRange((IEnumerable <IConvention>)source._conceptualToStoreMappingConventions);
     this._storeModelConventions.AddRange((IEnumerable <IConvention>)source._storeModelConventions);
 }
예제 #4
0
        public void AddBefore <TExistingConvention>(IConvention newConvention) where TExistingConvention : IConvention
        {
            Check.NotNull <IConvention>(newConvention, nameof(newConvention));
            bool flag = true;

            if (ConventionsTypeFilter.IsConfigurationConvention(newConvention.GetType()) && ConventionsTypeFilter.IsConfigurationConvention(typeof(TExistingConvention)))
            {
                flag = false;
                ConventionsConfiguration.Insert(typeof(TExistingConvention), 0, newConvention, (IList <IConvention>) this._configurationConventions);
            }
            if (ConventionsTypeFilter.IsConceptualModelConvention(newConvention.GetType()) && ConventionsTypeFilter.IsConceptualModelConvention(typeof(TExistingConvention)))
            {
                flag = false;
                ConventionsConfiguration.Insert(typeof(TExistingConvention), 0, newConvention, (IList <IConvention>) this._conceptualModelConventions);
            }
            if (ConventionsTypeFilter.IsStoreModelConvention(newConvention.GetType()) && ConventionsTypeFilter.IsStoreModelConvention(typeof(TExistingConvention)))
            {
                flag = false;
                ConventionsConfiguration.Insert(typeof(TExistingConvention), 0, newConvention, (IList <IConvention>) this._storeModelConventions);
            }
            if (ConventionsTypeFilter.IsConceptualToStoreMappingConvention(newConvention.GetType()) && ConventionsTypeFilter.IsConceptualToStoreMappingConvention(typeof(TExistingConvention)))
            {
                flag = false;
                ConventionsConfiguration.Insert(typeof(TExistingConvention), 0, newConvention, (IList <IConvention>) this._conceptualToStoreMappingConventions);
            }
            if (flag)
            {
                throw new InvalidOperationException(Strings.ConventionsConfiguration_ConventionTypeMissmatch((object)newConvention.GetType(), (object)typeof(TExistingConvention)));
            }
        }
        private EntityConventionConfiguration(ConventionsConfiguration conventionsConfiguration, IEnumerable <Func <Type, bool> > predicates)
        {
            DebugCheck.NotNull(conventionsConfiguration);
            DebugCheck.NotNull(predicates);

            _conventionsConfiguration = conventionsConfiguration;
            _predicates = predicates;
        }
        private ConventionsConfiguration(ConventionsConfiguration source)
        {
            DebugCheck.NotNull(source);

            _configurationConventions.AddRange(source._configurationConventions);
            _conceptualModelConventions.AddRange(source._conceptualModelConventions);
            _conceptualToStoreMappingConventions.AddRange(source._conceptualToStoreMappingConventions);
            _storeModelConventions.AddRange(source._storeModelConventions);
        }
예제 #7
0
 internal TypeConventionWithHavingConfiguration(
     ConventionsConfiguration conventionsConfiguration,
     IEnumerable <Func <Type, bool> > predicates,
     Func <Type, T> capturingPredicate)
 {
     this._conventionsConfiguration = conventionsConfiguration;
     this._predicates         = predicates;
     this._capturingPredicate = capturingPredicate;
 }
        public void Where_evaluates_preconditions()
        {
            var conventions = new ConventionsConfiguration();
            var entities    = new TypeConventionConfiguration(conventions);

            var ex = Assert.Throws <ArgumentNullException>(
                () => entities.Where(null));

            Assert.Equal("predicate", ex.ParamName);
        }
        public void Configure_evaluates_preconditions()
        {
            var conventions = new ConventionsConfiguration();
            var properties  = new PropertyConventionConfiguration(conventions);

            var ex = Assert.Throws <ArgumentNullException>(
                () => properties.Configure(null));

            Assert.Equal("propertyConfigurationAction", ex.ParamName);
        }
        public void ApplyModelConfiguration_should_run_model_configuration_conventions()
        {
            var mockConvention           = new Mock <IConfigurationConvention>();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });
            var modelConfiguration       = new ModelConfiguration();

            conventionsConfiguration.ApplyModelConfiguration(modelConfiguration);

            mockConvention.Verify(c => c.Apply(modelConfiguration), Times.Once());
        }
        public void AddAfter_should_throw_when_after_convention_not_found()
        {
            var mockConvention           = new Mock <IConvention>();
            var conventionsConfiguration = new ConventionsConfiguration();

            Assert.Equal(
                Strings.ConventionNotFound(mockConvention.Object.GetType(), typeof(ConventionFixture)),
                Assert.Throws <InvalidOperationException>(() => conventionsConfiguration.AddAfter <ConventionFixture>(mockConvention.Object)).
                Message);
        }
        public void AddBefore_should_add_before_existing_convention()
        {
            var mockConvention           = new Mock <IConvention>();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { new ConventionFixture() });

            conventionsConfiguration.AddBefore <ConventionFixture>(mockConvention.Object);

            Assert.Equal(2, conventionsConfiguration.Conventions.Count());
            Assert.Same(mockConvention.Object, conventionsConfiguration.Conventions.First());
        }
        public void ApplyDatabase_should_run_database_conventions()
        {
            var database                 = new EdmModel(DataSpace.CSpace);
            var mockConvention           = new Mock <IDbConvention>();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });

            conventionsConfiguration.ApplyDatabase(database);

            mockConvention.Verify(c => c.Apply(database), Times.AtMostOnce());
        }
        public void Having_evaluates_preconditions()
        {
            var conventions = new ConventionsConfiguration();
            var properties  = new PropertyConventionConfiguration(conventions);

            var ex = Assert.Throws <ArgumentNullException>(
                () => properties.Having <object>(null));

            Assert.Equal("capturingPredicate", ex.ParamName);
        }
        public void ApplyPropertyConfiguration_should_run_property_configuration_conventions()
        {
            var mockConvention           = new Mock <IConfigurationConvention <PropertyInfo, Properties.Primitive.StringPropertyConfiguration> >();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });
            var mockPropertyInfo         = new MockPropertyInfo(typeof(string), "S");

            conventionsConfiguration.ApplyPropertyConfiguration(mockPropertyInfo, () => new Properties.Primitive.StringPropertyConfiguration());

            mockConvention.Verify(c => c.Apply(mockPropertyInfo, It.IsAny <Func <Properties.Primitive.StringPropertyConfiguration> >()), Times.AtMostOnce());
        }
        public void ApplyModelConfiguration_should_run_type_model_configuration_conventions()
        {
            var mockConvention           = new Mock <IConfigurationConvention <Type, ModelConfiguration> >();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });
            var modelConfiguration       = new ModelConfiguration();

            conventionsConfiguration.ApplyModelConfiguration(typeof(object), modelConfiguration);

            mockConvention.Verify(c => c.Apply(typeof(object), It.IsAny <Func <ModelConfiguration> >()), Times.AtMostOnce());
        }
        public void ApplyModel_should_run_model_conventions()
        {
            var model                    = new EdmModel(DataSpace.CSpace);
            var mockConvention           = new Mock <IEdmConvention>();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention.Object });

            conventionsConfiguration.ApplyModel(model);

            mockConvention.Verify(c => c.Apply(model), Times.AtMostOnce());
        }
        public void Add_should_append_convention_on_to_internal_list()
        {
            var mockConvention1          = new Mock <IConvention>();
            var mockConvention2          = new Mock <IConvention>();
            var conventionsConfiguration = new ConventionsConfiguration(new[] { mockConvention1.Object });

            conventionsConfiguration.Add(mockConvention2.Object);

            Assert.Equal(2, conventionsConfiguration.Conventions.Count());
            Assert.Same(mockConvention2.Object, conventionsConfiguration.Conventions.Last());
        }
        public void ApplyPropertyConfiguration_should_run_property_model_conventions()
        {
            var mockConvention           = new Mock <IConfigurationConvention <PropertyInfo, ModelConfiguration> >();
            var conventionsConfiguration = new ConventionsConfiguration(
                new IConvention[] { mockConvention.Object });
            var mockPropertyInfo   = new MockPropertyInfo(typeof(object), "N");
            var modelConfiguration = new ModelConfiguration();

            conventionsConfiguration.ApplyPropertyConfiguration(mockPropertyInfo, modelConfiguration);

            mockConvention.Verify(c => c.Apply(mockPropertyInfo, It.IsAny <Func <ModelConfiguration> >()), Times.AtMostOnce());
        }
        public void ApplyTypeConfiguration_should_run_type_configuration_conventions()
        {
            var mockConvention1          = new Mock <IConfigurationConvention <Type, EntityTypeConfiguration> >();
            var mockConvention2          = new Mock <IConfigurationConvention <Type, StructuralTypeConfiguration> >();
            var conventionsConfiguration = new ConventionsConfiguration(
                new IConvention[] { mockConvention1.Object, mockConvention2.Object });
            var entityTypeConfiguration = new Func <EntityTypeConfiguration>(() => new EntityTypeConfiguration(typeof(object)));

            conventionsConfiguration.ApplyTypeConfiguration(typeof(object), entityTypeConfiguration);

            mockConvention1.Verify(c => c.Apply(typeof(object), entityTypeConfiguration), Times.AtMostOnce());
            mockConvention2.Verify(c => c.Apply(typeof(object), entityTypeConfiguration), Times.AtMostOnce());
        }
예제 #21
0
        internal TypeConventionWithHavingConfiguration(
            ConventionsConfiguration conventionsConfiguration,
            IEnumerable <Func <Type, bool> > predicates,
            Func <Type, T> capturingPredicate)
        {
            DebugCheck.NotNull(conventionsConfiguration);
            DebugCheck.NotNull(predicates);
            DebugCheck.NotNull(capturingPredicate);

            _conventionsConfiguration = conventionsConfiguration;
            _predicates         = predicates;
            _capturingPredicate = capturingPredicate;
        }
        public void ApplyPropertyTypeConfiguration_should_run_property_type_configuration_conventions()
        {
            var mockConvention1          = new Mock <IConfigurationConvention <PropertyInfo, ComplexTypeConfiguration> >();
            var mockConvention2          = new Mock <IConfigurationConvention <PropertyInfo, StructuralTypeConfiguration> >();
            var conventionsConfiguration = new ConventionsConfiguration(
                new IConvention[] { mockConvention1.Object, mockConvention2.Object });
            var complexTypeConfiguration = new Func <ComplexTypeConfiguration>(() => new ComplexTypeConfiguration(typeof(object)));
            var mockPropertyInfo         = new MockPropertyInfo();

            conventionsConfiguration.ApplyPropertyTypeConfiguration(mockPropertyInfo, complexTypeConfiguration);

            mockConvention1.Verify(c => c.Apply(mockPropertyInfo, complexTypeConfiguration), Times.AtMostOnce());
            mockConvention2.Verify(c => c.Apply(mockPropertyInfo, complexTypeConfiguration), Times.AtMostOnce());
        }
예제 #23
0
        private static void Insert(
            Type existingConventionType,
            int offset,
            IConvention newConvention,
            IList <IConvention> conventions)
        {
            int num = ConventionsConfiguration.IndexOf(existingConventionType, conventions);

            if (num < 0)
            {
                throw Error.ConventionNotFound((object)newConvention.GetType(), (object)existingConventionType);
            }
            conventions.Insert(num + offset, newConvention);
        }
        public void ApplyDatabase_should_run_targeted_model_conventions()
        {
            var database                 = new EdmModel(DataSpace.SSpace);
            var table                    = database.AddTable("T");
            var mockConvention           = new Mock <IDbConvention <EntityType> >();
            var conventionsConfiguration = new ConventionsConfiguration(
                new IConvention[]
            {
                mockConvention.Object
            });

            conventionsConfiguration.ApplyDatabase(database);

            mockConvention.Verify(c => c.Apply(table, database), Times.AtMostOnce());
        }
        public void ApplyModel_should_run_targeted_model_conventions()
        {
            var model                    = new EdmModel(DataSpace.CSpace);
            var entityType               = model.AddEntityType("E");
            var mockConvention           = new Mock <IEdmConvention <EntityType> >();
            var conventionsConfiguration = new ConventionsConfiguration(
                new IConvention[]
            {
                mockConvention.Object
            });

            conventionsConfiguration.ApplyModel(model);

            mockConvention.Verify(c => c.Apply(entityType, model), Times.AtMostOnce());
        }
        public void ApplyPropertyConfiguration_should_run_navigation_property_configuration_conventions()
        {
            var mockConvention1          = new Mock <IConfigurationConvention <PropertyInfo, PropertyConfiguration> >();
            var mockConvention2          = new Mock <IConfigurationConvention <PropertyInfo, NavigationPropertyConfiguration> >();
            var conventionsConfiguration = new ConventionsConfiguration(
                new IConvention[] { mockConvention1.Object, mockConvention2.Object });
            var mockPropertyInfo = new MockPropertyInfo(typeof(object), "N");

            conventionsConfiguration.ApplyPropertyConfiguration(
                mockPropertyInfo,
                () => new NavigationPropertyConfiguration(mockPropertyInfo));

            mockConvention1.Verify(c => c.Apply(mockPropertyInfo, It.IsAny <Func <PropertyConfiguration> >()), Times.AtMostOnce());
            mockConvention2.Verify(c => c.Apply(mockPropertyInfo, It.IsAny <Func <NavigationPropertyConfiguration> >()), Times.AtMostOnce());
        }
        public void Where_configures_predicates()
        {
            Func <PropertyInfo, bool> predicate1 = p => true;
            Func <PropertyInfo, bool> predicate2 = p => false;
            var conventions = new ConventionsConfiguration();
            var properties  = new PropertyConventionConfiguration(conventions);

            var config = properties
                         .Where(predicate1)
                         .Where(predicate2);

            Assert.NotNull(config);
            Assert.Same(conventions, config.ConventionsConfiguration);
            Assert.Equal(2, config.Predicates.Count());
            Assert.Same(predicate2, config.Predicates.Last());
        }
        public void Where_configures_predicates()
        {
            Func <Type, bool> predicate1 = t => true;
            Func <Type, bool> predicate2 = t => false;
            var conventions = new ConventionsConfiguration();
            var entities    = new TypeConventionConfiguration(conventions);

            var config = entities
                         .Where(predicate1)
                         .Where(predicate2);

            Assert.NotNull(config);
            Assert.Same(conventions, config.ConventionsConfiguration);
            Assert.Equal(2, config.Predicates.Count());
            Assert.Same(predicate2, config.Predicates.Last());
        }
        public void Having_configures_capturing_predicate()
        {
            var conventions = new ConventionsConfiguration();
            var properties  = new PropertyConventionConfiguration(conventions);
            Func <PropertyInfo, bool>   predicate          = p => true;
            Func <PropertyInfo, object> capturingPredicate = p => null;

            var config = properties
                         .Where(predicate)
                         .Having(capturingPredicate);

            Assert.NotNull(config);
            Assert.Same(conventions, config.ConventionsConfiguration);
            Assert.Equal(1, config.Predicates.Count());
            Assert.Same(predicate, config.Predicates.Single());
            Assert.Same(capturingPredicate, config.CapturingPredicate);
        }
        public void Configure_adds_convention()
        {
            Func <PropertyInfo, bool> predicate = p => true;
            Action <LightweightPropertyConfiguration> configurationAction = c => { };
            var conventions = new ConventionsConfiguration();
            var properties  = new PropertyConventionConfiguration(conventions);

            properties
            .Where(predicate)
            .Configure(configurationAction);

            Assert.Equal(36, conventions.Conventions.Count());

            var convention = (PropertyConvention)conventions.Conventions.Last();

            Assert.Equal(1, convention.Predicates.Count());
            Assert.Same(predicate, convention.Predicates.Single());
            Assert.Same(configurationAction, convention.PropertyConfigurationAction);
        }