public void Both_Should_Validate_Correcty() { var table1 = new Table { Name = "Table1"}; var table2 = new Table { Name = "Table2"}; var database = new Database("DB"); database.AddTable(table1); database.AddTable(table2); var failures = new List<ValidationFailure>(); Assert.That(table1.ValidateObject(failures), Is.True); Assert.That(failures, Is.Empty); }
public void Should_Return_This() { const string expectedXML = @"<LogicalSchema Version=""1""><DatabaseName>Database1</DatabaseName>" + "<Table><Description /><Enabled>True</Enabled><IsUserDefined>False</IsUserDefined><Name>Table1</Name><UID>00000000-0000-0000-0000-000000000000</UID></Table>" + "<Table><Description /><Enabled>True</Enabled><IsUserDefined>False</IsUserDefined><Name>Table2</Name><UID>00000000-0000-0000-0000-000000000000</UID></Table>" + "</LogicalSchema>"; Database db1 = new Database("Database1"); db1.AddTable(new Table("Table1")); db1.AddTable(new Table("Table2")); string outputXml = db1.Serialise(new DatabaseSerialisationScheme()); outputXml = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXml); Assert.That(outputXml, Is.EqualTo(expectedXML)); }
protected void SetupBase(string resourcePath) { loader = new EntityLoader(MockRepository.GenerateStub<IFileController>()); database = new Database("DB1"); table1 = new Table("Table1"); table1.AddColumn(new Column("ID") { Datatype = "int" }); table1.AddColumn(new Column("BasicClass2_Index") { Datatype = "int" }); database.AddEntity(table1); table2 = new Table("Table2"); table2.AddColumn(new Column("ID") { Datatype = "int" }); table2.AddColumn(new Column("BASIC_CLASS_1_ID")); database.AddEntity(table2); tableManyToMany = new Table("Class1Class2"); tableManyToMany.AddColumn(new Column("Class1ID") { Datatype = "int" }); tableManyToMany.AddColumn(new Column("Class2ID") { Datatype = "int" }); database.AddTable(tableManyToMany); relationship = table1.CreateRelationshipTo(table2); relationship.PrimaryKey.AddColumn("ID"); relationship.ForeignKey.AddColumn("BASIC_CLASS_1_ID"); // Call we are testing mappingSet = loader.GetEntities(new[] { Path.Combine("Resources", resourcePath) }, database); }
public void Setup() { database = new Database("DB1"); table = new Table("Table1"); database.AddTable(table); reference = new ReferenceImpl(new Guid("11111111-1111-1111-1111-111111111111")); entitySet = MockRepository.GenerateMock<EntitySet>(); entitySet.Stub(e => e.References).Return(new List<Reference> { reference }.AsReadOnly()); }
public void It_Should_Be_Reconstructed_Correctly() { const string xml = When_Serialising_Key_With_A_Referenced_Key.KeyWithReferencedKeyXml; XmlDocument document = new XmlDocument(); document.LoadXml(xml); Database db = new Database("Database1"); Table table1 = new Table("Table1"); Table table2 = new Table("Table2"); db.AddTable(table1); db.AddTable(table2); IKey key2 = new Key("ForeignKey") { Parent = table2 }; table2.AddKey(key2); var scheme = new DatabaseDeserialisationScheme(); IKey key = scheme.ProcessKeyNode(document.DocumentElement, table1, db); scheme.ProcessReferencedKey(key, document.DocumentElement, db); Assert.That(key.ReferencedKey, Is.SameAs(key2)); }
public void It_Should_Be_Reconstructed_Correctly() { IDatabase database = new Database("DB1"); var table1 = new Table("Table1"); var table2 = new Table("Table2"); var key1 = new Key("K1", DatabaseKeyType.Primary); var key2 = new Key("ForeignKey", DatabaseKeyType.Foreign); table1.AddKey(key1); table2.AddKey(key2); database.AddTable(table1); database.AddTable(table2); Relationship rel = new DatabaseDeserialisationScheme().DeserialiseRelationship(FullRelationshipXml.GetXmlDocRoot(), database); Assert.That(rel.Identifier, Is.EqualTo(new Guid("11111111-1111-1111-1111-111111111111"))); Assert.That(rel.Name, Is.EqualTo("Relation1")); Assert.That(rel.PrimaryTable, Is.SameAs(table1)); Assert.That(rel.ForeignTable, Is.SameAs(table2)); Assert.That(rel.PrimaryKey, Is.SameAs(key1)); Assert.That(rel.ForeignKey, Is.SameAs(key2)); }
public static Database TestDatabase() { Database db = new Database("Test Database"); var t1 = new Table("Table1"); db.AddTable(t1); t1.AddColumn(new Column("Column1") { InPrimaryKey = true, Datatype = "int", OrdinalPosition = 0, Size = 4}); t1.AddColumn(new Column("Column2") { Datatype = "nvarchar", OrdinalPosition = 1, Size = 100 }); t1.AddColumn(new Column("Column3") { Datatype = "datetime", OrdinalPosition = 2, Size = 8 }); t1.AddIndex(new Index("PK_Table1") { IsUnique = true, Datatype = DatabaseIndexType.PrimaryKey}).AddColumn("Column1"); t1.AddKey(new Key("PK_Table1", DatabaseKeyType.Primary)).AddColumn("Column1").AddColumn("Column2"); return db; }
private void buttonRunHBM2ModelTransform_Click(object sender, RoutedEventArgs args) { var loader = new EntityLoader(new FileController()); var database = new Database("DB1", ArchAngel.Providers.EntityModel.Controller.DatabaseLayer.DatabaseTypes.SQLServer2005); var table = new Table("TableName", ""); table.AddColumn(new Column("ID")); table.AddColumn(new Column("Speed")); table.AddColumn(new Column("Name")); table.AddColumn(new Column("Speed")); table.AddColumn(new Column("Discriminator")); table.AddColumn(new Column("Car_Make")); table.AddColumn(new Column("Bike_Model")); database.AddTable(table); loader.GetEntities(new[] {"nhtest.xml"}, database); }
public void Setup() { database = new Database("Db1"); entitySet = new EntitySetImpl(); table = new Table("Table1"); table.AddColumn(new Column("Column1")); entity1 = new EntityImpl("Entity1"); entity1.AddProperty(new PropertyImpl("Property1")); entity2 = new EntityImpl("Entity2"); entity2.AddProperty(new PropertyImpl("Property2")); var reference = entity1.CreateReferenceTo(entity2); reference.Identifier = new Guid("11111111-1111-1111-1111-111111111111"); reference.End1Name = "end1"; reference.End2Name = "end2"; entitySet.AddReference(reference); database.AddTable(table); entitySet.AddEntity(entity1); }
public void It_Should_Serialise_To_This() { XmlNode root = When_Serialising_A_Discriminator_With_One_Condition.FullDiscriminatorXml.GetXmlDocRoot(); Entity entity = new EntityImpl("Entity1"); var column = new Column("Column1"); Table table = new Table("Table1"); table.AddColumn(column); var database = new Database("db1"); database.AddTable(table); var dis = new EntitySetDeserialisationScheme().DeserialiseDiscriminator(root, database); Assert.That(dis, Is.Not.Null); Assert.That(dis.RootGrouping, Is.Not.Null); Assert.That(dis.RootGrouping.ContainsConditions, Is.True); Assert.That(dis.RootGrouping.ContainsGroupings, Is.False); var condition = dis.RootGrouping.Conditions.ElementAt(0); Assert.That(condition.Column, Is.SameAs(column)); Assert.That(condition.Operator, Is.SameAs(Operator.Equal)); Assert.That(condition.ExpressionValue.Value, Is.EqualTo("5")); }
public void Setup() { // Setup Database database = new Database("DB1"); var table = new Table("User"); table.AddColumn(new Column("Name")); table.AddColumn(new Column("AddressStreet")); table.AddColumn(new Column("AddressCity")); table.AddColumn(new Column("AddressCountry")); database.AddTable(table); // Setup Entities entitySet = new EntitySetImpl(); Entity userEntity = new EntityImpl("User"); userEntity.AddProperty(new PropertyImpl("Name")); // Create the Address type spec = new ComponentSpecificationImpl("Address"); spec.AddProperty(new ComponentPropertyImpl("Street")); spec.AddProperty(new ComponentPropertyImpl("City")); spec.AddProperty(new ComponentPropertyImpl("Country")); // Create the Address component for the User entity. component = spec.CreateImplementedComponentFor(userEntity, "HomeAddress"); entitySet.AddEntity(userEntity); entitySet.AddComponentSpecification(spec); // Setup the Mappings mappingSet = new MappingSetImpl(database, entitySet); componentMapping = new ComponentMappingImpl(); mappingSet.AddMapping(componentMapping); componentMapping.AddPropertyAndColumn(component.Properties[0], table.Columns[1]); componentMapping.AddPropertyAndColumn(component.Properties[1], table.Columns[2]); componentMapping.AddPropertyAndColumn(component.Properties[2], table.Columns[3]); // Add the mapping between the Name property and the Name column in the database table. mappingSet.ChangeMappedColumnFor(userEntity.ConcreteProperties[0]).To(table.Columns[0]); }
public void Both_Should_Not_Validate() { var table1 = new Table { Name = "Table"}; var table2 = new Table { Name = "Table"}; var database = new Database("DB"); database.AddTable(table1); database.AddTable(table2); ValidateTable(table1); ValidateTable(table2); }
public Database LoadDatabase(List<SchemaData> databaseObjectsToFetch, List<string> allowedSchemas) { try { connector.Open(); } catch (Exception e) { throw new DatabaseLoaderException("Error opening database connection. See inner exception.", e); } try { var db = new Database(connector.DatabaseName, DatabaseTypes.MySQL) { Loader = this }; db.ConnectionInformation = DatabaseConnector.ConnectionInformation; SetSchemaFilter(databaseObjectsToFetch); foreach (var table in GetTables(databaseObjectsToFetch)) db.AddTable(table); foreach (var view in GetViews(databaseObjectsToFetch)) db.AddView(view); GetForeignKeys(db); return db; } catch (Exception e) { throw new DatabaseLoaderException("Error opening database connection. See inner exception.", e); } finally { connector.Close(); } }
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 static Relationship GetRelationship() { Relationship relationship = new RelationshipImpl(); relationship.Name = "Name"; var table1 = new Table("Table1"); table1.AddColumn(new Column("ColumnX")); relationship.PrimaryKey = new Key("", DatabaseKeyType.Primary) { Parent = table1 }; relationship.PrimaryTable = table1; relationship.PrimaryKey.AddColumn("ColumnX"); var table2 = new Table("Table2"); table2.AddColumn(new Column("Column1")); relationship.ForeignKey = new Key("", DatabaseKeyType.Foreign) { Parent = table2 }; relationship.ForeignTable = table2; relationship.ForeignKey.AddColumn("Column1"); var database = new Database(""); database.AddTable(table1); database.AddTable(table2); relationship.Database = database; return relationship; }