Example #1
0
        public void OnEntityTypeAdded_calls_apply_on_conventions_in_order()
        {
            var conventionDispatcher = new ConventionsDispatcher();
            var builder = new InternalModelBuilder(new Model(), conventionDispatcher);

            InternalEntityBuilder entityBuilder = null;
            var convention = new Mock <IEntityTypeConvention>();

            convention.Setup(c => c.Apply(It.IsAny <InternalEntityBuilder>())).Returns <InternalEntityBuilder>(b =>
            {
                Assert.NotNull(b);
                entityBuilder = new InternalEntityBuilder(b.Metadata, b.ModelBuilder);
                return(entityBuilder);
            });
            conventionDispatcher.EntityTypeConventions.Add(convention.Object);

            var nullConvention = new Mock <IEntityTypeConvention>();

            nullConvention.Setup(c => c.Apply(It.IsAny <InternalEntityBuilder>())).Returns <InternalEntityBuilder>(b =>
            {
                Assert.Same(entityBuilder, b);
                return(null);
            });
            conventionDispatcher.EntityTypeConventions.Add(nullConvention.Object);

            Assert.Null(builder.Entity(typeof(Order), ConfigurationSource.Convention));

            Assert.NotNull(entityBuilder);
        }
Example #2
0
        public ModelBuilder([NotNull] Model model, [NotNull] ConventionsDispatcher conventions)
        {
            Check.NotNull(model, "model");
            Check.NotNull(conventions, "conventions");

            Conventions = conventions;
            _builder    = new InternalModelBuilder(model, conventions);
        }
Example #3
0
        protected virtual ConventionsDispatcher CreateConventionsDispatcher()
        {
            var conventions = new ConventionsDispatcher();

            conventions.EntityTypeConventions.Add(new PropertiesConvention());
            conventions.EntityTypeConventions.Add(new KeyConvention());
            conventions.EntityTypeConventions.Add(new RelationshipDiscoveryConvention());

            return(conventions);
        }
Example #4
0
 public InternalModelBuilder([NotNull] Model metadata, [CanBeNull] ConventionsDispatcher conventions)
     : base(metadata)
 {
     _conventions = conventions;
 }