コード例 #1
0
 public void CanSetGenerated()
 {
     var member = typeof(MyClass).GetProperty("Version");
     var mapping = new HbmVersion();
     var mapper = new VersionMapper(member, mapping);
     mapper.Generated(VersionGeneration.Always);
     mapping.generated.Should().Be(HbmVersionGeneration.Always);
 }
コード例 #2
0
        public void ShouldSetThePropertyNameImmediately()
        {
            var member = typeof(MyClass).GetProperty("Version");
            var mapping = new HbmVersion();
            new VersionMapper(member, mapping);

            mapping.name.Should().Be.EqualTo("Version");
        }
コード例 #3
0
 public void AfterSetMultiColumnsCantSetSimpleColumn()
 {
     var member = typeof(MyClass).GetProperty("Version");
     var mapping = new HbmVersion();
     var mapper = new VersionMapper(member, mapping);
     mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
     ActionAssert.Throws<ConfOrm.MappingException>(() => mapper.Column(cm => cm.Length(50)));
 }
コード例 #4
0
        public void WhenSetAccessorByTypeThenCheckCompatibility()
        {
            var member = typeof(MyClass).GetProperty("ReadOnly");
            var mapping = new HbmVersion();
            var mapper = new VersionMapper(member, mapping);

            ActionAssert.Throws<ArgumentOutOfRangeException>(() => mapper.Access(typeof(object)));
            ActionAssert.NotThrow(() => mapper.Access(typeof(FieldAccessor)));
            mapping.access.Should().Be.EqualTo(typeof(FieldAccessor).AssemblyQualifiedName);
        }
コード例 #5
0
 public void CanSetUsavedValue()
 {
     var member = typeof(MyClass).GetProperty("Version");
     var mapping = new HbmVersion();
     var mapper = new VersionMapper(member, mapping);
     mapper.UnsavedValue(null);
     mapping.unsavedvalue.Should().Be("null");
     mapper.UnsavedValue(0);
     mapping.unsavedvalue.Should().Be("0");
 }
コード例 #6
0
 public void CanSetInsert()
 {
     var member = typeof(MyClass).GetProperty("Version");
     var mapping = new HbmVersion();
     var mapper = new VersionMapper(member, mapping);
     mapper.Insert(true);
     mapping.insertSpecified.Should("True is the default value (not specified if true)").Be.False();
     mapper.Insert(false);
     mapping.insert.Should().Be.False();
     mapping.insertSpecified.Should().Be.True();
 }
コード例 #7
0
ファイル: RootClassBinder.cs プロジェクト: pallmall/WCell
		private void BindVersion(HbmVersion versionSchema, PersistentClass rootClass, Table table)
		{
			if (versionSchema == null)
				return;

			string versioningPropertyType = NHibernateUtil.Int32.Name;

			string propertyName = versionSchema.name;
			SimpleValue simpleValue = new SimpleValue(table);

			simpleValue.TypeName = versionSchema.type;
			BindColumns(versionSchema, simpleValue, false, propertyName);
			if (!simpleValue.IsTypeSpecified)
				simpleValue.TypeName = versioningPropertyType;

			Mapping.Property property = new Mapping.Property(simpleValue);
			BindProperty(versionSchema, property);

			// for version properties marked as being generated, make sure they are "always"
			// generated; "insert" is invalid. This is dis-allowed by the schema, but just to make
			// sure...

			if (property.Generation == PropertyGeneration.Insert)
				throw new MappingException("'generated' attribute cannot be 'insert' for versioning property");

			simpleValue.NullValue = versionSchema.unsavedvalue;
			rootClass.Version = property;
			rootClass.AddProperty(property);
		}
コード例 #8
0
		private void BindProperty(HbmVersion versionSchema, Property property, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			property.Name = versionSchema.name;

			if (property.Value.Type == null)
				throw new MappingException("could not determine a property type for: " + property.Name);

			property.PropertyAccessorName = versionSchema.access ?? mappings.DefaultAccess;
			property.Cascade = mappings.DefaultCascade;
			property.IsUpdateable = true;
			property.IsInsertable = true;
			property.IsOptimisticLocked = true;
			property.Generation = Convert(versionSchema.generated);

			if (property.Generation == PropertyGeneration.Always
				|| property.Generation == PropertyGeneration.Insert)
			{
				// generated properties can *never* be insertable...
				if (property.IsInsertable)
					// insertable simply because that is the user did not specify
					// anything; just override it
					property.IsInsertable = false;

				// properties generated on update can never be updateable...
				if (property.IsUpdateable && property.Generation == PropertyGeneration.Always)
					// updateable only because the user did not specify 
					// anything; just override it
					property.IsUpdateable = false;
			}

			property.MetaAttributes = GetMetas(versionSchema, inheritedMetas);

			property.LogMapped(log);
		}
コード例 #9
0
        public void WhenSetTypeByIUserVersionTypeThenSetTypeName()
        {
            var member = typeof(MyClass).GetProperty("Version");
            var mapping = new HbmVersion();
            var mapper = new VersionMapper(member, mapping);
            mapper.Type<MyVerionType>();

            mapping.type.Should().Contain("MyVerionType");
        }
コード例 #10
0
 public void WhenSetMultiColumnsValuesThenAutoassignColumnNames()
 {
     var member = typeof(MyClass).GetProperty("Version");
     var mapping = new HbmVersion();
     var mapper = new VersionMapper(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)));
 }
コード例 #11
0
 public void WhenSetMultiColumnsValuesThenAddColumns()
 {
     var member = typeof(MyClass).GetProperty("Version");
     var mapping = new HbmVersion();
     var mapper = new VersionMapper(member, mapping);
     mapper.Type<MyVerionType>();
     mapper.Columns(cm =>
         {
             cm.Name("column1");
             cm.Length(50);
         }, cm =>
             {
                 cm.Name("column2");
                 cm.SqlType("VARCHAR(10)");
             });
     mapping.Columns.Should().Have.Count.EqualTo(2);
 }
コード例 #12
0
 public void WhenSetInvalidTypeThenThrow()
 {
     var member = typeof(MyClass).GetProperty("Version");
     var mapping = new HbmVersion();
     var mapper = new VersionMapper(member, mapping);
     ActionAssert.Throws<ArgumentOutOfRangeException>(() => mapper.Type(typeof(object)));
     ActionAssert.Throws<ArgumentNullException>(() => mapper.Type((Type)null));
 }
コード例 #13
0
        public void WhenSetDifferentColumnNameThenSetTheName()
        {
            var member = typeof(MyClass).GetProperty("Version");
            var mapping = new HbmVersion();
            var mapper = new VersionMapper(member, mapping);
            mapper.Column(cm => cm.Name("pepe"));

            mapping.Columns.Should().Have.Count.EqualTo(1);
            mapping.Columns.Single().name.Should().Be("pepe");
        }
コード例 #14
0
 public void WhenSetDefaultColumnNameThenDoesNotSetTheName()
 {
     var member = typeof(MyClass).GetProperty("Version");
     var mapping = new HbmVersion();
     var mapper = new VersionMapper(member, mapping);
     mapper.Column(cm => cm.Name("Version"));
     mapping.column1.Should().Be.Null();
     mapping.Columns.Should().Be.Empty();
 }
コード例 #15
0
ファイル: RootClassBinder.cs プロジェクト: pallmall/WCell
		private void BindColumns(HbmVersion versionSchema, SimpleValue model, bool isNullable, string propertyPath)
		{
			Table table = model.Table;

			if (versionSchema.column != null)
			{
				Column col = new Column();
				col.Value = model;
				BindColumn(col, isNullable);
				col.Name = mappings.NamingStrategy.ColumnName(versionSchema.column);

				if (table != null)
					table.AddColumn(col);

				model.AddColumn(col);
			}

			if (model.ColumnSpan == 0)
			{
				Column col = new Column();
				col.Value = model;
				BindColumn(col, isNullable);
				col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath);
				model.Table.AddColumn(col);
				model.AddColumn(col);
			}
		}
コード例 #16
0
 public void WhenSetColumnValuesThenAddColumnTag()
 {
     var member = typeof(MyClass).GetProperty("Version");
     var mapping = new HbmVersion();
     var mapper = new VersionMapper(member, mapping);
     mapper.Column(cm =>
     {
         cm.SqlType("timestamp");
         cm.NotNullable(true);
     });
     mapping.Columns.Should().Not.Be.Null();
     mapping.Columns.Should().Have.Count.EqualTo(1);
 }
コード例 #17
0
		private void BindVersion(HbmVersion versionSchema, PersistentClass rootClass, Table table, IDictionary<string, MetaAttribute> inheritedMetas)
		{
			if (versionSchema == null)
				return;

			string propertyName = versionSchema.name;
			var simpleValue = new SimpleValue(table);
			new TypeBinder(simpleValue, Mappings).Bind(versionSchema.type);
			new ColumnsBinder(simpleValue, Mappings).Bind(versionSchema.Columns, false,
			                                              () =>
			                                              new HbmColumn
			                                              	{name = mappings.NamingStrategy.PropertyToColumnName(propertyName)});

			if (!simpleValue.IsTypeSpecified)
				simpleValue.TypeName = NHibernateUtil.Int32.Name;

			var property = new Property(simpleValue);
			BindProperty(versionSchema, property, inheritedMetas);

			// for version properties marked as being generated, make sure they are "always"
			// generated; "insert" is invalid. This is dis-allowed by the schema, but just to make
			// sure...

			if (property.Generation == PropertyGeneration.Insert)
				throw new MappingException("'generated' attribute cannot be 'insert' for versioning property");

			simpleValue.NullValue = versionSchema.unsavedvalue;
			rootClass.Version = property;
			rootClass.AddProperty(property);
		}
コード例 #18
0
        public void WhenSetTypeByIVersionTypeThenSetTypeName()
        {
            var member = typeof(MyClass).GetProperty("Version");
            var mapping = new HbmVersion();
            var mapper = new VersionMapper(member, mapping);
            mapper.Type((IVersionType)NHibernateUtil.Int32);

            mapping.type.Should().Be.EqualTo("Int32");
        }
コード例 #19
0
 public void Version(MemberInfo versionProperty, Action<IVersionMapper> versionMapping)
 {
     if(versionMapper == null)
     {
         var hbmVersion = new HbmVersion();
         classMapping.Item1 = hbmVersion;
         versionMapper = new VersionMapper(versionProperty, hbmVersion);
     }
     versionMapping(versionMapper);
 }
コード例 #20
0
		private void BindColumns(HbmVersion versionSchema, SimpleValue model, bool isNullable, string propertyPath)
		{
			Table table = model.Table;
			if (versionSchema.column1 != null)
			{
				var col = new Column {Value = model};
				BindColumn(col, isNullable);
				col.Name = mappings.NamingStrategy.ColumnName(versionSchema.column1);

				if (table != null)
					table.AddColumn(col);

				model.AddColumn(col);
			}
			else if (versionSchema.column != null)
			{
				foreach (HbmColumn hbmColumn in versionSchema.column)
				{
					var col = new Column {Value = model};
					BindColumn(hbmColumn, col, isNullable);
					if (table != null)
						table.AddColumn(col);

					model.AddColumn(col);
				}
			}

			if (model.ColumnSpan == 0)
			{
				var col = new Column {Value = model};
				BindColumn(col, isNullable);
				col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath);
				model.Table.AddColumn(col);
				model.AddColumn(col);
			}
		}