public static DataSetGraph ToGraph( #if !NET20 this #endif DataSet ds) { Contract.Requires(ds != null); var g = new DataSetGraph(ds); var populator = new DataSetGraphPopulatorAlgorithm(g, ds); populator.Compute(); return g; }
public void ToGraph() { // Empty data set var dataSet = new DataSet(); DataSetGraph graph = dataSet.ToGraph(); AssertEmptyGraph(graph); Assert.AreSame(dataSet, graph.DataSet); // Only tables data set dataSet = new DataSet(); var ships = new DataTable("Ships"); var shipIdCol = new DataColumn("ShipID", typeof(int)) { Unique = true }; ships.Columns.Add(shipIdCol); dataSet.Tables.Add(ships); var modules = new DataTable("Modules"); var moduleIdCol = new DataColumn("ModuleID", typeof(int)) { Unique = true }; modules.Columns.Add(moduleIdCol); dataSet.Tables.Add(modules); graph = dataSet.ToGraph(); AssertHasVertices(graph, new[] { ships, modules }); AssertNoEdge(graph); Assert.AreSame(dataSet, graph.DataSet); // Table with relations dataSet = new DataSet(); var computers = new DataTable("Computers"); var computerIdCol = new DataColumn("ComputerID", typeof(int)) { Unique = true }; var computerBrandCol = new DataColumn("Brand", typeof(string)); var computerWinVerCol = new DataColumn("WindowsVersion", typeof(string)); computers.Columns.Add(computerIdCol); computers.Columns.Add(computerBrandCol); computers.Columns.Add(computerWinVerCol); dataSet.Tables.Add(computers); var users = new DataTable("Users"); var userIdCol = new DataColumn("UserID", typeof(int)) { Unique = true }; var userNameCol = new DataColumn("Name", typeof(string)); users.Columns.Add(userIdCol); users.Columns.Add(userNameCol); dataSet.Tables.Add(users); var printers = new DataTable("Printers"); var printerIdCol = new DataColumn("PrinterID", typeof(int)) { Unique = true }; var printerBrandCol = new DataColumn("Brand", typeof(string)); printers.Columns.Add(printerIdCol); printers.Columns.Add(printerBrandCol); dataSet.Tables.Add(printers); var phones = new DataTable("Phones"); var phoneIdCol = new DataColumn("PhoneID", typeof(int)) { Unique = true }; var phoneMacAddrCol = new DataColumn("MacAddress", typeof(string)) { Unique = true }; var phoneNumberCol = new DataColumn("Number", typeof(string)); phones.Columns.Add(phoneIdCol); phones.Columns.Add(phoneMacAddrCol); phones.Columns.Add(phoneNumberCol); dataSet.Tables.Add(phones); var use = new DataRelation("Use", userIdCol, computerIdCol); dataSet.Relations.Add(use); var connectedTo = new DataRelation("ConnectedTo", computerIdCol, printerIdCol); dataSet.Relations.Add(connectedTo); var phoneWith = new DataRelation("phoneWith", userIdCol, phoneIdCol); dataSet.Relations.Add(phoneWith); graph = dataSet.ToGraph(); AssertHasVertices(graph, new[] { computers, users, printers, phones }); AssertHasRelations( graph, new[] { new DataRelationEdge(use), new DataRelationEdge(connectedTo), new DataRelationEdge(phoneWith) }); Assert.AreSame(dataSet, graph.DataSet); }