public void CanSetFormula()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Formula("SomeFormula");
     hbmDiscriminator.formula.Should().Be("SomeFormula");
 }
		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
				                                                	});
			}
		}
        public void CanSetLength()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Length(77);
            hbmDiscriminator.length.Should().Be("77");
        }
 public void Discriminator(Action<IDiscriminatorMapper> discriminatorMapping)
 {
     if (discriminatorMapper == null)
     {
         var hbmDiscriminator = new HbmDiscriminator();
         classMapping.discriminator = hbmDiscriminator;
         discriminatorMapper = new DiscriminatorMapper(hbmDiscriminator);
     }
     discriminatorMapping(discriminatorMapper);
 }
        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;
        }
        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);
        }
        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);
        }
        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);
        }
		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);
		}
		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);
			}
		}
		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;
		}
		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;
		}
 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>();
 }
 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();
 }
 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();
 }
 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");
 }
 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);
 }
 public void WhenSetTypeByITypeThenSetTypeName()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Type(NHibernateUtil.String);
     hbmDiscriminator.type.Should().Be.EqualTo("String");
 }
 public void WhenSetTypeByGenericMethodThenSetTypeName()
 {
     var hbmDiscriminator = new HbmDiscriminator();
     var mapper = new DiscriminatorMapper(hbmDiscriminator);
     mapper.Type<EnumStringType<MyEnum>>();
     hbmDiscriminator.type.Should().Contain(typeof(EnumStringType<MyEnum>).FullName);
 }
 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));
 }
 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();
 }
        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);
        }
 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);
 }
 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");
 }