public void WhenAssignReferenceOutSideTheOwnerEntityThenThrow()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            ActionAssert.Throws <ArgumentOutOfRangeException>(() => km.PropertyRef(ForClass <B> .Property(x => x.Name)));
        }
示例#2
0
        public void WhenAssignReferenceOutSideTheOwnerEntityThenThrow()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            Executing.This(() => km.PropertyRef(ConfOrm.ForClass <B> .Property(x => x.Name))).Should().Throw <ArgumentOutOfRangeException>();
        }
示例#3
0
        private void BindKey(HbmKey keyMapping, Mapping.Collection model)
        {
            if (keyMapping == null)
            {
                return;
            }
            string    propRef = model.ReferencedPropertyName;
            IKeyValue keyValue;

            if (propRef == null)
            {
                keyValue = model.Owner.Identifier;
            }
            else
            {
                keyValue = (IKeyValue)model.Owner.GetProperty(propRef).Value;
            }
            var key = new DependantValue(model.CollectionTable, keyValue)
            {
                IsCascadeDeleteEnabled = keyMapping.ondelete == HbmOndelete.Cascade
            };

            new ValuePropertyBinder(key, Mappings).BindSimpleValue(keyMapping, Mapping.Collection.DefaultKeyColumnName, model.IsOneToMany);

            if (key.Type.ReturnedClass.IsArray)
            {
                throw new MappingException("illegal use of an array as an identifier (arrays don't reimplement Equals)");
            }
            model.Key = key;

            key.SetNullable(keyMapping.IsNullable.HasValue ? keyMapping.IsNullable.Value : true);
            key.SetUpdateable(keyMapping.IsUpdatable.HasValue ? keyMapping.IsUpdatable.Value : true);
            BindForeignKey(keyMapping.foreignkey, key);
        }
示例#4
0
        public void AssignPropertyReference()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            km.PropertyRef(ConfOrm.ForClass <Animal> .Property(x => x.Name));
            hbm.propertyref.Should().Be("Name");
        }
示例#5
0
        public void SetOndelete()
        {
            var hbm    = new HbmKey();
            var mapper = new KeyMapper <string>(hbm);

            mapper.OnDeleteCascade();
            hbm.ondelete.Should().Be.EqualTo(HbmOndelete.Cascade);
        }
示例#6
0
        public void WhenAssignFKToWhiteSpacesThenAssignNone()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            km.ForeignKey("    ");
            hbm.foreignkey.Should().Be("none");
        }
示例#7
0
        public void WhenAssignReferenceToNullThenNullifyReference()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            km.PropertyRef(null);
            hbm.propertyref.Should().Be.Null();
        }
示例#8
0
        public void WhenExplicitAssignementThenOverrideDefaultColumnName()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            km.Column("blha");
            hbm.Columns.First().name.Should().Be.EqualTo("blha");
        }
示例#9
0
        public void AutoAssignColumnNameByDefault()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            hbm.Columns.Should().Have.Count.EqualTo(1);
            hbm.Columns.First().name.Should().Not.Be.Empty().And.Not.Be.Null();
        }
示例#10
0
        public void WhenAssignFKToValidNameThenAssignName()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            km.ForeignKey("FKDeLaPizza");
            hbm.foreignkey.Should().Be("FKDeLaPizza");
        }
示例#11
0
        public void SetNotNull()
        {
            var hbm    = new HbmKey();
            var mapper = new KeyMapper <string>(hbm);

            mapper.NotNull = true;
            hbm.IsNullable.Should().Have.Value();
            hbm.IsNullable.Value.Should().Be.False();
        }
示例#12
0
        public void SetUnique()
        {
            var hbm    = new HbmKey();
            var mapper = new KeyMapper <string>(hbm);

            mapper.Unique = true;
            hbm.unique.Should().Be.True();
            hbm.uniqueSpecified.Should().Be.True();
        }
示例#13
0
        public void SetColumn()
        {
            var hbm    = new HbmKey();
            var mapper = new KeyMapper <string>(hbm);

            mapper.Column = "peppe";
            hbm.Columns.Should().Have.Count.EqualTo(1);
            hbm.Columns.First().name.Should().Be.EqualTo("peppe");
        }
示例#14
0
        public void SetUpdate()
        {
            var hbm    = new HbmKey();
            var mapper = new KeyMapper <string>(hbm);

            mapper.Update = false;
            hbm.update.Should().Be.False();
            hbm.updateSpecified.Should().Be.True();
        }
示例#15
0
        public void AssignOnDeleteAction()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            km.OnDelete(OnDeleteAction.Cascade);
            hbm.ondelete.Should().Be.EqualTo(HbmOndelete.Cascade);
            km.OnDelete(OnDeleteAction.NoAction);
            hbm.ondelete.Should().Be.EqualTo(HbmOndelete.Noaction);
        }
示例#16
0
        public void WhenAssignFKToNullThenSetToNull()
        {
            var hbm = new HbmKey();

            hbm.foreignkey = "aPreviousValue";
            var km = new KeyMapper(typeof(Animal), hbm);

            km.ForeignKey(null);
            hbm.foreignkey.Should().Be.Null();
        }
示例#17
0
        private void BindKey(JoinedSubclass subclass, HbmKey keyMapping, Table mytable)
        {
            // TODO : property-ref ??
            SimpleValue key = new DependantValue(mytable, subclass.Identifier);

            subclass.Key = key;
            key.IsCascadeDeleteEnabled = keyMapping.ondelete == HbmOndelete.Cascade;
            key.ForeignKeyName         = keyMapping.foreignkey;

            new ValuePropertyBinder(key, Mappings).BindSimpleValue(keyMapping, subclass.EntityName, false);
        }
示例#18
0
        public void WhenInterfaceIsImplementedByEntitiesThenTheKeyShouldHaveFkToNone()
        {
            HbmMapping mapping = GetMapping();

            HbmClass hbmMyRelatedRoot1      = mapping.RootClasses.First(r => r.Name.Contains("MyRelatedRoot1"));
            HbmClass hbmMyRelatedRoot2      = mapping.RootClasses.First(r => r.Name.Contains("MyRelatedRoot2"));
            HbmKey   hbmKeyInMyRelatedRoot1 = ((HbmBag)hbmMyRelatedRoot1.Properties.Where(p => p.Name == "Items").Single()).Key;
            HbmKey   hbmKeyInMyRelatedRoot2 = ((HbmBag)hbmMyRelatedRoot2.Properties.Where(p => p.Name == "Items").Single()).Key;

            hbmKeyInMyRelatedRoot1.foreignkey.Should().Be("none");
            hbmKeyInMyRelatedRoot2.foreignkey.Should().Be("none");
        }
 public void BindSimpleValue(HbmKey propertyMapping, string propertyPath, bool isNullable)
 {
     new ColumnsBinder(value, Mappings).Bind(propertyMapping.Columns, isNullable,
                                             () =>
                                             new HbmColumn
     {
         name             = mappings.NamingStrategy.PropertyToColumnName(propertyPath),
         notnull          = propertyMapping.notnull,
         notnullSpecified = propertyMapping.notnullSpecified,
         unique           = propertyMapping.unique,
         uniqueSpecified  = propertyMapping.uniqueSpecified,
     });
 }
示例#20
0
        public void AssignUpdate()
        {
            var hbm = new HbmKey();
            var km  = new KeyMapper(typeof(Animal), hbm);

            km.Update(false);
            hbm.update.Should().Be.False();
            hbm.updateSpecified.Should().Be.True();

            km.Update(true);
            hbm.update.Should().Be.True();
            hbm.updateSpecified.Should().Be.True();
        }
示例#21
0
        public void WhenInterfaceIsImplementedByEntitiesThenTheColumnOfKeyShouldBeTheSameOfIdInTheAnyElement()
        {
            HbmMapping mapping = GetMapping();

            HbmClass hbmMyEntity          = mapping.RootClasses.First(r => r.Name.Contains("MyEntity"));
            var      hbmAny               = (HbmAny)hbmMyEntity.Properties.Where(p => p.Name == "RelatedRoot").Single();
            var      columnNameForIdInAny = hbmAny.Columns.Skip(1).First().name;

            HbmClass hbmMyRelatedRoot1      = mapping.RootClasses.First(r => r.Name.Contains("MyRelatedRoot1"));
            HbmClass hbmMyRelatedRoot2      = mapping.RootClasses.First(r => r.Name.Contains("MyRelatedRoot2"));
            HbmKey   hbmKeyInMyRelatedRoot1 = ((HbmBag)hbmMyRelatedRoot1.Properties.Where(p => p.Name == "Items").Single()).Key;
            HbmKey   hbmKeyInMyRelatedRoot2 = ((HbmBag)hbmMyRelatedRoot2.Properties.Where(p => p.Name == "Items").Single()).Key;

            hbmKeyInMyRelatedRoot1.column1.Should().Be(columnNameForIdInAny);
            hbmKeyInMyRelatedRoot2.column1.Should().Be(columnNameForIdInAny);
        }
示例#22
0
 public KeyMapper(Type ownerEntityType, HbmKey mapping)
 {
     this.ownerEntityType = ownerEntityType;
     this.mapping         = mapping;
     this.mapping.column1 = DefaultColumnName(ownerEntityType);
 }
示例#23
0
 public KeyMapper(HbmKey mapping)
 {
     this.mapping         = mapping;
     this.mapping.column1 = typeof(TEntity).Name.ToLowerInvariant() + "_key";
 }