public void CanSetIndex()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");

            mapper.Index("pizza");
            hbm.index.Should().Be("pizza");
        }
        public void CanSetCheck()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");

            mapper.Check("pizza");
            hbm.check.Should().Be("pizza");
        }
 public void Should_get_null_given_notnullSpecified_is_false()
 {
     HbmColumn column = new HbmColumn
         {
             notnullSpecified = false
         };
     bool? result = column.CanBeNull();
     result.ShouldBeNull();
 }
 public void Should_get_null_given_uniqueSpecified_is_false()
 {
     HbmColumn column = new HbmColumn
         {
             unique = true,
             uniqueSpecified = false
         };
     bool? result = column.IsUnique();
     result.ShouldBeNull();
 }
        public void CanSetName()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");

            hbm.name.Should("be assigned by default").Be("aColumn");

            mapper.Name("pizza");
            hbm.name.Should().Be("pizza");
        }
        protected static void BindColumn(HbmColumn columnSchema, Column column, bool isNullable)
        {
            if (columnSchema.length != null)
                column.Length = int.Parse(columnSchema.length);

            column.IsNullable = columnSchema.notnullSpecified ? !columnSchema.notnull : isNullable;
            column.IsUnique = columnSchema.uniqueSpecified && columnSchema.unique;
            column.CheckConstraint = columnSchema.check ?? string.Empty;
            column.SqlType = columnSchema.sqltype;
        }
        public void CanSetLength()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");
            mapper.Length(50);

            hbm.length.Should().Be("50");

            mapper.Executing(m => m.Length(0)).Throws<ArgumentOutOfRangeException>();
            mapper.Executing(m => m.Length(-1)).Throws<ArgumentOutOfRangeException>();
        }
 public void Should_get__true__given_notnullSpecified_is_true_and_notnull_is_false()
 {
     HbmColumn column = new HbmColumn
         {
             notnullSpecified = true,
             notnull = false
         };
     bool? result = column.CanBeNull();
     result.ShouldNotBeNull();
     result.Value.ShouldBeTrue();
 }
		public void Columns(params Action<IColumnMapper>[] columnMapper)
		{
			ResetColumnPlainValues();
			int i = 1;
			var columns = new List<HbmColumn>(columnMapper.Length);
			foreach (var action in columnMapper)
			{
				var hbm = new HbmColumn();
				string defaultColumnName = elementType.Name + i++;
				action(new ColumnMapper(hbm, defaultColumnName));
				columns.Add(hbm);
			}
			manyToMany.Items = columns.ToArray();
		}
 public void Columns(params Action<IColumnMapper>[] columnMapper)
 {
     mapping.column = null;
     int i = 1;
     var columns = new List<HbmColumn>(columnMapper.Length);
     foreach (var action in columnMapper)
     {
         var hbm = new HbmColumn();
         var defaultColumnName = DefaultColumnName + i++;
         action(new ColumnMapper(hbm, defaultColumnName));
         columns.Add(hbm);
     }
     mapping.Items = columns.ToArray();
 }
Beispiel #11
0
		public void Columns(params Action<IColumnMapper>[] columnMapper)
		{
			ResetColumnPlainValues();
			int i = 1;
			var columns = new List<HbmColumn>(columnMapper.Length);
			foreach (var action in columnMapper)
			{
				var hbm = new HbmColumn();
				string defaultColumnName = DefaultColumnName(ownerEntityType) + i++;
				action(new ColumnMapper(hbm, defaultColumnName));
				columns.Add(hbm);
			}
			mapping.column = columns.ToArray();
		}
        public void CanSetNotNullable()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");
            mapper.NotNullable(true);

            hbm.notnull.Should().Be(true);
            hbm.notnullSpecified.Should().Be(true);

            mapper.NotNullable(false);

            hbm.notnull.Should().Be(false);
            hbm.notnullSpecified.Should().Be(false);
        }
		private void BindColumn(HbmColumn hbmColumn, Table table, bool isNullable)
		{
			var col = new Column {Value = value};
			BindColumn(hbmColumn, col, isNullable);

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

			value.AddColumn(col);

			//column index
			BindIndex(hbmColumn.index, table, col);
			//column group index (although it can serve as a separate column index)
			BindUniqueKey(hbmColumn.uniquekey, table, col);
		}
Beispiel #14
0
        private static Column CreateColumn(HbmColumn columnSchema, IValue type, int index)
        {
            Column column = new Column();
            column.Value = type;
            column.TypeIndex = index;

            if (columnSchema.length != null)
                column.Length = int.Parse(columnSchema.length);

            column.IsNullable = columnSchema.notnullSpecified ? columnSchema.notnull : false;
            column.IsUnique = columnSchema.uniqueSpecified && columnSchema.unique;
            column.CheckConstraint = columnSchema.check ?? string.Empty;
            column.SqlType = columnSchema.sqltype;

            return column;
        }
        public void CanSetDefault()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");

            mapper.Default("pizza");
            [email protected]().Be("pizza");

            mapper.Default(123);
            [email protected]().Be("123");

            mapper.Default(12.3);
            [email protected]().Be("12.3");

            mapper.Default(null);
            [email protected]().Be("null");
        }
		private void BindColumn(HbmColumn columnMapping, Column column, bool isNullable)
		{
			column.Name = mappings.NamingStrategy.ColumnName(columnMapping.name);

			if (columnMapping.length != null)
				column.Length = int.Parse(columnMapping.length);
			if (columnMapping.scale != null)
				column.Scale = int.Parse(columnMapping.scale);
			if (columnMapping.precision != null)
				column.Precision = int.Parse(columnMapping.precision);

			column.IsNullable = columnMapping.notnullSpecified ? !columnMapping.notnull : isNullable;
			column.IsUnique = columnMapping.uniqueSpecified && columnMapping.unique;
			column.CheckConstraint = columnMapping.check ?? string.Empty;
			column.SqlType = columnMapping.sqltype;
			column.DefaultValue = columnMapping.@default;
			if (columnMapping.comment != null)
				column.Comment = columnMapping.comment.Text.LinesToString().Trim();
		}
 public ColumnMapper(HbmColumn mapping, string memberName)
 {
     if (mapping == null)
     {
         throw new ArgumentNullException("mapping");
     }
     if (memberName == null)
     {
         throw new ArgumentNullException("memberName");
     }
     if (string.Empty == memberName.Trim())
     {
         throw new ArgumentNullException("memberName","The column name should be a valid not empty name.");
     }
     this.mapping = mapping;
     if (string.IsNullOrEmpty(mapping.name))
     {
         mapping.name = memberName;
     }
 }
        public void CanSetPrecision()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");
            mapper.Precision(12);

            hbm.precision.Should().Be("12");

            mapper.Executing(m => m.Precision(0)).Throws<ArgumentOutOfRangeException>();
            mapper.Executing(m => m.Precision(-1)).Throws<ArgumentOutOfRangeException>();
        }
Beispiel #19
0
 public void Columns(params Action<IColumnMapper>[] columnMapper)
 {
     ResetColumnPlainValues();
     int i = 1;
     var columns = new List<HbmColumn>(columnMapper.Length);
     foreach (var action in columnMapper)
     {
         var hbm = new HbmColumn();
         string defaultColumnName = (member != null ? member.Name : "unnamedcolumn") + i++;
         action(new ColumnMapper(hbm, defaultColumnName));
         columns.Add(hbm);
     }
     manyToOne.column = columns.ToArray();
 }
        public void CanSetUnique()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");

            mapper.Unique(true);

            hbm.unique.Should().Be(true);
            hbm.uniqueSpecified.Should().Be(true);

            mapper.Unique(false);

            hbm.unique.Should().Be(false);
            hbm.uniqueSpecified.Should().Be(false);
        }
        public void CanSetUniqueKey()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");

            mapper.UniqueKey("pizza");
            hbm.uniquekey.Should().Be("pizza");
        }
 public void Should_get__false__given_uniqueSpecified_is_true_and_unique_is_false()
 {
     HbmColumn column = new HbmColumn
         {
             uniqueSpecified = true,
             unique = false
         };
     bool? result = column.IsUnique();
     result.ShouldNotBeNull();
     result.Value.ShouldBeFalse();
 }
        public void CanSetSqlType()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");

            mapper.SqlType("NVARCHAR(123)");
            hbm.sqltype.Should().Be("NVARCHAR(123)");
        }
 public static void SetColumn(this HbmDiscriminator hbmDiscriminator, HbmColumn column )
 {
     hbmDiscriminator.column = column;
 }
		public void Bind(HbmColumn column, bool isNullable)
		{
			this.BindColumn(column, value.Table, isNullable);
		}
		private bool ColumnTagIsRequired(HbmColumn hbm)
		{
			return hbm.length != null || hbm.precision != null || hbm.scale != null || hbm.notnull || hbm.uniquekey != null
			       || hbm.sqltype != null || hbm.index != null || hbm.@default != null || hbm.check != null;
		}
        public void CanSetScale()
        {
            var hbm = new HbmColumn();
            var mapper = new ColumnMapper(hbm, "aColumn");
            mapper.Scale(3);

            hbm.scale.Should().Be("3");

            mapper.Executing(m => m.Scale(0)).NotThrows();
            mapper.Executing(m => m.Scale(-1)).Throws<ArgumentOutOfRangeException>();
        }