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))); }
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>(); }
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); }
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"); }
public void SetOndelete() { var hbm = new HbmKey(); var mapper = new KeyMapper <string>(hbm); mapper.OnDeleteCascade(); hbm.ondelete.Should().Be.EqualTo(HbmOndelete.Cascade); }
public void WhenAssignFKToWhiteSpacesThenAssignNone() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); km.ForeignKey(" "); hbm.foreignkey.Should().Be("none"); }
public void WhenAssignReferenceToNullThenNullifyReference() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); km.PropertyRef(null); hbm.propertyref.Should().Be.Null(); }
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"); }
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(); }
public void WhenAssignFKToValidNameThenAssignName() { var hbm = new HbmKey(); var km = new KeyMapper(typeof(Animal), hbm); km.ForeignKey("FKDeLaPizza"); hbm.foreignkey.Should().Be("FKDeLaPizza"); }
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(); }
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(); }
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"); }
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(); }
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); }
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(); }
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); }
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, }); }
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(); }
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); }
public KeyMapper(Type ownerEntityType, HbmKey mapping) { this.ownerEntityType = ownerEntityType; this.mapping = mapping; this.mapping.column1 = DefaultColumnName(ownerEntityType); }
public KeyMapper(HbmKey mapping) { this.mapping = mapping; this.mapping.column1 = typeof(TEntity).Name.ToLowerInvariant() + "_key"; }