private void AcceptChanges() { var tablesToProcess = Form.SelectedTables; MappingProcessor proc = new MappingProcessor(new OneToOneEntityProcessor(Set.EntitySet.Entities.Select(e => e.Name))); proc.CreateOneToOneMappingsFor(tablesToProcess, Set); mainPanel.CloseDatabaseRefreshResultsForm(Changes.WereAccepted); }
public void It_Creates_A_Column_On_The_Many_Side() { var proc = new MappingProcessor(new OneToOneEntityProcessor()); var mappingSet = proc.CreateOneToOneMapping(entities); var table1 = mappingSet.Database.Tables[1]; var table2 = mappingSet.Database.Tables[1]; Assert.That(table2.Columns, Has.Count(2)); // Extra column added var newColumn = table2.Columns[1]; Assert.That(newColumn.Datatype, Is.SameAs(table1.Columns[0].Datatype)); }
public void It_Creates_A_Foreign_Key_On_The_Many_Side() { var proc = new MappingProcessor(new OneToOneEntityProcessor()); var mappingSet = proc.CreateOneToOneMapping(entities); var table1 = mappingSet.Database.Tables[0]; var table2 = mappingSet.Database.Tables[1]; Assert.That(table2.Keys, Has.Count(2), "Many table did not get the foreign key"); var key = table2.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Foreign); var primaryKey = table1.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Primary); Assert.That(key, Is.Not.Null); Assert.That(key.ReferencedKey, Is.Not.Null); Assert.That(key.ReferencedKey, Is.SameAs(primaryKey)); }
public void Correct_References_Are_Created() { EntityProcessor proc = MockRepository.GenerateMock<EntityProcessor>(); Entity entity1 = new EntityImpl(); Entity entity2 = new EntityImpl(); Reference reference = new ReferenceImpl(entity1, entity2); proc.Stub(p => p.CreateEntity(Table1)).Return(entity1); proc.Stub(p => p.CreateEntity(Table2)).Return(entity2); proc.Stub(p => p.CreateReference(Relationship12, Set.EntitySet)).Return(reference); MappingProcessor mappingProc = new MappingProcessor(proc); mappingProc.CreateOneToOneMappingsFor(new[] { Table1, Table2 }, Set); proc.AssertWasCalled(p => p.CreateEntity(Table1)); proc.AssertWasCalled(p => p.CreateEntity(Table2)); proc.AssertWasCalled(p => p.CreateReference(Relationship12, Set.EntitySet)); proc.AssertWasNotCalled(p => p.CreateReference(Relationship13, Set.EntitySet)); }
public void Correct_Entities_Are_Created() { EntityProcessor proc = MockRepository.GenerateMock<EntityProcessor>(); Entity entity1 = new EntityImpl(); proc.Stub(p => p.CreateEntity(Table1)).Return(entity1); MappingProcessor mappingProc = new MappingProcessor(proc); mappingProc.CreateOneToOneMappingsFor(new[] { Table1 }, Set); proc.AssertWasCalled(p => p.CreateEntity(Table1)); proc.AssertWasNotCalled(p => p.CreateEntity(Table2)); }
private MappingSet CreateMappingSet_TwoTables() { Database database = new Database("DB1"); var table1 = new Table("Table1"); table1.AddColumn(new Column("Column1") { Datatype = "int", InPrimaryKey = true }); var table2 = new Table("Table2"); table2.AddColumn(new Column("Column1") { Datatype = "int", InPrimaryKey = true }); database.AddTable(table1); database.AddTable(table2); MappingProcessor processor = new MappingProcessor(new OneToOneEntityProcessor()); return processor.CreateOneToOneMapping(database); }
private MappingSet CreateMappingSet_OneTable() { Database database = new Database("DB1"); var table = new Table("Table1"); table.AddColumn(new Column("Column1") { Datatype = "int", InPrimaryKey = true }); table.AddColumn(new Column("Column2") { Datatype = "nvarchar", Size = 50 }); database.AddTable(table); MappingProcessor processor = new MappingProcessor(new OneToOneEntityProcessor()); return processor.CreateOneToOneMapping(database); }
public void It_Creates_A_Single_Relationship_With_The_Right_Keys() { var proc = new MappingProcessor(new OneToOneEntityProcessor()); var mappingSet = proc.CreateOneToOneMapping(entities); var table1 = mappingSet.Database.Tables[0]; var table2 = mappingSet.Database.Tables[1]; var foreignKey = table2.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Foreign); var primaryKey = table1.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Primary); Assert.That(table1.Relationships, Has.Count(1)); var relationship = table1.Relationships[0]; Assert.That(relationship.PrimaryKey, Is.SameAs(primaryKey)); Assert.That(relationship.ForeignKey, Is.SameAs(foreignKey)); }
public void It_Creates_A_Unique_Key_On_The_Second_Entity() { var proc = new MappingProcessor(new OneToOneEntityProcessor()); var mappingSet = proc.CreateOneToOneMapping(entities); var table2 = mappingSet.Database.Tables[1]; Assert.That(table2.Keys, Has.Count(3), "The second table did not get the new keys"); var uniqueKey = table2.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Unique); var foreignKey = table2.Keys.FirstOrDefault(k => k.Keytype == DatabaseKeyType.Foreign); Assert.That(uniqueKey, Is.Not.Null); Assert.That(uniqueKey.Columns, Has.Count(1)); Assert.That(uniqueKey.Columns[0], Is.SameAs(foreignKey.Columns[0])); }
public void SetUp() { entities = new EntitySetImpl(); entity1 = new EntityImpl("Entity1"); entity1.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true }); entity2 = new EntityImpl("Entity2"); entity2.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true }); entities.AddEntity(entity1); entities.AddEntity(entity2); reference = entity1.CreateReferenceTo(entity2); reference.Cardinality1 = Cardinality.Many; reference.Cardinality2 = Cardinality.Many; var proc = new MappingProcessor(new OneToOneEntityProcessor()); mappingSet = proc.CreateOneToOneMapping(entities); }
public void SetUp() { entities = new EntitySetImpl(); entityParent = new EntityImpl("EntityParent"); entityParent.AddProperty(new PropertyImpl("PrimaryKey") { Type = "int", IsKeyProperty = true }); entityChild = new EntityImpl("EntityChild"); entityParent.AddChild(entityChild); entityChild.CopyPropertyFromParent(entityParent.ConcreteProperties[0]); entityChild.AddProperty(new PropertyImpl("ActualProperty"){ Type = "string" }); entities.AddEntity(entityParent); entities.AddEntity(entityChild); var proc = new MappingProcessor(new OneToOneEntityProcessor()); mappingSet = proc.CreateOneToOneMapping(entities); }
public override void RunCustomNewProjectLogic(ArchAngel.Interfaces.ProviderInfo theProviderInfo, IUserInteractor userInteractor) { //if (theProviderInfo is ArchAngel.Providers.EntityModel.ProviderInfo) //{ // ArchAngel.Providers.EntityModel.ProviderInfo providerInfo = (ArchAngel.Providers.EntityModel.ProviderInfo)theProviderInfo; // providerInfo.Clear(); // return; //} try { log.Debug("Loading project..."); userInteractor.UpdateWaitScreen("Loading project..."); NHibernateHelper.ProviderInfo providerInfo = (NHibernateHelper.ProviderInfo)theProviderInfo; providerInfo.Clear(); log.Debug("Loading database..."); Database database = DatabaseLoader.LoadDatabase(DatabaseLoader.DatabaseObjectsToFetch, null); DatabaseProcessor dbProcessor = new DatabaseProcessor(); dbProcessor.LogErrors = true; log.Debug("Creating relationships..."); dbProcessor.CreateRelationships(database); if (dbProcessor.Errors.Count > 0) { log.Debug("Database errors exist..." + dbProcessor.Errors.Count.ToString()); UI.FormErrors form = new UI.FormErrors("<b><font color='Red'>Note:</font></b> Database problems exist. Please <b>fix</b> these problems (or <b>omit the tables</b> in question) before trying again.", dbProcessor.Errors); form.ShowDialog(); return; } log.Debug("Creating 1 to 1 mappings..."); var mappingSet = new MappingProcessor(new OneToOneEntityProcessor()) .CreateOneToOneMapping(database, this.TablePrefixes, this.ColumnPrefixes, this.TableSuffixes, this.ColumnSuffixes); foreach (var entity in mappingSet.EntitySet.Entities) { ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.ExistingPropertyNames = new List<string>(); foreach (Property prop in entity.Properties) { IColumn mappedCol = prop.MappedColumn(); ArchAngel.Interfaces.Scripting.NHibernate.Model.IColumn scriptCol = new Interfaces.Scripting.NHibernate.Model.IColumn() { IsNullable = mappedCol.IsNullable, //IsText = Length = mappedCol.Size, Name = mappedCol.Name, ScriptObject = mappedCol, Type = mappedCol.OriginalDataType }; prop.Name = ArchAngel.Interfaces.ProjectOptions.ModelScripts.Scripts.GetPropertyName(scriptCol); } } providerInfo.EntityProviderInfo.MappingSet = mappingSet; ///////////////////////////////// providerInfo.EntityProviderInfo.Engine.AddModule(new NHibernateProjectLoaderModule(database)); // Then run the validation rules log.Debug("Validating model..."); userInteractor.UpdateWaitScreen("Validating model..."); //var rulesEngine = new ValidationRulesEngine(mappingSet); //rulesEngine.AddModule(new NHibernateProjectLoaderModule(database)); log.Debug("Running validation rules..."); providerInfo.EntityProviderInfo.RunValidationRules();//rulesEngine); } //catch (Exception ex) //{ // MessageBox. //} finally { log.Debug("Removing wait screen..."); userInteractor.RemoveWaitScreen(); } }