Inheritance: MapsMemberBase, IIdentityMapping, INameable
        public void CanSetIdToBeStandardIdMapping()
        {
            var idMapping = new IdMapping();
            _classMapping.Id = idMapping;

            _classMapping.Id.ShouldEqual(idMapping);
        }
        public void Should_not_write_the_default_access_type()
        {
            var idMapping = new IdMapping();

            _writer.VerifyXml(idMapping)
                .DoesntHaveAttribute("access");
        }
        public void CanSetIdToBeStandardIdMapping()
        {
            var idMapping = new IdMapping();
            mapping.Set(x => x.Id, Layer.Defaults, idMapping);

            mapping.Id.ShouldEqual(idMapping);
        }
        public void Should_produce_valid_hbm()
        {
            var id = new IdMapping { Generator = new IdGeneratorMapping()};
            _mocker.Get<IHbmWriter<IdGeneratorMapping>>()
                .Expect(x => x.Write(id.Generator)).Return(new HbmGenerator { @class = "native"});

            _writer.ShouldGenerateValidOutput(id);
        }
        public void ShouldWriteTheColumns()
        {
            var mapping = new IdMapping();
            mapping.AddColumn(Layer.Defaults, new ColumnMapping("Column1"));

            writer.VerifyXml(mapping)
                .Element("column").Exists();
        }
        public void ShouldWriteTheColumns()
        {
            var mapping = new IdMapping();
            mapping.AddColumn(new ColumnMapping { Name = "Column1" });

            writer.VerifyXml(mapping)
                .Element("column").Exists();
        }
        public void Should_apply_to_id_mapping()
        {
            var idMapping = new IdMapping();
            idMapping.BindToMember(ReflectionHelper.GetMember((Album a) => a.ID));

            _namingConvention.ProcessId(idMapping);

            idMapping.Name.ShouldEqual(idMapping.MappedMember.Name);
        }
        public void Should_apply_to_id_mapping()
        {
            var propertyInfo = ReflectionHelper.GetProperty((Album a) => a.ID);
            var idMapping = new IdMapping {PropertyInfo = propertyInfo};

            _namingConvention.ProcessId(idMapping);

            idMapping.Name.ShouldEqual(idMapping.PropertyInfo.Name);
        }
        public void Should_produce_valid_hbm()
        {
            var id = new IdMapping { Generator = new IdGeneratorMapping()};
            var generatorWriter = MockRepository.GenerateStub<IXmlWriter<IdGeneratorMapping>>();
            generatorWriter.Expect(x => x.Write(id.Generator)).Return(new HbmGenerator { @class = "native"});
            var writer = new HbmIdWriter(null, generatorWriter);

            writer.ShouldGenerateValidOutput(id);
        }
Exemple #10
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (!(classMap is ClassMapping)) {
                return;
            }

            var identity = ((ClassMapping) classMap).Id;
            if (identity == null) {
                var idMapping = new IdMapping {ContainingEntityType = classMap.Type};
                var columnMapping = new ColumnMapping();
                columnMapping.Set(x => x.Name, Layer.Defaults, member.Name);
                idMapping.AddColumn(Layer.Defaults, columnMapping);
                idMapping.Set(x => x.Name, Layer.Defaults, member.Name);
                idMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(member.PropertyType));
                idMapping.Member = member;
                idMapping.Set(x => x.Generator, Layer.Defaults, GetDefaultGenerator(member));

                SetDefaultAccess(member, idMapping);

                identity = idMapping;
            }
            else {
                if (identity is IdMapping) {
                    var idMapping = identity as IdMapping;
                    var compositeId = new CompositeIdMapping {ContainingEntityType = classMap.Type};

                    var idKeyPropertyMapping = GetKeyPropertyMapping(classMap.Type, idMapping.Name,
                                                                     idMapping.Type.GetUnderlyingSystemType());

                    var keyPropertyMapping = GetKeyPropertyMapping(classMap.Type, member.Name,
                                                                   member.PropertyType);

                    compositeId.AddKey(idKeyPropertyMapping);
                    compositeId.AddKey(keyPropertyMapping);

                    identity = compositeId;
                }
                else if (identity is CompositeIdMapping) {
                    var compositeId = identity as CompositeIdMapping;

                    var keyPropertyMapping = GetKeyPropertyMapping(classMap.Type, member.Name,
                                                                   member.PropertyType);

                    compositeId.AddKey(keyPropertyMapping);

                    identity = compositeId;
                }
                else {
                    throw new NotImplementedException(
                        string.Format("Mayank: Fluent nhibernate not exended to support type '{0}'",
                                      identity.GetType().Name));
                }
            }

            ((ClassMapping) classMap).Set(x => x.Id, Layer.Defaults, identity);
        }
        public void ShouldWriteTheGenerator()
        {
            var mapping = new IdMapping
            {
                Generator = new GeneratorMapping { Class = "Class" }
            };

            writer.VerifyXml(mapping)
                .Element("generator").Exists();
        }
        public void Should_write_the_generator()
        {
            var idMapping = new IdMapping {Generator = new IdGeneratorMapping()};

            _mocker.Get<IHbmWriter<IdGeneratorMapping>>()
                .Expect(x => x.Write(idMapping.Generator)).Return(new HbmGenerator());

            _writer.VerifyXml(idMapping)
                .Element("generator").Exists();
        }
        public void Should_write_the_columns()
        {
            var idMapping = new IdMapping(new ColumnMapping());

            _mocker.Get<IHbmWriter<ColumnMapping>>()
                .Expect(x => x.Write(idMapping.Columns.First())).Return(new HbmColumn());

            _writer.VerifyXml(idMapping)
                .Element("column").Exists();
        }
        public void Should_write_the_generator()
        {
            var idMapping = new IdMapping {Generator = new IdGeneratorMapping()};

            var generatorWriter = MockRepository.GenerateStub<IXmlWriter<IdGeneratorMapping>>();
            generatorWriter.Expect(x => x.Write(idMapping.Generator)).Return(new HbmGenerator());
            var writer = new HbmIdWriter(null, generatorWriter);

            writer.VerifyXml(idMapping)
                .Element("generator").Exists();
        }
        public void ShouldWriteTheGenerator()
        {
            var generatorMapping = new GeneratorMapping();
            generatorMapping.Set(x => x.Class, Layer.Defaults, "Class");
        
            var mapping = new IdMapping();
            mapping.Set(x => x.Generator, Layer.Defaults, generatorMapping);

            writer.VerifyXml(mapping)
                .Element("generator").Exists();
        }
        public void Should_write_the_columns()
        {
            var idMapping = new IdMapping(new ColumnMapping());

            var columnWriter = MockRepository.GenerateStub<IXmlWriter<ColumnMapping>>();
            columnWriter.Expect(x => x.Write(idMapping.Columns.First())).Return(new HbmColumn());
            var writer = new HbmIdWriter(columnWriter, null);

            writer.VerifyXml(idMapping)
                .Element("column").Exists();
        }
        public void Map(ClassMappingBase classMap, Member property)
        {
            if (!(classMap is ClassMapping)) return;

            var idMapping = new IdMapping { ContainingEntityType = classMap.Type };
            idMapping.AddDefaultColumn(new ColumnMapping() { Name = property.Name });
            idMapping.Name = property.Name;
            idMapping.Type = new TypeReference(property.PropertyType);
            idMapping.Member = property;
            idMapping.SetDefaultValue("Generator", GetDefaultGenerator(property));
            ((ClassMapping)classMap).Id = idMapping;        
        }
Exemple #18
0
 public bool Equals(IdMapping other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(base.Equals(other) && Equals(other.Member, Member) && Equals(other.ContainingEntityType, ContainingEntityType));
 }
 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;
 }
Exemple #20
0
        void SetDefaultAccess(Member member, IdMapping mapping)
        {
            var resolvedAccess = MemberAccessResolver.Resolve(member);

            if (resolvedAccess != Access.Property && resolvedAccess != Access.Unset)
            {
                // if it's a property or unset then we'll just let NH deal with it, otherwise
                // set the access to be whatever we determined it might be
                mapping.Set(x => x.Access, Layer.Defaults, resolvedAccess.ToString());
            }

            if (member.IsProperty && !member.CanWrite)
                mapping.Set(x => x.Access, Layer.Defaults, cfg.GetAccessStrategyForReadOnlyProperty(member).ToString());
        }
 public void BindId(IdMapping idMapping, PersistentClass clazz, Table table)
 {
     SimpleValue id = new SimpleValue(table);
     id.TypeName = idMapping.PropertyInfo.PropertyType.FullName;
     var property = CreateProperty(clazz, id, idMapping.PropertyInfo);
     clazz.IdentifierProperty = property;
     id.Table = clazz.Table;
     clazz.Identifier = id;
     foreach (var column in idMapping.Columns)
     {
         BindColumn(id, column);
     }
     BindGenerator(idMapping, id);
     id.Table.SetIdentifierValue(id);
 }
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (!(classMap is ClassMapping)) return;

            var idMapping = new IdMapping { ContainingEntityType = classMap.Type };
            idMapping.AddDefaultColumn(new ColumnMapping() { Name = member.Name });
            idMapping.Name = member.Name;
            idMapping.Type = new TypeReference(member.PropertyType);
            idMapping.Member = member;
            idMapping.SetDefaultValue("Generator", GetDefaultGenerator(member));

            if (member.IsProperty && !member.CanWrite)
                idMapping.SetDefaultValue("Access", cfg.GetAccessStrategyForReadOnlyProperty(member).ToString());                

            ((ClassMapping)classMap).Id = idMapping;        
        }
Exemple #23
0
        public void Map(ClassMappingBase classMap, Member member)
        {
            if (!(classMap is ClassMapping)) return;

            var idMapping = new IdMapping { ContainingEntityType = classMap.Type };
            var columnMapping = new ColumnMapping();
            columnMapping.Set(x => x.Name, Layer.Defaults, member.Name);
            idMapping.AddColumn(Layer.Defaults, columnMapping);
            idMapping.Set(x => x.Name, Layer.Defaults, member.Name);
            idMapping.Set(x => x.Type, Layer.Defaults, new TypeReference(member.PropertyType));
            idMapping.Member = member;
            idMapping.Set(x => x.Generator, Layer.Defaults, GetDefaultGenerator(member));

            SetDefaultAccess(member, idMapping);

            ((ClassMapping)classMap).Set(x => x.Id, Layer.Defaults, idMapping);        
        }
        IdMapping IIdentityMappingProvider.GetIdentityMapping()
        {
            var mapping = new IdMapping(attributes.CloneInner())
            {
                ContainingEntityType = entityType
            };

            if (columns.Count > 0)
            {
                foreach (var column in columns)
                    mapping.AddColumn(new ColumnMapping(columnAttributes.CloneInner()) {Name = column});
            }
            else
                mapping.AddDefaultColumn(new ColumnMapping(columnAttributes.CloneInner()) { Name = property.Name });

            mapping.Name = property.Name;
            mapping.SetDefaultValue(x => x.Type, new TypeReference(property.PropertyType));

            if (GeneratedBy.IsDirty)
                mapping.Generator = GeneratedBy.GetGeneratorMapping();

            return mapping;
        }
 public override void ProcessId(IdMapping idMapping)
 {
     ProcessIdentity(idMapping);
 }
        public void Should_write_the_specified_access_type()
        {
            var idMapping = new IdMapping();
            idMapping.MemberAccess = MemberAccess.Create(AccessStrategy.Field, NamingStrategy.CamelCase);

            _writer.VerifyXml(idMapping)
                .HasAttribute("access", "field.camelcase");
        }
 public virtual void ProcessId(IdMapping idMapping)
 {
 }
 public virtual void Visit(IdMapping mapping)
 {
 }
Exemple #29
0
 public bool Equals(IdMapping other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return base.Equals(other) && Equals(other.Member, Member) && Equals(other.ContainingEntityType, ContainingEntityType);
 }
 public IdentityInspector(IdMapping mapping)
     : base(mapping.Columns)
 {
     this.mapping = mapping;
     propertyMappings.Map(x => x.Nullable, "NotNull");
 }
 public void CreateDsl()
 {
     mapping = new IdMapping();
     inspector = new IdentityInspector(mapping);
 }