public void ShouldAddIdToClass()
        {
            var classMap = new ClassMapping() { Type = typeof(IdClass)};
            var mapper = new IdAutoMapper();
            mapper.Map(classMap);

            Assert.IsNotNull(classMap.Id);
        }
        public void Should_produce_valid_hbm()
        {
            var classMapping = new ClassMapping {Name = "class1", Id = new IdMapping()};

            _mocker.Get<IHbmWriter<IIdentityMapping>>()
                .Expect(x => x.Write(classMapping.Id)).Return(new HbmId { generator = new HbmGenerator { @class = "native" } });

            _classWriter.ShouldGenerateValidOutput(classMapping);
        }
        public void ShouldSetIdAsProperty()
        {
            var classMap = new ClassMapping() { Type = typeof(IdClass) };
            var mapper = new IdAutoMapper();
            mapper.Map(classMap);

            var id = classMap.Id as IdMapping;
            Assert.AreEqual(id.MappedMember.Name, "Id");
        }
 protected virtual void BindClass(ClassMapping classMapping, PersistentClass clazz)
 {
     Type type = classMapping.Type;
     string entityName = type.FullName;
     clazz.EntityName = entityName;
     clazz.ClassName = type.AssemblyQualifiedName;
     BindPocoRepresentation(classMapping, clazz);
     BindPersistentClassCommonValues(classMapping, clazz);
 }
        public void Should_write_the_components()
        {
            var classMapping = new ClassMapping();
            classMapping.AddComponent(new ComponentMapping());

            _mocker.Get<IHbmWriter<ComponentMapping>>()
                .Expect(x => x.Write(classMapping.Components.First())).Return(new HbmComponent());

            _classWriter.VerifyXml(classMapping)
                .Element("component").Exists();
        }
        public void ShouldSetColumnNameToMatchPropertyName()
        {
            var classMap = new ClassMapping() { Type = typeof(IdClass) };
            var mapper = new IdAutoMapper();
            mapper.Map(classMap);

            var id = classMap.Id as IdMapping;
            var column = id.Columns.FirstOrDefault();

            Assert.AreEqual(column.Name, "Id");
        }
        public void Should_write_the_collections()
        {
            var classMapping = new ClassMapping();
            classMapping.AddCollection(new BagMapping());

            _mocker.Get<IHbmWriter<ICollectionMapping>>()
                .Expect(x => x.Write(classMapping.Collections.First()))
                .Return(new HbmBag());

            _classWriter.VerifyXml(classMapping)
                .Element("bag").Exists();
        }
 public void Map(ClassMapping classMap)
 {
     var idProperty = classMap.Type.GetProperty("Id");
     var columnMapping = new ColumnMapping { Name = "Id", MappedMember = idProperty };
     var mapping = new IdMapping(columnMapping)
                       {
                           Name = "Id",
                           Generator = new IdGeneratorMapping()
                       };
     mapping.BindToMember(idProperty);
     classMap.Id = mapping;
 }
        public void Map(ClassMapping classMap)
        {
            foreach(var property in classMap.Type.GetProperties())
            {
                if (!classMap.HasMappedProperty(property))
                {
                    if (property.PropertyType.Namespace == "System")
                    {
                        var propMapping = new PropertyMapping {Name = property.Name};
                        propMapping.BindToMember(property);

                        classMap.AddProperty(propMapping);
                    }
                }
            }
        }
        protected virtual void BindPersistentClassCommonValues(ClassMapping classMapping, PersistentClass model)
        {
            //TODO: Introduce all those
            model.DiscriminatorValue = model.EntityName;
            model.DynamicUpdate = false; ;
            model.DynamicInsert = false;
            string qualifiedName = model.MappedClass == null ? model.EntityName : model.MappedClass.AssemblyQualifiedName;
            mappings.AddImport(qualifiedName, model.EntityName);
            if (mappings.IsAutoImport && model.EntityName.IndexOf('.') > 0)
                mappings.AddImport(qualifiedName, StringHelper.Unqualify(model.EntityName));

            model.BatchSize = 0;
            model.SelectBeforeUpdate = false;
            model.OptimisticLockMode = NHibernate.Engine.Versioning.OptimisticLock.Version;
            model.IsAbstract = false;
            model.IsLazy = true;
        }
        public virtual void Bind(ClassMapping classMapping)
        {
            RootClass rootClass = new RootClass();
            BindClass(classMapping, rootClass);
            string schema = mappings.SchemaName;
            string catalog = mappings.CatalogName;
            string tableName = classMapping.Tablename.ValueOrDefault(
                mappings.NamingStrategy.TableName(classMapping.Type.Name));

            Table table = mappings
                .AddTable(schema, catalog, tableName, null,
                          rootClass.IsAbstract.GetValueOrDefault());//Introduce SchemaAction
            ((ITableOwner)rootClass).Table = table;

            rootClass.IsMutable = true;
            rootClass.IsExplicitPolymorphism = false;
            new ClassIdBinder(this).BindId(classMapping.Id as IdMapping, rootClass, table);
            rootClass.CreatePrimaryKey(dialect);
            base.BindProperties(rootClass, classMapping);
            mappings.AddClass(rootClass);
        }
        public void Should_pass_the_discriminator_to_the_visitor()
        {
            var classMap = new ClassMapping {Name = "class1" };
            classMap.Discriminator = new DiscriminatorMapping();

            var visitor = MockRepository.GenerateMock<IMappingModelVisitor>();
            visitor.Expect(x => x.Visit(classMap.Discriminator));

            classMap.AcceptVisitor(visitor);

            visitor.VerifyAllExpectations();
        }
        public void Should_pass_subclasses_to_the_visitor()
        {
            var classMap = new ClassMapping {Name = "class1" };
            classMap.AddSubclass(new JoinedSubclassMapping());

            var visitor = MockRepository.GenerateMock<IMappingModelVisitor>();
            visitor.Expect(x => x.Visit(classMap.Subclasses.First()));

            classMap.AcceptVisitor(visitor);

            visitor.VerifyAllExpectations();
        }
        public void Should_not_pass_null_id_to_the_visitor()
        {
            var classMap = new ClassMapping {Name = "class1" };
            classMap.Id = null;

            var visitor = MockRepository.GenerateMock<IMappingModelVisitor>();
            visitor.Expect(x => x.Visit(classMap.Id)).Repeat.Never();

            classMap.AcceptVisitor(visitor);

            visitor.VerifyAllExpectations();
        }
 public void AddClass(ClassMapping classMapping)
 {
     _classes.Add(classMapping);
 }
        public void Should_clear_the_parent_class_for_the_discriminator()
        {
            var classMap = new ClassMapping {Name = "class1" };
            var discriminator = new DiscriminatorMapping();

            classMap.Discriminator = discriminator;
            classMap.Discriminator = null;

            discriminator.ParentClass.ShouldBeNull();
        }
 public virtual void Visit(ClassMapping classMapping)
 {
 }
 public override void ProcessClass(ClassMapping classMapping)
 {
     ProcessClassBase(classMapping);
 }
        public void Should_write_the_subclasses()
        {
            var classMapping = new ClassMapping();
            classMapping.AddSubclass(new JoinedSubclassMapping());

            _mocker.Get<IHbmWriter<ISubclassMapping>>()
                .Expect(x => x.Write(classMapping.Subclasses.First()))
                .Return(new HbmJoinedSubclass());

            _classWriter.VerifyXml(classMapping)
                .Element("joined-subclass").Exists();
        }
        public void Should_write_the_references()
        {
            var classMapping = new ClassMapping();
            classMapping.AddReference(new ManyToOneMapping());

            _mocker.Get<IHbmWriter<ManyToOneMapping>>()
                .Expect(x => x.Write(classMapping.References.First()))
                .Return(new HbmManyToOne());

            _classWriter.VerifyXml(classMapping)
                .Element("many-to-one").Exists();
        }
        public void Should_write_the_properties()
        {
            var classMapping = new ClassMapping();
            classMapping.AddProperty(new PropertyMapping());
            _mocker.Get<IHbmWriter<PropertyMapping>>()
                .Expect(x => x.Write(classMapping.Properties.First()))
                .Return(new HbmProperty());

            _classWriter.VerifyXml(classMapping)
                .Element("property").Exists();
        }
        protected virtual void BindProperties(PersistentClass model, ClassMapping mapping)
        {
            foreach (var propertyMapping in mapping.Properties)
            {
                var value = new SimpleValue(model.Table);
                BindSimpleValue(value, propertyMapping);
                BindProperty(propertyMapping, value, model);
                BindColumn(value, new ColumnMapping
                {
                    Name = propertyMapping.Name,
                    PropertyInfo = propertyMapping.PropertyInfo,
                    Length=propertyMapping.Length,
                    IsNotNullable = propertyMapping.IsNotNullable
                });

            }
            foreach (var propertyMapping in mapping.Collections)
            {
                //TODO: Implement collection mapping
            }
        }
 protected virtual void BindPocoRepresentation(ClassMapping classMapping, PersistentClass clazz)
 {
     string className = classMapping.Type.AssemblyQualifiedName;
     clazz.ClassName = className;
     clazz.ProxyInterfaceName = className;
 }
        public void Should_set_the_parent_class_for_the_discriminator()
        {
            var classMap = new ClassMapping {Name = "class1" };
            classMap.Discriminator = new DiscriminatorMapping();

            classMap.Discriminator.ParentClass.ShouldEqual(classMap);
        }
 public void SetUp()
 {
     _classMapping = new ClassMapping();
 }
 public void Add(ClassMapping mapping)
 {
     _mappings.Add(mapping);
 }
 public override void Visit(ClassMapping classMapping)
 {
     classMapping.AcceptVisitor(this);
 }
        public void Should_write_the_discriminator()
        {
            var classMapping = new ClassMapping {Discriminator = new DiscriminatorMapping()};

            _mocker.Get<IHbmWriter<DiscriminatorMapping>>()
                .Expect(x => x.Write(classMapping.Discriminator)).Return(new HbmDiscriminator());

            _classWriter.VerifyXml(classMapping)
                .Element("discriminator").Exists();
        }
 public virtual void ProcessClass(ClassMapping classMapping)
 {
 }
        public void Should_write_the_id()
        {
            var classMapping = new ClassMapping { Id = new IdMapping() };
            _mocker.Get<IHbmWriter<IIdentityMapping>>()
                .Expect(x => x.Write(classMapping.Id))
                .Return(new HbmId());

            _classWriter.VerifyXml(classMapping)
                .Element("id").Exists();
        }