private void BeforeBindMapping(object sender, BindMappingEventArgs e) { HbmProperty prop = e.Mapping.RootClasses[0].Properties.OfType <HbmProperty>().Single(p => p.Name == "NotNullData"); prop.notnull = true; prop.notnullSpecified = true; }
public void WhenSetBasicColumnValuesThroughShortCutThenMergeColumn() { var member = typeof(MyClass).GetProperty("Autoproperty"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Column("pizza"); mapper.Length(50); mapper.Precision(10); mapper.Scale(2); mapper.NotNullable(true); mapper.Unique(true); mapper.UniqueKey("AA"); mapper.Index("II"); mapping.Items.Should().Be.Null(); mapping.column.Should().Be("pizza"); mapping.length.Should().Be("50"); mapping.precision.Should().Be("10"); mapping.scale.Should().Be("2"); mapping.notnull.Should().Be(true); mapping.unique.Should().Be(true); mapping.uniquekey.Should().Be("AA"); mapping.index.Should().Be("II"); }
public void Should_return_null_given_Items_and_columns_are_null() { HbmProperty property = new HbmProperty(); string result = property.GetSqlType(); result.ShouldBeNull(); }
public void Execute(object sender, BindMappingEventArgs e) { if (IsEdFiQueryMappingEvent(e)) { return; } foreach (var classMapping in e.Mapping.Items.OfType <HbmClass>()) { // Entities mapped with <version> are aggregate roots. if (classMapping.Version == null) { continue; } // Maps the ChangeVersion column dynamically // Requires there be a property on the base entity already // nHibernate wraps property getter exception in PropertyAccessException if any // underlying mapped properties are set to access "none", due to an invoke exception being triggered. // generated = "always" to avoid nHibernate trying to set values for it // <property name="ChangeVersion" column="ChangeVersion" type="long" not-null="true" generated="always" /> var changeVersionProperty = new HbmProperty { name = ChangeQueriesDatabaseConstants.ChangeVersionColumnName, column = ChangeQueriesDatabaseConstants.ChangeVersionColumnName, type = new HbmType { name = "long" }, notnull = true, generated = HbmPropertyGeneration.Always }; classMapping.Items = classMapping.Items.Concat(changeVersionProperty).ToArray(); } }
public void WhenSetBasicColumnValuesThroughShortCutThenMergeColumn() { var member = typeof(MyClass).GetProperty("Autoproperty"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Column("pizza"); mapper.Length(50); mapper.Precision(10); mapper.Scale(2); mapper.NotNullable(true); mapper.Unique(true); mapper.UniqueKey("AA"); mapper.Index("II"); Assert.That(mapping.Items, Is.Null); Assert.That(mapping.column, Is.EqualTo("pizza")); Assert.That(mapping.length, Is.EqualTo("50")); Assert.That(mapping.precision, Is.EqualTo("10")); Assert.That(mapping.scale, Is.EqualTo("2")); Assert.That(mapping.notnull, Is.EqualTo(true)); Assert.That(mapping.unique, Is.EqualTo(true)); Assert.That(mapping.uniquekey, Is.EqualTo("AA")); Assert.That(mapping.index, Is.EqualTo("II")); }
//automatically makes a column with the default name if none is specified by XML public void BindSimpleValue(HbmProperty propertyMapping, string propertyPath, bool isNullable) { new TypeBinder(value, Mappings).Bind(propertyMapping.Type); var formulas = propertyMapping.Formulas.ToArray(); if (formulas.Length > 0) { BindFormulas(formulas); } else { new ColumnsBinder(value, Mappings).Bind(propertyMapping.Columns, isNullable, () => new HbmColumn { name = mappings.NamingStrategy.PropertyToColumnName(propertyPath), length = propertyMapping.length, scale = propertyMapping.scale, precision = propertyMapping.precision, notnull = propertyMapping.notnull, notnullSpecified = propertyMapping.notnullSpecified, unique = propertyMapping.unique, uniqueSpecified = true, uniquekey = propertyMapping.uniquekey, index = propertyMapping.index }); } }
public static bool?CanBeNull(this HbmProperty item) { if (item.notnullSpecified) { return(!item.notnull); } return(item.Column().CanBeNull()); }
public void Property <TProperty>(Expression <Func <TComponent, TProperty> > property) { var hbmProperty = new HbmProperty { name = TypeUtils.DecodeMemberAccessExpression(property).Name }; AddProperty(hbmProperty); }
internal void AddProperty(MemberInfo memberInfo) { var hbmProperty = new HbmProperty { name = memberInfo.Name }; AddProperty(hbmProperty); }
private static HbmColumn Column(this HbmProperty item) { if (item.Items == null) { return(null); } return((HbmColumn)item.Items[0]); }
public static string GetUniqueIndex(this HbmProperty item) { if (item.index != null) { return(item.index); } return(item.Column().GetUniqueIndex()); }
public void AfterSetMultiColumnsCantSetSimpleColumn() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)")); Executing.This(() => mapper.Column(cm => cm.Length(50))).Should().Throw <MappingException>(); }
public void WhenSetInvalidTypeThenThrow() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); Executing.This(() => mapper.Type(typeof(object), null)).Should().Throw <ArgumentOutOfRangeException>(); Executing.This(() => mapper.Type(null, null)).Should().Throw <ArgumentNullException>(); }
public void AfterSetMultiColumnsCantSetSimpleColumn() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)")); Assert.That(() => mapper.Column(cm => cm.Length(50)), Throws.TypeOf <MappingException>()); }
public void WhenSetInvalidTypeThenThrow() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); Assert.That(() => mapper.Type(typeof(object), null), Throws.TypeOf <ArgumentOutOfRangeException>()); Assert.That(() => mapper.Type(null, null), Throws.TypeOf <ArgumentNullException>()); }
public void Property(MemberInfo property, Action <IPropertyMapper> mapping) { var hbmProperty = new HbmProperty { name = property.Name }; mapping(new PropertyMapper(property, hbmProperty)); AddProperty(hbmProperty); }
public void WhenSetMultiColumnsValuesThenAutoassignColumnNames() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)")); mapping.Columns.Should().Have.Count.EqualTo(2); mapping.Columns.All(cm => cm.name.Satisfy(n => !string.IsNullOrEmpty(n))); }
public void Should_get_null_given_null_length_and_Items_length() { HbmProperty property = new HbmProperty { Items = new object[] { new HbmColumn() } }; int?result = property.GetMaxLength(); result.ShouldBeNull(); }
public void Should_get_null_given_null_index_and_Items_index() { HbmProperty property = new HbmProperty { Items = new object[] { new HbmColumn() } }; string result = property.GetUniqueIndex(); result.ShouldBeNull(); }
public void WhenSetMultiColumnsValuesThenAutoassignColumnNames() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)")); Assert.That(mapping.Columns.Count(), Is.EqualTo(2)); Assert.True(mapping.Columns.All(cm => !string.IsNullOrEmpty(cm.name))); }
public void WhenSettingByTypeThenCheckCompatibility() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); Executing.This(() => mapper.Access(typeof(object))).Should().Throw <ArgumentOutOfRangeException>(); Executing.This(() => mapper.Access(typeof(FieldAccessor))).Should().NotThrow(); mapping.Access.Should().Be.EqualTo(typeof(FieldAccessor).AssemblyQualifiedName); }
public void CanSetFormula() { var member = ForClass <MyClass> .Property(c => c.Autoproperty); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Formula("SomeFormula"); mapping.formula.Should().Be("SomeFormula"); }
public void WhenSettingByTypeThenCheckCompatibility() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); Assert.That(() => mapper.Access(typeof(object)), Throws.TypeOf <ArgumentOutOfRangeException>()); Assert.That(() => mapper.Access(typeof(FieldAccessor)), Throws.Nothing); Assert.That(mapping.Access, Is.EqualTo(typeof(FieldAccessor).AssemblyQualifiedName)); }
public void WhenSetTypeByITypeThenSetTypeName() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Type(NHibernateUtil.String); Assert.That(mapping.Type.name, Is.EqualTo("String")); }
public void WhenCreateWithGivenAccessorMapperThenUseTheGivenAccessoMapper() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var myAccessorMapper = new MyAccessorMapper(); var mapper = new PropertyMapper(member, mapping, myAccessorMapper); mapper.Access(Accessor.Field); Assert.That(myAccessorMapper.AccessorCalled, Is.True); }
public void WhenSetTypeByICompositeUserTypeThenSetTypeName() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Type <MyCompoType>(); Assert.That(mapping.Type.name, Does.Contain("MyCompoType")); Assert.That(mapping.type, Is.Null); }
public void WhenSetLazyThenSetAttributes() { var member = For <MyClass> .Property(x => x.ReadOnly); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Lazy(true); Assert.That(mapping.lazy, Is.True); Assert.That(mapping.IsLazyProperty, Is.True); }
public void WhenSetInsertThenSetAttributes() { var member = For <MyClass> .Property(x => x.ReadOnly); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Insert(false); Assert.That(mapping.insert, Is.False); Assert.That(mapping.insertSpecified, Is.True); }
public void WhenSetDifferentColumnNameThenSetTheName() { var member = typeof(MyClass).GetProperty("Autoproperty"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Column(cm => cm.Name("pepe")); Assert.That(mapping.Columns.Count(), Is.EqualTo(1)); Assert.That(mapping.Columns.Single().name, Is.EqualTo("pepe")); }
public void WhenSetDefaultColumnNameThenDoesNotSetTheName() { var member = typeof(MyClass).GetProperty("Autoproperty"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Column(cm => { cm.Name("Autoproperty"); cm.Length(50); }); Assert.That(mapping.column, Is.Null); Assert.That(mapping.length, Is.EqualTo("50")); Assert.That(mapping.Columns, Is.Empty); }