コード例 #1
0
 public void CanSetFormula()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Formula("SomeFormula");
     hbmDiscriminator.formula.Should().Be("SomeFormula");
 }
コード例 #2
0
		private void BindSimpleValue(HbmDiscriminator discriminatorSchema, SimpleValue discriminator)
		{
			if (discriminatorSchema.type != null)
				discriminator.TypeName = discriminatorSchema.type;

			if (discriminatorSchema.formula != null)
			{
				var f = new Formula {FormulaString = discriminatorSchema.formula};
				discriminator.AddFormula(f);
			}
			else
			{
				new ColumnsBinder(discriminator, Mappings).Bind(discriminatorSchema.Columns, false,
				                                                () =>
				                                                new HbmColumn
				                                                	{
				                                                		name =
				                                                			mappings.NamingStrategy.PropertyToColumnName(
				                                                			RootClass.DefaultDiscriminatorColumnName),
				                                                		length = discriminatorSchema.length,
																														notnull = discriminatorSchema.notnull,
																														notnullSpecified = true
				                                                	});
			}
		}
コード例 #3
0
        public void CanSetLength()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Length(77);
            hbmDiscriminator.length.Should().Be("77");
        }
コード例 #4
0
 public void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping)
 {
     if (discriminatorMapper == null)
     {
         var hbmDiscriminator = new HbmDiscriminator();
         classMapping.discriminator = hbmDiscriminator;
         discriminatorMapper = new DiscriminatorMapper(hbmDiscriminator);
     }
     discriminatorMapping(discriminatorMapper);
 }
コード例 #5
0
        private static void BindColumn(HbmDiscriminator discriminatorSchema, Column column)
        {
            if (discriminatorSchema.length != null)
                column.Length = int.Parse(discriminatorSchema.length);

            column.IsNullable = !discriminatorSchema.notnull;
            column.IsUnique = false;
            column.CheckConstraint = string.Empty;
            column.SqlType = null;
        }
コード例 #6
0
        public void CanSetInsert()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Insert(true);
            hbmDiscriminator.insert.Should().Be(true);

            mapper.Insert(false);
            hbmDiscriminator.insert.Should().Be(false);
        }
コード例 #7
0
        public void CanSetForce()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Force(true);
            hbmDiscriminator.force.Should().Be(true);

            mapper.Force(false);
            hbmDiscriminator.force.Should().Be(false);
        }
コード例 #8
0
        public void CanSetNotNullable()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper = new DiscriminatorMapper(hbmDiscriminator);

            mapper.NotNullable(true);
            hbmDiscriminator.notnull.Should().Be(true);

            mapper.NotNullable(false);
            hbmDiscriminator.notnull.Should().Be(false);
        }
コード例 #9
0
		private void BindSimpleValue(HbmDiscriminator discriminatorSchema, SimpleValue discriminator)
		{
			if (discriminatorSchema.type != null)
				discriminator.TypeName = discriminatorSchema.type;

			if (discriminatorSchema.formula != null)
			{
				Formula f = new Formula();
				f.FormulaString = discriminatorSchema.formula;
				discriminator.AddFormula(f);
			}
			else
				BindColumns(discriminatorSchema, discriminator);
		}
コード例 #10
0
		private void BindColumns(HbmDiscriminator discriminatorSchema, SimpleValue discriminator)
		{
			Table table = discriminator.Table;

			//COLUMN(S)
			if (discriminatorSchema.column != null)
			{
				Column col = new Column();
				col.Value = discriminator;
				BindColumn(discriminatorSchema, col);
				col.Name = mappings.NamingStrategy.ColumnName(discriminatorSchema.column);

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

				discriminator.AddColumn(col);
			}
			else if (discriminatorSchema.Item != null && discriminatorSchema.Item is HbmColumn)
			{
				HbmColumn theCol = (HbmColumn)discriminatorSchema.Item;
				Column col = new Column();
				col.Value = discriminator;
				BindColumn(theCol, col, false);

				col.Name = mappings.NamingStrategy.ColumnName(theCol.name);

				if (table != null)
					table.AddColumn(col);
				//table=null -> an association, fill it in later

				discriminator.AddColumn(col);

				BindIndex(theCol.index, table, col);
				BindUniqueKey(theCol.uniquekey, table, col);
			}

			if (discriminator.ColumnSpan == 0)
			{
				Column col = new Column();
				col.Value = discriminator;
				BindColumn(discriminatorSchema, col);

				col.Name = mappings.NamingStrategy.PropertyToColumnName(
					RootClass.DefaultDiscriminatorColumnName);

				discriminator.Table.AddColumn(col);
				discriminator.AddColumn(col);
			}
		}
コード例 #11
0
		public void BindDiscriminator(HbmDiscriminator discriminatorSchema, Table table)
		{
			if (discriminatorSchema == null)
				return;

			//DISCRIMINATOR
			var discriminator = new SimpleValue(table);
			rootClass.Discriminator = discriminator;
			BindSimpleValue(discriminatorSchema, discriminator);

			if (discriminator.Type == null)
			{
				discriminator.TypeName = NHibernateUtil.String.Name;
			}

			rootClass.IsPolymorphic = true;
			rootClass.IsForceDiscriminator = discriminatorSchema.force;
			rootClass.IsDiscriminatorInsertable = discriminatorSchema.insert;
		}
コード例 #12
0
		public void BindDiscriminator(HbmDiscriminator discriminatorSchema, PersistentClass rootClass,
			Table table)
		{
			if (discriminatorSchema == null)
				return;

			//DISCRIMINATOR
			SimpleValue discriminator = new SimpleValue(table);
			rootClass.Discriminator = discriminator;
			BindSimpleValue(discriminatorSchema, discriminator);

			if (discriminator.Type == null)
			{
				discriminator.TypeName = NHibernateUtil.String.Name;
			}

			rootClass.IsPolymorphic = true;

			if (discriminatorSchema.force)
				rootClass.IsForceDiscriminator = true;

			if (discriminatorSchema.insertSpecified && !discriminatorSchema.insert)
				rootClass.IsDiscriminatorInsertable = false;
		}
コード例 #13
0
 public void SettingColumnOverridesFormula()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Formula("formula");
     mapper.Column(cm => cm.Unique(true));
     hbmDiscriminator.formula.Should().Be.Null();
     hbmDiscriminator.Item.Should().Be.OfType<HbmColumn>();
 }
コード例 #14
0
 public void WhenSetFormulaThenResetColumn()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Column("MyColumn");
     mapper.Formula("SomeFormula");
     hbmDiscriminator.formula.Should().Be("SomeFormula");
     hbmDiscriminator.column.Should().Be.Null();
     hbmDiscriminator.Item.Should().Be.Null();
 }
コード例 #15
0
 public void WhenSetFormulaWithNullThenDoNothing()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Column("MyColumn");
     mapper.Formula(null);
     hbmDiscriminator.formula.Should().Be.Null();
     hbmDiscriminator.column.Should().Not.Be.Null();
 }
コード例 #16
0
 public void SettingColumnPlainValuesOverridesFormula()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Formula("formula");
     mapper.Column("colName");
     hbmDiscriminator.formula.Should().Be.Null();
     hbmDiscriminator.column.Should().Be("colName");
 }
コード例 #17
0
 public void WhenSetBasicColumnValuesThenSetPlainValues()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Column(cm =>
     {
         cm.Length(50);
         cm.NotNullable(true);
     });
     hbmDiscriminator.Item.Should().Be.Null();
     hbmDiscriminator.length.Should().Be("50");
     hbmDiscriminator.notnull.Should().Be(true);
 }
コード例 #18
0
 public void WhenSetTypeByITypeThenSetTypeName()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Type(NHibernateUtil.String);
     hbmDiscriminator.type.Should().Be.EqualTo("String");
 }
コード例 #19
0
 public void WhenSetTypeByGenericMethodThenSetTypeName()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Type<EnumStringType<MyEnum>>();
     hbmDiscriminator.type.Should().Contain(typeof(EnumStringType<MyEnum>).FullName);
 }
コード例 #20
0
 public void WhenSetInvalidTypeThenThrow()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     ActionAssert.Throws<ArgumentOutOfRangeException>(() => mapper.Type(typeof(object)));
     ActionAssert.Throws<ArgumentNullException>(() => mapper.Type((Type)null));
 }
コード例 #21
0
 public void SettingFormulaOverridesColumnPlainValues()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Column("colName");
     mapper.Length(10);
     mapper.NotNullable(true);
     mapper.Formula("formula");
     hbmDiscriminator.formula.Should().Be("formula");
     hbmDiscriminator.column.Should().Be(null);
     hbmDiscriminator.length.Should().Be(null);
     hbmDiscriminator.notnull.Should().Be(false);
     hbmDiscriminator.Item.Should().Be.Null();
 }
コード例 #22
0
        public void WhenSetBasicColumnValuesMoreThanOnceThenMergeColumn()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper = new DiscriminatorMapper(hbmDiscriminator);
            mapper.Column(cm => cm.Length(50));
            mapper.Column(cm => cm.NotNullable(true));

            hbmDiscriminator.Item.Should().Be.Null();
            hbmDiscriminator.length.Should().Be("50");
            hbmDiscriminator.notnull.Should().Be(true);
        }
コード例 #23
0
 public void WhenSetColumnValuesThenAddColumnTag()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Column(cm =>
     {
         cm.SqlType("VARCHAR(50)");
         cm.NotNullable(true);
     });
     hbmDiscriminator.Item.Should().Not.Be.Null();
     hbmDiscriminator.Columns.Should().Have.Count.EqualTo(1);
 }
コード例 #24
0
 public void WhenSetFormulaWithMultipleLinesThenSetFormulaNode()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     var formula = @"Line1
     Line2";
     mapper.Formula(formula);
     hbmDiscriminator.formula.Should().Be.Null();
     hbmDiscriminator.Item.Should().Not.Be.Null().And.Be.OfType<HbmFormula>();
     var hbmFormula = (HbmFormula) (hbmDiscriminator.Item);
     hbmFormula.Text.Length.Should().Be(2);
     hbmFormula.Text[0].Should().Be("Line1");
     hbmFormula.Text[1].Should().Be("Line2");
 }