public void AssignCascadeStyle()
 {
     var hbmMapping = new HbmMapping();
     var hbm = new HbmManyToOne();
     var mapper = new ManyToOneMapper(null, hbm, hbmMapping);
     mapper.Cascade(Cascade.Persist | Cascade.Remove);
     hbm.cascade.Split(',').Select(w => w.Trim()).Should().Contain("persist").And.Contain("delete");
 }
 public void AutoCleanUnsupportedCascadeStyle()
 {
     var hbmMapping = new HbmMapping();
     var hbm = new HbmManyToOne();
     var mapper = new ManyToOneMapper(null, hbm, hbmMapping);
     mapper.Cascade(Cascade.Persist | Cascade.DeleteOrphans | Cascade.Remove);
     hbm.cascade.Split(',').Select(w => w.Trim()).All(w => w.Satisfy(cascade => !cascade.Contains("orphan")));
 }
 public void AfterSetMultiColumnsCantSetSimpleColumn()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyClass).GetProperty("Relation");
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));
     ActionAssert.Throws<ConfOrm.MappingException>(() => mapper.Column(cm => cm.Length(50)));
 }
 public void SettingColumnOverridesFormula()
 {
     var hbmMapping = new HbmMapping();
     var member = ForClass<MyClass>.Property(c => c.Relation);
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Formula("formula");
     mapper.Column(cm => cm.Unique(true));
     mapping.formula.Should().Be.Null();
 }
        public void CanSetAccessor()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyClass).GetProperty("Relation");
            var hbm = new HbmManyToOne();
            var mapper = new ManyToOneMapper(member, hbm, hbmMapping);

            mapper.Access(Accessor.ReadOnly);
            hbm.Access.Should().Be("readonly");
        }
        public void CanSetFormula()
        {
            var hbmMapping = new HbmMapping();
            var member = ForClass<MyClass>.Property(c=> c.Relation);
            var mapping = new HbmManyToOne();
            var mapper = new ManyToOneMapper(member, mapping, hbmMapping);

            mapper.Formula("SomeFormula");
            mapping.formula.Should().Be("SomeFormula");
        }
 public void SettingColumnPlainValuesOverridesFormula()
 {
     var hbmMapping = new HbmMapping();
     var member = ForClass<MyClass>.Property(c => c.Relation);
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Formula("formula");
     mapper.Column("colName");
     mapping.formula.Should().Be.Null();
     mapping.column.Should().Be("colName");
 }
        public void CanForceClassRelation()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyClass).GetProperty("TheOtherRelation");
            var mapping = new HbmManyToOne();
            var mapper = new ManyToOneMapper(member, mapping, hbmMapping);

            mapper.Class(typeof (Relation));

            mapping.Class.Should().Contain("Relation").And.Not.Contain("IRelation");
        }
 public void SettingFormulaOverridesColumnNodes()
 {
     var hbmMapping = new HbmMapping();
     var member = ForClass<MyClass>.Property(c => c.Relation);
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Column(cm => cm.SqlType("VARCHAR(80)"));
     mapper.Formula("formula");
     mapping.formula.Should().Be("formula");
     mapping.column.Should().Be(null);
     mapping.Items.Should().Be.Null();
 }
 public void WhenSetFormulaWithNullThenDoNothing()
 {
     var hbmMapping = new HbmMapping();
     var member = ForClass<MyClass>.Property(c => c.Relation);
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Column("MyColumn");
     mapper.Formula(null);
     mapping.formula.Should().Be.Null();
     mapping.column.Should().Not.Be.Null();
 }
 public void WhenSetFormulaWithMultipleLinesThenSetFormulaNode()
 {
     var hbmMapping = new HbmMapping();
     var member = ForClass<MyClass>.Property(c => c.Relation);
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     var formula = @"Line1
     Line2";
     mapper.Formula(formula);
     mapping.formula.Should().Be.Null();
     mapping.Items.FirstOrDefault().Should().Not.Be.Null().And.Be.OfType<HbmFormula>();
     var hbmFormula = (HbmFormula)(mapping.Items.First());
     hbmFormula.Text.Length.Should().Be(2);
     hbmFormula.Text[0].Should().Be("Line1");
     hbmFormula.Text[1].Should().Be("Line2");
 }
 public void CanSetLazyness()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyClass).GetProperty("TheOtherRelation");
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Lazy(LazyRelation.NoProxy);
     mapping.Lazy.Should().Have.Value();
     mapping.Lazy.Should().Be(HbmLaziness.NoProxy);
 }
        public void CanSetInsert()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyClass).GetProperty("Relation");
            var hbm = new HbmManyToOne();
            var mapper = new ManyToOneMapper(member, hbm, hbmMapping);

            mapper.Insert(false);
            hbm.insert.Should().Be.False();
        }
 public void WhenSetDefaultColumnNameThenDoesNotSetTheName()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyClass).GetProperty("Relation");
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Column(cm => cm.Name("Relation"));
     mapping.column.Should().Be.Null();
     mapping.Columns.Should().Be.Empty();
 }
 public void WhenSetColumnValuesThenAddColumnTag()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyClass).GetProperty("Relation");
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Column(cm =>
     {
         cm.SqlType("BIGINT");
         cm.NotNullable(true);
     });
     mapping.Items.Should().Not.Be.Null();
     mapping.Columns.Should().Have.Count.EqualTo(1);
 }
        public void WhenSetDifferentColumnNameThenSetTheName()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyClass).GetProperty("Relation");
            var hbm = new HbmManyToOne();
            var mapper = new ManyToOneMapper(member, hbm, hbmMapping);
            mapper.Column(cm => cm.Name("RelationId"));

            hbm.Columns.Should().Have.Count.EqualTo(1);
            hbm.Columns.Single().name.Should().Be("RelationId");
        }
        public void WhenSetFetchModeToSelectThenResetFetch()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyClass).GetProperty("Relation");
            var mapping = new HbmManyToOne();
            var mapper = new ManyToOneMapper(member, mapping, hbmMapping);

            mapper.Fetch(FetchMode.Select);

            mapping.fetch.Should().Be(HbmFetchMode.Select);
            mapping.fetchSpecified.Should().Be.False();
        }
 public void WhenSetMultiColumnsValuesThenAutoassignColumnNames()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyClass).GetProperty("Relation");
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     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 WhenSetMultiColumnsValuesThenAddColumns()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyClass).GetProperty("Relation");
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Columns(cm =>
     {
         cm.Name("column1");
         cm.Length(50);
     }, cm =>
     {
         cm.Name("column2");
         cm.SqlType("VARCHAR(10)");
     });
     mapping.Columns.Should().Have.Count.EqualTo(2);
 }
 public void WhenSetBasicColumnValuesThenSetPlainValues()
 {
     var hbmMapping = new HbmMapping();
     var member = typeof(MyClass).GetProperty("Relation");
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Column(cm =>
     {
         cm.UniqueKey("theUnique");
         cm.NotNullable(true);
     });
     mapping.Items.Should().Be.Null();
     mapping.uniquekey.Should().Be("theUnique");
     mapping.notnull.Should().Be(true);
     mapping.notnullSpecified.Should().Be(true);
 }
        public void WhenSetBasicColumnValuesThroughShortCutThenMergeColumn()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof(MyClass).GetProperty("Relation");
            var mapping = new HbmManyToOne();
            var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
            mapper.Column("pizza");
            mapper.NotNullable(true);
            mapper.Unique(true);
            mapper.UniqueKey("AA");
            mapper.Index("II");

            mapping.Items.Should().Be.Null();
            mapping.column.Should().Be("pizza");
            mapping.notnull.Should().Be(true);
            mapping.unique.Should().Be(true);
            mapping.uniquekey.Should().Be("AA");
            mapping.index.Should().Be("II");
        }
 public void WhenSetFormulaThenResetColumn()
 {
     var hbmMapping = new HbmMapping();
     var member = ForClass<MyClass>.Property(c => c.Relation);
     var mapping = new HbmManyToOne();
     var mapper = new ManyToOneMapper(member, mapping, hbmMapping);
     mapper.Column("MyColumn");
     mapper.Formula("SomeFormula");
     mapping.formula.Should().Be("SomeFormula");
     mapping.column.Should().Be.Null();
     mapping.Items.Should().Be.Null();
 }
        public void WhenForceClassRelationToIncompatibleTypeThenThrows()
        {
            var hbmMapping = new HbmMapping();
            var member = typeof (MyClass).GetProperty("TheOtherRelation");
            var mapping = new HbmManyToOne();
            var mapper = new ManyToOneMapper(member, mapping, hbmMapping);

            ActionAssert.Throws<ArgumentOutOfRangeException>(() => mapper.Class(typeof (Whatever)));
        }