public void CanAssignEntityName()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     mapper.EntityName("myname");
     mapping.EntityName.Should().Be("myname");
 }
 public void CanAssignNotFoundMode()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     mapper.NotFound(NotFoundMode.Ignore);
     mapping.NotFoundMode.Should().Be(HbmNotFoundMode.Ignore);
 }
        public void WhenForceClassRelationToIncompatibleTypeThenThrows()
        {
            var mapping = new HbmManyToMany();
            var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);

            Executing.This(() => mapper.Class(typeof(Whatever))).Should().Throw<ArgumentOutOfRangeException>();
        }
 public void SettingColumnOverridesFormula()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     mapper.Formula("formula");
     mapper.Column(cm => cm.Unique(true));
     mapping.formula.Should().Be.Null();
 }
        public void CanSetFormula()
        {
            var mapping = new HbmManyToMany();
            var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);

            mapper.Formula("SomeFormula");
            mapping.formula.Should().Be("SomeFormula");
        }
        public void AfterSetMultiColumnsCantSetSimpleColumn()
        {
            var mapping = new HbmManyToMany();
            var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
            mapper.Columns(cm => cm.Length(50), cm => cm.SqlType("VARCHAR(10)"));

            mapper.Executing(x => x.Column(cm => cm.Length(50))).Throws<ConfOrm.MappingException>();
        }
 public void SettingColumnPlainValuesOverridesFormula()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     mapper.Formula("formula");
     mapper.Column("colName");
     mapping.formula.Should().Be.Null();
     mapping.column.Should().Be("colName");
 }
        public void CanForceClassRelation()
        {
            var mapping = new HbmManyToMany();
            var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);

            mapper.Class(typeof(MyClass));

            mapping.Class.Should().Contain("MyClass").And.Not.Contain("IMyInterface");
        }
 public void SettingFormulaOverridesColumnNodes()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     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 CanSetLazyness()
        {
            var mapping = new HbmManyToMany();
            var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);

            mapper.Lazy(LazyRelation.NoProxy);
            mapping.lazy.Should().Be(HbmRestrictedLaziness.False);

            mapper.Lazy(LazyRelation.NoLazy);
            mapping.lazy.Should().Be(HbmRestrictedLaziness.False);

            mapper.Lazy(LazyRelation.Proxy);
            mapping.lazy.Should().Be(HbmRestrictedLaziness.Proxy);
        }
 public void WhenSetFormulaWithNullThenDoNothing()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     mapper.Column("MyColumn");
     mapper.Formula(null);
     mapping.formula.Should().Be.Null();
     mapping.column.Should().Not.Be.Null();
 }
 public void WhenSetColumnValuesThenAddColumnTag()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     mapper.Column(cm =>
     {
         cm.SqlType("VARCHAR(3)");
         cm.NotNullable(true);
     });
     mapping.Columns.Should().Not.Be.Null();
     mapping.Columns.Should().Have.Count.EqualTo(1);
 }
        public void WhenSetDifferentColumnNameThenSetTheName()
        {
            var mapping = new HbmManyToMany();
            var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
            mapper.Column(cm => cm.Name("pepe"));

            mapping.Columns.Should().Have.Count.EqualTo(1);
            mapping.Columns.Single().name.Should().Be("pepe");
        }
 public void WhenSetMultiColumnsValuesThenAutoassignColumnNames()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     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 mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     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 WhenSetFormulaThenResetColumn()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     mapper.Column("MyColumn");
     mapper.Formula("SomeFormula");
     mapping.formula.Should().Be("SomeFormula");
     mapping.column.Should().Be.Null();
     mapping.Items.Should().Be.Null();
 }
 public void WhenSetFormulaWithMultipleLinesThenSetFormulaNode()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     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 WhenSetDefaultColumnNameThenDoesNotSetTheName()
 {
     var mapping = new HbmManyToMany();
     var mapper = new ManyToManyMapper(typeof(MyClass), mapping, null);
     mapper.Column(cm => cm.Name("MyClass"));
     mapping.column.Should().Be.Null();
     mapping.Columns.Should().Be.Empty();
 }