//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 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); myAccessorMapper.AccessorCalled.Should().Be.True(); }
public void SettingColumnOverridesFormula() { var member = ForClass<MyClass>.Property(c => c.Autoproperty); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Formula("formula"); mapper.Column(cm => cm.Unique(true)); mapping.formula.Should().Be.Null(); }
public void WhenSetTypeByITypeThenSetTypeName() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Type(NHibernateUtil.String); mapping.Type.name.Should().Be.EqualTo("String"); }
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 Should_get_null_given_notnullSpecified_is_false_and_Items_is_null() { HbmProperty property = new HbmProperty { notnullSpecified = false, Items = null }; bool? result = property.CanBeNull(); result.ShouldBeNull(); }
public void SettingColumnPlainValuesOverridesFormula() { var member = ForClass<MyClass>.Property(c => c.Autoproperty); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Formula("formula"); mapper.Column("colName"); mapping.formula.Should().Be.Null(); mapping.column.Should().Be("colName"); }
public virtual void Property(MemberInfo property, Action<IPropertyMapper> mapping) { if (!IsMemberSupportedByMappedContainer(property)) { throw new ArgumentOutOfRangeException("property", "Can't add a property of another graph"); } var hbmProperty = new HbmProperty {name = property.Name}; mapping(new PropertyMapper(property, hbmProperty)); AddProperty(hbmProperty); }
public void WhenSetTypeByIUserTypeThenSetTypeName() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Type<MyType>(); mapping.Type.name.Should().Contain("MyType"); mapping.type.Should().Be.Null(); }
public void WhenSetTypeByIUserTypeThenSetTypeName() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Type<MyType>(); Assert.That(mapping.Type.name, Is.StringContaining("MyType")); Assert.That(mapping.type, Is.Null); }
public virtual void Property(MemberInfo property, Action<IPropertyMapper> mapping) { if (!property.DeclaringType.IsAssignableFrom(container)) { throw new ArgumentOutOfRangeException("property","Can't add a property of another graph"); } var hbmProperty = new HbmProperty { name = property.Name }; mapping(new PropertyMapper(property, hbmProperty)); AddProperty(hbmProperty); }
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 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 Property(MemberInfo property, Action<IPropertyMapper> mapping) { var hbmProperty = new HbmProperty { name = property.Name, type1 = property.GetPropertyOrFieldType().GetNhTypeName() }; mapping(new PropertyMapper(property, hbmProperty, new NoMemberPropertyMapper())); AddProperty(hbmProperty); }
public void SettingFormulaOverridesColumnNodes() { var member = ForClass<MyClass>.Property(c => c.Autoproperty); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Column(cm=> cm.SqlType("VARCHAR(80)")); mapper.Formula("formula"); mapping.formula.Should().Be("formula"); mapping.column.Should().Be(null); mapping.Items.Should().Be.Null(); }
public void Should_get__false__given_notnullSpecified_and_notnull_are_both_true() { HbmProperty property = new HbmProperty { notnullSpecified = true, notnull = true }; bool? result = property.CanBeNull(); result.ShouldNotBeNull(); result.Value.ShouldBeFalse(); }
public void SettingFormulaOverridesColumnPlainValues() { var member = ForClass<MyClass>.Property(c => c.Autoproperty); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Column("colName"); mapper.Length(10); mapper.NotNullable(true); mapper.Formula("formula"); mapping.formula.Should().Be("formula"); mapping.column.Should().Be(null); mapping.length.Should().Be(null); mapping.notnull.Should().Be(false); mapping.Items.Should().Be.Null(); }
public void Should_get__false__given_notnullSpecified_is_false_and_Items_notnullSpecified_is_true_and_Items_notnull_is_true() { HbmProperty property = new HbmProperty { notnullSpecified = false, Items = new object[] { new HbmColumn { notnullSpecified = true, notnull = true } } }; bool? result = property.CanBeNull(); result.ShouldNotBeNull(); result.Value.ShouldBeFalse(); }
public void WhenSetColumnValuesThenAddColumnTag() { var member = typeof(MyClass).GetProperty("Autoproperty"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Column(cm => { cm.SqlType("VARCHAR(50)"); cm.NotNullable(true); }); mapping.Items.Should().Not.Be.Null(); mapping.Columns.Should().Have.Count.EqualTo(1); }
public void WhenSetLazyThenSetAttributes() { var member = For<MyClass>.Property(x => x.ReadOnly); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Lazy(true); mapping.lazy.Should().Be.True(); mapping.IsLazyProperty.Should().Be.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); mapping.insert.Should().Be.False(); mapping.insertSpecified.Should().Be.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 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 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 WhenSetMultiColumnsValuesThenAddColumns() { var member = typeof(MyClass).GetProperty("ReadOnly"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Type<MyType>(); mapper.Columns(cm => { cm.Name("column1"); cm.Length(50); }, cm => { cm.Name("column2"); cm.SqlType("VARCHAR(10)"); }); mapping.Columns.Should().Have.Count.EqualTo(2); }
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); }); mapping.column.Should().Be.Null(); mapping.length.Should().Be("50"); mapping.Columns.Should().Be.Empty(); }
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")); mapping.Columns.Should().Have.Count.EqualTo(1); mapping.Columns.Single().name.Should().Be("pepe"); }
public void WhenSetTypeByITypeTypeThenSetType() { var member = For<MyClass>.Property(c => c.EnumProp); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Type<EnumStringType<MyEnum>>(); mapping.Type.name.Should().Contain(typeof(EnumStringType<MyEnum>).FullName); mapping.type.Should().Be.Null(); }
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 WhenSetBasicColumnValuesMoreThanOnesThenMergeColumn() { var member = typeof(MyClass).GetProperty("Autoproperty"); var mapping = new HbmProperty(); var mapper = new PropertyMapper(member, mapping); mapper.Column(cm => cm.Length(50)); mapper.Column(cm => cm.NotNullable(true)); mapping.Items.Should().Be.Null(); mapping.length.Should().Be("50"); mapping.notnull.Should().Be(true); mapping.notnullSpecified.Should().Be(true); }