public void WhenCreateThenSetDefaultTableName() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); new JoinMapper(typeof(MyClass), " AA ", hbmJoin, mapdoc); hbmJoin.table.Should().Be("AA"); }
public void WhenCreateThenSetDefaultTableName() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); new JoinMapper(typeof(MyClass), " AA ", hbmJoin, mapdoc); Assert.That(hbmJoin.table, Is.EqualTo("AA")); }
public void CanSetTable() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Table(" Pizza "); Assert.That(hbmJoin.table, Is.EqualTo("Pizza")); }
public void WhenCreateWithEmptySplitGroupThenThrows() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); Assert.That(() => new JoinMapper(typeof(MyClass), null, hbmJoin, mapdoc), Throws.TypeOf<ArgumentNullException>()); Assert.That(() => new JoinMapper(typeof(MyClass), "", hbmJoin, mapdoc), Throws.TypeOf<ArgumentOutOfRangeException>()); Assert.That(() => new JoinMapper(typeof(MyClass), " ", hbmJoin, mapdoc), Throws.TypeOf<ArgumentOutOfRangeException>()); }
public void WhenCreateWithEmptySplitGroupThenThrows() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); Executing.This(() => new JoinMapper(typeof(MyClass), null, hbmJoin, mapdoc)).Should().Throw<ArgumentNullException>(); Executing.This(() => new JoinMapper(typeof(MyClass), "", hbmJoin, mapdoc)).Should().Throw<ArgumentOutOfRangeException>(); Executing.This(() => new JoinMapper(typeof(MyClass), " ", hbmJoin, mapdoc)).Should().Throw<ArgumentOutOfRangeException>(); }
public void CanSetTable() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Table(" Pizza "); hbmJoin.table.Should().Be("Pizza"); }
public void CanSetCatalog() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Catalog("pizza"); Assert.That(hbmJoin.catalog, Is.EqualTo("pizza")); }
public void CanSetCatalog() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Catalog("pizza"); hbmJoin.catalog.Should().Be("pizza"); }
public void WhenSetTableNameEmptyThenThrows() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); Assert.That(() => mapper.Table(null), Throws.TypeOf<ArgumentNullException>()); Assert.That(() => mapper.Table(""), Throws.TypeOf<ArgumentOutOfRangeException>()); Assert.That(() => mapper.Table(" "), Throws.TypeOf<ArgumentOutOfRangeException>()); }
public void WhenSetTableNameEmptyThenThrows() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Executing(x => x.Table(null)).Throws<ArgumentNullException>(); mapper.Executing(x => x.Table("")).Throws<ArgumentOutOfRangeException>(); mapper.Executing(x => x.Table(" ")).Throws<ArgumentOutOfRangeException>(); }
public void WhenTableNameChangesValueThenNotify() { bool eventCalled = false; var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.TableNameChanged += (m, x) => { m.Should().Be.SameInstanceAs(mapper); x.OldName.Should().Be("AA"); x.NewName.Should().Be("Pizza"); eventCalled = true; }; mapper.Table(" Pizza "); eventCalled.Should().Be.True(); }
public void WhenTableNameChangesValueThenNotify() { bool eventCalled = false; var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.TableNameChanged += (m, x) => { Assert.That(m, Is.SameAs(mapper)); Assert.That(x.OldName, Is.EqualTo("AA")); Assert.That(x.NewName, Is.EqualTo("Pizza")); eventCalled = true; }; mapper.Table(" Pizza "); Assert.That(eventCalled, Is.True); }
public JoinMapper(System.Type container, string splitGroupId, HbmJoin hbmJoin, HbmMapping mapDoc) : base(container, mapDoc) { if (splitGroupId == null) { throw new ArgumentNullException("splitGroupId"); } if (hbmJoin == null) { throw new ArgumentNullException("hbmJoin"); } this.hbmJoin = hbmJoin; this.hbmJoin.table = splitGroupId.Trim(); if (string.IsNullOrEmpty(this.hbmJoin.table)) { throw new ArgumentOutOfRangeException("splitGroupId", "The table-name cant be empty."); } if (hbmJoin.key == null) { hbmJoin.key = new HbmKey { column1 = container.Name.ToLowerInvariant() + "_key" }; } keyMapper = new KeyMapper(container, hbmJoin.key); }
public void SetSqlDelete() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.SqlDelete("blah"); hbmJoin.SqlDelete.Should().Not.Be.Null(); hbmJoin.SqlDelete.Text[0].Should().Be("blah"); }
public void CanSetFetch() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Fetch(FetchKind.Select); Assert.That(hbmJoin.fetch, Is.EqualTo(HbmJoinFetch.Select)); }
public void CallKeyMapper() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); var keyMapperCalled = false; mapper.Key(km => keyMapperCalled = true); Assert.That(keyMapperCalled, Is.True); }
public void WhenAddPropertyThenAddItem() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Property(For<MyClass>.Property(mc => mc.Something), x => { }); hbmJoin.Properties.Should().Have.Count.EqualTo(1); }
public void WhenCallKeyMapperMoreThanOnceThenKeyMapperIsTheSame() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); IKeyMapper firstCallInstance = null; IKeyMapper secondCallInstance= null; mapper.Key(km => firstCallInstance = km); mapper.Key(km => secondCallInstance = km); firstCallInstance.Should().Be.SameInstanceAs(secondCallInstance); }
public void WhenCallKeyMapperThenKeyMapperIsNotNull() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Key(km => km.Should().Not.Be.Null()); }
public void CallKeyMapper() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); var keyMapperCalled = false; mapper.Key(km => keyMapperCalled = true); keyMapperCalled.Should().Be.True(); }
public void CanSetFetch() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Fetch(FetchKind.Select); hbmJoin.fetch.Should().Be(HbmJoinFetch.Select); }
public void WhenCallKeyMapperThenKeyMapperIsNotNull() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Key(km => Assert.That(km, Is.Not.Null)); }
public void CanSetOptional() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Optional(true); hbmJoin.optional.Should().Be.True(); }
public void WhenAddPropertyThenAddItem() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Property(For<MyClass>.Property(mc => mc.Something), x => { }); Assert.That(hbmJoin.Properties.Count(), Is.EqualTo(1)); }
public void CanSetSchema() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Schema("pizza"); hbmJoin.schema.Should().Be("pizza"); }
private void BindJoin(HbmJoin joinMapping, Join join, IDictionary<string, MetaAttribute> inheritedMetas) { PersistentClass persistentClass = join.PersistentClass; // TABLENAME string schema = joinMapping.schema ?? mappings.SchemaName; string catalog = joinMapping.catalog ?? mappings.CatalogName; string action = "all"; // joinMapping.schemaaction ?? "all"; string tableName = joinMapping.table; Table table = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, tableName), joinMapping.Subselect, false, action); join.Table = table; join.IsSequentialSelect = joinMapping.fetch == HbmJoinFetch.Select; join.IsInverse = joinMapping.inverse; join.IsOptional = joinMapping.optional; log.InfoFormat("Mapping class join: {0} -> {1}", persistentClass.EntityName, join.Table.Name); // KEY SimpleValue key; if (!String.IsNullOrEmpty(joinMapping.key.propertyref)) { string propertyRef = joinMapping.key.propertyref; var propertyRefKey = new SimpleValue(persistentClass.Table) { IsAlternateUniqueKey = true }; var property = persistentClass.GetProperty(propertyRef); join.RefIdProperty = property; //we only want one column var column = (Column) property.ColumnIterator.First(); if (!column.Unique) throw new MappingException( string.Format( "Property {0}, on class {1} must be marked as unique to be joined to with a property-ref.", property.Name, persistentClass.ClassName)); propertyRefKey.AddColumn(column); propertyRefKey.TypeName = property.Type.Name; key = new ReferenceDependantValue(table, propertyRefKey); } else { key = new DependantValue(table, persistentClass.Identifier); } key.ForeignKeyName = joinMapping.key.foreignkey; join.Key = key; key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade; new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false); join.CreatePrimaryKey(dialect); join.CreateForeignKey(); // PROPERTIES new PropertiesBinder(Mappings, persistentClass, dialect).Bind(joinMapping.Properties, join.Table, inheritedMetas, p => { }, join.AddProperty); // CUSTOM SQL HandleCustomSQL(joinMapping, join); }
public void CanSetSqlSubselect() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Subselect("blah"); hbmJoin.Subselect.Should().Not.Be.Null(); hbmJoin.subselect.Text[0].Should().Be("blah"); }
public void CanSetInverse() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Inverse(true); hbmJoin.inverse.Should().Be.True(); }
private void BindJoin(HbmJoin joinMapping, Join join, IDictionary<string, MetaAttribute> inheritedMetas) { PersistentClass persistentClass = join.PersistentClass; // TABLENAME string schema = joinMapping.schema ?? mappings.SchemaName; string catalog = joinMapping.catalog ?? mappings.CatalogName; string action = "all"; // joinMapping.schemaaction ?? "all"; string tableName = joinMapping.table; Table table = mappings.AddTable(schema, catalog, GetClassTableName(persistentClass, tableName), joinMapping.Subselect, false, action); join.Table = table; join.IsSequentialSelect = joinMapping.fetch == HbmJoinFetch.Select; join.IsInverse = joinMapping.inverse; join.IsOptional = joinMapping.optional; log.InfoFormat("Mapping class join: {0} -> {1}", persistentClass.EntityName, join.Table.Name); // KEY SimpleValue key = new DependantValue(table, persistentClass.Identifier); key.ForeignKeyName = joinMapping.key.foreignkey; join.Key = key; key.IsCascadeDeleteEnabled = joinMapping.key.ondelete == HbmOndelete.Cascade; new ValuePropertyBinder(key, Mappings).BindSimpleValue(joinMapping.key, persistentClass.EntityName, false); join.CreatePrimaryKey(dialect); join.CreateForeignKey(); // PROPERTIES new PropertiesBinder(Mappings, persistentClass, dialect).Bind(joinMapping.Properties, join.Table, inheritedMetas, p => { }, join.AddProperty); // CUSTOM SQL HandleCustomSQL(joinMapping, join); }
public void CanSetOptional() { var mapdoc = new HbmMapping(); var hbmJoin = new HbmJoin(); var mapper = new JoinMapper(typeof(MyClass), "AA", hbmJoin, mapdoc); mapper.Optional(true); Assert.That(hbmJoin.optional, Is.True); }