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 Discriminator(Action <IDiscriminatorMapper> discriminatorMapping)
 {
     if (discriminatorMapper == null)
     {
         var hbmDiscriminator = new HbmDiscriminator();
         classMapping.discriminator = hbmDiscriminator;
         discriminatorMapper        = new DiscriminatorMapper(hbmDiscriminator);
     }
     discriminatorMapping(discriminatorMapper);
 }
        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 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");
        }
예제 #5
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);
        }
예제 #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 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);
        }
예제 #8
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();
        }
        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);
            }
        }
예제 #10
0
        public void WhenSetBasicColumnValuesMoreThanOnceThenMergeColumn()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper           = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Column(cm => cm.Length(50));
            mapper.Column(cm => cm.NotNullable(false));

            hbmDiscriminator.Item.Should().Be.Null();
            hbmDiscriminator.length.Should().Be("50");
            hbmDiscriminator.notnull.Should().Be(false);
        }
        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;
        }
예제 #12
0
        public void WhenSetColumnValuesThenAddColumnTag()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper           = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Column(cm =>
            {
                cm.SqlType("VARCHAR(50)");
                cm.NotNullable(false);
            });
            hbmDiscriminator.Item.Should().Not.Be.Null();
            hbmDiscriminator.Columns.Should().Have.Count.EqualTo(1);
        }
예제 #13
0
        public void WhenSetBasicColumnValuesThenSetPlainValues()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper           = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Column(cm =>
            {
                cm.Length(50);
                cm.NotNullable(false);
            });
            hbmDiscriminator.Item.Should().Be.Null();
            hbmDiscriminator.length.Should().Be("50");
            hbmDiscriminator.notnull.Should().Be(false);
        }
예제 #14
0
        public void SettingFormulaOverridesColumnPlainValues()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper           = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Column("colName");
            mapper.Length(10);
            mapper.Formula("formula");
            hbmDiscriminator.formula.Should().Be("formula");
            hbmDiscriminator.column.Should().Be(null);
            hbmDiscriminator.length.Should().Be(null);
            hbmDiscriminator.notnull.Should().Be(true);
            hbmDiscriminator.Item.Should().Be.Null();
        }
예제 #15
0
        public void WhenSetColumnValuesThenDefaultNotNullableShouldBeTrue()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper           = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Column(cm =>
            {
                cm.SqlType("VARCHAR(50)");
            });
            var hbmColumn = hbmDiscriminator.Columns.Single();

            hbmColumn.notnullSpecified.Should().Be.True();
            hbmColumn.notnull.Should().Be.True();
            hbmDiscriminator.notnull.Should().Be.True();
        }
예제 #16
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");
        }
예제 #17
0
        public void WhenSetColumnValuesThenOverrideDefaultNotNullable()
        {
            var hbmDiscriminator = new HbmDiscriminator();
            var mapper           = new DiscriminatorMapper(hbmDiscriminator);

            mapper.Column(cm =>
            {
                cm.SqlType("VARCHAR(50)");
                cm.NotNullable(false);
            });
            var hbmColumn = hbmDiscriminator.Columns.Single();

            hbmColumn.notnullSpecified.Should().Be.False();
            hbmColumn.notnull.Should().Be.False();
            hbmDiscriminator.notnull.Should("the not-null should be the default and should not be present in the mapping.").Be.True();
        }
        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);
            }
        }
예제 #19
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;
        }