public void AfterSetMultiColumnsCantSetSimpleColumn()
 {
     var member = typeof(MyClass).GetProperty("ReadOnly");
     var mapping = new HbmKeyProperty();
     var mapper = new KeyPropertyMapper(member, mapping);
     mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
     mapper.Executing(m => m.Column(cm => cm.Length(50))).Throws<ConfOrm.MappingException>();
 }
 public void WhenSetBasicColumnValuesThenSetPlainValues()
 {
     var member = typeof(MyClass).GetProperty("Autoproperty");
     var mapping = new HbmKeyProperty();
     var mapper = new KeyPropertyMapper(member, mapping);
     mapper.Column(cm => cm.Length(50));
     mapping.column.Should().Be.Null();
     mapping.length.Should().Be("50");
 }
示例#3
0
        private static void BindColumn(HbmKeyProperty keyPropertySchema, Column model, bool isNullable)
        {
            if (keyPropertySchema.length != null)
                model.Length = int.Parse(keyPropertySchema.length);

            model.IsNullable = isNullable;
            model.IsUnique = false;
            model.CheckConstraint = string.Empty;
            model.SqlType = null;
        }
 public void WhenSetDefaultColumnNameThenDoesNotSetTheName()
 {
     var member = typeof(MyClass).GetProperty("Autoproperty");
     var mapping = new HbmKeyProperty();
     var mapper = new KeyPropertyMapper(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 WhenSetColumnValuesThenAddColumnTag()
 {
     var member = typeof(MyClass).GetProperty("Autoproperty");
     var mapping = new HbmKeyProperty();
     var mapper = new KeyPropertyMapper(member, mapping);
     mapper.Column(cm =>
     {
         cm.SqlType("VARCHAR(50)");
         cm.NotNullable(true);
     });
     mapping.column.Should().Not.Be.Null();
     mapping.Columns.Should().Have.Count.EqualTo(1);
 }
		private Property CreateProperty(SimpleValue value, string propertyName, System.Type parentClass,
			HbmKeyProperty keyPropertySchema)
		{
			if (parentClass != null && value.IsSimpleValue)
				value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName,
				                             keyPropertySchema.access ?? mappings.DefaultAccess);

			// This is done here 'cos we might only know the type here (ugly!)
			var toOne = value as ToOne;
			if (toOne != null)
			{
				string propertyRef = toOne.ReferencedPropertyName;
				if (propertyRef != null)
					mappings.AddUniquePropertyReference(toOne.ReferencedEntityName, propertyRef);
			}

			value.CreateForeignKey();
			var prop = new Property {Value = value};
			BindProperty(keyPropertySchema, prop);

			return prop;
		}
		private void BindColumns(HbmKeyProperty keyPropertySchema, SimpleValue model, bool isNullable, bool autoColumn,
			string propertyPath)
		{
			Table table = model.Table;

			if (keyPropertySchema.column1 == null)
			{
				int count = 0;

				foreach (HbmColumn columnSchema in keyPropertySchema.column ?? new HbmColumn[0])
				{
					Column col = new Column();
					col.Value = model;
					col.TypeIndex = count++;
					BindColumn(columnSchema, col, isNullable);

					col.Name = mappings.NamingStrategy.ColumnName(columnSchema.name);
					if (table != null)
						table.AddColumn(col);
					//table=null -> an association, fill it in later
					model.AddColumn(col);

					//column index
					BindIndex(columnSchema.index, table, col);
					//column group index (although it can serve as a separate column index)

					BindUniqueKey(columnSchema.uniquekey, table, col);
				}
			}
			else
			{
				Column col = new Column();
				col.Value = compositeId;
				BindColumn(keyPropertySchema, col, isNullable);
				col.Name = mappings.NamingStrategy.ColumnName(keyPropertySchema.column1);
				if (table != null)
					table.AddColumn(col);
				model.AddColumn(col);
				//column group index (although can serve as a separate column index)
			}

			if (autoColumn && model.ColumnSpan == 0)
			{
				Column col = new Column();
				col.Value = model;
				BindColumn(keyPropertySchema, col, isNullable);
				col.Name = mappings.NamingStrategy.PropertyToColumnName(propertyPath);
				model.Table.AddColumn(col);
				model.AddColumn(col);
				//column group index (although can serve as a separate column index)
			}
		}
		private void BindSimpleValue(HbmKeyProperty keyPropertySchema, SimpleValue model, bool isNullable, string path)
		{
			if (keyPropertySchema.type1 != null)
				model.TypeName = keyPropertySchema.type1;
			BindColumns(keyPropertySchema, model, isNullable, true, path);
		}
		public void BindSimpleValue(HbmKeyProperty mapKeyManyToManyMapping, string propertyPath, bool isNullable)
		{
			new TypeBinder(value, Mappings).Bind(mapKeyManyToManyMapping.Type);
			new ColumnsBinder(value, Mappings).Bind(mapKeyManyToManyMapping.Columns, isNullable,
			                                        () =>
			                                        new HbmColumn
			                                        	{
			                                        		name = mappings.NamingStrategy.PropertyToColumnName(propertyPath),
			                                        		length = mapKeyManyToManyMapping.length,
			                                        	});

		}
        public void WhenSetDifferentColumnNameThenSetTheName()
        {
            var member = typeof(MyClass).GetProperty("Autoproperty");
            var mapping = new HbmKeyProperty();
            var mapper = new KeyPropertyMapper(member, mapping);
            mapper.Column(cm => cm.Name("pepe"));

            mapping.Columns.Should().Have.Count.EqualTo(1);
            mapping.Columns.Single().name.Should().Be("pepe");
        }
 public void WhenSetMultiColumnsValuesThenAutoassignColumnNames()
 {
     var member = typeof(MyClass).GetProperty("ReadOnly");
     var mapping = new HbmKeyProperty();
     var mapper = new KeyPropertyMapper(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 WhenSetInvalidTypeThenThrow()
 {
     var member = typeof(MyClass).GetProperty("ReadOnly");
     var mapping = new HbmKeyProperty();
     var mapper = new KeyPropertyMapper(member, mapping);
     mapper.Executing(m=> m.Type(typeof(object), null)).Throws<ArgumentOutOfRangeException>();
     mapper.Executing(m => m.Type(null, null)).Throws<ArgumentNullException>();
 }
		private void BindSimpleValue(HbmKeyProperty keyPropertySchema, SimpleValue model, bool isNullable, string path)
		{
			if (keyPropertySchema.type1 != null)
			{
				model.TypeName = keyPropertySchema.type1;
			}
			new ColumnsBinder(model, Mappings).Bind(keyPropertySchema.Columns, isNullable,
																							() => new HbmColumn { name = mappings.NamingStrategy.PropertyToColumnName(path), length = keyPropertySchema.length });
		}
        public void WhenSetTypeByIUserTypeWithParamsThenSetType()
        {
            var member = typeof(MyClass).GetProperty("ReadOnly");
            var mapping = new HbmKeyProperty();
            var mapper = new KeyPropertyMapper(member, mapping);
            mapper.Type<MyType>(new { Param1="a", Param2=12 });

            mapping.type1.Should().Be.Null();
            mapping.Type.name.Should().Contain("MyType");
            mapping.Type.param.Should().Have.Count.EqualTo(2);
            mapping.Type.param.Select(p => p.name).Should().Have.SameValuesAs("Param1","Param2");
            mapping.Type.param.Select(p => p.GetText()).Should().Have.SameValuesAs("a", "12");
        }
        public void WhenSetTypeByIUserTypeWithNullParamsThenSetTypeName()
        {
            var member = typeof(MyClass).GetProperty("ReadOnly");
            var mapping = new HbmKeyProperty();
            var mapper = new KeyPropertyMapper(member, mapping);
            mapper.Type<MyType>(null);

            mapping.Type.name.Should().Contain("MyType");
            mapping.type.Should().Be.Null();
        }
        public void WhenSetTypeByITypeTypeThenSetType()
        {
            var member = ForClass<MyClass>.Property(c => c.EnumProp);
            var mapping = new HbmKeyProperty();
            var mapper = new KeyPropertyMapper(member, mapping);
            mapper.Type<EnumStringType<MyEnum>>();

            mapping.Type.name.Should().Contain(typeof(EnumStringType<MyEnum>).FullName);
            mapping.type.Should().Be.Null();
        }
        public void WhenSetTypeByITypeThenSetTypeName()
        {
            var member = typeof(MyClass).GetProperty("ReadOnly");
            var mapping = new HbmKeyProperty();
            var mapper = new KeyPropertyMapper(member, mapping);
            mapper.Type(NHibernateUtil.String);

            mapping.Type.name.Should().Be.EqualTo("String");
        }
        public void WhenSettingByTypeThenCheckCompatibility()
        {
            var member = typeof(MyClass).GetProperty("ReadOnly");
            var mapping = new HbmKeyProperty();
            var mapper = new KeyPropertyMapper(member, mapping);

            mapper.Executing(m=> m.Access(typeof(object))).Throws<ArgumentOutOfRangeException>();
            mapper.Executing(m => m.Access(typeof(FieldAccessor))).NotThrows();
            mapping.Access.Should().Be.EqualTo(typeof(FieldAccessor).AssemblyQualifiedName);
        }
		private void BindProperty(HbmKeyProperty keyPropertySchema, Property property)
		{
			property.Name = keyPropertySchema.name;

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

			property.PropertyAccessorName = keyPropertySchema.access ?? mappings.DefaultAccess;
			property.Cascade = mappings.DefaultCascade;
			property.IsUpdateable = true;
			property.IsInsertable = true;
			property.IsOptimisticLocked = true;
			property.Generation = PropertyGeneration.Never;
			property.MetaAttributes = new Dictionary<string, MetaAttribute>();
			LogMappedProperty(property);
		}
		public void Property(MemberInfo property, Action<IPropertyMapper> mapping)
		{
			var hbmProperty = new HbmKeyProperty { name = property.Name };
			mapping(new KeyPropertyMapper(property, hbmProperty));
			AddProperty(hbmProperty);
		}
 public void WhenSetMultiColumnsValuesThenAddColumns()
 {
     var member = typeof(MyClass).GetProperty("ReadOnly");
     var mapping = new HbmKeyProperty();
     var mapper = new KeyPropertyMapper(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);
 }